Commit ac5fe1f9 authored by guilhermeblanco's avatar guilhermeblanco

[2.0] Some Annotations parser docblocks, optimizations, etc. Fixed wrong...

[2.0] Some Annotations parser docblocks, optimizations, etc. Fixed wrong syntax error token report in DQL parser
parent 33fc28ff
...@@ -68,16 +68,18 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -68,16 +68,18 @@ class Lexer extends \Doctrine\Common\Lexer
protected function _getType(&$value) protected function _getType(&$value)
{ {
$type = self::T_NONE; $type = self::T_NONE;
$newVal = $this->_getNumeric($value); $newVal = $this->_getNumeric($value);
if ($newVal !== false){ if ($newVal !== false){
$value = $newVal; $value = $newVal;
if (strpos($value, '.') !== false || stripos($value, 'e') !== false) { if (strpos($value, '.') !== false || stripos($value, 'e') !== false) {
$type = self::T_FLOAT; $type = self::T_FLOAT;
} else { } else {
$type = self::T_INTEGER; $type = self::T_INTEGER;
} }
} }
if ($value[0] === '"') { if ($value[0] === '"') {
$type = self::T_STRING; $type = self::T_STRING;
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2)); $value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
...@@ -89,7 +91,10 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -89,7 +91,10 @@ class Lexer extends \Doctrine\Common\Lexer
} }
/** /**
* @todo Doc * Checks if a value is numeric or not
*
* @param mixed $value Value to be inspected
* @return boolean|integer|float Processed value
*/ */
private function _getNumeric($value) private function _getNumeric($value)
{ {
...@@ -108,7 +113,7 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -108,7 +113,7 @@ class Lexer extends \Doctrine\Common\Lexer
* Checks if an identifier is a keyword and returns its correct type. * Checks if an identifier is a keyword and returns its correct type.
* *
* @param string $identifier identifier name * @param string $identifier identifier name
* @return int token type * @return integer token type
*/ */
private function _checkLiteral($identifier) private function _checkLiteral($identifier)
{ {
......
This diff is collapsed.
...@@ -223,8 +223,9 @@ class Parser ...@@ -223,8 +223,9 @@ class Parser
{ {
$key = (is_string($token)) ? 'value' : 'type'; $key = (is_string($token)) ? 'value' : 'type';
if ( ! ($this->_lexer->lookahead[$key] === $token)) if ( ! ($this->_lexer->lookahead[$key] === $token)) {
$this->syntaxError($this->_lexer->getLiteral($token)); $this->syntaxError($this->_lexer->getLiteral($token));
}
$this->_lexer->moveNext(); $this->_lexer->moveNext();
} }
...@@ -301,7 +302,7 @@ class Parser ...@@ -301,7 +302,7 @@ class Parser
if ($this->_lexer->lookahead === null) { if ($this->_lexer->lookahead === null) {
$message .= 'end of string.'; $message .= 'end of string.';
} else { } else {
$message .= "'{$this->_lexer->lookahead['value']}'"; $message .= "'{$token['value']}'";
} }
throw \Doctrine\ORM\Query\QueryException::syntaxError($message); throw \Doctrine\ORM\Query\QueryException::syntaxError($message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment