Commit 89a62502 authored by romanb's avatar romanb

[2.0] Refactored and reenabled Lexer tests.

parent b718cd1a
...@@ -114,7 +114,7 @@ class Lexer ...@@ -114,7 +114,7 @@ class Lexer
public $lookahead; public $lookahead;
/** /**
* @var array The last matched token. * @var array The last matched/seen token.
*/ */
public $token; public $token;
...@@ -151,17 +151,43 @@ class Lexer ...@@ -151,17 +151,43 @@ class Lexer
* *
* @return array|null the next token; null if there is no more tokens left * @return array|null the next token; null if there is no more tokens left
*/ */
public function next() public function moveNext()
{ {
$this->token = $this->lookahead; $this->token = $this->lookahead;
$this->_peek = 0; $this->_peek = 0;
if (isset($this->_tokens[$this->_position])) { if (isset($this->_tokens[$this->_position])) {
$this->lookahead = $this->_tokens[$this->_position++]; $this->lookahead = $this->_tokens[$this->_position++];
return true;
} else { } else {
$this->lookahead = null; $this->lookahead = null;
return false;
} }
} }
/**
* Attempts to match the given token with the current lookahead token.
*
* If they match, the lexer moves on to the next token, otherwise a syntax error
* is raised.
*
* @param int|string token type or value
* @return bool True, if tokens match; false otherwise.
*/
/*public function match($token)
{
if (is_string($token)) {
$isMatch = ($this->lookahead['value'] === $token);
} else {
$isMatch = ($this->lookahead['type'] === $token);
}
if ( ! $isMatch) {
$this->syntaxError($this->getLiteral($token));
}
$this->moveNext();
}*/
/** /**
* Checks if an identifier is a keyword and returns its correct type. * Checks if an identifier is a keyword and returns its correct type.
* *
......
...@@ -60,21 +60,21 @@ class Parser ...@@ -60,21 +60,21 @@ class Parser
* *
* @var Doctrine_ORM_Query_Scanner * @var Doctrine_ORM_Query_Scanner
*/ */
protected $_lexer; private $_lexer;
/** /**
* The Parser Result object. * The Parser Result object.
* *
* @var Doctrine_ORM_Query_ParserResult * @var Doctrine_ORM_Query_ParserResult
*/ */
protected $_parserResult; private $_parserResult;
/** /**
* The EntityManager. * The EntityManager.
* *
* @var EnityManager * @var EnityManager
*/ */
protected $_em; private $_em;
/** /**
* Creates a new query parser object. * Creates a new query parser object.
...@@ -131,8 +131,7 @@ class Parser ...@@ -131,8 +131,7 @@ class Parser
$this->syntaxError($this->_lexer->getLiteral($token)); $this->syntaxError($this->_lexer->getLiteral($token));
} }
$this->_lexer->next(); $this->_lexer->moveNext();
return true;
} }
public function isA($value, $token) public function isA($value, $token)
...@@ -322,7 +321,7 @@ class Parser ...@@ -322,7 +321,7 @@ class Parser
*/ */
private function _QueryLanguage() private function _QueryLanguage()
{ {
$this->_lexer->next(); $this->_lexer->moveNext();
switch ($this->_lexer->lookahead['type']) { switch ($this->_lexer->lookahead['type']) {
case Lexer::T_SELECT: case Lexer::T_SELECT:
return $this->_SelectStatement(); return $this->_SelectStatement();
......
...@@ -22,9 +22,10 @@ class AllTests ...@@ -22,9 +22,10 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\Query\IdentifierRecognitionTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\IdentifierRecognitionTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\SelectSqlGenerationTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\SelectSqlGenerationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\LanguageRecognitionTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\LanguageRecognitionTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\LexerTest');
/* /*
$suite->addTestSuite('Orm_Query_ScannerTest');
$suite->addTestSuite('Orm_Query_DqlGenerationTest'); $suite->addTestSuite('Orm_Query_DqlGenerationTest');
$suite->addTestSuite('Orm_Query_DeleteSqlGenerationTest'); $suite->addTestSuite('Orm_Query_DeleteSqlGenerationTest');
$suite->addTestSuite('Orm_Query_UpdateSqlGenerationTest');*/ $suite->addTestSuite('Orm_Query_UpdateSqlGenerationTest');*/
......
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