Commit 42a1af82 authored by guilhermeblanco's avatar guilhermeblanco

[2.0][DDC-183] Fixed issue with Annotations parser failing on identifiers that...

[2.0][DDC-183] Fixed issue with Annotations parser failing on identifiers that matches with token types.
parent bf0cfba2
...@@ -91,10 +91,8 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -91,10 +91,8 @@ class Lexer extends \Doctrine\Common\Lexer
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2)); $value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
return self::T_STRING; return self::T_STRING;
} else if (ctype_alpha($value[0]) || $value[0] === '_') {
return $this->_checkLiteral($value);
} else { } else {
switch ($value) { switch (strtolower($value)) {
case '@': return self::T_AT; case '@': return self::T_AT;
case ',': return self::T_COMMA; case ',': return self::T_COMMA;
case '(': return self::T_OPEN_PARENTHESIS; case '(': return self::T_OPEN_PARENTHESIS;
...@@ -103,8 +101,13 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -103,8 +101,13 @@ class Lexer extends \Doctrine\Common\Lexer
case '}': return self::T_CLOSE_CURLY_BRACES; case '}': return self::T_CLOSE_CURLY_BRACES;
case '=': return self::T_EQUALS; case '=': return self::T_EQUALS;
case '\\': return self::T_NAMESPACE_SEPARATOR; case '\\': return self::T_NAMESPACE_SEPARATOR;
case 'true': return self::T_TRUE;
case 'false': return self::T_FALSE;
default: default:
// Do nothing if (ctype_alpha($value[0]) || $value[0] === '_') {
return self::T_IDENTIFIER;
}
break; break;
} }
} }
...@@ -130,21 +133,4 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -130,21 +133,4 @@ class Lexer extends \Doctrine\Common\Lexer
return false; return false;
} }
/**
* Checks if an identifier is a keyword and returns its correct type.
*
* @param string $identifier identifier name
* @return integer token type
*/
private function _checkLiteral($identifier)
{
$name = 'Doctrine\Common\Annotations\Lexer::T_' . strtoupper($identifier);
if (defined($name)) {
return constant($name);
}
return self::T_IDENTIFIER;
}
} }
\ No newline at end of file
...@@ -122,6 +122,31 @@ DOCBLOCK; ...@@ -122,6 +122,31 @@ DOCBLOCK;
$parser = $this->createTestParser(); $parser = $this->createTestParser();
$parser->parse("@Name(foo='bar')", "class \Doctrine\Tests\Common\Annotations\Name"); $parser->parse("@Name(foo='bar')", "class \Doctrine\Tests\Common\Annotations\Name");
} }
/**
* @group DDC-183
*/
public function testSyntaxErrorWithUnknownCharacters()
{
$docblock = <<<DOCBLOCK
/**
* @test at.
*/
class A {
}
DOCBLOCK;
//$lexer = new \Doctrine\Common\Annotations\Lexer();
//$lexer->setInput(trim($docblock, '/ *'));
//var_dump($lexer);
try {
$parser = $this->createTestParser();
$result = $parser->parse($docblock);
} catch (Exception $e) {
$this->fail($e->getMessage());
}
}
} }
class Name extends \Doctrine\Common\Annotations\Annotation { class Name extends \Doctrine\Common\Annotations\Annotation {
......
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