[ExpressionLanguage] replaced the =~ operator by matches (removed the != operator)
This commit is contained in:
parent
96fb922e67
commit
4c2d2e287a
@ -38,9 +38,9 @@ class BinaryNode extends Node
|
||||
{
|
||||
$operator = $this->attributes['operator'];
|
||||
|
||||
if ('=~' == $operator || '!~' == $operator) {
|
||||
if ('matches' == $operator) {
|
||||
$compiler
|
||||
->raw(('!~' == $operator ? '!' : '').'preg_match(')
|
||||
->raw('preg_match(')
|
||||
->compile($this->nodes['right'])
|
||||
->raw(', ')
|
||||
->compile($this->nodes['left'])
|
||||
@ -136,7 +136,7 @@ class BinaryNode extends Node
|
||||
return $left / $right;
|
||||
case '%':
|
||||
return $left % $right;
|
||||
case '=~':
|
||||
case 'matches':
|
||||
return preg_match($right, $left);
|
||||
case '!~':
|
||||
return !preg_match($right, $left);
|
||||
|
@ -43,33 +43,32 @@ class Parser
|
||||
'+' => array('precedence' => 500),
|
||||
);
|
||||
$this->binaryOperators = array(
|
||||
'or' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'||' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'and' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'&&' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'|' => array('precedence' => 16, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'^' => array('precedence' => 17, '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),
|
||||
'not in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'in' => array('precedence' => 20, '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' => 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' => 70, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'**' => array('precedence' => 200, 'associativity' => Parser::OPERATOR_RIGHT),
|
||||
'or' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'||' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'and' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'&&' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'|' => array('precedence' => 16, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'^' => array('precedence' => 17, '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),
|
||||
'not in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'matches' => array('precedence' => 20, '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' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'/' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'%' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT),
|
||||
'**' => 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(1, new BinaryNode('=~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||
array(false, new BinaryNode('!~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||
array(1, new BinaryNode('matches', 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('preg_match("/^[a-z]+/i\$/", "abc")', new BinaryNode('=~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+/i$/'))),
|
||||
array('!preg_match("/^[a-z]+\$/", "abc")', new BinaryNode('!~', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))),
|
||||
array('preg_match("/^[a-z]+/i\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+/i$/'))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user