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->o
* | ^
* o---->|
* </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;
}
Aggregations