Commit e1973487 authored by guilhermeblanco's avatar guilhermeblanco

[2.0] Implemented more TODO items. Fixed some grammar rules.

parent 7297ac7b
...@@ -148,13 +148,9 @@ class Parser ...@@ -148,13 +148,9 @@ class Parser
*/ */
public function match($token) public function match($token)
{ {
if (is_string($token)) { $key = (is_string($token)) ? 'value' : 'type';
$isMatch = ($this->_lexer->lookahead['value'] === $token);
} else {
$isMatch = ($this->_lexer->lookahead['type'] === $token);
}
if ( ! $isMatch) { if ( ! ($this->_lexer->lookahead[$key] === $token)) {
$this->syntaxError($this->_lexer->getLiteral($token)); $this->syntaxError($this->_lexer->getLiteral($token));
} }
...@@ -517,7 +513,15 @@ class Parser ...@@ -517,7 +513,15 @@ class Parser
* NewValue ::= SimpleArithmeticExpression | StringPrimary | DatetimePrimary | BooleanPrimary | * NewValue ::= SimpleArithmeticExpression | StringPrimary | DatetimePrimary | BooleanPrimary |
* EnumPrimary | SimpleEntityExpression | "NULL" * EnumPrimary | SimpleEntityExpression | "NULL"
* *
* @todo Implementation still incomplete. * NOTE: Since it is not possible to correctly recognize individual types, here is the full
* grammar that needs to be supported:
*
* NewValue ::= SimpleArithmeticExpression | "NULL"
*
* SimpleArithmeticExpression covers all *Primary grammar rules and also SimplEntityExpression
*
* @todo Find why removal of InputParameter check causes ClassTableInheritanceTest to fail with
* wrong parameter count (Should be processed in Literal, part of SimpleArithmeticExpression)
*/ */
public function NewValue() public function NewValue()
{ {
...@@ -527,12 +531,9 @@ class Parser ...@@ -527,12 +531,9 @@ class Parser
} else if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { } else if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) {
$this->match(Lexer::T_INPUT_PARAMETER); $this->match(Lexer::T_INPUT_PARAMETER);
return new AST\InputParameter($this->_lexer->token['value']); return new AST\InputParameter($this->_lexer->token['value']);
} else if ($this->_lexer->isNextToken(Lexer::T_STRING)) {
//TODO: Can be StringPrimary or EnumPrimary
return $this->StringPrimary();
} else {
$this->syntaxError('Not yet implemented-1.');
} }
return $this->SimpleArithmeticExpression();
} }
/** /**
...@@ -627,12 +628,12 @@ class Parser ...@@ -627,12 +628,12 @@ class Parser
/** /**
* SelectExpression ::= * SelectExpression ::=
* IdentificationVariable | StateFieldPathExpression | * IdentificationVariable | StateFieldPathExpression |
* (AggregateExpression | "(" Subselect ")" | Function) [["AS"] FieldAliasIdentificationVariable] * (AggregateExpression | "(" Subselect ")" | Function) [["AS"] ResultVariable]
*/ */
public function SelectExpression() public function SelectExpression()
{ {
$expression = null; $expression = null;
$fieldIdentificationVariable = null; $fieldAliasIdentificationVariable = null;
$peek = $this->_lexer->glimpse(); $peek = $this->_lexer->glimpse();
// First we recognize for an IdentificationVariable (DQL class alias) // First we recognize for an IdentificationVariable (DQL class alias)
...@@ -656,7 +657,7 @@ class Parser ...@@ -656,7 +657,7 @@ class Parser
} }
if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) { if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) {
$fieldIdentificationVariable = $this->ResultVariable(); $fieldAliasIdentificationVariable = $this->ResultVariable();
} }
} else { } else {
// Deny hydration of partial objects if doctrine.forcePartialLoad query hint not defined // Deny hydration of partial objects if doctrine.forcePartialLoad query hint not defined
...@@ -671,7 +672,7 @@ class Parser ...@@ -671,7 +672,7 @@ class Parser
$expression = $this->StateFieldPathExpression(); $expression = $this->StateFieldPathExpression();
} }
return new AST\SelectExpression($expression, $fieldIdentificationVariable); return new AST\SelectExpression($expression, $fieldAliasIdentificationVariable);
} }
/** /**
...@@ -904,11 +905,6 @@ class Parser ...@@ -904,11 +905,6 @@ class Parser
{ {
$pathExpr = $this->PathExpression(AST\PathExpression::TYPE_STATE_FIELD); $pathExpr = $this->PathExpression(AST\PathExpression::TYPE_STATE_FIELD);
// @TODO It seems PathExpression already checks for the minimum amount of parts
// if (count($pathExpr->getParts()) > 1) {
// $this->syntaxError('SimpleStateFieldPathExpression');
// }
if ( ! empty($this->_deferredPathExpressionStacks)) { if ( ! empty($this->_deferredPathExpressionStacks)) {
$exprStack = array_pop($this->_deferredPathExpressionStacks); $exprStack = array_pop($this->_deferredPathExpressionStacks);
$exprStack[] = $pathExpr; $exprStack[] = $pathExpr;
...@@ -1210,25 +1206,32 @@ class Parser ...@@ -1210,25 +1206,32 @@ class Parser
/** /**
* GroupByClause ::= "GROUP" "BY" GroupByItem {"," GroupByItem}* * GroupByClause ::= "GROUP" "BY" GroupByItem {"," GroupByItem}*
* GroupByItem ::= IdentificationVariable | SingleValuedPathExpression
* @todo Implementation incomplete for GroupByItem.
*/ */
public function GroupByClause() public function GroupByClause()
{ {
$this->match(Lexer::T_GROUP); $this->match(Lexer::T_GROUP);
$this->match(Lexer::T_BY); $this->match(Lexer::T_BY);
$groupByItems = array(); $groupByItems = array($this->GroupByItem());
$groupByItems[] = $this->StateFieldPathExpression();
while ($this->_lexer->isNextToken(',')) { while ($this->_lexer->isNextToken(',')) {
$this->match(','); $this->match(',');
$groupByItems[] = $this->StateFieldPathExpression(); $groupByItems[] = $this->GroupByItem();
} }
return new AST\GroupByClause($groupByItems); return new AST\GroupByClause($groupByItems);
} }
/**
* GroupByItem ::= IdentificationVariable | SingleValuedPathExpression
*
* @todo Finish this implementation
*/
public function GroupByItem()
{
return $this->SingleValuedPathExpression();
}
/** /**
* HavingClause ::= "HAVING" ConditionalExpression * HavingClause ::= "HAVING" ConditionalExpression
*/ */
...@@ -1360,11 +1363,10 @@ class Parser ...@@ -1360,11 +1363,10 @@ class Parser
$condPrimary = new AST\ConditionalPrimary; $condPrimary = new AST\ConditionalPrimary;
if ($this->_lexer->isNextToken('(')) { if ($this->_lexer->isNextToken('(')) {
$peek = $this->_lexer->peek();
// We need to inner inspect for a subselect (ArithmeticExpression) // We need to inner inspect for a subselect (ArithmeticExpression)
if ($peek['type'] != Lexer::T_SELECT) { if ( ! $this->_isSubselect()) {
// Peek beyond and not until matching closing parenthesis // Peek beyond and not until matching closing parenthesis
$peek = $this->_lexer->peek();
$arithmeticOps = array("+", "-", "*", "/"); $arithmeticOps = array("+", "-", "*", "/");
$numUnmatched = 1; $numUnmatched = 1;
...@@ -1859,7 +1861,7 @@ class Parser ...@@ -1859,7 +1861,7 @@ class Parser
} }
/** /**
* SimpleSelectExpression ::= StateFieldPathExpression | IdentificationVariable | (AggregateExpression [["AS"] FieldAliasIdentificationVariable]) * SimpleSelectExpression ::= StateFieldPathExpression | IdentificationVariable | (AggregateExpression [["AS"] ResultVariable])
*/ */
public function SimpleSelectExpression() public function SimpleSelectExpression()
{ {
...@@ -1882,8 +1884,7 @@ class Parser ...@@ -1882,8 +1884,7 @@ class Parser
} }
if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) { if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) {
$this->match(Lexer::T_IDENTIFIER); $expr->setFieldIdentificationVariable($this->ResultVariable());
$expr->setFieldIdentificationVariable($this->_lexer->token['value']);
} }
return $expr; return $expr;
......
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