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

Dmitri Blinov commented on JEXL-390:
------------------------------------

I understand your point to keep the things as much backward compatible as 
possible but if pragmas are allowed to be placed closer to the the point where 
they are used, they stiil can unintentionally influence the interpretation of 
the code before them, because they are still pragmas and not lexical 
preprocessor directives, like in CPP. Here is artificial example.
{code}
    @Test
    public void testPragmaOptions1() {
        final String str = "i; #pragma jexl.options '-strict'\n";
        final JexlEngine jexl = new JexlBuilder().strict(true).create();
        final JexlScript e = jexl.createScript(str);
        final JexlContext ctxt = new MapContext();
        try {
            final Object o = e.execute(ctxt);
            Assert.fail("i should not be resolved");
        } catch (final JexlException xany) {
            Assert.assertNotNull(xany);
        }
    }
{code}

> Pragmas should not be statements
> --------------------------------
>
>                 Key: JEXL-390
>                 URL: https://issues.apache.org/jira/browse/JEXL-390
>             Project: Commons JEXL
>          Issue Type: Improvement
>    Affects Versions: 3.2.1
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Minor
>             Fix For: 3.3
>
>
> In Jexl pragmas are treated as statements syntactically, but do not find 
> their way to AST tree and this leads to strange bugs like in the following 
> example
> {code}
>     @Test
>     public void testBadPragmas() throws Exception {
>         final JexlEngine jexl = new 
> JexlBuilder().cache(1024).debug(true).create();
>         final JexlScript script = jexl.createScript("if (true) #pragma one 
> 42");
>         JexlContext jc = new MapContext();
>         final Object result = script.execute(jc);
>         debuggerCheck(jexl);      
>     }
> {code}
> While this partucular bug can be trivially fixed, in fact the whole idea to 
> allow putting pragmas for example inside a loop or inside if-branch is a 
> strange language design (I'm not aware of examples in other languages) as it 
> gives false idea of the pragma being controlled by script execution logic. 
> If there's no reason or use case to keep this design as is, my proposal is to 
> make a grammar change and allow pragmas to be declared only at the top of the 
> script. Another point to change current pragma implementation is that pragmas 
> can not be used with expressions, e.g. no way to specify standard options / 
> imports.  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to