Search in sources :

Example 6 with SyntaxErrorMessage

use of org.eclipse.xtext.nodemodel.SyntaxErrorMessage in project xtext-core by eclipse.

the class AbstractInternalAntlrParser method createLeafNode.

private ILeafNode createLeafNode(Token token, EObject grammarElement) {
    boolean isHidden = token.getChannel() == HIDDEN;
    SyntaxErrorMessage error = null;
    if (!isHidden) {
        if (currentError != null) {
            error = currentError;
            currentError = null;
        }
    }
    if (token.getType() == Token.INVALID_TOKEN_TYPE) {
        if (error == null) {
            String lexerErrorMessage = ((XtextTokenStream) input).getLexerErrorMessage(token);
            LexerErrorContext errorContext = new LexerErrorContext(lexerErrorMessage);
            error = syntaxErrorProvider.getSyntaxErrorMessage(errorContext);
        }
    }
    if (grammarElement == null) {
        String ruleName = antlrTypeToLexerName.get(token.getType());
        grammarElement = allRules.get(ruleName);
    }
    CommonToken commonToken = (CommonToken) token;
    if (error != null)
        hadErrors = true;
    return nodeBuilder.newLeafNode(commonToken.getStartIndex(), commonToken.getStopIndex() - commonToken.getStartIndex() + 1, grammarElement, isHidden, error, currentNode);
}
Also used : SyntaxErrorMessage(org.eclipse.xtext.nodemodel.SyntaxErrorMessage) CommonToken(org.antlr.runtime.CommonToken)

Example 7 with SyntaxErrorMessage

use of org.eclipse.xtext.nodemodel.SyntaxErrorMessage in project xtext-core by eclipse.

the class XtextResource method addSyntaxDiagnostic.

/**
 * @since 2.7
 */
protected void addSyntaxDiagnostic(List<Diagnostic> diagnostics, INode error) {
    SyntaxErrorMessage syntaxErrorMessage = error.getSyntaxErrorMessage();
    if (org.eclipse.xtext.diagnostics.Diagnostic.SYNTAX_DIAGNOSTIC_WITH_RANGE.equals(syntaxErrorMessage.getIssueCode())) {
        String[] issueData = syntaxErrorMessage.getIssueData();
        if (issueData.length == 1) {
            String data = issueData[0];
            int colon = data.indexOf(':');
            diagnostics.add(new XtextSyntaxDiagnosticWithRange(error, Integer.valueOf(data.substring(0, colon)), Integer.valueOf(data.substring(colon + 1)), null));
            return;
        }
    }
    diagnostics.add(new XtextSyntaxDiagnostic(error));
}
Also used : SyntaxErrorMessage(org.eclipse.xtext.nodemodel.SyntaxErrorMessage)

Aggregations

SyntaxErrorMessage (org.eclipse.xtext.nodemodel.SyntaxErrorMessage)7 INode (org.eclipse.xtext.nodemodel.INode)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 CommonToken (org.antlr.runtime.CommonToken)1 GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)1 Test (org.junit.Test)1