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);  }
@Test public void functionTest4() { String ruleCode = "set col: speed value: ismissing('')"; RuleVisitorParser parser = new RuleVisitorParser(); Set setRule = (Set) parser.parse(ruleCode); ExprEval exprEval = ((Expr)setRule.getValue()).eval(null); System.out.println(exprEval.toString()); }
@Test public void functionTest1() { String ruleCode = "set col: speed value: timestamp('2011-01-01','yyyy-MM-dd')"; RuleVisitorParser parser = new RuleVisitorParser(); Set setRule = (Set) parser.parse(ruleCode); ExprEval exprEval = ((Expr)setRule.getValue()).eval(null); System.out.println(exprEval.toString()); assertEquals("2011-01-01T00:00:00.000+09:00", exprEval.asString()); }
@Test public void functionTest2() { String ruleCode = "set col: speed value: time_diff(now(), add_time(now(), 1, 'hour'))"; RuleVisitorParser parser = new RuleVisitorParser(); Set setRule = (Set) parser.parse(ruleCode); ExprEval exprEval = ((Expr)setRule.getValue()).eval(null); System.out.println(exprEval.toString()); assertEquals("3600", exprEval.asString().substring(0,4)); }
@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()); }