minor #9201 [ExpressionLanguage] replaced the =~ operator by matches (removed the != operator) (fabpot)
This PR was merged into the master branch.
Discussion
----------
[ExpressionLanguage] replaced the =~ operator by matches (removed the != operator)
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
To be consistent with fabpot/Twig#1209
Commits
-------
4c2d2e2
[ExpressionLanguage] replaced the =~ operator by matches (removed the != operator)
This commit is contained in:
commit
c6b3ec2729
@ -38,9 +38,9 @@ class BinaryNode extends Node
|
|||||||
{
|
{
|
||||||
$operator = $this->attributes['operator'];
|
$operator = $this->attributes['operator'];
|
||||||
|
|
||||||
if ('=~' == $operator || '!~' == $operator) {
|
if ('matches' == $operator) {
|
||||||
$compiler
|
$compiler
|
||||||
->raw(('!~' == $operator ? '!' : '').'preg_match(')
|
->raw('preg_match(')
|
||||||
->compile($this->nodes['right'])
|
->compile($this->nodes['right'])
|
||||||
->raw(', ')
|
->raw(', ')
|
||||||
->compile($this->nodes['left'])
|
->compile($this->nodes['left'])
|
||||||
@ -136,7 +136,7 @@ class BinaryNode extends Node
|
|||||||
return $left / $right;
|
return $left / $right;
|
||||||
case '%':
|
case '%':
|
||||||
return $left % $right;
|
return $left % $right;
|
||||||
case '=~':
|
case 'matches':
|
||||||
return preg_match($right, $left);
|
return preg_match($right, $left);
|
||||||
case '!~':
|
case '!~':
|
||||||
return !preg_match($right, $left);
|
return !preg_match($right, $left);
|
||||||
|
@ -43,33 +43,32 @@ class Parser
|
|||||||
'+' => array('precedence' => 500),
|
'+' => array('precedence' => 500),
|
||||||
);
|
);
|
||||||
$this->binaryOperators = array(
|
$this->binaryOperators = array(
|
||||||
'or' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
'or' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'||' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
'||' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'and' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
'and' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'&&' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
'&&' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'|' => array('precedence' => 16, 'associativity' => Parser::OPERATOR_LEFT),
|
'|' => array('precedence' => 16, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'^' => array('precedence' => 17, 'associativity' => Parser::OPERATOR_LEFT),
|
'^' => array('precedence' => 17, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'&' => array('precedence' => 18, 'associativity' => Parser::OPERATOR_LEFT),
|
'&' => array('precedence' => 18, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'===' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'===' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'!=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'!=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'!==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'!==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'<' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'<' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'>' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'>' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'>=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'>=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'<=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'<=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'not in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'not in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
'in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'..' => array('precedence' => 25, 'associativity' => Parser::OPERATOR_LEFT),
|
'matches' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'+' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT),
|
'..' => array('precedence' => 25, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'-' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT),
|
'+' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'~' => array('precedence' => 40, 'associativity' => Parser::OPERATOR_LEFT),
|
'-' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'*' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
'~' => array('precedence' => 40, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'/' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
'*' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'%' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
'/' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'=~' => array('precedence' => 70, 'associativity' => Parser::OPERATOR_LEFT),
|
'%' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||||
'!~' => array('precedence' => 70, 'associativity' => Parser::OPERATOR_LEFT),
|
'**' => array('precedence' => 200, 'associativity' => Parser::OPERATOR_RIGHT),
|
||||||
'**' => array('precedence' => 200, 'associativity' => Parser::OPERATOR_RIGHT),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +62,7 @@ class BinaryNodeTest extends AbstractNodeTest
|
|||||||
|
|
||||||
array(array(1, 2, 3), new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))),
|
array(array(1, 2, 3), new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))),
|
||||||
|
|
||||||
array(1, new BinaryNode('=~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
array(1, new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||||
array(false, new BinaryNode('!~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,8 +111,7 @@ class BinaryNodeTest extends AbstractNodeTest
|
|||||||
|
|
||||||
array('range(1, 3)', new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))),
|
array('range(1, 3)', new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))),
|
||||||
|
|
||||||
array('preg_match("/^[a-z]+/i\$/", "abc")', new BinaryNode('=~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+/i$/'))),
|
array('preg_match("/^[a-z]+/i\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+/i$/'))),
|
||||||
array('!preg_match("/^[a-z]+\$/", "abc")', new BinaryNode('!~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user