Hi Timo,
As I just delved into the parser code and it's fresh in my mind, let me
throw out two ideas...
(1) Write a custom directive #IfBoolean that would operate as described.
The benefit is that you could use the "official" version of Velocity,
updating as new releases come out.
(2) Alter the Velocity source code. User javacc to compile a revised
Parser.jjt. Since your syntax currently works in Velocity (you want to
limit what's acceptable, not add new syntax), I don't think you'd have to do
anything else. (correction: you'd need to change ASTIfStatement.java to
throw an exception for non-boolean references).
This would be the section to revise in Parser.jjt. You'd need to change
"Expression()" to only allow a reference or a method call.
void IfStatement() : {}
{
<IF_DIRECTIVE> [<WHITESPACE>] <LPAREN> Expression() <RPAREN>
( Statement() )+ #Block
[ LOOKAHEAD(1) ( ElseIfStatement() )+ ]
[ LOOKAHEAD(1) ElseStatement() ]
<END>
}
Best,
WILL
----- Original Message -----
From: "Tim Colson" <[EMAIL PROTECTED]>
To: "'Velocity Developers List'" <[EMAIL PROTECTED]>
Sent: Tuesday, July 01, 2003 9:31 AM
Subject: Can comparisons be limited to true/false?
> Howdy folks -
> I'm wondering how I might limit the comparisons in velocity templates
> to only boolean conditions.
>
> For example:
> #if ($value > 20) HIGHLIGHTED BUTTON #else stdbutton #end
> would throw an exception and would need to be written with
> a context containing "IS_OVER_LIMIT", new Boolean() and this template:
> #if ($IS_OVER_LIMIT) HIGHLIGHTED BUTTON #else stdbutton #end
>
> Another example:
> #if ($widget.size == "LARGE") large #else not large #end
> would throw an exception and would need to be written as:
> #if ($widget.size.isLarge()) large #else not large #end
>
> The question here is academic at this point. I do not care to argue
> about why this might be good/bad/weird, nor do I want to hear how it
> could be done in another engine.
>
> I'm just curious to know how one might go about messing with Velocity to
> alter it's behaviour as described. Maybe I'll learn something in the
> process of looking. :-)
>
> Thanks!
> Timo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]