Bug 404438 - Unhelpful "no viable alternative at input '<EOF>'"
Summary: Unhelpful "no viable alternative at input '<EOF>'"
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.4.0   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-27 08:37 EDT by Ed Willink CLA
Modified: 2013-12-11 03:05 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Willink CLA 2013-03-27 08:37:01 EDT
2.4 Examination of the XtextSyntaxDiagnostic for a "no viable alternative at input '<EOF>'" shows that it has an errorNode with a much more precise character range for the offending input.

Unfortunately theere is no public API to get at the errorNode so it is hard for users to improve it.

Please provide a public API, or better still improve the message.
Comment 1 Ed Willink CLA 2013-12-11 03:05:15 EST
My message rewriting solution is to provide the following override in a derived LazyLinkingResource

	private static final String NO_VIABLE_ALTERNATIVE_AT_INPUT_EOF = "no viable alternative at input '<EOF>'";
	private static final String NO_VIABLE_ALTERNATIVE_FOLLOWING = "no viable alternative following input ";

	@Override		// FIXME This workaround should be eliminated by a BUG 404438 fix
	protected void addSyntaxErrors() {
		if (isValidationDisabled()) {
			return;
		}
		IParseResult parseResult = getParseResult();
		if (parseResult == null) {
			return;
		}
		List<Diagnostic> errors2 = getErrors();
		for (final INode error : parseResult.getSyntaxErrors()) {
			AbstractDiagnostic diagnostic = null;
			final SyntaxErrorMessage syntaxErrorMessage = error.getSyntaxErrorMessage();
			if (syntaxErrorMessage != null) {
				String message = syntaxErrorMessage.getMessage();
				// BUG 404438 "no viable alternative at input '<EOF>'" message is unhelpful.
				if ((message != null) && message.contains(NO_VIABLE_ALTERNATIVE_AT_INPUT_EOF)){
					int index = message.indexOf(NO_VIABLE_ALTERNATIVE_AT_INPUT_EOF);
					if (index >= 0) {
						String tokenText = NodeModelUtils.getTokenText(error);
						if (tokenText != null) {
							final String newMessage = message.substring(0, index) + NO_VIABLE_ALTERNATIVE_FOLLOWING + "'" + tokenText + "'" + message.substring(index+NO_VIABLE_ALTERNATIVE_AT_INPUT_EOF.length());
							diagnostic = new AbstractDiagnostic()
							{
								public String getMessage() {
									return newMessage;
								}

								@Override
								protected INode getNode() {
									return error;
								}

								@Override
								public String getCode() {
									return syntaxErrorMessage.getIssueCode();
								}

								@Override
								public String[] getData() {
									return syntaxErrorMessage.getIssueData();
								}
							};
						}
					}
				}
			}
			if (diagnostic == null) {
				diagnostic = new XtextSyntaxDiagnostic(error);
			}
			errors2.add(diagnostic);
		}
	}