Example usage for org.antlr.v4.runtime Token EOF

List of usage examples for org.antlr.v4.runtime Token EOF

Introduction

In this page you can find the example usage for org.antlr.v4.runtime Token EOF.

Prototype

int EOF

To view the source code for org.antlr.v4.runtime Token EOF.

Click Source Link

Usage

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporter.java

License:Apache License

private void handleDefaultMode(ImporterContext context) {
    String methodName = "defaultMode";
    Token token;/*from ww w  . ja  va2 s.c o  m*/
    do {
        token = context.nextToken();
        if (token.getType() != Token.EOF) {
            String ruleName = context.getRuleName();
            String modeName = context.getModeName();
            log(methodName, ruleName, modeName, token, context);
            switch (token.getType()) {
            case LMNLLexer.BEGIN_OPEN_RANGE:
                handleOpenRange(context);
                break;

            case LMNLLexer.BEGIN_CLOSE_RANGE:
                handleCloseRange(context);
                break;

            case LMNLLexer.TEXT:
                TAGTextNodeDTO textNode = new TAGTextNodeDTO(token.getText());
                update(textNode);
                context.addTextNode(textNode);
                break;

            // case LMNLLexer.TagOpenStartChar:
            // case LMNLLexer.TagOpenEndChar:
            // case LMNLLexer.TagCloseStartChar:
            // case LMNLLexer.TagCloseEndChar:
            // break;

            default:
                handleUnexpectedToken(methodName, token, ruleName, modeName);
                break;
            }
        }
    } while (token.getType() != Token.EOF);
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporter.java

License:Apache License

private void handleOpenRange(ImporterContext context) {
    String methodName = "handleOpenRange";
    boolean goOn = true;
    while (goOn) {
        Token token = context.nextToken();
        String ruleName = context.getRuleName();
        String modeName = context.getModeName();
        log(methodName, ruleName, modeName, token, context);
        switch (token.getType()) {
        case LMNLLexer.Name_Open_Range:
            TAGMarkupDTO markup = context.newMarkup(token.getText());
            context.openMarkup(markup);/*w w w.j  ava  2  s  .co  m*/
            break;
        case LMNLLexer.BEGIN_OPEN_ANNO:
            handleAnnotation(context);
            break;
        case LMNLLexer.END_OPEN_RANGE:
            context.popOpenMarkup();
            goOn = false;
            break;
        case LMNLLexer.END_ANONYMOUS_RANGE:
            TAGTextNodeDTO textNode = new TAGTextNodeDTO("");
            update(textNode);
            context.addTextNode(textNode);
            context.closeMarkup();
            goOn = false;
            break;

        // case LMNLLexer.TagOpenStartChar:
        // case LMNLLexer.TagOpenEndChar:
        // case LMNLLexer.TagCloseStartChar:
        // case LMNLLexer.TagCloseEndChar:
        // break;

        default:
            handleUnexpectedToken(methodName, token, ruleName, modeName);
            break;
        }
        goOn = goOn && token.getType() != Token.EOF;
    }
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporter.java

License:Apache License

private void handleCloseRange(ImporterContext context) {
    String methodName = "handleCloseRange";
    boolean goOn = true;
    while (goOn) {
        Token token = context.nextToken();
        String ruleName = context.getRuleName();
        String modeName = context.getModeName();
        log(methodName, ruleName, modeName, token, context);
        switch (token.getType()) {
        case LMNLLexer.Name_Close_Range:
            String rangeName = token.getText();
            context.pushOpenMarkup(rangeName);
            break;
        case LMNLLexer.BEGIN_OPEN_ANNO_IN_RANGE_CLOSER:
            handleAnnotation(context);//from w  ww.ja v a  2 s . c  o m
            break;
        case LMNLLexer.END_CLOSE_RANGE:
            context.closeMarkup();
            goOn = false;
            break;

        // case LMNLLexer.TagOpenStartChar:
        // case LMNLLexer.TagOpenEndChar:
        // case LMNLLexer.TagCloseStartChar:
        // case LMNLLexer.TagCloseEndChar:
        // break;

        default:
            handleUnexpectedToken(methodName, token, ruleName, modeName);
            break;
        }
        goOn = goOn && token.getType() != Token.EOF;
    }
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporterInMemory.java

License:Apache License

private void handleDefaultMode(ImporterContext context) {
    String methodName = "defaultMode";
    Token token;/*from w  w  w.  jav a2s.  c o  m*/
    do {
        token = context.nextToken();
        if (token.getType() != Token.EOF) {
            String ruleName = context.getRuleName();
            String modeName = context.getModeName();
            log(methodName, ruleName, modeName, token, context);
            switch (token.getType()) {
            case LMNLLexer.BEGIN_OPEN_RANGE:
                handleOpenRange(context);
                break;

            case LMNLLexer.BEGIN_CLOSE_RANGE:
                handleCloseRange(context);
                break;

            case LMNLLexer.TEXT:
                TextNode textNode = new TextNode(token.getText());
                context.addTextNode(textNode);
                break;

            // case LMNLLexer.TagOpenStartChar:
            // case LMNLLexer.TagOpenEndChar:
            // case LMNLLexer.TagCloseStartChar:
            // case LMNLLexer.TagCloseEndChar:
            // break;

            default:
                handleUnexpectedToken(methodName, token, ruleName, modeName);
                break;
            }
        }
    } while (token.getType() != Token.EOF);
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporterInMemory.java

License:Apache License

private void handleOpenRange(ImporterContext context) {
    String methodName = "handleOpenRange";
    boolean goOn = true;
    while (goOn) {
        Token token = context.nextToken();
        String ruleName = context.getRuleName();
        String modeName = context.getModeName();
        log(methodName, ruleName, modeName, token, context);
        switch (token.getType()) {
        case LMNLLexer.Name_Open_Range:
            Markup markup = context.newMarkup(token.getText());
            context.openMarkup(markup);//from   ww  w .j  a  va2 s.c  o  m
            break;
        case LMNLLexer.BEGIN_OPEN_ANNO:
            handleAnnotation(context);
            break;
        case LMNLLexer.END_OPEN_RANGE:
            context.popOpenMarkup();
            goOn = false;
            break;
        case LMNLLexer.END_ANONYMOUS_RANGE:
            TextNode textNode = new TextNode("");
            context.addTextNode(textNode);
            context.closeMarkup();
            goOn = false;
            break;

        // case LMNLLexer.TagOpenStartChar:
        // case LMNLLexer.TagOpenEndChar:
        // case LMNLLexer.TagCloseStartChar:
        // case LMNLLexer.TagCloseEndChar:
        // break;

        default:
            handleUnexpectedToken(methodName, token, ruleName, modeName);
            break;
        }
        goOn = goOn && token.getType() != Token.EOF;
    }
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporterInMemory.java

License:Apache License

private void handleAnnotation(ImporterContext context) {
    String methodName = "handleAnnotation";
    Annotation annotation = new Annotation("");
    context.openAnnotation(annotation);//from www .j ava 2  s . c  o m
    boolean goOn = true;
    while (goOn) {
        Token token = context.nextToken();
        String ruleName = context.getRuleName();
        String modeName = context.getModeName();
        log(methodName, ruleName, modeName, token, context);
        switch (token.getType()) {
        case LMNLLexer.Name_Open_Annotation:
            annotation.setTag(token.getText());
            break;
        case LMNLLexer.OPEN_ANNO_IN_ANNO_OPENER:
        case LMNLLexer.OPEN_ANNO_IN_ANNO_CLOSER:
            handleAnnotation(context);
            break;
        case LMNLLexer.END_OPEN_ANNO:
            context.pushLimenContext(context.currentAnnotationLimen());
            break;

        case LMNLLexer.ANNO_TEXT:
            context.addTextNode(new TextNode(token.getText()));
            break;

        case LMNLLexer.BEGIN_ANNO_OPEN_RANGE:
            handleOpenRange(context);
            break;

        case LMNLLexer.BEGIN_ANNO_CLOSE_RANGE:
            handleCloseRange(context);
            break;

        case LMNLLexer.BEGIN_CLOSE_ANNO:
        case LMNLLexer.Name_Close_Annotation:
            break;
        case LMNLLexer.END_CLOSE_ANNO:
            context.popLimenContext();
        case LMNLLexer.END_EMPTY_ANNO:
            context.closeAnnotation();
            goOn = false;
            break;

        // case LMNLLexer.TagOpenStartChar:
        // case LMNLLexer.TagOpenEndChar:
        // case LMNLLexer.TagCloseStartChar:
        // case LMNLLexer.TagCloseEndChar:
        // break;

        default:
            handleUnexpectedToken(methodName, token, ruleName, modeName);
            break;
        }
        goOn = goOn && token.getType() != Token.EOF;
    }
}

From source file:org.beetl.core.parser.BeetlAntlrErrorStrategy.java

License:BSD License

protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) {
    TokenStream tokens = recognizer.getInputStream();
    String input;//from  w w  w.  j  av a  2 s .c  o m
    if (tokens instanceof TokenStream) {
        if (e.getStartToken().getType() == Token.EOF)
            input = "<>";
        else
            input = tokens.getText(e.getStartToken(), e.getOffendingToken());
    } else {
        input = "<>";
    }
    //      String msg = "no viable alternative at input " + escapeWSAndQuote(input);
    BeetlException exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR,
            escapeWSAndQuote(input), e);
    exception.token = this.getGrammarToken(e.getOffendingToken());
    throw exception;
}

From source file:org.eclipse.titan.designer.AST.ASN1.Object.ObjectClassSyntax_Builder.java

License:Open Source License

public ObjectClassSyntax_Builder(final Block aBlock, final FieldSpecifications aFieldSpecifications) {
    this.mBlock = aBlock;
    this.fieldSpecifications = aFieldSpecifications;
    if (aBlock != null) {
        final List<Token> internalTokens = new ArrayList<Token>(aBlock.getTokenList().size());
        Token token;//from   ww  w  . j av a 2  s . c om

        for (int i = 0; i < aBlock.getTokenList().size(); i++) {
            token = aBlock.getTokenList().get(i);

            if (token.getType() == Asn1Lexer.LEFTVERSIONBRACKETS) {
                final CommonToken token2 = ((TokenWithIndexAndSubTokens) token).copy();
                token2.setType(Asn1Lexer.SQUAREOPEN);
                internalTokens.add(token2);
                internalTokens.add(token2);
            } else if (token.getType() == Asn1Lexer.RIGHTVERSIONBRACKETS) {
                final CommonToken token2 = ((TokenWithIndexAndSubTokens) token).copy();
                token2.setType(Asn1Lexer.SQUARECLOSE);
                internalTokens.add(token2);
                internalTokens.add(token2);
            } else {
                internalTokens.add(token);
            }
        }
        internalTokens.add(new TokenWithIndexAndSubTokens(Token.EOF));

        this.mBlock = new Block(internalTokens, aBlock.getLocation());
    }
}

From source file:org.eclipse.titan.designer.AST.ASN1.Object.ObjectClassSyntax_Parser.java

License:Open Source License

public ObjectClassSyntax_Parser(final Block aBlock, final Object_Definition myObject) {
    this.myObject = myObject;
    final List<Token> tempTokens = aBlock.getTokenList();
    final List<Token> temp = new ArrayList<Token>(tempTokens.size());
    for (int i = 0; i < tempTokens.size(); i++) {
        temp.add(tempTokens.get(i));/*from  www.  jav  a  2  s .c  o m*/
    }
    temp.add(new TokenWithIndexAndSubTokens(Token.EOF));

    this.mBlock = new Block(temp, aBlock.getLocation());
    this.mBlock.setFullNameParent(aBlock);
    success = true;
    internalIndex = 0;
}

From source file:org.eclipse.titan.designer.AST.ASN1.Object.ObjectClassSyntax_Parser.java

License:Open Source License

@Override
public void visitRoot(final ObjectClassSyntax_root parameter) {
    if (mBlock != null) {
        if (!success || !parameter.getIsBuilded() || (mBlock.getTokenList().isEmpty())) {
            // FATAL ERROR, but now OK
            return;
        }/*  w w  w  .ja va2s. com*/
    }

    previousSuccess = false;
    parameter.getSequence().accept(this);
    if (null != mBlock) {
        if (success && internalIndex < mBlock.getTokenList().size()
                && mBlock.getTokenList().get(internalIndex).getType() != Token.EOF) {
            success = false;
            final Token token = mBlock.getTokenList().get(internalIndex);
            myObject.getLocation()
                    .reportSemanticError("Unexpected `" + token.getText() + "', it is a superfluous part");
        }
    }

    if (!success) {
        myObject.getLocation().reportSemanticError("Check the syntax of objectclass");
        myObject.setIsErroneous(true);
    }
}