1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-11 17:09:41 +01:00

Give all Scalar nodes and the special nodes Name and Variable specialized constructors for easier use

This commit is contained in:
nikic 2011-08-09 14:55:45 +02:00
parent 800bb9d94a
commit f67ff50550
19 changed files with 276 additions and 113 deletions

View File

@ -99,14 +99,29 @@ function resolveNodes($code) {
$matches['params'] $matches['params']
); );
$paramCodes = array(); if (array() === $params) {
foreach ($params as $param) { return 'new PHPParser_Node_' . $matches['name'] . '($line, $docComment)';
list($key, $value) = explode(': ', $param, 2);
$paramCodes[] = '\'' . $key . '\' => ' . $value;
} }
$withArray = false;
$paramCodes = array();
foreach ($params as $param) {
if (false !== strpos($param, ': ')) {
$withArray = true;
list($key, $value) = explode(': ', $param, 2);
$paramCodes[] = '\'' . $key . '\' => ' . $value;
} else {
$paramCodes[] = $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'] . '(array(' . implode(', ', $paramCodes) . '), $line, $docComment)';
}
}, },
$code $code
); );

View File

@ -113,7 +113,7 @@ top_statement_list:
; ;
namespace_name: namespace_name:
namespace_name_sub { $$ = Name[parts: $1, type: Name::NORMAL]; } namespace_name_sub { $$ = Name[$1, Name::NORMAL]; }
; ;
namespace_name_sub: namespace_name_sub:
@ -365,9 +365,9 @@ global_var_list:
; ;
global_var: global_var:
T_VARIABLE { $$ = Variable[name: parseVar($1)]; } T_VARIABLE { $$ = Variable[parseVar($1)]; }
| '$' variable { $$ = Variable[name: $2]; } | '$' variable { $$ = Variable[$2]; }
| '$' '{' expr '}' { $$ = Variable[name: $3]; } | '$' '{' expr '}' { $$ = Variable[$3]; }
; ;
static_var_list: static_var_list:
@ -554,7 +554,7 @@ function_call:
} }
$$ = Expr_StaticCall[class: $tmp->var->class, func: $1, args: $3]; $$ = Expr_StaticCall[class: $tmp->var->class, func: $1, args: $3];
$tmp->var = Variable[name: $tmp->var->name]; $tmp->var = Variable[$tmp->var->name];
} else { } else {
throw new Exception; throw new Exception;
} }
@ -611,9 +611,9 @@ ctor_arguments:
; ;
common_scalar: common_scalar:
T_LNUMBER { $$ = Scalar_LNumber[value: parseLNumber($1)]; } T_LNUMBER { $$ = Scalar_LNumber[parseLNumber($1)]; }
| T_DNUMBER { $$ = Scalar_DNumber[value: parseDNumber($1)]; } | T_DNUMBER { $$ = Scalar_DNumber[parseDNumber($1)]; }
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar_String::create($1, $line); } | T_CONSTANT_ENCAPSED_STRING { $$ = Scalar_String::create($1, $line, $docComment); }
| T_LINE { $$ = Scalar_LineConst[]; } | T_LINE { $$ = Scalar_LineConst[]; }
| T_FILE { $$ = Scalar_FileConst[]; } | T_FILE { $$ = Scalar_FileConst[]; }
| T_DIR { $$ = Scalar_DirConst[]; } | T_DIR { $$ = Scalar_DirConst[]; }
@ -622,9 +622,9 @@ common_scalar:
| T_FUNC_C { $$ = Scalar_FuncConst[]; } | T_FUNC_C { $$ = Scalar_FuncConst[]; }
| T_NS_C { $$ = Scalar_NSConst[]; } | T_NS_C { $$ = Scalar_NSConst[]; }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ $$ = Scalar_String[value: Scalar_String::parseEscapeSequences($2)]; } { $$ = Scalar_String[Scalar_String::parseEscapeSequences($2)]; }
| T_START_HEREDOC T_END_HEREDOC | T_START_HEREDOC T_END_HEREDOC
{ $$ = Scalar_String[value: '']; } { $$ = Scalar_String['']; }
; ;
static_scalar: /* compile-time evaluated scalars */ static_scalar: /* compile-time evaluated scalars */
@ -637,12 +637,12 @@ static_scalar: /* compile-time evaluated scalars */
; ;
scalar: scalar:
T_STRING_VARNAME { $$ = Scalar_String[value: $1]; } T_STRING_VARNAME { $$ = Scalar_String[$1]; }
| class_constant { $$ = $1; } | class_constant { $$ = $1; }
| name { $$ = Expr_ConstFetch[name: $1]; } | name { $$ = Expr_ConstFetch[name: $1]; }
| common_scalar { $$ = $1; } | common_scalar { $$ = $1; }
| '"' encaps_list '"' { $$ = Scalar_Encapsed[parts: $2]; } | '"' encaps_list '"' { $$ = Scalar_Encapsed[$2]; }
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = Scalar_Encapsed[parts: $2]; } | T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = Scalar_Encapsed[$2]; }
; ;
static_array_pair_list: static_array_pair_list:
@ -686,7 +686,7 @@ object_access_arrayable:
variable_without_objects: variable_without_objects:
reference_variable { $$ = $1; } reference_variable { $$ = $1; }
| '$' reference_variable { $$ = Variable[name: $2]; } | '$' reference_variable { $$ = Variable[$2]; }
; ;
base_variable: base_variable:
@ -714,8 +714,8 @@ static_property_with_arrays:
reference_variable: reference_variable:
reference_variable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } reference_variable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
| reference_variable '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; } | reference_variable '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
| T_VARIABLE { $$ = Variable[name: parseVar($1)]; } | T_VARIABLE { $$ = Variable[parseVar($1)]; }
| '$' '{' expr '}' { $$ = Variable[name: $3]; } | '$' '{' expr '}' { $$ = Variable[$3]; }
; ;
dim_offset: dim_offset:
@ -766,19 +766,19 @@ encaps_list:
; ;
encaps_var: encaps_var:
T_VARIABLE { $$ = Variable[name: parseVar($1)]; } T_VARIABLE { $$ = Variable[parseVar($1)]; }
| T_VARIABLE '[' encaps_var_offset ']' { $$ = Expr_ArrayDimFetch[var: Variable[name: parseVar($1)], dim: $3]; } | T_VARIABLE '[' encaps_var_offset ']' { $$ = Expr_ArrayDimFetch[var: Variable[parseVar($1)], dim: $3]; }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = Expr_PropertyFetch[var: Variable[name: parseVar($1)], name: $3]; } | T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = Expr_PropertyFetch[var: Variable[parseVar($1)], name: $3]; }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Variable[name: $2]; } | T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Variable[$2]; }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
{ $$ = Expr_ArrayDimFetch[var: Variable[name: $2], dim: $4]; } { $$ = Expr_ArrayDimFetch[var: Variable[$2], dim: $4]; }
| T_CURLY_OPEN variable '}' { $$ = $2; } | T_CURLY_OPEN variable '}' { $$ = $2; }
; ;
encaps_var_offset: encaps_var_offset:
T_STRING { $$ = Scalar_String[value: $1]; } T_STRING { $$ = Scalar_String[$1]; }
| T_NUM_STRING { $$ = Scalar_LNumber[value: parseLNumber($1)]; } | T_NUM_STRING { $$ = Scalar_LNumber[parseLNumber($1)]; }
| T_VARIABLE { $$ = Variable[name: parseVar($1)]; } | T_VARIABLE { $$ = Variable[parseVar($1)]; }
; ;
class_constant: class_constant:

View File

@ -10,6 +10,24 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract
const FULLY_QUALIFIED = 1; const FULLY_QUALIFIED = 1;
const RELATIVE = 2; const RELATIVE = 2;
/**
* Constructs a name node.
*
* @param array $parts Parts of the name
* @param int $type Resolve type
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $parts, $type = self::NORMAL, $line = -1, $docComment = null) {
parent::__construct(
array(
'parts' => $parts,
'type' => $type
),
$line, $docComment
);
}
/** /**
* Gets the first part of the name, i.e. everything before the first namespace separator. * Gets the first part of the name, i.e. everything before the first namespace separator.
* *

View File

@ -2,4 +2,13 @@
class PHPParser_Node_Scalar_ClassConst extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_ClassConst extends PHPParser_Node_Scalar
{ {
/**
* Constructs a __CLASS__ const node
*
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($line = -1, $docComment = null) {
parent::__construct(array(), $line, $docComment);
}
} }

View File

@ -5,4 +5,19 @@
*/ */
class PHPParser_Node_Scalar_DNumber extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_DNumber extends PHPParser_Node_Scalar
{ {
/**
* Constructs a float number scalar node.
*
* @param double $value Value of the number
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($value = 0.0, $line = -1, $docComment = null) {
parent::__construct(
array(
'value' => $value
),
$line, $docComment
);
}
} }

View File

@ -2,4 +2,13 @@
class PHPParser_Node_Scalar_DirConst extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_DirConst extends PHPParser_Node_Scalar
{ {
/**
* Constructs a __DIR__ const node
*
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($line = -1, $docComment = null) {
parent::__construct(array(), $line, $docComment);
}
} }

View File

@ -5,4 +5,19 @@
*/ */
class PHPParser_Node_Scalar_Encapsed extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_Encapsed extends PHPParser_Node_Scalar
{ {
/**
* Constructs an encapsed string node.
*
* @param array $parts Encaps list
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $parts = array(), $line = -1, $docComment = null) {
parent::__construct(
array(
'parts' => $parts
),
$line, $docComment
);
}
} }

View File

@ -2,4 +2,13 @@
class PHPParser_Node_Scalar_FileConst extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_FileConst extends PHPParser_Node_Scalar
{ {
/**
* Constructs a __FILE__ const node
*
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($line = -1, $docComment = null) {
parent::__construct(array(), $line, $docComment);
}
} }

View File

@ -2,4 +2,13 @@
class PHPParser_Node_Scalar_FuncConst extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_FuncConst extends PHPParser_Node_Scalar
{ {
/**
* Constructs a __FUNCTION__ const node
*
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($line = -1, $docComment = null) {
parent::__construct(array(), $line, $docComment);
}
} }

View File

@ -5,4 +5,19 @@
*/ */
class PHPParser_Node_Scalar_LNumber extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_LNumber extends PHPParser_Node_Scalar
{ {
/**
* Constructs an integer number scalar node.
*
* @param int $value Value of the number
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($value = 0, $line = -1, $docComment = null) {
parent::__construct(
array(
'value' => $value
),
$line, $docComment
);
}
} }

View File

@ -2,4 +2,13 @@
class PHPParser_Node_Scalar_LineConst extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_LineConst extends PHPParser_Node_Scalar
{ {
/**
* Constructs a __LINE__ const node
*
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($line = -1, $docComment = null) {
parent::__construct(array(), $line, $docComment);
}
} }

View File

@ -2,4 +2,13 @@
class PHPParser_Node_Scalar_MethodConst extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_MethodConst extends PHPParser_Node_Scalar
{ {
/**
* Constructs a __METHOD__ const node
*
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($line = -1, $docComment = null) {
parent::__construct(array(), $line, $docComment);
}
} }

View File

@ -2,4 +2,13 @@
class PHPParser_Node_Scalar_NSConst extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_NSConst extends PHPParser_Node_Scalar
{ {
/**
* Constructs a __NAMESPACE__ const node
*
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($line = -1, $docComment = null) {
parent::__construct(array(), $line, $docComment);
}
} }

View File

@ -5,15 +5,32 @@
*/ */
class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar
{ {
/**
* Constructs a string scalar node.
*
* @param string $value Value of the string
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($value = '', $line = -1, $docComment = null) {
parent::__construct(
array(
'value' => $value
),
$line, $docComment
);
}
/** /**
* Creates a String node from a string token (parses escape sequences). * Creates a String node from a string token (parses escape sequences).
* *
* @param string $s String * @param string $s String
* @param int $line Line * @param int $line Line
* @param null|string $docComment Nearest doc comment
* *
* @return PHPParser_Node_Scalar_String String Node * @return PHPParser_Node_Scalar_String String Node
*/ */
public static function create($s, $line) { public static function create($s, $line, $docComment) {
$bLength = 0; $bLength = 0;
if ('b' === $s[0]) { if ('b' === $s[0]) {
$bLength = 1; $bLength = 1;
@ -29,10 +46,7 @@ class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar
$s = self::parseEscapeSequences(substr($s, $bLength + 1, -1)); $s = self::parseEscapeSequences(substr($s, $bLength + 1, -1));
} }
return new self( return new self($s, $line, $docComment);
array('value' => $s),
$line
);
} }
/** /**

View File

@ -5,4 +5,19 @@
*/ */
class PHPParser_Node_Variable extends PHPParser_NodeAbstract class PHPParser_Node_Variable extends PHPParser_NodeAbstract
{ {
/**
* Constructs a variable node.
*
* @param string|PHPParser_Node_Variable|PHPParser_Node_Expr $name Name
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($name, $line = -1, $docComment = null) {
parent::__construct(
array(
'name' => $name
),
$line, $docComment
);
}
} }

View File

@ -1016,7 +1016,7 @@ class PHPParser_Parser
} }
private function yyn4($line, $docComment) { private function yyn4($line, $docComment) {
$this->yyval = new PHPParser_Node_Name(array('parts' => $this->yyastk[$this->yysp-(1-1)], 'type' => PHPParser_Node_Name::NORMAL), $line, $docComment); $this->yyval = new PHPParser_Node_Name($this->yyastk[$this->yysp-(1-1)], PHPParser_Node_Name::NORMAL, $line, $docComment);
} }
private function yyn5($line, $docComment) { private function yyn5($line, $docComment) {
@ -1492,15 +1492,15 @@ class PHPParser_Parser
} }
private function yyn123($line, $docComment) { private function yyn123($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn124($line, $docComment) { private function yyn124($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(2-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(2-2)], $line, $docComment);
} }
private function yyn125($line, $docComment) { private function yyn125($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(4-3)], $line, $docComment);
} }
private function yyn126($line, $docComment) { private function yyn126($line, $docComment) {
@ -1974,7 +1974,7 @@ class PHPParser_Parser
} }
$this->yyval = new PHPParser_Node_Expr_StaticCall(array('class' => $tmp->var->class, 'func' => $this->yyastk[$this->yysp-(4-1)], 'args' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_StaticCall(array('class' => $tmp->var->class, 'func' => $this->yyastk[$this->yysp-(4-1)], 'args' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment);
$tmp->var = new PHPParser_Node_Variable(array('name' => $tmp->var->name), $line, $docComment); $tmp->var = new PHPParser_Node_Variable($tmp->var->name, $line, $docComment);
} else { } else {
throw new Exception; throw new Exception;
} }
@ -2074,51 +2074,51 @@ class PHPParser_Parser
} }
private function yyn265($line, $docComment) { private function yyn265($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_LNumber((int) $this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn266($line, $docComment) { private function yyn266($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_DNumber(array('value' => (double) $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_DNumber((double) $this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn267($line, $docComment) { private function yyn267($line, $docComment) {
$this->yyval = PHPParser_Node_Scalar_String::create($this->yyastk[$this->yysp-(1-1)], $line); $this->yyval = PHPParser_Node_Scalar_String::create($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn268($line, $docComment) { private function yyn268($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_LineConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_LineConst($line, $docComment);
} }
private function yyn269($line, $docComment) { private function yyn269($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_FileConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_FileConst($line, $docComment);
} }
private function yyn270($line, $docComment) { private function yyn270($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_DirConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_DirConst($line, $docComment);
} }
private function yyn271($line, $docComment) { private function yyn271($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_ClassConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_ClassConst($line, $docComment);
} }
private function yyn272($line, $docComment) { private function yyn272($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_MethodConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_MethodConst($line, $docComment);
} }
private function yyn273($line, $docComment) { private function yyn273($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_FuncConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_FuncConst($line, $docComment);
} }
private function yyn274($line, $docComment) { private function yyn274($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_NSConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_NSConst($line, $docComment);
} }
private function yyn275($line, $docComment) { private function yyn275($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)])), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
} }
private function yyn276($line, $docComment) { private function yyn276($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => ''), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String('', $line, $docComment);
} }
private function yyn277($line, $docComment) { private function yyn277($line, $docComment) {
@ -2146,7 +2146,7 @@ class PHPParser_Parser
} }
private function yyn283($line, $docComment) { private function yyn283($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn284($line, $docComment) { private function yyn284($line, $docComment) {
@ -2162,11 +2162,11 @@ class PHPParser_Parser
} }
private function yyn287($line, $docComment) { private function yyn287($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_Encapsed(array('parts' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_Encapsed($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
} }
private function yyn288($line, $docComment) { private function yyn288($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_Encapsed(array('parts' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_Encapsed($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
} }
private function yyn289($line, $docComment) { private function yyn289($line, $docComment) {
@ -2242,7 +2242,7 @@ class PHPParser_Parser
} }
private function yyn307($line, $docComment) { private function yyn307($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(2-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(2-2)], $line, $docComment);
} }
private function yyn308($line, $docComment) { private function yyn308($line, $docComment) {
@ -2294,11 +2294,11 @@ class PHPParser_Parser
} }
private function yyn320($line, $docComment) { private function yyn320($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn321($line, $docComment) { private function yyn321($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(4-3)], $line, $docComment);
} }
private function yyn322($line, $docComment) { private function yyn322($line, $docComment) {
@ -2398,23 +2398,23 @@ class PHPParser_Parser
} }
private function yyn346($line, $docComment) { private function yyn346($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn347($line, $docComment) { private function yyn347($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(4-1)], 1)), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(4-1)], 1), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment);
} }
private function yyn348($line, $docComment) { private function yyn348($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_PropertyFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(3-1)], 1)), $line, $docComment), 'name' => $this->yyastk[$this->yysp-(3-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_PropertyFetch(array('var' => new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(3-1)], 1), $line, $docComment), 'name' => $this->yyastk[$this->yysp-(3-3)]), $line, $docComment);
} }
private function yyn349($line, $docComment) { private function yyn349($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
} }
private function yyn350($line, $docComment) { private function yyn350($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(6-2)]), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(6-4)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable($this->yyastk[$this->yysp-(6-2)], $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(6-4)]), $line, $docComment);
} }
private function yyn351($line, $docComment) { private function yyn351($line, $docComment) {
@ -2422,15 +2422,15 @@ class PHPParser_Parser
} }
private function yyn352($line, $docComment) { private function yyn352($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn353($line, $docComment) { private function yyn353($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_LNumber((int) $this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn354($line, $docComment) { private function yyn354($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn355($line, $docComment) { private function yyn355($line, $docComment) {

View File

@ -1415,7 +1415,7 @@ class PHPParser_ParserDebug
} }
private function yyn4($line, $docComment) { private function yyn4($line, $docComment) {
$this->yyval = new PHPParser_Node_Name(array('parts' => $this->yyastk[$this->yysp-(1-1)], 'type' => PHPParser_Node_Name::NORMAL), $line, $docComment); $this->yyval = new PHPParser_Node_Name($this->yyastk[$this->yysp-(1-1)], PHPParser_Node_Name::NORMAL, $line, $docComment);
} }
private function yyn5($line, $docComment) { private function yyn5($line, $docComment) {
@ -1891,15 +1891,15 @@ class PHPParser_ParserDebug
} }
private function yyn123($line, $docComment) { private function yyn123($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn124($line, $docComment) { private function yyn124($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(2-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(2-2)], $line, $docComment);
} }
private function yyn125($line, $docComment) { private function yyn125($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(4-3)], $line, $docComment);
} }
private function yyn126($line, $docComment) { private function yyn126($line, $docComment) {
@ -2373,7 +2373,7 @@ class PHPParser_ParserDebug
} }
$this->yyval = new PHPParser_Node_Expr_StaticCall(array('class' => $tmp->var->class, 'func' => $this->yyastk[$this->yysp-(4-1)], 'args' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_StaticCall(array('class' => $tmp->var->class, 'func' => $this->yyastk[$this->yysp-(4-1)], 'args' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment);
$tmp->var = new PHPParser_Node_Variable(array('name' => $tmp->var->name), $line, $docComment); $tmp->var = new PHPParser_Node_Variable($tmp->var->name, $line, $docComment);
} else { } else {
throw new Exception; throw new Exception;
} }
@ -2473,51 +2473,51 @@ class PHPParser_ParserDebug
} }
private function yyn265($line, $docComment) { private function yyn265($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_LNumber((int) $this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn266($line, $docComment) { private function yyn266($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_DNumber(array('value' => (double) $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_DNumber((double) $this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn267($line, $docComment) { private function yyn267($line, $docComment) {
$this->yyval = PHPParser_Node_Scalar_String::create($this->yyastk[$this->yysp-(1-1)], $line); $this->yyval = PHPParser_Node_Scalar_String::create($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn268($line, $docComment) { private function yyn268($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_LineConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_LineConst($line, $docComment);
} }
private function yyn269($line, $docComment) { private function yyn269($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_FileConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_FileConst($line, $docComment);
} }
private function yyn270($line, $docComment) { private function yyn270($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_DirConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_DirConst($line, $docComment);
} }
private function yyn271($line, $docComment) { private function yyn271($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_ClassConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_ClassConst($line, $docComment);
} }
private function yyn272($line, $docComment) { private function yyn272($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_MethodConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_MethodConst($line, $docComment);
} }
private function yyn273($line, $docComment) { private function yyn273($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_FuncConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_FuncConst($line, $docComment);
} }
private function yyn274($line, $docComment) { private function yyn274($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_NSConst(array(), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_NSConst($line, $docComment);
} }
private function yyn275($line, $docComment) { private function yyn275($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)])), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String(PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
} }
private function yyn276($line, $docComment) { private function yyn276($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => ''), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String('', $line, $docComment);
} }
private function yyn277($line, $docComment) { private function yyn277($line, $docComment) {
@ -2545,7 +2545,7 @@ class PHPParser_ParserDebug
} }
private function yyn283($line, $docComment) { private function yyn283($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn284($line, $docComment) { private function yyn284($line, $docComment) {
@ -2561,11 +2561,11 @@ class PHPParser_ParserDebug
} }
private function yyn287($line, $docComment) { private function yyn287($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_Encapsed(array('parts' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_Encapsed($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
} }
private function yyn288($line, $docComment) { private function yyn288($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_Encapsed(array('parts' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_Encapsed($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
} }
private function yyn289($line, $docComment) { private function yyn289($line, $docComment) {
@ -2641,7 +2641,7 @@ class PHPParser_ParserDebug
} }
private function yyn307($line, $docComment) { private function yyn307($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(2-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(2-2)], $line, $docComment);
} }
private function yyn308($line, $docComment) { private function yyn308($line, $docComment) {
@ -2693,11 +2693,11 @@ class PHPParser_ParserDebug
} }
private function yyn320($line, $docComment) { private function yyn320($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn321($line, $docComment) { private function yyn321($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(4-3)], $line, $docComment);
} }
private function yyn322($line, $docComment) { private function yyn322($line, $docComment) {
@ -2797,23 +2797,23 @@ class PHPParser_ParserDebug
} }
private function yyn346($line, $docComment) { private function yyn346($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn347($line, $docComment) { private function yyn347($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(4-1)], 1)), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(4-1)], 1), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(4-3)]), $line, $docComment);
} }
private function yyn348($line, $docComment) { private function yyn348($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_PropertyFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(3-1)], 1)), $line, $docComment), 'name' => $this->yyastk[$this->yysp-(3-3)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_PropertyFetch(array('var' => new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(3-1)], 1), $line, $docComment), 'name' => $this->yyastk[$this->yysp-(3-3)]), $line, $docComment);
} }
private function yyn349($line, $docComment) { private function yyn349($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment); $this->yyval = new PHPParser_Node_Variable($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
} }
private function yyn350($line, $docComment) { private function yyn350($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => $this->yyastk[$this->yysp-(6-2)]), $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(6-4)]), $line, $docComment); $this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable($this->yyastk[$this->yysp-(6-2)], $line, $docComment), 'dim' => $this->yyastk[$this->yysp-(6-4)]), $line, $docComment);
} }
private function yyn351($line, $docComment) { private function yyn351($line, $docComment) {
@ -2821,15 +2821,15 @@ class PHPParser_ParserDebug
} }
private function yyn352($line, $docComment) { private function yyn352($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_String($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn353($line, $docComment) { private function yyn353($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $this->yyastk[$this->yysp-(1-1)]), $line, $docComment); $this->yyval = new PHPParser_Node_Scalar_LNumber((int) $this->yyastk[$this->yysp-(1-1)], $line, $docComment);
} }
private function yyn354($line, $docComment) { private function yyn354($line, $docComment) {
$this->yyval = new PHPParser_Node_Variable(array('name' => substr($this->yyastk[$this->yysp-(1-1)], 1)), $line, $docComment); $this->yyval = new PHPParser_Node_Variable(substr($this->yyastk[$this->yysp-(1-1)], 1), $line, $docComment);
} }
private function yyn355($line, $docComment) { private function yyn355($line, $docComment) {

View File

@ -27,12 +27,13 @@ class Unit_NodeDumperTest extends PHPUnit_Framework_TestCase
)' )'
), ),
array( array(
new PHPParser_Node_Name(array('parts' => array('Hallo', 'World'))), new PHPParser_Node_Name(array('Hallo', 'World')),
'Name( 'Name(
parts: array( parts: array(
0: Hallo 0: Hallo
1: World 1: World
) )
type: 0
)' )'
), ),
array( array(

View File

@ -5,21 +5,15 @@ class Unit_NodeTraverserTest extends PHPUnit_Framework_TestCase
function getTestNode() { function getTestNode() {
return array( return array(
new PHPParser_Node_Stmt_Namespace(array( new PHPParser_Node_Stmt_Namespace(array(
'name' => new PHPParser_Node_Name(array( 'name' => new PHPParser_Node_Name(array('Foo', 'Bar')),
'parts' => array('Foo', 'Bar')
)),
'stmts' => array( 'stmts' => array(
new PHPParser_Node_Stmt_Echo(array( new PHPParser_Node_Stmt_Echo(array(
'exprs' => array( 'exprs' => array(
new PHPParser_Node_Scalar_String(array( new PHPParser_Node_Scalar_String('Hallo World')
'value' => 'Hallo World'
))
) )
)), )),
new PHPParser_Node_Expr_Print(array( new PHPParser_Node_Expr_Print(array(
'expr' => new PHPParser_Node_Scalar_String(array( 'expr' => new PHPParser_Node_Scalar_String('Hallo World, again!')
'value' => 'Hallo World, again!'
))
)), )),
) )
)), )),
@ -77,9 +71,7 @@ class Unit_NodeTraverserTest extends PHPUnit_Framework_TestCase
array( array(
new PHPParser_Node_Stmt_Echo(array( new PHPParser_Node_Stmt_Echo(array(
'exprs' => array( 'exprs' => array(
new PHPParser_Node_Scalar_String(array( new PHPParser_Node_Scalar_String('Foo Bar')
'value' => 'Foo Bar'
))
) )
)), )),
), ),