欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【aviator】aviator 报错 Syntax error:Unexpect token 'OR' Parsing expression

程序员文章站 2022-07-03 08:49:36
...

【aviator】aviator 报错 Syntax error:Unexpect token 'OR' Parsing expression

1.背景

aviator 报错

 @Test
    public void aviatorPatternPerformanceStringTest() throws Exception {

        String rule = "appProtocol == 'http' OR appProtocol == 'https' ";

        AviatorEvaluator.setOptimize(AviatorEvaluator.EVAL);
        Expression compile = AviatorEvaluator.compile(rule);

        Map<String, Object> env = new HashMap<String, Object>();
        env.put("appProtocol", "http" );
        compile.execute(env);
        env.clear();

    }

报错如下

com.googlecode.aviator.exception.ExpressionSyntaxErrorException: Syntax error:Unexpect token 'OR' at 22, current token: [type='variable',lexeme='OR',index=22]. Parsing expression: `appProtocol == 'http' OR^^`

	at com.googlecode.aviator.parser.ExpressionParser.reportSyntaxError(ExpressionParser.java:832)
	at com.googlecode.aviator.parser.ExpressionParser.parse(ExpressionParser.java:858)
	at com.googlecode.aviator.AviatorEvaluatorInstance.innerCompile(AviatorEvaluatorInstance.java:857)
	at com.googlecode.aviator.AviatorEvaluatorInstance.compile(AviatorEvaluatorInstance.java:836)
	at com.googlecode.aviator.AviatorEvaluator.compile(AviatorEvaluator.java:479)
	at com.googlecode.aviator.AviatorEvaluator.compile(AviatorEvaluator.java:490)
	at com.googlecode.aviator.AviatorDemoTest.aviatorPatternPerformanceStringTest(AviatorDemoTest.java:144)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


这是因为你表达式写错了,Aviator中的表达式或者 是使用 || 不是使用 OR

 	@Test
    public void aviatorPatternPerformanceStringTest() throws Exception {

        String rule = "appProtocol == 'http' || appProtocol == 'https' ";

        AviatorEvaluator.setOptimize(AviatorEvaluator.EVAL);
        Expression compile = AviatorEvaluator.compile(rule);

        Map<String, Object> env = new HashMap<String, Object>();
        env.put("appProtocol", "http" );
        compile.execute(env);
        env.clear();

    }
相关标签: 表达式引擎