|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
yankee Smarty Rookie
Joined: 02 Mar 2009 Posts: 31
|
Posted: Fri Mar 06, 2009 4:53 pm Post subject: Numbers and concat does not work |
|
|
This template:
leads to the following ouput:
Code: | <?php echo $_smarty_tpl->getVariable('a')->value*2.'asdf';?> |
Which does not work, since php thinks that the dot introduces a floating point number.
This patch will set braces at need:
Code: | Index: Smarty3Alpha/libs/sysplugins/internal.templateparser.php
===================================================================
--- Smarty3Alpha/libs/sysplugins/internal.templateparser.php (revision 3021)
+++ Smarty3Alpha/libs/sysplugins/internal.templateparser.php (working copy)
@@ -1726,7 +1726,12 @@
function yy_r39(){ $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor . $this->yystack[$this->yyidx + -1]->minor . $this->yystack[$this->yyidx + 0]->minor; }
#line 1732 "internal.templateparser.php"
#line 216 "internal.templateparser.y"
- function yy_r40(){ $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor . '.' . $this->yystack[$this->yyidx + 0]->minor; }
+ function yy_r40(){
+ if (is_numeric(substr($this->yystack[$this->yyidx + -2]->minor, -1)))
+ $this->_retvalue = '('.$this->yystack[$this->yyidx + -2]->minor . ').' . $this->yystack[$this->yyidx + 0]->minor;
+ else
+ $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor .'.'. $this->yystack[$this->yyidx + 0]->minor;
+ }
#line 1735 "internal.templateparser.php"
#line 249 "internal.templateparser.y"
function yy_r46(){ $this->_retvalue = "'".$this->yystack[$this->yyidx + -1]->minor."'"; }
|
But I fear that it's not the point of an automtic parser generator to edit it's output .
I suppose the issue could be fixed by rebuilding the parser using the following patch:
Code: | Index: Smarty3Alpha/libs/lexer/internal.templateparser.y
===================================================================
--- Smarty3Alpha/libs/lexer/internal.templateparser.y (revision 3021)
+++ Smarty3Alpha/libs/lexer/internal.templateparser.y (working copy)
@@ -213,7 +213,7 @@
// arithmetic expression
exprs(res) ::= exprs(e) math(m) value(v). { res = e . m . v; }
// catenate
-exprs(res) ::= exprs(e) ANDSYM value(v). { res = e . '.' . v; }
+exprs(res) ::= exprs(e) ANDSYM value(v). { res = '('.e.')' . '.' . v; }
//
// mathematical operators |
It will set braces even when they are not needed, but I can't see to much harm in this behaviour right now. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Mar 06, 2009 5:24 pm Post subject: |
|
|
Many thanks for your input.
The patch is needed also for the right side of '&'.
Is fixed in the SVN.
Regards Uwe |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|