Re: [PHPTAL] Escaping of dollar sign ($)

2009-11-04 Thread Kornel Lesiński
On 03-11-2009 at 17:56:02 Tobias Herp bruno-the-questiona...@gmx.net  
wrote:



Kornel Lesiński wrote:

I could change it to:

${x} → value
$${x} → ${x}
$$${x} → $value
{x} → $${x}
${x} → $$value
$${x} → $$${x}
etc.


Yes, please!

This is logical, and it is the behaviour defined by the TALES standard  
(http://wiki.zope.org/ZPT/TALESSpecification13#required_type_prefixes).

The current behaviour is a *bug* and should be fixed.


OK. That's a good point.


• Pre-filters may need to deal with this to (un)escape text properly.
With simpler rules you can just replace ${ with $${ to escape text.
It's not so easy when you need to observe even/odd number of $s.


Well, you can consume the text sequentially and change every $$ into $,  
and treat every ${ or $\w as the beginning of a variable. Doesn't look  
very complicated to me.


Using regular expressions, you could look for $(.); if \1 is another $,  
you have a literal $, etc.  Anything else but [${\w] should yield an  
error, of course!


How do you halve/double number of $'s with regular expression?

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escaping of dollar sign ($)

2009-11-04 Thread Kornel Lesiński

On 04-11-2009 at 10:22:56 Tjerk Meesters tjerk.meest...@gmail.com wrote:


Would it be possible to use a preg_replace() with two expressions, one
to replace $$ by $ and one to handle \b${?(\w+)


You'd have to use assertions or other tricks, to avoid replacing unrelated  
$$s.


I think I'll just have to provide (un)escaping function for prefilters.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escaping of dollar sign ($)

2009-11-03 Thread Tobias Herp
Kornel Lesiński wrote:
 I could change it to:
 
 ${x} → value
 $${x} → ${x}
 $$${x} → $value
 {x} → $${x}
 ${x} → $$value
 $${x} → $$${x}
 etc.

Yes, please!

This is logical, and it is the behaviour defined by the TALES standard 
(http://wiki.zope.org/ZPT/TALESSpecification13#required_type_prefixes).
The current behaviour is a *bug* and should be fixed.

It's ok to add features to ZPT (especially the definition of operators); but 
IMO it's /not/ ok to change the meaning of existing syntax.

 However:
 
 • Pre-filters may need to deal with this to (un)escape text properly.
 With simpler rules you can just replace ${ with $${ to escape text.
 It's not so easy when you need to observe even/odd number of $s.

Well, you can consume the text sequentially and change every $$ into $, and 
treat every ${ or $\w as the beginning of a variable. Doesn't look very 
complicated to me.

Using regular expressions, you could look for $(.); if \1 is another $, you 
have a literal $, etc.  Anything else but [${\w] should yield an error, of 
course!

 • It breaks backwards compatibility (hopefully not many people have
 $$${x} in their templates)

I doubt so; I can hardly imagine a serious use of sequences of two or more 
dollar signs.

-- 
Cheers,

Tobias

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escaping of dollar sign ($)

2009-10-27 Thread Nick Pack
What about the html entity: #36;


On 26/10/2009 23:10, Cameron Junge cameron.ju...@finda.co.nz wrote:

 Hi All,
 
 Not sure if this has been covered on this list before, my quick search
 couldn't find anything that seemed appropriate.
 
 If I wish to display a $ followed by a tal variable using the inline
 syntax (ie. ${variable}) then I have to either:
 a) put a space between the 2 $ signs; or
 b) use a tag to spit the variable out; or
 c) use a phptal_tales expression.
 
 Eg. if I have a variable amount with the value 100, and I want to
 display is as $100 then I either have to do:
 a) $ ${amount}; or
 b) $tal:block replace=amount /; or
 c) tal:block replace=money: amount /
 
 Various attempts at escaping have failed. $$${amount} comes out as
 $${amount}; $${amount} comes out as ${amount}
 
 I know that there are workarounds, but surely there must be some way to
 do what is relatively simple? or is this a bug?
 
 Cheers, Cameron.
 
 Notice
 
 This email and any attachments are strictly confidential and subject to
 copyright.  They may contain privileged information.  If you are not the
 intended recipient please delete the message and notify the sender. You should
 not read, copy, use, change, alter or disclose this email or its attachments
 without authorisation.  The company and any related or associated companies do
 not accept any liability in connection with this email and any attachments
 including in connection with computer viruses, data corruption, delay,
 interruption, unauthorised access or unauthorised amendment. Any views
 expressed in this email and any attachments do not necessarily reflect the
 views of the company or the views of any of our related or associated
 companies.
 
 ___
 PHPTAL mailing list
 PHPTAL@lists.motion-twin.com
 http://lists.motion-twin.com/mailman/listinfo/phptal


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escaping of dollar sign ($)

2009-10-27 Thread Kornel Lesiński

On 26-10-2009 at 23:10:45 Cameron Junge cameron.ju...@finda.co.nz wrote:

Eg. if I have a variable amount with the value 100, and I want to  
display is as $100 then I either have to do:

a) $ ${amount}; or
b) $tal:block replace=amount /; or
c) tal:block replace=money: amount /


$x tal:replace=amount/

${money:amount}

I think the last one isn't bad.

Various attempts at escaping have failed. $$${amount} comes out as  
$${amount}; $${amount} comes out as ${amount}


I know that there are workarounds, but surely there must be some way to  
do what is relatively simple? or is this a bug?


Strictly speaking it's not a bug (it's deliberately coded that way). It's  
PHPTAL's simplistic approach to escaping of ${}:


1. '$${' is not interpreted as start of interpolated expression
2. '$${' is replaced with '${'

This gives:

${x} → value
$${x} → ${x}
$$${x} → $${x}
{x} → $$${x}
${x} → {x}
etc.

I could change it to:

${x} → value
$${x} → ${x}
$$${x} → $value
{x} → $${x}
${x} → $$value
$${x} → $$${x}
etc.


However:

• Pre-filters may need to deal with this to (un)escape text properly. With  
simpler rules you can just replace ${ with $${ to escape text. It's not so  
easy when you need to observe even/odd number of $s.
• It breaks backwards compatibility (hopefully not many people have $$${x}  
in their templates)



Deal PHPTAL users, what's your opinion on this?

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escaping of dollar sign ($)

2009-10-27 Thread Tjerk Meesters
I vote for not changing the current behaviour; I agree that if it's
documented, it can be a little weird ;-)

Personally I would choose to have a money formatter TALES construct,
because I hate having to go through my templates again when I start
adding another currency for instance.


Best,
  Tjerk

2009/10/27 Kornel Lesiński kor...@aardvarkmedia.co.uk:
 On 27-10-2009 at 12:34:42 Iván Montes drsl...@pollinimini.net wrote:

 I vote for not changing the behavior but I would like, for next major
 version of PHPTAL, to break BC for escaping and remove the escaping of
 the dollar symbol:

 ${variable} - variable
 $${variable} - $variable

 Since TAL is heavily based on HTML/XML semantics I guess it makes more
 sense to escape using unicode point codes (#36; for $) or custom
 entities.

 Unfortunately in XML it shouldn't matter whether you use literal $ or #36;
 (the difference is completely lost if you use W3C DOM for example).
 Theoretically PHPTAL should support #x24;#x7b;var#x7d; as well as ${var}
 :/

 Custom entities require custom DOCTYPE/DTD, and that's just a can of worms.


 This would remove the need for backtracking when parsing
 interpolatable texts and remove possible ambiguities like the one
 described in the original mail.

 It can be unambiguous. It just has to be clearly defined and implemented in
 one way or another :)

 --
 regards, Kornel

 ___
 PHPTAL mailing list
 PHPTAL@lists.motion-twin.com
 http://lists.motion-twin.com/mailman/listinfo/phptal




-- 
--
Tjerk

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal