Search in sources :

Example 6 with GrammarSemanticsMessage

use of org.antlr.v4.tool.GrammarSemanticsMessage in project antlr4 by antlr.

the class TestCompositeGrammars method testImportedTokenVocabIgnoredWithWarning.

@Test
public void testImportedTokenVocabIgnoredWithWarning() throws Exception {
    ErrorQueue equeue = new ErrorQueue();
    String slave = "parser grammar S;\n" + "options {tokenVocab=whatever;}\n" + "tokens { A }\n" + "x : A {System.out.println(\"S.x\");} ;\n";
    BaseRuntimeTest.mkdir(tmpdir);
    writeFile(tmpdir, "S.g4", slave);
    String master = "grammar M;\n" + "import S;\n" + "s : x ;\n" + "WS : (' '|'\\n') -> skip ;\n";
    writeFile(tmpdir, "M.g4", master);
    Grammar g = new Grammar(tmpdir + "/M.g4", master, equeue);
    Object expectedArg = "S";
    ErrorType expectedMsgID = ErrorType.OPTIONS_IN_DELEGATE;
    GrammarSemanticsMessage expectedMessage = new GrammarSemanticsMessage(expectedMsgID, g.fileName, null, expectedArg);
    checkGrammarSemanticsWarning(equeue, expectedMessage);
    assertEquals("unexpected errors: " + equeue, 0, equeue.errors.size());
    assertEquals("unexpected warnings: " + equeue, 1, equeue.warnings.size());
}
Also used : ErrorType(org.antlr.v4.tool.ErrorType) ErrorQueue(org.antlr.v4.test.runtime.ErrorQueue) Grammar(org.antlr.v4.tool.Grammar) GrammarSemanticsMessage(org.antlr.v4.tool.GrammarSemanticsMessage) BaseRuntimeTest(org.antlr.v4.test.runtime.BaseRuntimeTest) Test(org.junit.Test)

Example 7 with GrammarSemanticsMessage

use of org.antlr.v4.tool.GrammarSemanticsMessage in project antlr4 by antlr.

the class BaseNodeTest method checkGrammarSemanticsWarning.

protected void checkGrammarSemanticsWarning(ErrorQueue equeue, GrammarSemanticsMessage expectedMessage) throws Exception {
    ANTLRMessage foundMsg = null;
    for (int i = 0; i < equeue.warnings.size(); i++) {
        ANTLRMessage m = equeue.warnings.get(i);
        if (m.getErrorType() == expectedMessage.getErrorType()) {
            foundMsg = m;
        }
    }
    assertNotNull("no error; " + expectedMessage.getErrorType() + " expected", foundMsg);
    assertTrue("error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage);
    assertEquals(Arrays.toString(expectedMessage.getArgs()), Arrays.toString(foundMsg.getArgs()));
    if (equeue.size() != 1) {
        System.err.println(equeue);
    }
}
Also used : GrammarSemanticsMessage(org.antlr.v4.tool.GrammarSemanticsMessage) ANTLRMessage(org.antlr.v4.tool.ANTLRMessage)

Example 8 with GrammarSemanticsMessage

use of org.antlr.v4.tool.GrammarSemanticsMessage in project antlr4 by antlr.

the class BaseBrowserTest method checkGrammarSemanticsError.

protected void checkGrammarSemanticsError(ErrorQueue equeue, GrammarSemanticsMessage expectedMessage) throws Exception {
    ANTLRMessage foundMsg = null;
    for (int i = 0; i < equeue.errors.size(); i++) {
        ANTLRMessage m = equeue.errors.get(i);
        if (m.getErrorType() == expectedMessage.getErrorType()) {
            foundMsg = m;
        }
    }
    assertNotNull("no error; " + expectedMessage.getErrorType() + " expected", foundMsg);
    assertTrue("error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage);
    assertEquals(Arrays.toString(expectedMessage.getArgs()), Arrays.toString(foundMsg.getArgs()));
    if (equeue.size() != 1) {
        System.err.println(equeue);
    }
}
Also used : GrammarSemanticsMessage(org.antlr.v4.tool.GrammarSemanticsMessage) ANTLRMessage(org.antlr.v4.tool.ANTLRMessage)

Example 9 with GrammarSemanticsMessage

use of org.antlr.v4.tool.GrammarSemanticsMessage in project antlr4 by antlr.

the class BaseBrowserTest method checkGrammarSemanticsWarning.

protected void checkGrammarSemanticsWarning(ErrorQueue equeue, GrammarSemanticsMessage expectedMessage) throws Exception {
    ANTLRMessage foundMsg = null;
    for (int i = 0; i < equeue.warnings.size(); i++) {
        ANTLRMessage m = equeue.warnings.get(i);
        if (m.getErrorType() == expectedMessage.getErrorType()) {
            foundMsg = m;
        }
    }
    assertNotNull("no error; " + expectedMessage.getErrorType() + " expected", foundMsg);
    assertTrue("error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage);
    assertEquals(Arrays.toString(expectedMessage.getArgs()), Arrays.toString(foundMsg.getArgs()));
    if (equeue.size() != 1) {
        System.err.println(equeue);
    }
}
Also used : GrammarSemanticsMessage(org.antlr.v4.tool.GrammarSemanticsMessage) ANTLRMessage(org.antlr.v4.tool.ANTLRMessage)

Example 10 with GrammarSemanticsMessage

use of org.antlr.v4.tool.GrammarSemanticsMessage in project antlr4 by antlr.

the class BaseNodeTest method checkError.

protected void checkError(ErrorQueue equeue, ANTLRMessage expectedMessage) throws Exception {
    // System.out.println("errors="+equeue);
    ANTLRMessage foundMsg = null;
    for (int i = 0; i < equeue.errors.size(); i++) {
        ANTLRMessage m = equeue.errors.get(i);
        if (m.getErrorType() == expectedMessage.getErrorType()) {
            foundMsg = m;
        }
    }
    assertTrue("no error; " + expectedMessage.getErrorType() + " expected", !equeue.errors.isEmpty());
    assertTrue("too many errors; " + equeue.errors, equeue.errors.size() <= 1);
    assertNotNull("couldn't find expected error: " + expectedMessage.getErrorType(), foundMsg);
    /*
		 * assertTrue("error is not a GrammarSemanticsMessage", foundMsg
		 * instanceof GrammarSemanticsMessage);
		 */
    assertArrayEquals(expectedMessage.getArgs(), foundMsg.getArgs());
}
Also used : ANTLRMessage(org.antlr.v4.tool.ANTLRMessage)

Aggregations

ANTLRMessage (org.antlr.v4.tool.ANTLRMessage)19 GrammarSemanticsMessage (org.antlr.v4.tool.GrammarSemanticsMessage)14 BaseRuntimeTest (org.antlr.v4.test.runtime.BaseRuntimeTest)1 ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)1 ErrorType (org.antlr.v4.tool.ErrorType)1 Grammar (org.antlr.v4.tool.Grammar)1 Test (org.junit.Test)1