google-code-export / nutz

Automatically exported from code.google.com/p/nutz
Apache License 2.0
1 stars 1 forks source link

发现某种情况下EL表达式与Java的表达式不一致 #486

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
注:以下只写出主要的代码,其他略

1)
代码如下
        System.out.println(2+(-3));
        ElValue val = El.eval("2+(-3)");
        System.out.println(val.get());

控制台显示如下
-1
log4j:WARN No appenders could be found for logger (org.nutz.resource.Scans).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.nutz.el.ElException: Unexcept symbol "3" nearby 
: 2+(-3
    at org.nutz.el.impl.NutElAnalyzer.analyze(NutElAnalyzer.java:103)
    at org.nutz.el.impl.normalizer.LeftParenthesisNormalizer.normalize(LeftParenthesisNormalizer.java:14)
    at org.nutz.el.impl.NutElAnalyzer.analyze(NutElAnalyzer.java:113)
    at org.nutz.el.El.compile(El.java:105)
    at org.nutz.el.El.compile(El.java:85)
    at org.nutz.el.El.eval(El.java:118)
    at org.nutz.el.El.eval(El.java:130)
    at testEL.main(testEL.java:12)

2)
代码如下
        System.out.println(2+(-3));
        ElValue val = El.eval("2+(-3)");
        System.out.println(val.get());

控制台显示如下
-1
log4j:WARN No appenders could be found for logger (org.nutz.resource.Scans).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.nutz.el.ElException: I don't know how to handle 
char '-'
    at org.nutz.el.impl.NutElSpliter.splite(NutElSpliter.java:62)
    at org.nutz.el.El.compile(El.java:96)
    at org.nutz.el.El.compile(El.java:85)
    at org.nutz.el.El.eval(El.java:118)
    at org.nutz.el.El.eval(El.java:130)
    at testEL.main(testEL.java:12)

Original issue reported on code.google.com by ywjno....@gmail.com on 26 May 2011 at 8:26

GoogleCodeExporter commented 9 years ago
例子2)里面的代码写错了,抱歉

正确的如下
        System.out.println(2+-3);
        ElValue val = El.eval("2+-3");
        System.out.println(val.get());

PS:貌似没法直接在iss里面更改内容么?

Original comment by ywjno....@gmail.com on 26 May 2011 at 8:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
继续在来一个会出错的例子
代码
        System.out.println(-3*-3);
        ElValue val = El.eval("-3*-3");
        System.out.println(val.get());

控制台显示如下
9
log4j:WARN No appenders could be found for logger (org.nutz.resource.Scans).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.nutz.el.ElException: I don't know how to handle 
char '-'
    at org.nutz.el.impl.NutElSpliter.splite(NutElSpliter.java:62)
    at org.nutz.el.El.compile(El.java:96)
    at org.nutz.el.El.compile(El.java:85)
    at org.nutz.el.El.eval(El.java:118)
    at org.nutz.el.El.eval(El.java:130)
    at testEL.main(testEL.java:17)

貌似el表达式里面有负号的话都不怎么好使

Original comment by ywjno....@gmail.com on 3 Jun 2011 at 8:03

GoogleCodeExporter commented 9 years ago
的确,不知道是不是不支持呢

Original comment by wendal1985@gmail.com on 3 Jun 2011 at 12:58

GoogleCodeExporter commented 9 years ago
貌似是NutElSpliter类的splite方法里面把“-”当成了运算符而没�
��到还有表示负数的意思

Original comment by ywjno....@gmail.com on 8 Jun 2011 at 2:17

GoogleCodeExporter commented 9 years ago
在新版EL中已经将这个问题解决了

Original comment by juq...@gmail.com on 30 Jun 2011 at 6:14