use of org.antlr.v4.tool.Grammar 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);
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestATNLexerInterpreter method testLexerEscapeInString.
@Test
public void testLexerEscapeInString() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "STR : '[' ('~' ']' | .)* ']' ;\n");
checkLexerMatches(lg, "[a~]b]", "STR, EOF");
checkLexerMatches(lg, "[a]", "STR, EOF");
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestATNLexerInterpreter method testLexerSetUnicodeBMP.
@Test
public void testLexerSetUnicodeBMP() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ('愛'|'愜')\n ;");
String expecting = "ID, EOF";
checkLexerMatches(lg, "愛", expecting);
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestATNLexerInterpreter method testGreedyBetweenRules.
@Test
public void testGreedyBetweenRules() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : '<a>' ;\n" + "B : '<' .+ '>' ;\n");
String expecting = "B, EOF";
checkLexerMatches(lg, "<a><x>", expecting);
}
use of org.antlr.v4.tool.Grammar in project antlr4 by antlr.
the class TestATNParserPrediction method testEmptyInput.
@Test
public void testEmptyInput() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n" + "B : 'b' ;\n" + "C : 'c' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "a : A | ;");
int decision = 0;
checkPredictedAlt(lg, g, decision, "a", 1);
checkPredictedAlt(lg, g, decision, "", 2);
// After matching these inputs for decision, what is DFA after each prediction?
String[] inputs = { "a", "" };
String[] dfa = { "s0-'a'->:s1=>1\n", "s0-EOF->:s2=>2\n" + "s0-'a'->:s1=>1\n" };
checkDFAConstruction(lg, g, decision, inputs, dfa);
}
Aggregations