Search in sources :

Example 91 with LexerGrammar

use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.

the class TestGrammarParserInterpreter method testOneAlt.

@Test
public void testOneAlt() throws Exception {
    LexerGrammar lg = new LexerGrammar(lexerText);
    Grammar g = new Grammar("parser grammar T;\n" + "s : ID\n" + "  ;\n", lg);
    testInterp(lg, g, "s", "a", "(s:1 a)");
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 92 with LexerGrammar

use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.

the class TestParserInterpreter method testEmptyRuleAfterEOFInChild.

@Test
public void testEmptyRuleAfterEOFInChild() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
    Grammar g = new Grammar("parser grammar T;\n" + "s : x y;\n" + "x : A EOF ;\n" + "y : ;", lg);
    ParseTree t = testInterp(lg, g, "s", "a", "(s (x a <EOF>) y)");
    // s
    assertEquals("0..1", t.getSourceInterval().toString());
    // x
    assertEquals("0..1", t.getChild(0).getSourceInterval().toString());
// unspecified		assertEquals("1..0", t.getChild(1).getSourceInterval().toString()); // y
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Test(org.junit.Test)

Example 93 with LexerGrammar

use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.

the class TestParserInterpreter method testEmptyInputWithCallsAfter.

@Test
public void testEmptyInputWithCallsAfter() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
    Grammar g = new Grammar("parser grammar T;\n" + "s : x y ;\n" + "x : EOF ;\n" + "y : z ;\n" + "z : ;", lg);
    ParseTree t = testInterp(lg, g, "s", "", "(s (x <EOF>) (y z))");
    // s
    assertEquals("0..0", t.getSourceInterval().toString());
    // x
    assertEquals("0..0", t.getChild(0).getSourceInterval().toString());
// unspecified		assertEquals("0..-1", t.getChild(1).getSourceInterval().toString()); // x
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Test(org.junit.Test)

Example 94 with LexerGrammar

use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.

the class TestParserInterpreter method testStarAorB.

@Test
public void testStarAorB() 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" + "s : (A{;}|B)* C ;\n", lg);
    testInterp(lg, g, "s", "c", "(s c)");
    testInterp(lg, g, "s", "ac", "(s a c)");
    testInterp(lg, g, "s", "bc", "(s b c)");
    testInterp(lg, g, "s", "abaaabc", "(s a b a a a b c)");
    testInterp(lg, g, "s", "babac", "(s b a b a c)");
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 95 with LexerGrammar

use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.

the class TestParserInterpreter method testEmptyInput.

@Test
public void testEmptyInput() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n");
    Grammar g = new Grammar("parser grammar T;\n" + "s : x EOF ;\n" + "x : ;\n", lg);
    ParseTree t = testInterp(lg, g, "s", "", "(s x <EOF>)");
    // s
    assertEquals("0..0", t.getSourceInterval().toString());
    // x
    assertEquals("0..-1", t.getChild(0).getSourceInterval().toString());
}
Also used : Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Test(org.junit.Test)

Aggregations

LexerGrammar (org.antlr.v4.tool.LexerGrammar)444 Test (org.junit.Test)410 Grammar (org.antlr.v4.tool.Grammar)140 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)120 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)100 TokenStreamRewriter (org.antlr.v4.runtime.TokenStreamRewriter)86 ATN (org.antlr.v4.runtime.atn.ATN)72 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)58 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)43 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)26 ParseTree (org.antlr.v4.runtime.tree.ParseTree)24 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)22 CharStream (org.antlr.v4.runtime.CharStream)20 TokenStream (org.antlr.v4.runtime.TokenStream)17 LexerATNSimulator (org.antlr.v4.runtime.atn.LexerATNSimulator)14 STGroupString (org.stringtemplate.v4.STGroupString)14 ArrayList (java.util.ArrayList)13 ATNFactory (org.antlr.v4.automata.ATNFactory)12 DFA (org.antlr.v4.runtime.dfa.DFA)12 SemanticPipeline (org.antlr.v4.semantics.SemanticPipeline)12