Community
Participate
Working Groups
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.
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); } }