Re: how to find out what variables an expression references?
Attila Szegedi <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
This should work (code lifted from "?eval" built-in's code):
SimpleCharStream scs = new SimpleCharStream(new
StringReader("(" + s + ")"), 1, 1, s.length() + 2);
FMParserTokenManager token_source = new
FMParserTokenManager(scs);
token_source.SwitchTo(FMParserConstants.FM_EXPRESSION);
FMParser parser = new FMParser(token_source);
parser.template = getTemplate();
Expression exp = parser.Expression();
Attila.
--
weblog: http://constc.blogspot.com
twitter: http://twitter.com/szegedi
On Oct 7, 2008, at 1:31 PM, conrad wrote:
> Hi,
>
> I'm wondering if anyone can help me with following situation...
>
> I'm trying to figure out how I could parse a freemarker expression
> in order to
> get a list of the variables the expression (or template) references.
>
> I need this because I want to dynamically fetch the referenced
> variables from a
> user interface when the template is rendered.
>
> I tried parsing an expression using the FMParser, but I run into all
> kinds of
> trouble, so this does not seem the appropriate way to go about this.
>
> ... anyone know how to handle this?
>
>
>
> Thnx,
> Conrad.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/