use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by tunnelvisionlabs.
the class BaseTest 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);
}
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by tunnelvisionlabs.
the class BaseTest 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;
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by tunnelvisionlabs.
the class BaseTest method antlr.
protected ErrorQueue antlr(String grammarFileName, boolean defaultListener, String... extraOptions) {
final List<String> options = new ArrayList<String>();
Collections.addAll(options, extraOptions);
if (!options.contains("-o")) {
options.add("-o");
options.add(tmpdir);
}
if (!options.contains("-lib")) {
options.add("-lib");
options.add(tmpdir);
}
if (!options.contains("-encoding")) {
options.add("-encoding");
options.add("UTF-8");
}
options.add(new File(tmpdir, grammarFileName).toString());
final String[] optionsA = new String[options.size()];
options.toArray(optionsA);
Tool antlr = newTool(optionsA);
ErrorQueue equeue = new ErrorQueue(antlr);
antlr.addListener(equeue);
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
if (!defaultListener && !equeue.errors.isEmpty()) {
System.err.println("antlr reports errors from " + options);
for (int i = 0; i < equeue.errors.size(); i++) {
ANTLRMessage msg = equeue.errors.get(i);
System.err.println(msg);
}
System.out.println("!!!\ngrammar:");
try {
System.out.println(new String(Utils.readFile(tmpdir + "/" + grammarFileName)));
} catch (IOException ioe) {
System.err.println(ioe.toString());
}
System.out.println("###");
}
if (!defaultListener && !equeue.warnings.isEmpty()) {
System.err.println("antlr reports warnings from " + options);
for (int i = 0; i < equeue.warnings.size(); i++) {
ANTLRMessage msg = equeue.warnings.get(i);
System.err.println(msg);
}
}
if (!defaultListener && !equeue.warnings.isEmpty()) {
System.err.println("antlr reports warnings from " + options);
for (int i = 0; i < equeue.warnings.size(); i++) {
ANTLRMessage msg = equeue.warnings.get(i);
System.err.println(msg);
}
}
return equeue;
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by tunnelvisionlabs.
the class BaseTest 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;
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by tunnelvisionlabs.
the class TestCompositeGrammars method testSyntaxErrorsInImportsNotThrownOut.
@Test
public void testSyntaxErrorsInImportsNotThrownOut() throws Exception {
ErrorQueue equeue = new ErrorQueue();
String slave = "parser grammar S;\n" + "options {toke\n";
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);
@SuppressWarnings("unused") Grammar g = new Grammar(tmpdir + "/M.g4", master, equeue);
assertEquals(ErrorType.SYNTAX_ERROR, equeue.errors.get(0).getErrorType());
}
Aggregations