Search in sources :

Example 26 with ANTLRMessage

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

the class BaseNodeTest 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 27 with ANTLRMessage

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

the class BaseJavaTest method checkRuleDFA.

List<ANTLRMessage> checkRuleDFA(String gtext, int decision, String expecting) throws Exception {
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(gtext, equeue);
    ATN atn = createATN(g, false);
    DecisionState blk = atn.decisionToState.get(decision);
    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)

Example 28 with ANTLRMessage

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

the class BaseCppTest method checkRuleDFA.

List<ANTLRMessage> checkRuleDFA(String gtext, int decision, String expecting) throws Exception {
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(gtext, equeue);
    ATN atn = createATN(g, false);
    DecisionState blk = atn.decisionToState.get(decision);
    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)

Example 29 with ANTLRMessage

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

the class BaseCppTest 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 30 with ANTLRMessage

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

the class BaseCppTest method checkLexerDFA.

List<ANTLRMessage> checkLexerDFA(String gtext, String modeName, String expecting) throws Exception {
    ErrorQueue equeue = new ErrorQueue();
    LexerGrammar g = new LexerGrammar(gtext, equeue);
    g.atn = createATN(g, false);
    //		return equeue.all;
    return null;
}
Also used : ErrorQueue(org.antlr.v4.test.runtime.ErrorQueue) LexerGrammar(org.antlr.v4.tool.LexerGrammar)

Aggregations

ANTLRMessage (org.antlr.v4.tool.ANTLRMessage)29 GrammarSemanticsMessage (org.antlr.v4.tool.GrammarSemanticsMessage)15 LexerGrammar (org.antlr.v4.tool.LexerGrammar)12 ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)11 ATN (org.antlr.v4.runtime.atn.ATN)8 DecisionState (org.antlr.v4.runtime.atn.DecisionState)8 Grammar (org.antlr.v4.tool.Grammar)8 File (java.io.File)5 ATNState (org.antlr.v4.runtime.atn.ATNState)4 Test (org.junit.Test)3 ST (org.stringtemplate.v4.ST)3 ArrayList (java.util.ArrayList)2 Tool (org.antlr.v4.Tool)2 BaseRuntimeTest (org.antlr.v4.test.runtime.BaseRuntimeTest)2 BaseRuntimeTest.writeFile (org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile)2 DefaultToolListener (org.antlr.v4.tool.DefaultToolListener)2 IOException (java.io.IOException)1 STGroupFile (org.stringtemplate.v4.STGroupFile)1 STGroupString (org.stringtemplate.v4.STGroupString)1