Permalink
Browse files

Added filters for contansts

  • Loading branch information...
1 parent fbe9ea5 commit b07a5da31e053065c5a107d9e79bb06655f4df3d @crodas committed Feb 1, 2012
View
@@ -646,19 +646,24 @@ function get_filtered_var($variable, &$varname, $accept_string=NULL)
$this->var_is_safe = FALSE;
if ($accept_string === NULL && is_array($variable[0])) {
- $accept_string = $variable[0][0] === 'block';
+ $accept_string = !empty($variable[0]['string'])
+ || $variable[0][0] === 'block';
}
if (count($variable) > 1) {
$count = count($variable);
- $target = $this->generate_variable_name($variable[0]);
+ if ($accept_string && isset($variable[0]['string'])) {
+ $target = $variable[0];
+ } else {
+ $target = $this->generate_variable_name($variable[0]);
+ }
- if (!Haanga_AST::is_var($target)) {
+ if (!Haanga_AST::is_var($target) && !$accept_string) {
/* block.super can't have any filter */
throw new Exception("This variable can't have any filter");
}
- if ($this->isMethod($target['var'], $return)) {
+ if (!empty($target['var']) && $this->isMethod($target['var'], $return)) {
$target = $return;
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -67,7 +67,7 @@
%nonassoc T_IN.
%left T_PLUS T_MINUS T_CONCAT.
%left T_TIMES T_DIV T_MOD.
-%left T_PIPE T_BITWISE.
+%left T_PIPE T_BITWISE T_FILTER_PIPE.
%syntax_error {
$expect = array();
@@ -337,7 +337,8 @@ filter_stmt(A) ::= T_FILTER filtered_var(B) T_TAG_CLOSE body(X) T_TAG_OPEN T_CUS
regroup(A) ::= T_REGROUP filtered_var(B) T_BY varname(C) T_AS varname(X). { A=array('operation' => 'regroup', 'array' => B, 'row' => C, 'as' => X); }
/* variables with filters */
-filtered_var(A) ::= filtered_var(B) T_PIPE varname_args(C). { A = B; A[] = C; }
+filtered_var(A) ::= filtered_var(B) T_FILTER_PIPE varname_args(C). { A = B; A[] = C; }
+filtered_var(A) ::= string(B) T_FILTER_PIPE varname_args(C). { A = array(array('string' => B)); A[] = C; }
filtered_var(A) ::= varname_args(B). { A = array(B); }
varname_args(A) ::= varname(B) T_COLON var_or_string(X) . { A = array(B, 'args'=>array(X)); }
@@ -372,7 +373,8 @@ expr(A) ::= expr(B) T_OR(X) expr(C). { A = array('op_expr' => @X, B, C); }
expr(A) ::= expr(B) T_PLUS|T_MINUS|T_CONCAT(X) expr(C). { A = array('op_expr' => @X, B, C); }
expr(A) ::= expr(B) T_EQ|T_NE|T_GT|T_GE|T_LT|T_LE|T_IN(X) expr(C). { A = array('op_expr' => trim(@X), B, C); }
expr(A) ::= expr(B) T_TIMES|T_DIV|T_MOD(X) expr(C). { A = array('op_expr' => @X, B, C); }
-expr(A) ::= expr(B) T_BITWISE|T_PIPE(X) expr(C). { A = array('op_expr' => 'expr', array('op_expr' => @X, B, C)); }
+expr(A) ::= expr(B) T_BITWISE(X) expr(C). { A = array('op_expr' => 'expr', array('op_expr' => @X, B, C)); }
+expr(A) ::= expr(B) T_PIPE expr(C). { A = array('op_expr' => 'expr', array('op_expr' => '|', B, C)); }
expr(A) ::= T_LPARENT expr(B) T_RPARENT. { A = array('op_expr' => 'expr', B); }
expr(A) ::= fvar_or_string(B). { A = B; }
@@ -98,7 +98,7 @@ class Haanga_Compiler_Tokenizer
'>' => HG_Parser::T_GT,
'[' => HG_Parser::T_BRACKETS_OPEN,
']' => HG_Parser::T_BRACKETS_CLOSE,
- '|' => HG_Parser::T_PIPE,
+ '|' => HG_Parser::T_FILTER_PIPE,
);
static $operators = array(
'!==' => HG_Parser::T_NE,
@@ -113,7 +113,7 @@ class Haanga_Compiler_Tokenizer
'==' => HG_Parser::T_EQ,
'>=' => HG_Parser::T_GE,
'>>' => HG_Parser::T_BITWISE,
- '||' => HG_Parser::T_OR,
+ '||' => HG_Parser::T_PIPE,
);
static $close_tags = array();
@@ -4,6 +4,6 @@
{% if 13 & 2 == 0 %}
Match
{% endif %}
-{% if 15 | 8 == 15 %}
+{% if 15 || 8 == 15 %}
Match
{% endif %}
@@ -1,6 +1,6 @@
-{% if 1 == 2 || 1+2 == 3 %}True{% else %}False{% endif %}
+{% if 1 == 2 OR 1+2 == 3 %}True{% else %}False{% endif %}
{% if var|upper == var %}True{% else %}False{% endif %}
-{% if 1 === 2 || 1+2 === 3 %}True{% else %}False{% endif %}
+{% if 1 === 2 OR 1+2 === 3 %}True{% else %}False{% endif %}
{% if 1 !== 2 %}True{% else %}False{% endif %}
{% if 1 > 2 %}True{% else %}False{% endif %}
{% if 1 >= 2 %}True{% else %}False{% endif %}
@@ -1 +1,2 @@
hi I'm 5 !
+Hola
@@ -1 +1,2 @@
hi I'm {{ 1+1+b }} !
+{{ "hola"|title}}

0 comments on commit b07a5da

Please sign in to comment.