use of org.antlr.v4.codegen.model.Wildcard in project antlr4 by tunnelvisionlabs.
the class TestATNSerialization method testLexerWildcardWithMode.
@Test
public void testLexerWildcardWithMode() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : 'a'..'z'+ ;\n" + "mode CMT;" + "COMMENT : '*/' {skip(); popMode();} ;\n" + "JUNK : . {more();} ;\n");
String expecting = "max type 3\n" + "0:TOKEN_START -1\n" + "1:TOKEN_START -1\n" + "2:RULE_START 0\n" + "3:RULE_STOP 0\n" + "4:RULE_START 1\n" + "5:RULE_STOP 1\n" + "6:RULE_START 2\n" + "7:RULE_STOP 2\n" + "8:BASIC 0\n" + "9:PLUS_BLOCK_START 0 10\n" + "10:BLOCK_END 0\n" + "11:PLUS_LOOP_BACK 0\n" + "12:LOOP_END 0 11\n" + "13:BASIC 1\n" + "14:BASIC 1\n" + "15:BASIC 1\n" + "16:BASIC 1\n" + "17:BASIC 1\n" + "18:BASIC 2\n" + "19:BASIC 2\n" + "20:BASIC 2\n" + "rule 0:2 1\n" + "rule 1:4 2\n" + "rule 2:6 3\n" + "mode 0:0\n" + "mode 1:1\n" + "0->2 EPSILON 0,0,0\n" + "1->4 EPSILON 0,0,0\n" + "1->6 EPSILON 0,0,0\n" + "2->9 EPSILON 0,0,0\n" + "4->13 EPSILON 0,0,0\n" + "6->18 EPSILON 0,0,0\n" + "8->10 RANGE 97,122,0\n" + "9->8 EPSILON 0,0,0\n" + "10->11 EPSILON 0,0,0\n" + "11->9 EPSILON 0,0,0\n" + "11->12 EPSILON 0,0,0\n" + "12->3 EPSILON 0,0,0\n" + "13->14 ATOM 42,0,0\n" + "14->15 ATOM 47,0,0\n" + "15->16 EPSILON 0,0,0\n" + "16->17 ACTION 1,0,0\n" + "17->5 EPSILON 0,0,0\n" + "18->19 WILDCARD 0,0,0\n" + "19->20 ACTION 2,1,0\n" + "20->7 EPSILON 0,0,0\n" + "0:0\n" + "1:1\n" + "2:11\n";
ATN atn = createATN(lg, true);
String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getRuleNames()), Arrays.asList(lg.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.codegen.model.Wildcard in project antlr4 by tunnelvisionlabs.
the class TestATNSerialization method testWildcard.
@Test
public void testWildcard() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "tokens {A, B, C}\n" + "a : . ;");
String expecting = "max type 3\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + "rule 0:0\n" + "0->2 EPSILON 0,0,0\n" + "2->3 WILDCARD 0,0,0\n" + "3->1 EPSILON 0,0,0\n";
ATN atn = createATN(g, true);
String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getRuleNames()), Arrays.asList(g.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.codegen.model.Wildcard 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);
}
use of org.antlr.v4.codegen.model.Wildcard in project antlr4 by antlr.
the class TestATNSerialization method testWildcard.
@Test
public void testWildcard() throws Exception {
Grammar g = new Grammar("parser grammar T;\n" + "tokens {A, B, C}\n" + "a : . ;");
String expecting = "max type 3\n" + "0:RULE_START 0\n" + "1:RULE_STOP 0\n" + "2:BASIC 0\n" + "3:BASIC 0\n" + "4:BASIC 0\n" + "rule 0:0\n" + "0->2 EPSILON 0,0,0\n" + "2->3 WILDCARD 0,0,0\n" + "3->1 EPSILON 0,0,0\n";
ATN atn = createATN(g, true);
String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
assertEquals(expecting, result);
}
use of org.antlr.v4.codegen.model.Wildcard in project antlr4 by antlr.
the class TestATNLexerInterpreter method testEOFInSetAtEndOfLineComment.
/**
* only positive sets like (EOF|'\n') can match EOF and not in wildcard or ~foo sets
* EOF matches but does not advance cursor.
*/
@Test
public void testEOFInSetAtEndOfLineComment() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "CMT : '//' .* (EOF|'\\n') ;\n");
String expecting = "CMT, EOF";
checkLexerMatches(lg, "//", expecting);
}
Aggregations