Search in sources :

Example 1 with TokenRef

use of org.antlr.v4.codegen.model.chunk.TokenRef in project antlr4 by tunnelvisionlabs.

the class LexerATNFactory method tokenRef.

@Override
public Handle tokenRef(TerminalAST node) {
    // Ref to EOF in lexer yields char transition on -1
    if (node.getText().equals("EOF")) {
        ATNState left = newState(node);
        ATNState right = newState(node);
        left.addTransition(new AtomTransition(right, IntStream.EOF));
        return new Handle(left, right);
    }
    return _ruleRef(node);
}
Also used : AtomTransition(org.antlr.v4.runtime.atn.AtomTransition) ATNState(org.antlr.v4.runtime.atn.ATNState)

Example 2 with TokenRef

use of org.antlr.v4.codegen.model.chunk.TokenRef in project antlr4 by tunnelvisionlabs.

the class ParserATNFactory method tokenRef.

/**
 * From label {@code A} build graph {@code o-A->o}.
 */
@NotNull
@Override
public Handle tokenRef(@NotNull TerminalAST node) {
    ATNState left = newState(node);
    ATNState right = newState(node);
    int ttype = g.getTokenType(node.getText());
    left.addTransition(new AtomTransition(right, ttype));
    node.atnState = left;
    return new Handle(left, right);
}
Also used : AtomTransition(org.antlr.v4.runtime.atn.AtomTransition) ATNState(org.antlr.v4.runtime.atn.ATNState) NotNull(org.antlr.v4.runtime.misc.NotNull)

Example 3 with TokenRef

use of org.antlr.v4.codegen.model.chunk.TokenRef in project antlr4 by tunnelvisionlabs.

the class ParserFactory method wildcard.

@Override
public List<SrcOp> wildcard(GrammarAST ast, GrammarAST labelAST) {
    Wildcard wild = new Wildcard(this, ast);
    // TODO: dup with tokenRef
    if (labelAST != null) {
        String label = labelAST.getText();
        Decl d = getTokenLabelDecl(label);
        wild.labels.add(d);
        getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d);
        if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
            TokenListDecl l = getTokenListLabelDecl(label);
            getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), l);
        }
    }
    if (controller.needsImplicitLabel(ast, wild))
        defineImplicitLabel(ast, wild);
    AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(wild, labelAST);
    return list(wild, listLabelOp);
}
Also used : Wildcard(org.antlr.v4.codegen.model.Wildcard) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl) AddToLabelList(org.antlr.v4.codegen.model.AddToLabelList)

Example 4 with TokenRef

use of org.antlr.v4.codegen.model.chunk.TokenRef in project antlr4 by tunnelvisionlabs.

the class ParserFactory method tokenRef.

@Override
public List<SrcOp> tokenRef(GrammarAST ID, GrammarAST labelAST, GrammarAST args) {
    MatchToken matchOp = new MatchToken(this, (TerminalAST) ID);
    if (labelAST != null) {
        String label = labelAST.getText();
        RuleFunction rf = getCurrentRuleFunction();
        if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
            // add Token _X and List<Token> X decls
            // adds _X
            defineImplicitLabel(ID, matchOp);
            TokenListDecl l = getTokenListLabelDecl(label);
            rf.addContextDecl(ID.getAltLabel(), l);
        } else {
            Decl d = getTokenLabelDecl(label);
            matchOp.labels.add(d);
            rf.addContextDecl(ID.getAltLabel(), d);
        }
    // Decl d = getTokenLabelDecl(label);
    // ((MatchToken)matchOp).labels.add(d);
    // getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), d);
    // if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
    // TokenListDecl l = getTokenListLabelDecl(label);
    // getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), l);
    // }
    }
    if (controller.needsImplicitLabel(ID, matchOp))
        defineImplicitLabel(ID, matchOp);
    AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(matchOp, labelAST);
    return list(matchOp, listLabelOp);
}
Also used : TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) MatchToken(org.antlr.v4.codegen.model.MatchToken) LeftFactoredRuleFunction(org.antlr.v4.codegen.model.LeftFactoredRuleFunction) LeftUnfactoredRuleFunction(org.antlr.v4.codegen.model.LeftUnfactoredRuleFunction) RuleFunction(org.antlr.v4.codegen.model.RuleFunction) LeftRecursiveRuleFunction(org.antlr.v4.codegen.model.LeftRecursiveRuleFunction) TokenDecl(org.antlr.v4.codegen.model.decl.TokenDecl) Decl(org.antlr.v4.codegen.model.decl.Decl) TokenListDecl(org.antlr.v4.codegen.model.decl.TokenListDecl) RuleContextDecl(org.antlr.v4.codegen.model.decl.RuleContextDecl) AddToLabelList(org.antlr.v4.codegen.model.AddToLabelList)

Example 5 with TokenRef

use of org.antlr.v4.codegen.model.chunk.TokenRef in project antlr4 by antlr.

the class LexerATNFactory method tokenRef.

@Override
public Handle tokenRef(TerminalAST node) {
    // Ref to EOF in lexer yields char transition on -1
    if (node.getText().equals("EOF")) {
        ATNState left = newState(node);
        ATNState right = newState(node);
        left.addTransition(new AtomTransition(right, IntStream.EOF));
        return new Handle(left, right);
    }
    return _ruleRef(node);
}
Also used : AtomTransition(org.antlr.v4.runtime.atn.AtomTransition) ATNState(org.antlr.v4.runtime.atn.ATNState)

Aggregations

AddToLabelList (org.antlr.v4.codegen.model.AddToLabelList)4 Decl (org.antlr.v4.codegen.model.decl.Decl)4 RuleContextDecl (org.antlr.v4.codegen.model.decl.RuleContextDecl)4 TokenDecl (org.antlr.v4.codegen.model.decl.TokenDecl)4 TokenListDecl (org.antlr.v4.codegen.model.decl.TokenListDecl)4 ATNState (org.antlr.v4.runtime.atn.ATNState)4 AtomTransition (org.antlr.v4.runtime.atn.AtomTransition)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 LeftRecursiveRuleFunction (org.antlr.v4.codegen.model.LeftRecursiveRuleFunction)2 MatchToken (org.antlr.v4.codegen.model.MatchToken)2 RuleFunction (org.antlr.v4.codegen.model.RuleFunction)2 Wildcard (org.antlr.v4.codegen.model.Wildcard)2 ArgRef (org.antlr.v4.codegen.model.chunk.ArgRef)2 LabelRef (org.antlr.v4.codegen.model.chunk.LabelRef)2 ListLabelRef (org.antlr.v4.codegen.model.chunk.ListLabelRef)2 LocalRef (org.antlr.v4.codegen.model.chunk.LocalRef)2 QRetValueRef (org.antlr.v4.codegen.model.chunk.QRetValueRef)2 RetValueRef (org.antlr.v4.codegen.model.chunk.RetValueRef)2