You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christoph Reck <Ch...@dlr.de> on 2002/03/19 10:21:15 UTC

Re: Escaping braindead :) + proposal

I agree with Geir on the current idea of references should be known
beforehand. Thus any character stream can be passed trough Vel.

The escaping hack came in later to allow something like \$reference 
to emit the plain $. People have been asking to escape quotes in 
strings, but has been voted down.

The simple solution is to put in a #set( $D = '$' ) and use that
format notaion ${D}refernces to enusre a dollar sign is in the
right place. Same works for quotes. This maybe doesn't look as
clean, but it is failsafe and works properly as expected.

The observations of Daniel Dekany with the current escaping 
behaviour must be checked:
 \##x -> \
vs.
 \#\#x -> \#\#x
Here the issue is the priority of comments, to mee the behavious 
is consitent; again: you can use 
 #set( $H = '#' ) 
 ${H}${H}x -> ##x

And the tree swallowing escapes:
 \
 \\
 \\\
 \\\\
is another strange one!?
If one uses some formal escape symbol reference it would work 
properly (but looks strange):
 #set( $E = '\' )
 ${E}
 ${E}${E}
 ${E}${E}${E}
 ${E}${E}${E}${E}

So the conclusion is that escaping was hacked in to make some 
people happy, but has strange effects. 

Other noted bugs are: $#**#foo and $mytool.dollar()foo trying 
to access the $foo reference.

I miss some #local( list of vars ) ... #end directive to make
localy defined/used references dissapear after the block.
I know this would be *very* easy to implement (just stripping
the #foreach directive), but it should be part of the velocity
distribution. It would make macros less dependant on callers
and side-effects.

The whitespace issue/prposal is open in another thread...

-- 
:) Christoph Reck

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Escaping braindead :) + proposal

Posted by Daniel Dekany <dd...@freemail.hu>.
On Tuesday, March 19, 2002 10:21 AM "Christoph Reck" <Ch...@dlr.de>
writen:


[snip]
> The simple solution is to put in a #set( $D = '$' ) and use that
> format notaion ${D}refernces to enusre a dollar sign is in the
> right place. Same works for quotes. This maybe doesn't look as
> clean, but it is failsafe and works properly as expected.

[snip]

I feel that the key problem (not my problem in practice BTW) with this
solution is that I can't express "print a dollar literally" in VTL
independly of the context, since the VTL fragment will assume that D exists
in the context, and that it will print a dollar. Thus I can't do plain
text -> VTL-fragment transformation in a portable way.
So perhaps the current escaping rule should not changed at all (however I
*hate* it...), but then at least add something to Velocity core that can do
the job of ${D} and ${H} and ${B}. Perhaps add #echo(valueToPrintLiterally)
so I can write #echo('$'),
or even #echo("#stop $the \$evil ###schomoos\\\")? Awkward but I have no
better idea for now...
<offtopic>
However, if you combine it with whitespace eating directives (they are not
existing today, but I hope in the near future all directive will eat
whitespace like #set does now (sweet dreams... :))) it can be useful in a
different way too:

#echo('a')
#if ($foo)
  #echo('b')
    #if ($baar)
      #echo('c')
    #end
#end
d

can print abcd.
</offtopic>

I know... -1 of course. What else? :)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>