Java Code Examples for org.antlr.v4.runtime.misc.IntervalSet#or()
The following examples show how to use
org.antlr.v4.runtime.misc.IntervalSet#or() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LL1OptionalBlockSingleAlt.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public LL1OptionalBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlockForAlt> alts) { super(factory, blkAST, alts); this.decision = ((DecisionState)blkAST.atnState).decision; /** Lookahead for each alt 1..n */ // IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa); IntervalSet[] altLookSets = factory.getGrammar().decisionLOOK.get(decision); altLook = getAltLookaheadAsStringLists(altLookSets); IntervalSet look = altLookSets[0]; IntervalSet followLook = altLookSets[1]; IntervalSet expecting = look.or(followLook); this.error = getThrowNoViableAlt(factory, blkAST, expecting); expr = addCodeForLookaheadTempVar(look); followExpr = factory.getLL1Test(followLook, blkAST); }
Example 2
Source File: BatfishANTLRErrorStrategy.java From batfish with Apache License 2.0 | 6 votes |
/** * Consume all tokens a whole line at a time until the next token is one expected by the current * rule. Each line (as delimited by supplied separator token) starting from the current line up to * the last line consumed is placed in an {@link ErrorNode} and inserted as a child of the current * rule. * * @param recognizer The {@link Parser} to whom to delegate creation of each {@link ErrorNode} */ private void consumeBlocksUntilWanted(Parser recognizer) { IntervalSet expecting = recognizer.getExpectedTokens(); IntervalSet whatFollowsLoopIterationOrRule = expecting.or(getErrorRecoverySet(recognizer)); int nextToken; do { // Eat tokens until we are at the end of the line consumeUntilEndOfLine(recognizer); // Get the line number and separator text from the separator token Token separatorToken = recognizer.getCurrentToken(); // Insert the current line as an {@link ErrorNode} as a child of the current rule createErrorNode(recognizer, recognizer.getContext(), separatorToken); // Eat the separator token recognizer.consume(); nextToken = recognizer.getInputStream().LA(1); } while (!whatFollowsLoopIterationOrRule.contains(nextToken) && nextToken != Lexer.EOF); }
Example 3
Source File: LL1AltBlock.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public LL1AltBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlockForAlt> alts) { super(factory, blkAST, alts); this.decision = ((DecisionState)blkAST.atnState).decision; /** Lookahead for each alt 1..n */ IntervalSet[] altLookSets = factory.getGrammar().decisionLOOK.get(decision); altLook = getAltLookaheadAsStringLists(altLookSets); IntervalSet expecting = IntervalSet.or(altLookSets); // combine alt sets this.error = getThrowNoViableAlt(factory, blkAST, expecting); }