Search in sources :

Example 6 with QuantifierAST

use of org.antlr.v4.tool.ast.QuantifierAST in project antlr4 by antlr.

the class ParserATNFactory method optional.

/**
 * From {@code (A)?} build either:
 *
 * <pre>
 *  o--A-&gt;o
 *  |     ^
 *  o----&gt;|
 * </pre>
 *
 * or, if {@code A} is a block, just add an empty alt to the end of the
 * block
 */
@Override
public Handle optional(GrammarAST optAST, Handle blk) {
    BlockStartState blkStart = (BlockStartState) blk.left;
    ATNState blkEnd = blk.right;
    preventEpsilonOptionalBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));
    boolean greedy = ((QuantifierAST) optAST).isGreedy();
    blkStart.nonGreedy = !greedy;
    epsilon(blkStart, blk.right, !greedy);
    optAST.atnState = blk.left;
    return blk;
}
Also used : QuantifierAST(org.antlr.v4.tool.ast.QuantifierAST) Rule(org.antlr.v4.tool.Rule) LeftRecursiveRule(org.antlr.v4.tool.LeftRecursiveRule) PlusBlockStartState(org.antlr.v4.runtime.atn.PlusBlockStartState) StarBlockStartState(org.antlr.v4.runtime.atn.StarBlockStartState) BasicBlockStartState(org.antlr.v4.runtime.atn.BasicBlockStartState) BlockStartState(org.antlr.v4.runtime.atn.BlockStartState) ATNState(org.antlr.v4.runtime.atn.ATNState)

Aggregations

QuantifierAST (org.antlr.v4.tool.ast.QuantifierAST)6 ATNState (org.antlr.v4.runtime.atn.ATNState)4 BlockEndState (org.antlr.v4.runtime.atn.BlockEndState)4 LoopEndState (org.antlr.v4.runtime.atn.LoopEndState)4 PlusBlockStartState (org.antlr.v4.runtime.atn.PlusBlockStartState)4 StarBlockStartState (org.antlr.v4.runtime.atn.StarBlockStartState)4 BlockAST (org.antlr.v4.tool.ast.BlockAST)4 NotNull (org.antlr.v4.runtime.misc.NotNull)3 LeftRecursiveRule (org.antlr.v4.tool.LeftRecursiveRule)3 Rule (org.antlr.v4.tool.Rule)3 BasicBlockStartState (org.antlr.v4.runtime.atn.BasicBlockStartState)2 BlockStartState (org.antlr.v4.runtime.atn.BlockStartState)2 PlusLoopbackState (org.antlr.v4.runtime.atn.PlusLoopbackState)2 StarLoopEntryState (org.antlr.v4.runtime.atn.StarLoopEntryState)2 StarLoopbackState (org.antlr.v4.runtime.atn.StarLoopbackState)2