Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you can swap operators like <code>&gt;</code> and <code>=</code> for the facelets-like <code>gt</code> and <code>eq</code>, respectively, i THINK your case may be doable, though it will require a lot of effort:</p> <pre><code>x gt 10 and y eq 20 or not z </code></pre> <p>resolves to:</p> <pre><code>x(gt).10(and).y(eq).20(or).not(z) </code></pre> <p>And this will be hell to parse.</p> <p>The way @Brian Henry suggested is the easiest way, though not user-friendly, since it needs the parens and dots.</p> <p>Well, considering we can swap the operators, you could try to intercept the <code>Integer.call</code> to start expressions. Having the missing properties in a script being resolved to operations can solve your new keywords problem. Then you can build expressions and save them to a list, executing them in the end of the script. It's not finished, but i came along with this:</p> <pre><code>// the operators that can be used in the script enum Operation { eq, and, gt, not } // every unresolved variable here will try to be resolved as an Operation def propertyMissing(String property) { Operation.find { it.name() == property} } // a class to contain what should be executed in the end of the script @groovy.transform.ToString class Instruction { def left; Operation operation; def right } // a class to handle the next allowed tokens class Expression { Closure handler; Instruction instruction def methodMissing(String method, args) { println "method=$method, args=$args" handler method, args } } // a list to contain the instructions that will need to be parsed def instructions = [] // the start of the whole mess: an integer will get this called Integer.metaClass { call = { Operation op -&gt; instruction = new Instruction(operation: op, left: delegate) instructions &lt;&lt; instruction new Expression( instruction: instruction, handler:{ String method, args -&gt; instruction.right = method.toInteger() println instructions this }) } } x = 12 y = 19 z = false x gt 10 and y eq 20 or not z </code></pre> <p>Which will give an exception, due the <code>not()</code> part not being implemented, but it can build two Instruction objects before failing:</p> <pre><code>[Instruction(12, gt, 10), Instruction(19, eq, 20)] </code></pre> <p>Not sure if it is worth it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload