[
https://issues.apache.org/jira/browse/JEXL-346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henri Biestro updated JEXL-346:
-------------------------------
Assignee: Henri Biestro
> namespace function syntax leads to strange error for "common case" of ternary
> operator
> --------------------------------------------------------------------------------------
>
> Key: JEXL-346
> URL: https://issues.apache.org/jira/browse/JEXL-346
> Project: Commons JEXL
> Issue Type: Improvement
> Affects Versions: 3.1
> Reporter: David Costanzo
> Assignee: Henri Biestro
> Priority: Minor
>
> The "namespace function call" syntax has precedence over the "ternary
> operator" syntax, which leads to a strange error message for something that
> should intuitively work:
> {code:java}
> x != null ? x : myfunc(y){code}
> Here, {{x}} and {{y}} are String objects and {{myfunc}} is a registered
> library function that is implemented in JEXL. In JEXL 3.1 this results in the
> error:
> {{myfile.jexl:211@1:25 parsing error in ''}}
> With the source code that's currently in github the error is a little better
> but still confusing:
> {{myfile.jexl:211@1:25 parsing error in ')'}}
> The error is because the expression is parsed as:
> {code:java}
> x != null ? (x:myfunc(y)){code}
> That is, the function name is taken to be {{x:myfunc}} despite the spaces and
> despite the fact that my application doesn't support namespaces. This
> swallows up the colon, leaving the ternary operation incomplete when the end
> of the expression is reached.
> This function name is parsed as {{x:myfunc}} because of the first rule in
> FunctionCallLookahead in Parser.jjt.
> {code:java}
> void FunctionCallLookahead() #void : {}
> {
> LOOKAHEAD(4) <IDENTIFIER> <COLON> <IDENTIFIER> <LPAREN>
> |
> LOOKAHEAD(2) <IDENTIFIER> <LPAREN>
> |
> LOOKAHEAD(2) <REGISTER> <LPAREN>
> }{code}
> There are many ways to adjust the expression so that it parses as intended.
> The hard part is for the JEXL programmer to understand what's going on.
> I'd prefer for my application to treat the above JEXL expression as a ternary
> operation, perhaps by requiring that there is no whitespace between the
> namespace and the function name, or perhaps by disabling the "namespace
> function" parsing as a JexlFeature. Failing that, it'd be nice to have a
> somewhat clearer error message like "unable to locate the : in ternary
> operation". With a stronger error message, a web search might explain the
> problem.
> h4. Impact
> This was encountered by one of our application's JEXL programmers. She was
> mystified and reported it to a member of the application's development team.
> After an hour of trial-and-error, he worked out a solution by extra parens
> and then reported this to me. After several hour of stepping through the JEXL
> internals, I finally figured out what was going on. That JavaCC-generated
> code takes some patience!
> The JEXL programmer is not a purist and doesn't care that she had to add some
> extra parens to get it to work. Mostly, I would like to save my other JEXL
> programmers from a similar frustration and associated support cost.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)