[ExpressionLanguage] Fixed conflict between punctation and range

This commit is contained in:
Wouter J 2013-11-18 21:49:06 +01:00 committed by Fabien Potencier
parent 4e9332b6b6
commit b521dc5ace
2 changed files with 8 additions and 4 deletions

View File

@ -63,10 +63,6 @@ class Lexer
throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur);
}
$tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1);
++$cursor;
} elseif (false !== strpos('.,?:', $expression[$cursor])) {
// punctuation
$tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1);
++$cursor;
} elseif (preg_match('/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As', $expression, $match, null, $cursor)) {
@ -77,6 +73,10 @@ class Lexer
// operators
$tokens[] = new Token(Token::OPERATOR_TYPE, $match[0], $cursor + 1);
$cursor += strlen($match[0]);
} elseif (false !== strpos('.,?:', $expression[$cursor])) {
// punctuation
$tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1);
++$cursor;
} elseif (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A', $expression, $match, null, $cursor)) {
// names
$tokens[] = new Token(Token::NAME_TYPE, $match[0], $cursor + 1);

View File

@ -70,6 +70,10 @@ class LexerTest extends \PHPUnit_Framework_TestCase
),
'(3 + 5) ~ foo("bar").baz[4]',
),
array(
array(new Token('operator', '..', 1)),
'..',
),
);
}
}