use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.
the class AnalysisPipeline method disjoint.
/** Return whether lookahead sets are disjoint; no lookahead ⇒ not disjoint */
public static boolean disjoint(IntervalSet[] altLook) {
boolean collision = false;
IntervalSet combined = new IntervalSet();
if (altLook == null)
return false;
for (IntervalSet look : altLook) {
// lookahead must've computation failed
if (look == null)
return false;
if (!look.and(combined).isNil()) {
collision = true;
break;
}
combined.addAll(look);
}
return !collision;
}
use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.
the class AnalysisPipeline method processLexer.
protected void processLexer() {
// make sure all non-fragment lexer rules must match at least one symbol
for (Rule rule : g.rules.values()) {
if (rule.isFragment()) {
continue;
}
LL1Analyzer analyzer = new LL1Analyzer(g.atn);
IntervalSet look = analyzer.LOOK(g.atn.ruleToStartState[rule.index], null);
if (look.contains(Token.EPSILON)) {
g.tool.errMgr.grammarError(ErrorType.EPSILON_TOKEN, g.fileName, ((GrammarAST) rule.ast.getChild(0)).getToken(), rule.name);
}
}
}
use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.
the class TestExpectedTokens method testFollowIncludedInLeftRecursiveRule.
// Test for https://github.com/antlr/antlr4/issues/1480
// can't reproduce
@Test
public void testFollowIncludedInLeftRecursiveRule() throws Exception {
String gtext = "grammar T;\n" + "s : expr EOF ;\n" + "expr : L expr R\n" + " | expr PLUS expr\n" + " | ID\n" + " ;\n";
Grammar g = new Grammar(gtext);
String atnText = "RuleStart_expr_2->BlockStart_13\n" + "BlockStart_13->s7\n" + "BlockStart_13->s12\n" + "s7-action_1:-1->s8\n" + "s12-ID->BlockEnd_14\n" + "s8-L->s9\n" + "BlockEnd_14->StarLoopEntry_20\n" + "s9-expr->RuleStart_expr_2\n" + "StarLoopEntry_20->StarBlockStart_18\n" + "StarLoopEntry_20->s21\n" + "s10-R->s11\n" + "StarBlockStart_18->s15\n" + "s21->RuleStop_expr_3\n" + "s11->BlockEnd_14\n" + "s15-2 >= _p->s16\n" + "RuleStop_expr_3->s5\n" + "RuleStop_expr_3->s10\n" + "RuleStop_expr_3->BlockEnd_19\n" + "s16-PLUS->s17\n" + "s17-expr->RuleStart_expr_2\n" + "BlockEnd_19->StarLoopBack_22\n" + "StarLoopBack_22->StarLoopEntry_20\n";
checkRuleATN(g, "expr", atnText);
ATN atn = g.getATN();
// DOTGenerator gen = new DOTGenerator(g);
// String dot = gen.getDOT(atn.states.get(2), g.getRuleNames(), false);
// System.out.println(dot);
// Simulate call stack after input '(x' from rule s
ParserRuleContext callStackFrom_s = new ParserRuleContext(null, 4);
ParserRuleContext callStackFrom_expr = new ParserRuleContext(callStackFrom_s, 9);
int afterID = 14;
IntervalSet tokens = atn.getExpectedTokens(afterID, callStackFrom_expr);
assertEquals("{R, PLUS}", tokens.toString(g.getTokenNames()));
// Simulate call stack after input '(x' from within rule expr
callStackFrom_expr = new ParserRuleContext(null, 9);
tokens = atn.getExpectedTokens(afterID, callStackFrom_expr);
assertEquals("{R, PLUS}", tokens.toString(g.getTokenNames()));
}
use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.
the class UnicodeDataTemplateController method addUnicodeBinaryPropertyCodesToCodePointRanges.
private static void addUnicodeBinaryPropertyCodesToCodePointRanges(Map<String, IntervalSet> propertyCodePointRanges) {
for (int property = UProperty.BINARY_START; property < UProperty.BINARY_LIMIT; property++) {
String propertyName = getShortPropertyName(property);
IntervalSet intervalSet = new IntervalSet();
UnicodeSet unicodeSet = new UnicodeSet();
unicodeSet.applyIntPropertyValue(property, 1);
for (UnicodeSet.EntryRange range : unicodeSet.ranges()) {
intervalSet.add(range.codepoint, range.codepointEnd);
}
propertyCodePointRanges.put(propertyName, intervalSet);
}
}
use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.
the class UnicodeDataTemplateController method addIntPropertyRanges.
private static void addIntPropertyRanges(int property, String namePrefix, Map<String, IntervalSet> propertyCodePointRanges) {
for (int propertyValue = UCharacter.getIntPropertyMinValue(property); propertyValue <= UCharacter.getIntPropertyMaxValue(property); propertyValue++) {
UnicodeSet set = new UnicodeSet();
set.applyIntPropertyValue(property, propertyValue);
String propertyName = namePrefix + UCharacter.getPropertyValueName(property, propertyValue, UProperty.NameChoice.SHORT);
IntervalSet intervalSet = propertyCodePointRanges.get(propertyName);
if (intervalSet == null) {
intervalSet = new IntervalSet();
propertyCodePointRanges.put(propertyName, intervalSet);
}
addUnicodeSetToIntervalSet(set, intervalSet);
}
}
Aggregations