You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Guy Dumais <gu...@radialpoint.com> on 2011/09/29 17:08:01 UTC

[jexl] limiting the expressions accepted by JEXL

Hi all,

Is there a  recommended way to constrain the expressions that are
accepted as valid JEXL expressions?  I need a very limited language
(mostly boolean expressions) and would like to make sure any expression
fits the language before evaluating it.  There is always the option to
write my own parser but I thought it would be handy to do it in JEXL
directly.

 

Also, is it possible to access the expression AST without overriding the
JexlEngine class?

 

Thanks,

Guy.


***********************************************************************

This e-mail and attachments are confidential, legally privileged, may be subject to copyright and sent solely for the attention of the addressee(s). Any unauthorized use or disclosure is prohibited. Statements and opinions expressed in this e-mail may not represent those of Radialpoint.

Le contenu du pr�sent courriel est confidentiel, privil�gi� et peut �tre soumis � des droits d'auteur. Il est envoy� � l'intention exclusive de son ou de ses destinataires. Il est interdit de l'utiliser ou de le divulguer sans autorisation. Les opinions exprim�es dans le pr�sent courriel peuvent diverger de celles de Radialpoint.

RE: [jexl] limiting the expressions accepted by JEXL

Posted by Guy Dumais <gu...@radialpoint.com>.
Hi Henri,
Thanks for the detailed response.

My syntax is a small subset of the JEXL language.  It contains no
arithmetic and none of the JEXL built-in functions.  In summary, it is a
single statement to be evaluated as a boolean expression with method
calls and possibly array or map literals.  It would look something like:
(f(x) and g("string")) or h(r) //no pun intended :-)

Implementing my own parser to validate the expression prior to passing
to JEXL seems the best approach.  My syntax is also valid Jython which I
may decide to use at some point so keeping the parser independent of
JEXL seems like the best approach.

Thanks,
Guy.


-----Original Message-----
From: henrib [mailto:henrib@apache.org] 
Sent: 29 septembre 2011 12:57
To: user@commons.apache.org
Subject: Re: [jexl] limiting the expressions accepted by JEXL

Hi Guy;

About limiting the valid expressions, i'm afraid this is a new usage
(AKAIK)... I so far thought the language to be minimalist. :-)
Would you need to only block operators (comparison / arithmetic),
literals
(map/array) or even more (variable, new) etc?

On actually blocking / rejecting syntactically acceptable expressions,
the
first route that comes to mind would be to walk the tree (like the
Debugger
does) after the parse and throw a JexlException on rejection. It means
overriding the JexlEngine (at least the 
JexlEngine.createScript(ASTJexlScript tree, String text) and no, there
is no
better route to validating the AST). This also implies "deep"
integration
which might not be desirable . 

The other way would be to validate the syntax using a dedicated (home
brewed
/ javacc) parser and wrap Jexl under your own engine (considering the
syntax
as a valid subset of JEXL's).

In both cases, you'll have to maintain some code; if the language you
seek
is very limited and a strict subset of JEXL, my gut feel is it might be
easier to javacc the grammar and front JEXL with it.

As a side note, JEXL expressions can be used as boolean conditions (i.e.
false and null are false, others are true); so you may already use the
language as is and restrict it later to test the water.

Hope this helps,
Cheers
Henrib

--
View this message in context:
http://apache-commons.680414.n4.nabble.com/jexl-limiting-the-expressions
-accepted-by-JEXL-tp3856155p3856673.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


***********************************************************************

This e-mail and attachments are confidential, legally privileged, may be subject to copyright and sent solely for the attention of the addressee(s). Any unauthorized use or disclosure is prohibited. Statements and opinions expressed in this e-mail may not represent those of Radialpoint.

Le contenu du pr�sent courriel est confidentiel, privil�gi� et peut �tre soumis � des droits d'auteur. Il est envoy� � l'intention exclusive de son ou de ses destinataires. Il est interdit de l'utiliser ou de le divulguer sans autorisation. Les opinions exprim�es dans le pr�sent courriel peuvent diverger de celles de Radialpoint.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [jexl] limiting the expressions accepted by JEXL

Posted by henrib <he...@apache.org>.
Hi Guy;

About limiting the valid expressions, i'm afraid this is a new usage
(AKAIK)... I so far thought the language to be minimalist. :-)
Would you need to only block operators (comparison / arithmetic),  literals
(map/array) or even more (variable, new) etc?

On actually blocking / rejecting syntactically acceptable expressions, the
first route that comes to mind would be to walk the tree (like the Debugger
does) after the parse and throw a JexlException on rejection. It means
overriding the JexlEngine (at least the 
JexlEngine.createScript(ASTJexlScript tree, String text) and no, there is no
better route to validating the AST). This also implies "deep" integration
which might not be desirable . 

The other way would be to validate the syntax using a dedicated (home brewed
/ javacc) parser and wrap Jexl under your own engine (considering the syntax
as a valid subset of JEXL's).

In both cases, you'll have to maintain some code; if the language you seek
is very limited and a strict subset of JEXL, my gut feel is it might be
easier to javacc the grammar and front JEXL with it.

As a side note, JEXL expressions can be used as boolean conditions (i.e.
false and null are false, others are true); so you may already use the
language as is and restrict it later to test the water.

Hope this helps,
Cheers
Henrib

--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-limiting-the-expressions-accepted-by-JEXL-tp3856155p3856673.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org