Search in sources :

Example 96 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.

the class TestCompositeGrammars method testBigTreeOfImports.

@Test
public void testBigTreeOfImports() throws Exception {
    ErrorQueue equeue = new ErrorQueue();
    String slave = "parser grammar T;\n" + "tokens{T}\n" + "x : T ;\n";
    RuntimeTestUtils.mkdir(getTempDirPath());
    writeFile(getTempDirPath(), "T.g4", slave);
    slave = "parser grammar S;\n" + "import T;\n" + "tokens{S}\n" + "y : S ;\n";
    RuntimeTestUtils.mkdir(getTempDirPath());
    writeFile(getTempDirPath(), "S.g4", slave);
    slave = "parser grammar C;\n" + "tokens{C}\n" + "i : C ;\n";
    RuntimeTestUtils.mkdir(getTempDirPath());
    writeFile(getTempDirPath(), "C.g4", slave);
    slave = "parser grammar B;\n" + "tokens{B}\n" + "j : B ;\n";
    RuntimeTestUtils.mkdir(getTempDirPath());
    writeFile(getTempDirPath(), "B.g4", slave);
    slave = "parser grammar A;\n" + "import B,C;\n" + "tokens{A}\n" + "k : A ;\n";
    RuntimeTestUtils.mkdir(getTempDirPath());
    writeFile(getTempDirPath(), "A.g4", slave);
    String master = "grammar M;\n" + "import S,A;\n" + "tokens{M}\n" + "a : M ;\n";
    writeFile(getTempDirPath(), "M.g4", master);
    Grammar g = new Grammar(getTempDirPath() + "/M.g4", master, equeue);
    assertEquals("[]", equeue.errors.toString());
    assertEquals("[]", equeue.warnings.toString());
    String expectedTokenIDToTypeMap = "{EOF=-1, M=1, S=2, T=3, A=4, B=5, C=6}";
    String expectedStringLiteralToTypeMap = "{}";
    String expectedTypeToTokenList = "[M, S, T, A, B, C]";
    assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString());
    assertEquals(expectedStringLiteralToTypeMap, g.stringLiteralToTypeMap.toString());
    assertEquals(expectedTypeToTokenList, realElements(g.typeToTokenList).toString());
    boolean ok = rawGenerateAndBuildRecognizer("M.g4", master, "MParser", null);
    // should be ok
    boolean expecting = true;
    assertEquals(expecting, ok);
}
Also used : ErrorQueue(org.antlr.v4.test.runtime.ErrorQueue) Grammar(org.antlr.v4.tool.Grammar) BaseRuntimeTest(org.antlr.v4.test.runtime.BaseRuntimeTest) Test(org.junit.Test)

Example 97 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.

the class TestLookaheadTrees method testAlts2.

@Test
public void testAlts2() throws Exception {
    LexerGrammar lg = new LexerGrammar(lexerText);
    Grammar g = new Grammar("parser grammar T;\n" + "s : e? SEMI EOF ;\n" + "e : ID\n" + "  | e BANG" + "  ;\n", lg);
    String startRuleName = "s";
    // (...)* in e.
    int decision = 1;
    testLookaheadTrees(lg, g, "a;", startRuleName, decision, new String[] { // Decision for alt 1 is error as no ! char, but alt 2 (exit) is good.
    "(e:2 (e:1 a) <error ;>)", // root s:1 is included to show ';' node
    "(s:1 (e:1 a) ; <EOF>)" });
}
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 98 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.

the class TestLookaheadTrees method testIncludeEOF.

@Test
public void testIncludeEOF() throws Exception {
    LexerGrammar lg = new LexerGrammar(lexerText);
    Grammar g = new Grammar("parser grammar T;\n" + "s : e ;\n" + "e : ID DOT ID EOF\n" + "  | ID DOT ID EOF\n" + "  ;\n", lg);
    int decision = 0;
    testLookaheadTrees(lg, g, "a.b", "s", decision, new String[] { "(e:1 a . b <EOF>)", "(e:2 a . b <EOF>)" });
}
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 99 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.

the class TestLookaheadTrees method testAlts.

@Test
public void testAlts() throws Exception {
    LexerGrammar lg = new LexerGrammar(lexerText);
    Grammar g = new Grammar("parser grammar T;\n" + "s : e SEMI EOF ;\n" + "e : ID DOT ID\n" + "  | ID LPAREN RPAREN\n" + "  ;\n", lg);
    String startRuleName = "s";
    int decision = 0;
    testLookaheadTrees(lg, g, "a.b;", startRuleName, decision, new String[] { "(e:1 a . b)", "(e:2 a <error .>)" });
}
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 100 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.

the class TestATNLexerInterpreter method testLexerNotSMPSetMatchesBMP.

@Test
public void testLexerNotSMPSetMatchesBMP() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ~('\\u{1F4A9}'|'\\u{1F4AA}')\n ;");
    String expecting = "ID, EOF";
    checkLexerMatches(lg, "\u611B", expecting);
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)218 LexerGrammar (org.antlr.v4.tool.LexerGrammar)182 Grammar (org.antlr.v4.tool.Grammar)110 CommonToken (org.antlr.v4.runtime.CommonToken)35 JavadocContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocContext)31 TextContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.TextContext)29 Token (org.antlr.v4.runtime.Token)19 ArrayList (java.util.ArrayList)18 ATN (org.antlr.v4.runtime.atn.ATN)18 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)18 DescriptionContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.DescriptionContext)15 ParseTree (org.antlr.v4.runtime.tree.ParseTree)13 HtmlElementContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.HtmlElementContext)12 JavadocTagContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocTagContext)12 JavadocInlineTagContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocInlineTagContext)10 ReferenceContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.ReferenceContext)10 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)10 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)10 HtmlElementCloseContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.HtmlElementCloseContext)9 HtmlElementOpenContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.HtmlElementOpenContext)9