[API] Make all constructors specialized

For nodes that accept many optional arguments I chose to keep the $subNodes argument, but provide default values instead.
This commit is contained in:
nikic 2011-10-28 19:06:24 +02:00
parent 5f0a1535ff
commit f202aa9814
15 changed files with 322 additions and 103 deletions

View File

@ -13,10 +13,12 @@ What do all those files mean?
The `.phpy` file is a normal grammer in `kmyacc` (`yacc`) style, with some transformations
applied to it:
* Nodes are created using the syntax `Name[subNode1: ..., subNode2: ...]`. This is transformed into
`new PHPParser_Node_Name(array('subNode1' => ..., 'subNode2' => ...), $line, $docComment)`
* Nodes are created using the syntax `Name[..., ...]`. This is transformed into
`new PHPParser_Node_Name(..., ..., $line, $docComment)`
* `Name::abc` is transformed to `PHPParser_Node_Name::abc`
* Some function-like constructs are resolved (see `rebuildParser.php` for a list)
* Associative arrays are written as `[key: value, ...]`, which is transformed to
`array('key' => value, ...)`
Building the parser
===================

View File

@ -29,9 +29,10 @@ echo 'Building temporary preproprocessed grammar file.', "\n";
$grammarCode = file_get_contents(GRAMMAR_FILE);
$grammarCode = preg_replace('~[A-Z][a-zA-Z_]++::~', 'PHPParser_Node_$0', $grammarCode);
$grammarCode = resolveConstants($grammarCode);
$grammarCode = resolveNodes($grammarCode);
$grammarCode = resolveMacros($grammarCode);
$grammarCode = resolveArrays($grammarCode);
file_put_contents(TMP_FILE, $grammarCode);
@ -57,6 +58,10 @@ echo '</pre>';
/// Preprocessing functions ///
///////////////////////////////
function resolveConstants($code) {
return preg_replace('~[A-Z][a-zA-Z_]++::~', 'PHPParser_Node_$0', $code);
}
function resolveNodes($code) {
return preg_replace_callback(
'~(?<name>[A-Z][a-zA-Z_]++)\s*' . PARAMS . '~',
@ -69,29 +74,12 @@ function resolveNodes($code) {
$matches['params']
);
if (array() === $params) {
return 'new PHPParser_Node_' . $matches['name'] . '($line, $docComment)';
}
$withArray = false;
$paramCodes = array();
$paramCode = '';
foreach ($params as $param) {
if (false !== strpos($param, ': ')) {
$withArray = true;
list($key, $value) = explode(': ', $param, 2);
$paramCodes[] = '\'' . $key . '\' => ' . $value;
} else {
$paramCodes[] = $param;
}
$paramCode .= $param . ', ';
}
if (!$withArray) {
return 'new PHPParser_Node_' . $matches['name'] . '(' . implode(', ', $paramCodes) . ', $line, $docComment)';
} else {
return 'new PHPParser_Node_' . $matches['name'] . '(array(' . implode(', ', $paramCodes) . '), $line, $docComment)';
}
return 'new PHPParser_Node_' . $matches['name'] . '(' . $paramCode . '$line, $docComment)';
},
$code
);
@ -99,7 +87,7 @@ function resolveNodes($code) {
function resolveMacros($code) {
return preg_replace_callback(
'~(?<name>error|init|push|pushNormalizing|toArray|parse(?:Var|LNumber|DNumber|Encapsed))' . ARGS . '~',
'~\b(?<!::|->)(?!array\()(?<name>[a-z][A-Za-z]++)' . ARGS . '~',
function($matches) {
// recurse
$matches['args'] = resolveMacros($matches['args']);
@ -161,6 +149,8 @@ function resolveMacros($code) {
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = PHPParser_Node_Scalar_String::parseEscapeSequences($s, ' . $args[1] . '); } }';
}
throw new Exception(sprintf('Unknown macro "%s"', $name));
},
$code
);
@ -172,6 +162,37 @@ function assertArgs($num, $args, $name) {
}
}
function resolveArrays($code) {
return preg_replace_callback(
'~' . PARAMS . '~',
function ($matches) {
$elements = magicSplit(
'(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,',
$matches['params']
);
// don't convert [] to array, it might have different meaning
if (empty($elements)) {
return $matches[0];
}
$elementCodes = array();
foreach ($elements as $element) {
// convert only arrays where all elements have keys
if (false === strpos($element, ':')) {
return $matches[0];
}
list($key, $value) = explode(':', $element, 2);
$elementCodes[] = "'" . $key . "' =>" . $value;
}
return 'array(' . implode(', ', $elementCodes) . ')';
},
$code
);
}
//////////////////////////////
/// Regex helper functions ///
//////////////////////////////

View File

@ -168,13 +168,13 @@ inner_statement:
statement:
'{' inner_statement_list '}' { $$ = $2; }
| T_IF '(' expr ')' statement elseif_list else_single { $$ = Stmt_If[cond: $3, stmts: toArray($5), elseifList: $6, else: $7]; }
| T_IF '(' expr ')' statement elseif_list else_single { $$ = Stmt_If[$3, [stmts: toArray($5), elseifs: $6, else: $7]]; }
| T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
{ $$ = Stmt_If[cond: $3, stmts: $6, elseifList: $7, else: $8]; }
{ $$ = Stmt_If[$3, [stmts: $6, elseifs: $7, else: $8]]; }
| T_WHILE '(' expr ')' while_statement { $$ = Stmt_While[$3, toArray($5)]; }
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = Stmt_Do [$5, toArray($2)]; }
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
{ $$ = Stmt_For[init: $3, cond: $5, loop: $7, stmts: toArray($9)]; }
{ $$ = Stmt_For[[init: $3, cond: $5, loop: $7, stmts: toArray($9)]]; }
| T_SWITCH '(' expr ')' switch_case_list { $$ = Stmt_Switch[$3, $5]; }
| T_BREAK ';' { $$ = Stmt_Break[null]; }
| T_BREAK expr ';' { $$ = Stmt_Break[$2]; }
@ -189,11 +189,11 @@ statement:
| expr ';' { $$ = $1; }
| T_UNSET '(' variables_list ')' ';' { $$ = Stmt_Unset[$3]; }
| T_FOREACH '(' expr T_AS variable ')' foreach_statement
{ $$ = Stmt_Foreach[expr: $3, keyVar: null, byRef: false, valueVar: $5, stmts: toArray($7)]; }
{ $$ = Stmt_Foreach[$3, $5, [keyVar: null, byRef: false, stmts: toArray($7)]]; }
| T_FOREACH '(' expr T_AS '&' variable ')' foreach_statement
{ $$ = Stmt_Foreach[expr: $3, keyVar: null, byRef: true, valueVar: $6, stmts: toArray($8)]; }
{ $$ = Stmt_Foreach[$3, $6, [keyVar: null, byRef: true, stmts: toArray($8)]]; }
| T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW optional_ref variable ')' foreach_statement
{ $$ = Stmt_Foreach[expr: $3, keyVar: $5, byRef: $7, valueVar: $8, stmts: toArray($10)]; }
{ $$ = Stmt_Foreach[$3, $8, [keyVar: $5, byRef: $7, stmts: toArray($10)]]; }
| T_DECLARE '(' declare_list ')' declare_statement { $$ = Stmt_Declare[$3, toArray($5)]; }
| ';' { $$ = array(); /* means: no statement */ }
| T_TRY '{' inner_statement_list '}' catches { $$ = Stmt_TryCatch[$3, $5]; }
@ -224,14 +224,14 @@ optional_ref:
function_declaration_statement:
T_FUNCTION optional_ref T_STRING '(' parameter_list ')' '{' inner_statement_list '}'
{ $$ = Stmt_Func[byRef: $2, name: $3, params: $5, stmts: $8]; }
{ $$ = Stmt_Func[$3, [byRef: $2, params: $5, stmts: $8]]; }
;
class_declaration_statement:
class_entry_type T_STRING extends_from implements_list '{' class_statement_list '}'
{ $$ = Stmt_Class[type: $1, name: $2, extends: $3, implements: $4, stmts: $6]; }
{ $$ = Stmt_Class[$2, [type: $1, extends: $3, implements: $4, stmts: $6]]; }
| T_INTERFACE T_STRING interface_extends_list '{' class_statement_list '}'
{ $$ = Stmt_Interface[name: $2, extends: $3, stmts: $5]; }
{ $$ = Stmt_Interface[$2, [extends: $3, stmts: $5]]; }
;
class_entry_type:
@ -307,23 +307,23 @@ while_statement:
elseif_list:
/* empty */ { init();}
| elseif_list T_ELSEIF '(' expr ')' statement { push($1, Stmt_ElseIf[cond: $4, stmts: toArray($6)]); }
| elseif_list T_ELSEIF '(' expr ')' statement { push($1, Stmt_ElseIf[$4, toArray($6)]); }
;
new_elseif_list:
/* empty */ { init(); }
| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
{ push($1, Stmt_ElseIf[cond: $4, stmts: $7]); }
{ push($1, Stmt_ElseIf[$4, $7]); }
;
else_single:
/* empty */ { $$ = null; }
| T_ELSE statement { $$ = Stmt_Else[stmts: toArray($2)]; }
| T_ELSE statement { $$ = Stmt_Else[toArray($2)]; }
;
new_else_single:
/* empty */ { $$ = null; }
| T_ELSE ':' inner_statement_list { $$ = Stmt_Else[stmts: $3]; }
| T_ELSE ':' inner_statement_list { $$ = Stmt_Else[$3]; }
;
parameter_list:
@ -390,7 +390,7 @@ class_statement:
variable_modifiers class_variable_declaration ';' { $$ = Stmt_Property[$1, $2]; }
| T_CONST constant_declaration_list ';' { $$ = Stmt_ClassConst[$2]; }
| method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' method_body
{ $$ = Stmt_ClassMethod[type: $1, byRef: $3, name: $4, params: $6, stmts: $8]; }
{ $$ = Stmt_ClassMethod[$4, [type: $1, byRef: $3, params: $6, stmts: $8]]; }
;
method_body:
@ -522,7 +522,7 @@ expr:
| '`' backticks_expr '`' { $$ = Expr_ShellExec[$2]; }
| T_PRINT expr { $$ = Expr_Print[$2]; }
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
{ $$ = Expr_Closure[$8, $4, $6, $2]; }
{ $$ = Expr_Closure[[byRef: $2, params: $4, uses: $6, stmts: $8]]; }
;
lexical_vars:

View File

@ -11,20 +11,21 @@ class PHPParser_Node_Expr_Closure extends PHPParser_Node_Expr
/**
* Constructs a lambda function node.
*
* @param PHPParser_Node[] $stmts Statements
* @param PHPParser_Node_Stmt_FuncParam[] $params Parameters
* @param PHPParser_Node_Expr_ClosureUse[] $uses use()s
* @param bool $byRef Whether to return by reference
* @param int $line Line
* @param null|string $docComment Nearest doc comment
* @param array $subNodes Array of the following optional subnodes:
* 'stmts' => array(): Statements
* 'params' => array(): Parameters
* 'uses' => array(): use()s
* 'byRef' => false : Whether to return by reference
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $stmts, array $params = array(), array $uses = array(), $byRef = false, $line = -1, $docComment = null) {
public function __construct(array $subNodes = array(), $line = -1, $docComment = null) {
parent::__construct(
array(
'stmts' => $stmts,
'params' => $params,
'uses' => $uses,
'byRef' => $byRef
$subNodes + array(
'stmts' => array(),
'params' => array(),
'uses' => array(),
'byRef' => false,
),
$line, $docComment
);

View File

@ -4,8 +4,8 @@
* @property int $type Type
* @property string $name Name
* @property null|PHPParser_Node_Name $extends Name of extended class
* @property array $implements Names of implemented interfaces
* @property array $stmts Statements
* @property PHPParser_Node_Name[] $implements Names of implemented interfaces
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_Class extends PHPParser_Node_Stmt
{
@ -16,19 +16,46 @@ class PHPParser_Node_Stmt_Class extends PHPParser_Node_Stmt
const MODIFIER_ABSTRACT = 16;
const MODIFIER_FINAL = 32;
public function __construct(array $subNodes, $line = -1, $docComment = null) {
parent::__construct($subNodes, $line, $docComment);
protected static $specialClassNames = array(
'self' => true,
'parent' => true,
'static' => true,
);
if ('self' == $this->name || 'parent' == $this->name) { // 'static' cannot occur
/**
* Constructs a class node.
*
* @param string $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'type' => 0 : Type
* 'extends' => null : Name of extended class
* 'implements' => array(): Names of implemented interfaces
* 'stmts' => array(): Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($name, array $subNodes, $line = -1, $docComment = null) {
parent::__construct(
$subNodes + array(
'type' => 0,
'extends' => null,
'implements' => array(),
'stmts' => array(),
),
$line, $docComment
);
$this->name = $name;
if (isset(self::$specialClassNames[(string) $this->name])) {
throw new PHPParser_Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->name));
}
if ('self' == $this->extends || 'parent' == $this->extends || 'static' == $this->extends) {
if (isset(self::$specialClassNames[(string) $this->extends])) {
throw new PHPParser_Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->extends));
}
foreach ($this->implements as $interface) {
if ('self' == $interface || 'parent' == $interface || 'static' == $interface) {
if (isset(self::$specialClassNames[(string) $interface])) {
throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface));
}
}

View File

@ -1,16 +1,38 @@
<?php
/**
* @property int $type Type
* @property bool $byRef Whether to return by reference
* @property string $name Name
* @property array $params Parameters
* @property array $stmts Statements
* @property int $type Type
* @property bool $byRef Whether to return by reference
* @property string $name Name
* @property PHPParser_Node_Param[] $params Parameters
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_ClassMethod extends PHPParser_Node_Stmt
{
public function __construct(array $subNodes, $line = -1, $docComment = null) {
parent::__construct($subNodes, $line, $docComment);
/**
* Constructs a class method node.
*
* @param string $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'type' => MODIFIER_PUBLIC: Type
* 'byRef' => false : Whether to return by reference
* 'params' => array() : Parameters
* 'stmts' => array() : Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($name, array $subNodes, $line = -1, $docComment = null) {
parent::__construct(
$subNodes + array(
'type' => PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC,
'byRef' => false,
'params' => array(),
'stmts' => array(),
),
$line, $docComment
);
$this->name = $name;
if (($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC)
&& ('__construct' == $this->name || '__destruct' == $this->name || '__clone' == $this->name)

View File

@ -1,8 +1,23 @@
<?php
/**
* @property array $stmts Statements
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_Else extends PHPParser_Node_Stmt
{
/**
* Constructs an else node.
*
* @param PHPParser_Node[] $stmts Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $stmts, $line = -1, $docComment = null) {
parent::__construct(
array(
'stmts' => $stmts,
),
$line, $docComment
);
}
}

View File

@ -2,8 +2,25 @@
/**
* @property PHPParser_Node_Expr $cond Condition
* @property array $stmts Statements
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_ElseIf extends PHPParser_Node_Stmt
{
/**
* Constructs an elseif node.
*
* @param PHPParser_Node_Expr $cond Condition
* @param PHPParser_Node[] $stmts Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($cond, array $stmts, $line = -1, $docComment = null) {
parent::__construct(
array(
'cond' => $cond,
'stmts' => $stmts,
),
$line, $docComment
);
}
}

View File

@ -1,11 +1,33 @@
<?php
/**
* @property array $init Init expression
* @property array $cond Loop condition
* @property array $loop Loop expression
* @property array $stmts Statements
* @property PHPParser_Node_Expr[] $init Init expressions
* @property PHPParser_Node_Expr[] $cond Loop conditions
* @property PHPParser_Node_Expr[] $loop Loop expressions
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_For extends PHPParser_Node_Stmt
{
/**
* Constructs a for loop node.
*
* @param array $subNodes Array of the following optional subnodes:
* 'init' => array(): Init expressions
* 'cond' => array(): Loop conditions
* 'loop' => array(): Loop expressions
* 'stmts' => array(): Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $subNodes = array(), $line = -1, $docComment = null) {
parent::__construct(
$subNodes + array(
'init' => array(),
'cond' => array(),
'loop' => array(),
'stmts' => array(),
),
$line, $docComment
);
}
}

View File

@ -5,8 +5,32 @@
* @property null|PHPParser_Node_Expr $keyVar Variable to assign key to
* @property bool $byRef Whether to assign value by reference
* @property PHPParser_Node_Expr $valueVar Variable to assign value to
* @property array $stmts Statements
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_Foreach extends PHPParser_Node_Stmt
{
/**
* Constructs a foreach node.
*
* @param PHPParser_Node_Expr $expr Expression to iterate
* @param PHPParser_Node_Expr $valueVar Variable to assign value to
* @param array $subNodes Array of the following optional subnodes:
* 'keyVar' => null : Variable to assign key to
* 'byRef' => false : Whether to assign value by reference
* 'stmts' => array(): Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(PHPParser_Node_Expr $expr, PHPParser_Node_Expr $valueVar, array $subNodes, $line = -1, $docComment = null) {
parent::__construct(
$subNodes + array(
'keyVar' => null,
'byRef' => false,
'stmts' => array(),
),
$line, $docComment
);
$this->expr = $expr;
$this->valueVar = $valueVar;
}
}

View File

@ -1,11 +1,33 @@
<?php
/**
* @property bool $byRef Whether returns by reference
* @property string $name Name
* @property array $params Parameters
* @property array $stmts Statements
* @property bool $byRef Whether returns by reference
* @property string $name Name
* @property PHPParser_Node_Param[] $params Parameters
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_Func extends PHPParser_Node_Stmt
{
/**
* Constructs a function node.
*
* @param string $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'byRef' => false : Whether to return by reference
* 'params' => array(): Parameters
* 'stmts' => array(): Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($name, array $subNodes, $line = -1, $docComment = null) {
parent::__construct(
$subNodes + array(
'byRef' => false,
'params' => array(),
'stmts' => array(),
),
$line, $docComment
);
$this->name = $name;
}
}

View File

@ -1,11 +1,34 @@
<?php
/**
* @property PHPParser_Node_Expr $cond Condition expression
* @property array $stmts Statements
* @property array $elseifList Elseif clauses
* @property null|PHPParser_Node_Stmt_Else $else Else clause
* @property PHPParser_Node_Expr $cond Condition expression
* @property PHPParser_Node[] $stmts Statements
* @property PHPParser_Node_Stmt_ElseIf[] $elseifs Elseif clauses
* @property null|PHPParser_Node_Stmt_Else $else Else clause
*/
class PHPParser_Node_Stmt_If extends PHPParser_Node_Stmt
{
/**
* Constructs an if node.
*
* @param PHPParser_Node_Expr $cond Condition
* @param array $subNodes Array of the following optional subnodes:
* 'stmts' => array(): Statements
* 'elseifs' => array(): Elseif clauses
* 'else' => null : Else clause
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(PHPParser_Node_Expr $cond, array $subNodes, $line = -1, $docComment = null) {
parent::__construct(
$subNodes + array(
'stmts' => array(),
'elseifs' => array(),
'else' => null,
),
$line, $docComment
);
$this->cond = $cond;
}
}

View File

@ -1,21 +1,44 @@
<?php
/**
* @property string $name Name
* @property array $extends Extended interfaces
* @property array $stmts Statements
* @property string $name Name
* @property PHPParser_Node_Name[] $extends Extended interfaces
* @property PHPParser_Node[] $stmts Statements
*/
class PHPParser_Node_Stmt_Interface extends PHPParser_Node_Stmt
{
public function __construct(array $subNodes, $line = -1, $docComment = null) {
parent::__construct($subNodes, $line, $docComment);
protected static $specialInterfaceNames = array(
'self' => true,
'parent' => true,
'static' => true,
);
if ('self' == $this->name || 'parent' == $this->name) { // 'static' cannot occur
throw new PHPParser_Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->name));
/**
* Constructs a class node.
*
* @param string $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'extends' => array(): Name of extended interfaces
* 'stmts' => array(): Statements
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($name, array $subNodes, $line = -1, $docComment = null) {
parent::__construct(
$subNodes + array(
'extends' => array(),
'stmts' => array(),
),
$line, $docComment
);
$this->name = $name;
if (isset(self::$specialInterfaceNames[(string) $this->name])) {
throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $this->name));
}
foreach ($this->extends as $interface) {
if ('self' == $interface || 'parent' == $interface || 'static' == $interface) {
if (isset(self::$specialInterfaceNames[(string) $interface])) {
throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface));
}
}

View File

@ -1099,11 +1099,11 @@ class PHPParser_Parser
}
protected function yyn31($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_If(array('cond' => $this->yyastk[$this->yysp-(7-3)], 'stmts' => is_array($this->yyastk[$this->yysp-(7-5)]) ? $this->yyastk[$this->yysp-(7-5)] : array($this->yyastk[$this->yysp-(7-5)]), 'elseifList' => $this->yyastk[$this->yysp-(7-6)], 'else' => $this->yyastk[$this->yysp-(7-7)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_If($this->yyastk[$this->yysp-(7-3)], array('stmts' => is_array($this->yyastk[$this->yysp-(7-5)]) ? $this->yyastk[$this->yysp-(7-5)] : array($this->yyastk[$this->yysp-(7-5)]), 'elseifs' => $this->yyastk[$this->yysp-(7-6)], 'else' => $this->yyastk[$this->yysp-(7-7)]), $line, $docComment);
}
protected function yyn32($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_If(array('cond' => $this->yyastk[$this->yysp-(10-3)], 'stmts' => $this->yyastk[$this->yysp-(10-6)], 'elseifList' => $this->yyastk[$this->yysp-(10-7)], 'else' => $this->yyastk[$this->yysp-(10-8)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_If($this->yyastk[$this->yysp-(10-3)], array('stmts' => $this->yyastk[$this->yysp-(10-6)], 'elseifs' => $this->yyastk[$this->yysp-(10-7)], 'else' => $this->yyastk[$this->yysp-(10-8)]), $line, $docComment);
}
protected function yyn33($line, $docComment) {
@ -1171,15 +1171,15 @@ class PHPParser_Parser
}
protected function yyn49($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Foreach(array('expr' => $this->yyastk[$this->yysp-(7-3)], 'keyVar' => null, 'byRef' => false, 'valueVar' => $this->yyastk[$this->yysp-(7-5)], 'stmts' => is_array($this->yyastk[$this->yysp-(7-7)]) ? $this->yyastk[$this->yysp-(7-7)] : array($this->yyastk[$this->yysp-(7-7)])), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Foreach($this->yyastk[$this->yysp-(7-3)], $this->yyastk[$this->yysp-(7-5)], array('keyVar' => null, 'byRef' => false, 'stmts' => is_array($this->yyastk[$this->yysp-(7-7)]) ? $this->yyastk[$this->yysp-(7-7)] : array($this->yyastk[$this->yysp-(7-7)])), $line, $docComment);
}
protected function yyn50($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Foreach(array('expr' => $this->yyastk[$this->yysp-(8-3)], 'keyVar' => null, 'byRef' => true, 'valueVar' => $this->yyastk[$this->yysp-(8-6)], 'stmts' => is_array($this->yyastk[$this->yysp-(8-8)]) ? $this->yyastk[$this->yysp-(8-8)] : array($this->yyastk[$this->yysp-(8-8)])), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Foreach($this->yyastk[$this->yysp-(8-3)], $this->yyastk[$this->yysp-(8-6)], array('keyVar' => null, 'byRef' => true, 'stmts' => is_array($this->yyastk[$this->yysp-(8-8)]) ? $this->yyastk[$this->yysp-(8-8)] : array($this->yyastk[$this->yysp-(8-8)])), $line, $docComment);
}
protected function yyn51($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Foreach(array('expr' => $this->yyastk[$this->yysp-(10-3)], 'keyVar' => $this->yyastk[$this->yysp-(10-5)], 'byRef' => $this->yyastk[$this->yysp-(10-7)], 'valueVar' => $this->yyastk[$this->yysp-(10-8)], 'stmts' => is_array($this->yyastk[$this->yysp-(10-10)]) ? $this->yyastk[$this->yysp-(10-10)] : array($this->yyastk[$this->yysp-(10-10)])), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Foreach($this->yyastk[$this->yysp-(10-3)], $this->yyastk[$this->yysp-(10-8)], array('keyVar' => $this->yyastk[$this->yysp-(10-5)], 'byRef' => $this->yyastk[$this->yysp-(10-7)], 'stmts' => is_array($this->yyastk[$this->yysp-(10-10)]) ? $this->yyastk[$this->yysp-(10-10)] : array($this->yyastk[$this->yysp-(10-10)])), $line, $docComment);
}
protected function yyn52($line, $docComment) {
@ -1235,15 +1235,15 @@ class PHPParser_Parser
}
protected function yyn65($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Func(array('byRef' => $this->yyastk[$this->yysp-(9-2)], 'name' => $this->yyastk[$this->yysp-(9-3)], 'params' => $this->yyastk[$this->yysp-(9-5)], 'stmts' => $this->yyastk[$this->yysp-(9-8)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Func($this->yyastk[$this->yysp-(9-3)], array('byRef' => $this->yyastk[$this->yysp-(9-2)], 'params' => $this->yyastk[$this->yysp-(9-5)], 'stmts' => $this->yyastk[$this->yysp-(9-8)]), $line, $docComment);
}
protected function yyn66($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Class(array('type' => $this->yyastk[$this->yysp-(7-1)], 'name' => $this->yyastk[$this->yysp-(7-2)], 'extends' => $this->yyastk[$this->yysp-(7-3)], 'implements' => $this->yyastk[$this->yysp-(7-4)], 'stmts' => $this->yyastk[$this->yysp-(7-6)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Class($this->yyastk[$this->yysp-(7-2)], array('type' => $this->yyastk[$this->yysp-(7-1)], 'extends' => $this->yyastk[$this->yysp-(7-3)], 'implements' => $this->yyastk[$this->yysp-(7-4)], 'stmts' => $this->yyastk[$this->yysp-(7-6)]), $line, $docComment);
}
protected function yyn67($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Interface(array('name' => $this->yyastk[$this->yysp-(6-2)], 'extends' => $this->yyastk[$this->yysp-(6-3)], 'stmts' => $this->yyastk[$this->yysp-(6-5)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Interface($this->yyastk[$this->yysp-(6-2)], array('extends' => $this->yyastk[$this->yysp-(6-3)], 'stmts' => $this->yyastk[$this->yysp-(6-5)]), $line, $docComment);
}
protected function yyn68($line, $docComment) {
@ -1371,7 +1371,7 @@ class PHPParser_Parser
}
protected function yyn99($line, $docComment) {
$this->yyastk[$this->yysp-(6-1)][] = new PHPParser_Node_Stmt_ElseIf(array('cond' => $this->yyastk[$this->yysp-(6-4)], 'stmts' => is_array($this->yyastk[$this->yysp-(6-6)]) ? $this->yyastk[$this->yysp-(6-6)] : array($this->yyastk[$this->yysp-(6-6)])), $line, $docComment); $this->yyval = $this->yyastk[$this->yysp-(6-1)];
$this->yyastk[$this->yysp-(6-1)][] = new PHPParser_Node_Stmt_ElseIf($this->yyastk[$this->yysp-(6-4)], is_array($this->yyastk[$this->yysp-(6-6)]) ? $this->yyastk[$this->yysp-(6-6)] : array($this->yyastk[$this->yysp-(6-6)]), $line, $docComment); $this->yyval = $this->yyastk[$this->yysp-(6-1)];
}
protected function yyn100($line, $docComment) {
@ -1379,7 +1379,7 @@ class PHPParser_Parser
}
protected function yyn101($line, $docComment) {
$this->yyastk[$this->yysp-(7-1)][] = new PHPParser_Node_Stmt_ElseIf(array('cond' => $this->yyastk[$this->yysp-(7-4)], 'stmts' => $this->yyastk[$this->yysp-(7-7)]), $line, $docComment); $this->yyval = $this->yyastk[$this->yysp-(7-1)];
$this->yyastk[$this->yysp-(7-1)][] = new PHPParser_Node_Stmt_ElseIf($this->yyastk[$this->yysp-(7-4)], $this->yyastk[$this->yysp-(7-7)], $line, $docComment); $this->yyval = $this->yyastk[$this->yysp-(7-1)];
}
protected function yyn102($line, $docComment) {
@ -1387,7 +1387,7 @@ class PHPParser_Parser
}
protected function yyn103($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Else(array('stmts' => is_array($this->yyastk[$this->yysp-(2-2)]) ? $this->yyastk[$this->yysp-(2-2)] : array($this->yyastk[$this->yysp-(2-2)])), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Else(is_array($this->yyastk[$this->yysp-(2-2)]) ? $this->yyastk[$this->yysp-(2-2)] : array($this->yyastk[$this->yysp-(2-2)]), $line, $docComment);
}
protected function yyn104($line, $docComment) {
@ -1395,7 +1395,7 @@ class PHPParser_Parser
}
protected function yyn105($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Else(array('stmts' => $this->yyastk[$this->yysp-(3-3)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Else($this->yyastk[$this->yysp-(3-3)], $line, $docComment);
}
protected function yyn106($line, $docComment) {
@ -1515,7 +1515,7 @@ class PHPParser_Parser
}
protected function yyn135($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_ClassMethod(array('type' => $this->yyastk[$this->yysp-(8-1)], 'byRef' => $this->yyastk[$this->yysp-(8-3)], 'name' => $this->yyastk[$this->yysp-(8-4)], 'params' => $this->yyastk[$this->yysp-(8-6)], 'stmts' => $this->yyastk[$this->yysp-(8-8)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_ClassMethod($this->yyastk[$this->yysp-(8-4)], array('type' => $this->yyastk[$this->yysp-(8-1)], 'byRef' => $this->yyastk[$this->yysp-(8-3)], 'params' => $this->yyastk[$this->yysp-(8-6)], 'stmts' => $this->yyastk[$this->yysp-(8-8)]), $line, $docComment);
}
protected function yyn136($line, $docComment) {
@ -1907,7 +1907,7 @@ class PHPParser_Parser
}
protected function yyn233($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_Closure($this->yyastk[$this->yysp-(9-8)], $this->yyastk[$this->yysp-(9-4)], $this->yyastk[$this->yysp-(9-6)], $this->yyastk[$this->yysp-(9-2)], $line, $docComment);
$this->yyval = new PHPParser_Node_Expr_Closure(array('byRef' => $this->yyastk[$this->yysp-(9-2)], 'params' => $this->yyastk[$this->yysp-(9-4)], 'uses' => $this->yyastk[$this->yysp-(9-6)], 'stmts' => $this->yyastk[$this->yysp-(9-8)]), $line, $docComment);
}
protected function yyn234($line, $docComment) {

View File

@ -509,7 +509,7 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
public function pStmt_If(PHPParser_Node_Stmt_If $node) {
return 'if (' . $this->p($node->cond) . ') {'
. "\n" . $this->pStmts($node->stmts) . "\n" . '}'
. $this->pImplode($node->elseifList)
. $this->pImplode($node->elseifs)
. (null !== $node->else ? $this->p($node->else) : '');
}