Fix parsing of static methods with dynamic method name

This commit is contained in:
nikic 2011-06-02 16:29:28 +02:00
parent fabe44ecb1
commit 1c4d47613c
7 changed files with 15598 additions and 16022 deletions

View File

@ -152,7 +152,5 @@ For the code mentioned in the above section this should create the output:
Known Issues
============
* Parsing expressions of type `a::$b[c]()` (I.e. the method name is specifed by an array)
currently does not work (causes 1 parse fail in test against Symfony Beta 3).
* When pretty printing strings and InlineHTML those are indented like any other code, thus causing
extra whitespace to be inserted (causes 23 compare fails in test against Symfony Beta 3).

File diff suppressed because it is too large Load Diff

View File

@ -544,12 +544,23 @@ function_call:
name '(' function_call_argument_list ')' { $$ = new Node_Expr_FuncCall(array('func' => $1, 'args' => $3)); }
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
{ $$ = new Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5)); }
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects '(' function_call_argument_list ')'
{ $$ = new Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5)); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
{ $$ = new Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5)); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM variable_without_objects '(' function_call_argument_list ')'
{ $$ = new Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5)); }
| static_property_with_arrays '(' function_call_argument_list ')' {
if ($1 instanceof Node_Expr_StaticPropertyFetch) {
$$ = new Node_Expr_StaticCall(array('class' => $1->class, 'func' => $1->name, 'args' => $3));
} elseif ($1 instanceof Node_Expr_ArrayDimFetch) {
$2 = $1; // $2 is just a temporary variable. Nothing to do with the '('
while ($2->var instanceof Node_Expr_ArrayDimFetch) {
$2 = $2->var;
}
$$ = new Node_Expr_StaticCall(array('class' => $2->var->class, 'func' => $1, 'args' => $3));
$2->var = new Node_Variable(array('name' => $2->var->name));
} else {
throw new Exception;
}
}
| variable_without_objects '(' function_call_argument_list ')'
{ $$ = new Node_Expr_FuncCall(array('func' => $1, 'args' => $3)); }
;

View File

@ -544,12 +544,23 @@ function_call:
name '(' function_call_argument_list ')' { $$ = Expr_FuncCall[func: $1, args: $3]; }
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
{ $$ = Expr_StaticCall[class: $1, func: $3, args: $5]; }
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects '(' function_call_argument_list ')'
{ $$ = Expr_StaticCall[class: $1, func: $3, args: $5]; }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
{ $$ = Expr_StaticCall[class: $1, func: $3, args: $5]; }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM variable_without_objects '(' function_call_argument_list ')'
{ $$ = Expr_StaticCall[class: $1, func: $3, args: $5]; }
| static_property_with_arrays '(' function_call_argument_list ')' {
if ($1 instanceof Node_Expr_StaticPropertyFetch) {
$$ = Expr_StaticCall[class: $1->class, func: $1->name, args: $3];
} elseif ($1 instanceof Node_Expr_ArrayDimFetch) {
$2 = $1; // $2 is just a temporary variable. Nothing to do with the '('
while ($2->var instanceof Node_Expr_ArrayDimFetch) {
$2 = $2->var;
}
$$ = Expr_StaticCall[class: $2->var->class, func: $1, args: $3];
$2->var = Variable[name: $2->var->name];
} else {
throw new Exception;
}
}
| variable_without_objects '(' function_call_argument_list ')'
{ $$ = Expr_FuncCall[func: $1, args: $3]; }
;

View File

@ -30,6 +30,16 @@ abstract class NodeAbstract implements IteratorAggregate
return $this->subNodes[$name];
}
/**
* Sets a sub node.
*
* @param string $name Name of sub node
* @param mixed $value Value to set sub node to
*/
public function __set($name, $value) {
$this->subNodes[$name] = $value;
}
/**
* Checks whether a subnode exists.
*

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff