Search in sources :

Example 11 with ErrorQueue

use of org.antlr.v4.test.runtime.ErrorQueue 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 12 with ErrorQueue

use of org.antlr.v4.test.runtime.ErrorQueue 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 13 with ErrorQueue

use of org.antlr.v4.test.runtime.ErrorQueue 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 14 with ErrorQueue

use of org.antlr.v4.test.runtime.ErrorQueue 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)

Example 15 with ErrorQueue

use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.

the class BasePythonTest method checkRuleDFA.

List<ANTLRMessage> checkRuleDFA(String gtext, String ruleName, String expecting) throws Exception {
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(gtext, equeue);
    ATN atn = createATN(g, false);
    ATNState s = atn.ruleToStartState[g.getRule(ruleName).index];
    if (s == null) {
        System.err.println("no such rule: " + ruleName);
        return null;
    }
    ATNState t = s.transition(0).target;
    if (!(t instanceof DecisionState)) {
        System.out.println(ruleName + " has no decision");
        return null;
    }
    DecisionState blk = (DecisionState) t;
    checkRuleDFA(g, blk, expecting);
    return equeue.all;
}
Also used : ErrorQueue(org.antlr.v4.test.runtime.ErrorQueue) Grammar(org.antlr.v4.tool.Grammar) LexerGrammar(org.antlr.v4.tool.LexerGrammar) ATN(org.antlr.v4.runtime.atn.ATN) DecisionState(org.antlr.v4.runtime.atn.DecisionState) ATNState(org.antlr.v4.runtime.atn.ATNState)

Aggregations

ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)45 Grammar (org.antlr.v4.tool.Grammar)34 Test (org.junit.Test)34 ANTLRMessage (org.antlr.v4.tool.ANTLRMessage)27 BaseRuntimeTest (org.antlr.v4.test.runtime.BaseRuntimeTest)23 LexerGrammar (org.antlr.v4.tool.LexerGrammar)23 GrammarSemanticsMessage (org.antlr.v4.tool.GrammarSemanticsMessage)17 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)12 STGroupString (org.stringtemplate.v4.STGroupString)12 ArrayList (java.util.ArrayList)10 ST (org.stringtemplate.v4.ST)10 ATNFactory (org.antlr.v4.automata.ATNFactory)9 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)9 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)9 CodeGenerator (org.antlr.v4.codegen.CodeGenerator)9 SemanticPipeline (org.antlr.v4.semantics.SemanticPipeline)9 ATN (org.antlr.v4.runtime.atn.ATN)8 DecisionState (org.antlr.v4.runtime.atn.DecisionState)8 STGroup (org.stringtemplate.v4.STGroup)7 HashSet (java.util.HashSet)6