Search in sources :

Example 51 with ErrorQueue

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

the class BaseBrowserTest 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 52 with ErrorQueue

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

the class BasePythonTest 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 53 with ErrorQueue

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

the class BaseBrowserTest method rawGenerateAndBuildRecognizer.

/** Return true if all is well */
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName, String grammarStr, String parserName, String lexerName, boolean defaultListener, String... extraOptions) {
    ErrorQueue equeue = antlrOnString(getTmpDir(), "JavaScript", grammarFileName, grammarStr, defaultListener, extraOptions);
    if (!equeue.errors.isEmpty()) {
        return false;
    }
    List<String> files = new ArrayList<String>();
    if (lexerName != null) {
        files.add(lexerName + ".js");
    }
    if (parserName != null) {
        files.add(parserName + ".js");
        Set<String> optionsSet = new HashSet<String>(Arrays.asList(extraOptions));
        if (!optionsSet.contains("-no-listener")) {
            files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.')) + "Listener.js");
        }
        if (optionsSet.contains("-visitor")) {
            files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.')) + "Visitor.js");
        }
    }
    // allIsWell: no compile
    return true;
}
Also used : ArrayList(java.util.ArrayList) ErrorQueue(org.antlr.v4.test.runtime.ErrorQueue) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) HashSet(java.util.HashSet)

Example 54 with ErrorQueue

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

the class BasePythonTest 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 55 with ErrorQueue

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

the class BasePythonTest method rawGenerateAndBuildRecognizer.

/** Return true if all is well */
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName, String grammarStr, String parserName, String lexerName, boolean defaultListener, String... extraOptions) {
    ErrorQueue equeue = antlrOnString(getTmpDir(), getLanguage(), grammarFileName, grammarStr, defaultListener, extraOptions);
    if (!equeue.errors.isEmpty()) {
        return false;
    }
    List<String> files = new ArrayList<String>();
    if (lexerName != null) {
        files.add(lexerName + ".py");
    }
    if (parserName != null) {
        files.add(parserName + ".py");
        Set<String> optionsSet = new HashSet<String>(Arrays.asList(extraOptions));
        if (!optionsSet.contains("-no-listener")) {
            files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.')) + "Listener.py");
        }
        if (optionsSet.contains("-visitor")) {
            files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.')) + "Visitor.py");
        }
    }
    // allIsWell: no compile
    return true;
}
Also used : ArrayList(java.util.ArrayList) ErrorQueue(org.antlr.v4.test.runtime.ErrorQueue) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString) HashSet(java.util.HashSet)

Aggregations

ErrorQueue (org.antlr.v4.test.runtime.ErrorQueue)40 ANTLRMessage (org.antlr.v4.tool.ANTLRMessage)21 Grammar (org.antlr.v4.tool.Grammar)21 LexerGrammar (org.antlr.v4.tool.LexerGrammar)17 Test (org.junit.Test)16 BaseRuntimeTest (org.antlr.v4.test.runtime.BaseRuntimeTest)15 GrammarSemanticsMessage (org.antlr.v4.tool.GrammarSemanticsMessage)14 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)11 STGroupString (org.stringtemplate.v4.STGroupString)11 ArrayList (java.util.ArrayList)9 ST (org.stringtemplate.v4.ST)8 HashSet (java.util.HashSet)7 ATNFactory (org.antlr.v4.automata.ATNFactory)7 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)7 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)7 CodeGenerator (org.antlr.v4.codegen.CodeGenerator)7 SemanticPipeline (org.antlr.v4.semantics.SemanticPipeline)7 ATN (org.antlr.v4.runtime.atn.ATN)6 DecisionState (org.antlr.v4.runtime.atn.DecisionState)6 STGroup (org.stringtemplate.v4.STGroup)6