@Test public void functionTest3() { String ruleCode = "set col: speed value: -1.0"; RuleVisitorParser parser = new RuleVisitorParser(); Set setRule = (Set) parser.parse(ruleCode); ExprEval exprEval = ((Expr)setRule.getValue()).eval(null); System.out.println(exprEval.toString()); }
@Override public Rule parse(String code) { CharStream charStream = new ANTLRInputStream(code); RuleLexer lexer = new RuleLexer(charStream); TokenStream tokens = new CommonTokenStream(lexer); RuleParser parser = new RuleParser(tokens); RuleSetVisitor ruleSetVisitor = new RuleSetVisitor(); Rule traverseResult = ruleSetVisitor.visit(parser.ruleset()); return traverseResult; }
RuleVisitorParser implements Parser { @Override public Rule parse(String code) { CharStream charStream = new ANTLRInputStream(code); RuleLexer lexer = new RuleLexer(charStream); TokenStream tokens = new CommonTokenStream(lexer); RuleParser parser = new RuleParser(tokens); RuleSetVisitor ruleSetVisitor = new RuleSetVisitor(); Rule traverseResult = ruleSetVisitor.visit(parser.ruleset()); return traverseResult; } }
RuleVisitorParser implements Parser { @Override public Rule parse(String code) { CharStream charStream = new ANTLRInputStream(code); RuleLexer lexer = new RuleLexer(charStream); TokenStream tokens = new CommonTokenStream(lexer); RuleParser parser = new RuleParser(tokens); RuleSetVisitor ruleSetVisitor = new RuleSetVisitor(); Rule traverseResult = ruleSetVisitor.visit(parser.ruleset()); return traverseResult; }  }
RuleVisitorParser implements Parser { @Override public Rule parse(String code) { CharStream charStream = new ANTLRInputStream(code); RuleLexer lexer = new RuleLexer(charStream); TokenStream tokens = new CommonTokenStream(lexer); RuleParser parser = new RuleParser(tokens); RuleSetVisitor ruleSetVisitor = new RuleSetVisitor(); Rule traverseResult = ruleSetVisitor.visit(parser.ruleset()); return traverseResult; }  static void register(Class parent); @Override Rule parse(String code); }
RuleVisitorParser implements Parser { @Override public Rule parse(String code) { CharStream charStream = new ANTLRInputStream(code); RuleLexer lexer = new RuleLexer(charStream); TokenStream tokens = new CommonTokenStream(lexer); RuleParser parser = new RuleParser(tokens); RuleSetVisitor ruleSetVisitor = new RuleSetVisitor(); Rule traverseResult = ruleSetVisitor.visit(parser.ruleset()); return traverseResult; }  static void register(Class parent); @Override Rule parse(String code);  }