use of org.antlr.v4.tool.Rule in project antlr4 by antlr.
the class BaseJavaTest 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.tool.Rule in project antlr4 by antlr.
the class BaseCppTest 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.tool.Rule in project antlr4 by antlr.
the class BaseBrowserTest method checkRuleATN.
void checkRuleATN(Grammar g, String ruleName, String expecting) {
ParserATNFactory f = new ParserATNFactory(g);
ATN atn = f.createATN();
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule(ruleName).index]));
Rule r = g.getRule(ruleName);
ATNState startState = atn.ruleToStartState[r.index];
ATNPrinter serializer = new ATNPrinter(g, startState);
String result = serializer.asString();
//System.out.print(result);
assertEquals(expecting, result);
}
use of org.antlr.v4.tool.Rule 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;
}
use of org.antlr.v4.tool.Rule in project SSM by Intel-bigdata.
the class TestSmartRuleParser method parseAndExecuteRule.
private void parseAndExecuteRule(String rule) throws Exception {
System.out.println("--> " + rule);
InputStream input = new ByteArrayInputStream(rule.getBytes());
ANTLRInputStream antlrInput = new ANTLRInputStream(input);
SmartRuleLexer lexer = new SmartRuleLexer(antlrInput);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SmartRuleParser parser = new SmartRuleParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new SSMRuleErrorListener());
ParseTree tree = parser.ssmrule();
System.out.println("Parser tree: " + tree.toStringTree(parser));
System.out.println("Total number of errors: " + parseErrors.size());
SmartRuleVisitTranslator visitor = new SmartRuleVisitTranslator();
visitor.visit(tree);
System.out.println("\nQuery:");
TranslateResult result = visitor.generateSql();
int index = 1;
for (String sql : result.getSqlStatements()) {
System.out.println("" + index + ". " + sql);
index++;
}
if (parseErrors.size() > 0) {
throw new IOException("Error while parse rule");
}
ExecutionContext ctx = new ExecutionContext();
ctx.setProperty(ExecutionContext.RULE_ID, 2016);
DBAdapter dbAdapter = new DBAdapter(TestDBUtil.getTestDBInstance());
RuleQueryExecutor qe = new RuleQueryExecutor(null, ctx, result, dbAdapter);
List<String> paths = qe.executeFileRuleQuery();
index = 1;
System.out.println("\nFiles:");
for (String path : paths) {
System.out.println("" + index + ". " + path);
index++;
}
}
Aggregations