commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Blinov (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (JEXL-200) Support for dynamic scripting in jexl scripts
Date Mon, 20 Jun 2016 17:23:05 GMT

    [ https://issues.apache.org/jira/browse/JEXL-200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15339956#comment-15339956
] 

Dmitri Blinov edited comment on JEXL-200 at 6/20/16 5:22 PM:
-------------------------------------------------------------

As for dedicated syntax - I'm also in favour of reusing existing syntax where appropriate,
so I tried to propose as little new keywords and operators as possible, for the whole thing
to resemble ordinary function declaration. The only problem is that I don't know how far existing
syntax can be adopted for this in terms of grammar parsing rules etc. If the same thing can
be done without any new grammar, for example like this:

{code}
var x = function(y) -> "return y+2";
{code} 

Then it will suffice, I do not insist on any particular form.

As for your example, I've got the idea I could wrap the script with {code} (x) -> { ....
} {code} brackets to explicitly define parameters for the script, and it gives me almost everything
I need at the moment, but for the sake of argument, compared to locally declared functions
it will be a "top-level" function which cannot see and bind to any local variables aside its
parameters and top-level context variables. It may be not bad in some use-cases, but using
local variables can be essential for mimicking output parameters, as these variables are writeable.
So it is not a 100% replacement.



was (Author: dmitri_blinov):
As for dedicated syntax - I'm also in favour of reusing existing syntax where appropriate,
so I tried to propose as little new keywords and operators as possible, for the whole thing
to resemble ordinary function declaration. The only problem is that I don't know how far existing
syntax can be adopted for this in terms of grammar parsing rules etc. If the same thing can
be done without any new grammar, for example like this:

{code}
var x = function(y) -> "return y+2";
{code} 

Then it will suffice, I do not insist on any particular form.

As for your example, I've got the idea I could wrap the script with {code} (x) -> { ....
} {code} brackets to explicitly define parameters for the script, and it gives me almost everything
I need at the moment, but for the sake of argument, compared to locally declared functions
it will be a "top-level" function which cannot see and bind to any local variables aside its
parameters and top-level context variables. It may not bad in some use-cases, but using local
variables can be essential for mimicking output parameters, as these variables are writeable.
So it is not a 100% replacement.


> Support for dynamic scripting in jexl scripts
> ---------------------------------------------
>
>                 Key: JEXL-200
>                 URL: https://issues.apache.org/jira/browse/JEXL-200
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.0
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Minor
>
> Allow for dynamically defined functions inside a script where the definition of the function
comes from a string expression, for example:
> {code}
> var x = function(y) => "return y+2";
> {code}
> the defined function should be accessible after its definition is successfully parsed
as ordinary function, and can be evaluated in the current context.
> {code}
> if (x(40) eq 42) {...
> {code}
> I think the idea of dynamic script evaluation is not unusual, and though to some extent
can be implemented via side-added functions like *eval(expr)* a dedicated syntax for this
will benefit from the simplicity of ordinal functions and the ability to control mapping of
the arguments between a caller and the defined function.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message