I think he is looking for C# Linq-like support. Support for that was mentioned 
a few months back. 
In the meantime maybe the new macro functionality can help ?
-------- Ursprüngliche Nachricht --------Von: Jesper Steen Møller 
<jes...@selskabet.org> Datum: 26.11.17  12:32  (GMT+01:00) An: 
dev@groovy.apache.org Betreff: Re: How to find out the names of variables used 
in a groovy expression 
HI Greg,
Note: This list is primarily for developers and maintainers of the Groovy 
project, not for how to use Groovy. You could try us...@groovy.apache.org 
instead. As for your question, which is admittedly borderline:1) At compile 
time (i.e. in a macro or AST transformer), this should be doable, but it's not 
a slam-dunk oneliner (you need to drill down into each GString-expression in 
the abstract syntax tree and find out how each expression is constructed, and 
which variable/field names are in use)2) At runtime, string interpolation has 
already expanded into a construction of a GString by the compiler, and by that 
time, the expressions are no logner recognizable (generally speaking).
I can't quite guess what you're trying to accomplish, but perhaps you should 
consider a templating engine instead, for the ability to parse and work with 
GString-like templates. Have a look at 
http://docs.groovy-lang.org/latest/html/documentation/template-engines.html
-Jesper
On 26 Nov 2017, at 11.32, bayareagreg <bayareag...@gmail.com> wrote:
Hello,

I need to programmatically find out the names of variables used in a
"simple" groovy expression that reads a value from one or more variables.
One can assume the expression is read-only, that is no modifications of any
state will be used. E.g. in an expression like this

"${foo}", it should return "foo"
also same in "${foo.bar.zot}"

is what I am asking possible? If yes please point me in the direction of
which API to use for this.
Thank you in advance




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Reply via email to