Associate last encountered doccomment with next node

This commit is contained in:
nikic 2011-07-03 16:35:45 +02:00
parent 033f5c81a0
commit 78f15cd50b
9 changed files with 1455 additions and 1414 deletions

View File

@ -154,6 +154,7 @@ class YYParser
$yysstk = array($yystate = 0); // State stack
$this->yyastk = array(); // AST stack (?)
$yylstk = array($yyline = 1); // Line stack
$yydstk = array($yyDC = null); // Doc comment stack
$yychar = -1;
@ -165,11 +166,12 @@ class YYParser
$yyn = self::$yydefault[$yystate];
} else {
if ($yychar < 0) {
if (($yychar = $lexer->lex($yylval, $yyline)) < 0)
if (($yychar = $lexer->lex($yylval, $yyline, $yyDC)) < 0)
$yychar = 0;
$yychar = $yychar < self::YYMAXLEX ?
self::$yytranslate[$yychar] : self::YYBADCH;
$yylstk[$this->yysp] = $yyline;
$yydstk[$this->yysp] = $yyDC;
#if -t
$this->YYTRACE_READ($yychar);
#endif
@ -199,6 +201,7 @@ class YYParser
$yysstk[$this->yysp] = $yystate = $yyn;
$this->yyastk[$this->yysp] = $yylval;
$yylstk[$this->yysp] = $yyline;
$yydstk[$this->yysp] = $yyDC;
$yychar = -1;
if ($yyn < self::YYNLSTATES)
@ -228,7 +231,10 @@ class YYParser
$this->YYTRACE_REDUCE($yyn);
#endif
try {
$this->{'yyn' . $yyn}($yylstk[$this->yysp - self::$yylen[$yyn]]);
$this->{'yyn' . $yyn}(
$yylstk[$this->yysp - self::$yylen[$yyn]],
$yydstk[$this->yysp - self::$yylen[$yyn]]
);
} catch (PHPParser_Error $e) {
$e->setRawLine($yyline);
@ -251,6 +257,7 @@ class YYParser
$yysstk[$this->yysp] = $yystate;
$this->yyastk[$this->yysp] = $this->yyval;
$yylstk[$this->yysp] = $yyline;
$yydstk[$this->yysp] = $yyDC;
} else {
/* error */
throw new PHPParser_Error(
@ -268,7 +275,7 @@ class YYParser
}
#reduce
private function yyn%n($line) {
private function yyn%n($line, $docComment) {
%b
}
#noact

View File

@ -63,7 +63,7 @@ function resolveNodes($code) {
$paramCodes[] = '\'' . $key . '\' => ' . $value;
}
return 'new PHPParser_Node_' . $matches['name'] . '(array(' . implode(', ', $paramCodes) . '), #line)';
return 'new PHPParser_Node_' . $matches['name'] . '(array(' . implode(', ', $paramCodes) . '), #line, #docComment)';
},
$code
);

View File

@ -520,8 +520,8 @@ state 5
. error
state 6
(97) while_statement : ':' inner_statement_list . T_ENDWHILE ';'
(24) inner_statement_list : inner_statement_list . inner_statement
(97) while_statement : ':' inner_statement_list . T_ENDWHILE ';'
T_INCLUDE shift 56
T_INCLUDE_ONCE shift 57
@ -924,8 +924,8 @@ state 9
. error
state 10
(233) expr : T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list . '}'
(24) inner_statement_list : inner_statement_list . inner_statement
(233) expr : T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list . '}'
T_INCLUDE shift 56
T_INCLUDE_ONCE shift 57
@ -1227,8 +1227,8 @@ state 12
. error
state 13
(136) method_body : '{' inner_statement_list . '}'
(24) inner_statement_list : inner_statement_list . inner_statement
(136) method_body : '{' inner_statement_list . '}'
T_INCLUDE shift 56
T_INCLUDE_ONCE shift 57
@ -1530,8 +1530,8 @@ state 15
. reduce (93)
state 16
(105) new_else_single : T_ELSE ':' inner_statement_list .
(24) inner_statement_list : inner_statement_list . inner_statement
(105) new_else_single : T_ELSE ':' inner_statement_list .
T_INCLUDE shift 56
T_INCLUDE_ONCE shift 57
@ -1730,8 +1730,8 @@ state 17
. reduce (92)
state 18
(101) new_elseif_list : new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list .
(24) inner_statement_list : inner_statement_list . inner_statement
(101) new_elseif_list : new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list .
T_INCLUDE shift 56
T_INCLUDE_ONCE shift 57
@ -10246,6 +10246,7 @@ state 134
. error
state 135
(92) case_list : case_list T_CASE expr . case_separator inner_statement_list
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10273,7 +10274,6 @@ state 135
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(92) case_list : case_list T_CASE expr . case_separator inner_statement_list
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10307,6 +10307,7 @@ state 135
. error
state 136
(47) statement : expr . ';'
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10334,7 +10335,6 @@ state 136
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(47) statement : expr . ';'
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10366,6 +10366,7 @@ state 136
. error
state 137
(38) statement : T_BREAK expr . ';'
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10393,7 +10394,6 @@ state 137
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(38) statement : T_BREAK expr . ';'
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10425,6 +10425,7 @@ state 137
. error
state 138
(40) statement : T_CONTINUE expr . ';'
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10452,7 +10453,6 @@ state 138
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(40) statement : T_CONTINUE expr . ';'
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10484,6 +10484,7 @@ state 138
. error
state 139
(42) statement : T_RETURN expr . ';'
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10511,7 +10512,6 @@ state 139
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(42) statement : T_RETURN expr . ';'
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10543,6 +10543,7 @@ state 139
. error
state 140
(55) statement : T_THROW expr . ';'
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10570,7 +10571,6 @@ state 140
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(55) statement : T_THROW expr . ';'
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10779,6 +10779,8 @@ state 143
. error
state 144
(31) statement : T_IF '(' expr . ')' statement elseif_list else_single
(32) statement : T_IF '(' expr . ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10806,8 +10808,6 @@ state 144
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(31) statement : T_IF '(' expr . ')' statement elseif_list else_single
(32) statement : T_IF '(' expr . ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10839,6 +10839,7 @@ state 144
. error
state 145
(33) statement : T_WHILE '(' expr . ')' while_statement
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10866,7 +10867,6 @@ state 145
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(33) statement : T_WHILE '(' expr . ')' while_statement
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10898,6 +10898,9 @@ state 145
. error
state 146
(49) statement : T_FOREACH '(' expr . T_AS variable ')' foreach_statement
(50) statement : T_FOREACH '(' expr . T_AS '&' variable ')' foreach_statement
(51) statement : T_FOREACH '(' expr . T_AS variable T_DOUBLE_ARROW optional_ref variable ')' foreach_statement
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10925,9 +10928,6 @@ state 146
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(49) statement : T_FOREACH '(' expr . T_AS variable ')' foreach_statement
(50) statement : T_FOREACH '(' expr . T_AS '&' variable ')' foreach_statement
(51) statement : T_FOREACH '(' expr . T_AS variable T_DOUBLE_ARROW optional_ref variable ')' foreach_statement
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -10959,6 +10959,7 @@ state 146
. error
state 147
(36) statement : T_SWITCH '(' expr . ')' switch_case_list
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -10986,7 +10987,6 @@ state 147
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(36) statement : T_SWITCH '(' expr . ')' switch_case_list
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -11610,6 +11610,7 @@ state 157
. error
state 158
(34) statement : T_DO statement T_WHILE '(' expr . ')' ';'
(181) expr : expr . T_BOOLEAN_OR expr
(182) expr : expr . T_BOOLEAN_AND expr
(183) expr : expr . T_LOGICAL_OR expr
@ -11637,7 +11638,6 @@ state 158
(209) expr : expr . T_INSTANCEOF class_name_reference
(211) expr : expr . '?' expr ':' expr
(212) expr : expr . '?' ':' expr
(34) statement : T_DO statement T_WHILE '(' expr . ')' ';'
T_LOGICAL_OR shift 83
T_LOGICAL_XOR shift 84
@ -14905,8 +14905,8 @@ state 226
. reduce (208)
state 227
(130) class_statement_list : class_statement_list . class_statement
(67) class_declaration_statement : T_INTERFACE T_STRING interface_extends_list '{' class_statement_list . '}'
(130) class_statement_list : class_statement_list . class_statement
(139) method_modifiers : .
T_CONST shift 477
@ -14927,8 +14927,8 @@ state 227
. reduce (139)
state 228
(130) class_statement_list : class_statement_list . class_statement
(66) class_declaration_statement : class_entry_type T_STRING extends_from implements_list '{' class_statement_list . '}'
(130) class_statement_list : class_statement_list . class_statement
(139) method_modifiers : .
T_CONST shift 477
@ -15972,10 +15972,10 @@ state 277
. error
state 278
(246) name : T_NAMESPACE . T_NS_SEPARATOR namespace_name
(11) top_statement : T_NAMESPACE . namespace_name ';'
(12) top_statement : T_NAMESPACE . namespace_name '{' top_statement_list '}'
(13) top_statement : T_NAMESPACE . '{' top_statement_list '}'
(246) name : T_NAMESPACE . T_NS_SEPARATOR namespace_name
T_STRING shift 563 and reduce (5)
T_NS_SEPARATOR shift 340
@ -16164,10 +16164,10 @@ state 294
. error
state 295
(302) object_access : variable . T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
(303) object_access_arrayable : variable . T_OBJECT_OPERATOR object_property
(49) statement : T_FOREACH '(' expr T_AS variable . ')' foreach_statement
(51) statement : T_FOREACH '(' expr T_AS variable . T_DOUBLE_ARROW optional_ref variable ')' foreach_statement
(302) object_access : variable . T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
(303) object_access_arrayable : variable . T_OBJECT_OPERATOR object_property
T_OBJECT_OPERATOR shift 264
T_DOUBLE_ARROW shift 359
@ -16263,8 +16263,8 @@ state 304
state 305
305: shift/reduce conflict (shift 27, reduce 102) on T_ELSE
305: shift/reduce conflict (shift 483, reduce 102) on T_ELSEIF
(99) elseif_list : elseif_list . T_ELSEIF '(' expr ')' statement
(31) statement : T_IF '(' expr ')' statement elseif_list . else_single
(99) elseif_list : elseif_list . T_ELSEIF '(' expr ')' statement
(102) else_single : .
T_ELSEIF shift 483
@ -16273,8 +16273,8 @@ state 305
. reduce (102)
state 306
(101) new_elseif_list : new_elseif_list . T_ELSEIF '(' expr ')' ':' inner_statement_list
(32) statement : T_IF '(' expr ')' ':' inner_statement_list new_elseif_list . new_else_single T_ENDIF ';'
(101) new_elseif_list : new_elseif_list . T_ELSEIF '(' expr ')' ':' inner_statement_list
(104) new_else_single : .
T_ELSEIF shift 493
@ -16325,16 +16325,16 @@ state 311
. reduce (311)
state 312
(155) expr_list : expr_list . ',' expr
(45) statement : T_ECHO expr_list . ';'
(155) expr_list : expr_list . ',' expr
',' shift 122
';' shift 600 and reduce (45)
. error
state 313
(233) expr : T_FUNCTION optional_ref . '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
(65) function_declaration_statement : T_FUNCTION optional_ref . T_STRING '(' parameter_list ')' '{' inner_statement_list '}'
(233) expr : T_FUNCTION optional_ref . '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
T_STRING shift 411
'(' shift 256
@ -16349,17 +16349,17 @@ state 314
. error
state 315
(121) global_var_list : global_var_list . ',' global_var
(43) statement : T_GLOBAL global_var_list . ';'
(121) global_var_list : global_var_list . ',' global_var
',' shift 303
';' shift 607 and reduce (43)
. error
state 316
(44) statement : T_STATIC static_var_list . ';'
(126) static_var_list : static_var_list . ',' T_VARIABLE
(127) static_var_list : static_var_list . ',' T_VARIABLE '=' static_scalar
(44) statement : T_STATIC static_var_list . ';'
',' shift 415
';' shift 608 and reduce (44)
@ -16428,8 +16428,8 @@ state 323
. error
state 324
(213) expr : T_ISSET '(' variables_list . ')'
(62) variables_list : variables_list . ',' variable
(213) expr : T_ISSET '(' variables_list . ')'
',' shift 246
')' shift 644 and reduce (213)
@ -16507,9 +16507,9 @@ state 332
. error
state 333
(50) statement : T_FOREACH '(' expr T_AS '&' variable . ')' foreach_statement
(302) object_access : variable . T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
(303) object_access_arrayable : variable . T_OBJECT_OPERATOR object_property
(50) statement : T_FOREACH '(' expr T_AS '&' variable . ')' foreach_statement
T_OBJECT_OPERATOR shift 264
')' shift 22
@ -16533,9 +16533,9 @@ state 335
. error
state 336
(51) statement : T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW optional_ref variable . ')' foreach_statement
(302) object_access : variable . T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
(303) object_access_arrayable : variable . T_OBJECT_OPERATOR object_property
(51) statement : T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW optional_ref variable . ')' foreach_statement
T_OBJECT_OPERATOR shift 264
')' shift 24
@ -16600,8 +16600,8 @@ state 343
. reduce (257)
state 344
(233) expr : T_FUNCTION . optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
(65) function_declaration_statement : T_FUNCTION . optional_ref T_STRING '(' parameter_list ')' '{' inner_statement_list '}'
(233) expr : T_FUNCTION . optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
(63) optional_ref : .
'&' shift 584 and reduce (64)
@ -16609,8 +16609,8 @@ state 344
. reduce (63)
state 345
(243) class_name : T_STATIC .
(44) statement : T_STATIC . static_var_list ';'
(243) class_name : T_STATIC .
T_VARIABLE shift 401
static_var_list goto 316
@ -17139,9 +17139,9 @@ state 415
. error
state 416
(61) variables_list : variable .
(302) object_access : variable . T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
(303) object_access_arrayable : variable . T_OBJECT_OPERATOR object_property
(61) variables_list : variable .
T_OBJECT_OPERATOR shift 264
. reduce (61)
@ -17537,9 +17537,9 @@ state 464
. error
state 465
(62) variables_list : variables_list ',' variable .
(302) object_access : variable . T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
(303) object_access_arrayable : variable . T_OBJECT_OPERATOR object_property
(62) variables_list : variables_list ',' variable .
T_OBJECT_OPERATOR shift 264
. reduce (62)
@ -19432,4 +19432,4 @@ Statistics for zend_language_parser.phpy:
3815 items
1124 lookahead sets used
13442+794=14236 action entries
229536 bytes used
229560 bytes used

View File

@ -113,7 +113,7 @@ top_statement_list:
;
namespace_name:
namespace_name_sub { $$ = new PHPParser_Node_Name(array('parts' => $1), #line); }
namespace_name_sub { $$ = new PHPParser_Node_Name(array('parts' => $1), #line, #docComment); }
;
namespace_name_sub:
@ -126,12 +126,12 @@ top_statement:
| function_declaration_statement { $$ = $1; }
| class_declaration_statement { $$ = $1; }
| T_HALT_COMPILER
{ $$ = new PHPParser_Node_Stmt_HaltCompiler(array('remaining' => #this->lexer->handleHaltCompiler()), #line); }
| T_NAMESPACE namespace_name ';' { $$ = new PHPParser_Node_Stmt_Namespace(array('name' => $2, 'stmts' => null), #line); }
| T_NAMESPACE namespace_name '{' top_statement_list '}' { $$ = new PHPParser_Node_Stmt_Namespace(array('name' => $2, 'stmts' => $4), #line); }
| T_NAMESPACE '{' top_statement_list '}' { $$ = new PHPParser_Node_Stmt_Namespace(array('name' => null, 'stmts' => $3), #line); }
| T_USE use_declarations ';' { $$ = new PHPParser_Node_Stmt_Use(array('uses' => $2), #line); }
| constant_declaration ';' { $$ = new PHPParser_Node_Stmt_Const(array('consts' => $1), #line); }
{ $$ = new PHPParser_Node_Stmt_HaltCompiler(array('remaining' => #this->lexer->handleHaltCompiler()), #line, #docComment); }
| T_NAMESPACE namespace_name ';' { $$ = new PHPParser_Node_Stmt_Namespace(array('name' => $2, 'stmts' => null), #line, #docComment); }
| T_NAMESPACE namespace_name '{' top_statement_list '}' { $$ = new PHPParser_Node_Stmt_Namespace(array('name' => $2, 'stmts' => $4), #line, #docComment); }
| T_NAMESPACE '{' top_statement_list '}' { $$ = new PHPParser_Node_Stmt_Namespace(array('name' => null, 'stmts' => $3), #line, #docComment); }
| T_USE use_declarations ';' { $$ = new PHPParser_Node_Stmt_Use(array('uses' => $2), #line, #docComment); }
| constant_declaration ';' { $$ = new PHPParser_Node_Stmt_Const(array('consts' => $1), #line, #docComment); }
;
use_declarations:
@ -140,15 +140,15 @@ use_declarations:
;
use_declaration:
namespace_name { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $1, 'alias' => null), #line); }
| namespace_name T_AS T_STRING { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $1, 'alias' => $3), #line); }
| T_NS_SEPARATOR namespace_name { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $2, 'alias' => null), #line); }
| T_NS_SEPARATOR namespace_name T_AS T_STRING { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $2, 'alias' => $4), #line); }
namespace_name { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $1, 'alias' => null), #line, #docComment); }
| namespace_name T_AS T_STRING { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $1, 'alias' => $3), #line, #docComment); }
| T_NS_SEPARATOR namespace_name { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $2, 'alias' => null), #line, #docComment); }
| T_NS_SEPARATOR namespace_name T_AS T_STRING { $$ = new PHPParser_Node_Stmt_UseUse(array('ns' => $2, 'alias' => $4), #line, #docComment); }
;
constant_declaration:
constant_declaration ',' T_STRING '=' static_scalar { $1[] = new PHPParser_Node_Stmt_ConstConst(array('name' => $3, 'value' => $5), #line); $$ = $1; }
| T_CONST T_STRING '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_ConstConst(array('name' => $2, 'value' => $4), #line)); }
constant_declaration ',' T_STRING '=' static_scalar { $1[] = new PHPParser_Node_Stmt_ConstConst(array('name' => $3, 'value' => $5), #line, #docComment); $$ = $1; }
| T_CONST T_STRING '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_ConstConst(array('name' => $2, 'value' => $4), #line, #docComment)); }
;
inner_statement_list:
@ -165,38 +165,38 @@ inner_statement:
statement:
'{' inner_statement_list '}' { $$ = $2; }
| T_IF '(' expr ')' statement elseif_list else_single { $$ = new PHPParser_Node_Stmt_If(array('cond' => $3, 'stmts' => is_array($5) ? $5 : array($5), 'elseifList' => $6, 'else' => $7), #line); }
| T_IF '(' expr ')' statement elseif_list else_single { $$ = new PHPParser_Node_Stmt_If(array('cond' => $3, 'stmts' => is_array($5) ? $5 : array($5), 'elseifList' => $6, 'else' => $7), #line, #docComment); }
| T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
{ $$ = new PHPParser_Node_Stmt_If(array('cond' => $3, 'stmts' => $6, 'elseifList' => $7, 'else' => $8), #line); }
| T_WHILE '(' expr ')' while_statement { $$ = new PHPParser_Node_Stmt_While(array('cond' => $3, 'stmts' => is_array($5) ? $5 : array($5)), #line); }
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = new PHPParser_Node_Stmt_Do(array('stmts' => is_array($2) ? $2 : array($2), 'cond' => $5), #line); }
{ $$ = new PHPParser_Node_Stmt_If(array('cond' => $3, 'stmts' => $6, 'elseifList' => $7, 'else' => $8), #line, #docComment); }
| T_WHILE '(' expr ')' while_statement { $$ = new PHPParser_Node_Stmt_While(array('cond' => $3, 'stmts' => is_array($5) ? $5 : array($5)), #line, #docComment); }
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = new PHPParser_Node_Stmt_Do(array('stmts' => is_array($2) ? $2 : array($2), 'cond' => $5), #line, #docComment); }
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
{ $$ = new PHPParser_Node_Stmt_For(array('init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => is_array($9) ? $9 : array($9)), #line); }
| T_SWITCH '(' expr ')' switch_case_list { $$ = new PHPParser_Node_Stmt_Switch(array('cond' => $3, 'caseList' => $5), #line); }
| T_BREAK ';' { $$ = new PHPParser_Node_Stmt_Break(array('num' => null), #line); }
| T_BREAK expr ';' { $$ = new PHPParser_Node_Stmt_Break(array('num' => $2), #line); }
| T_CONTINUE ';' { $$ = new PHPParser_Node_Stmt_Continue(array('num' => null), #line); }
| T_CONTINUE expr ';' { $$ = new PHPParser_Node_Stmt_Continue(array('num' => $2), #line); }
| T_RETURN ';' { $$ = new PHPParser_Node_Stmt_Return(array('expr' => null), #line); }
| T_RETURN expr ';' { $$ = new PHPParser_Node_Stmt_Return(array('expr' => $2), #line); }
| T_GLOBAL global_var_list ';' { $$ = new PHPParser_Node_Stmt_Global(array('vars' => $2), #line); }
| T_STATIC static_var_list ';' { $$ = new PHPParser_Node_Stmt_Static(array('vars' => $2), #line); }
| T_ECHO expr_list ';' { $$ = new PHPParser_Node_Stmt_Echo(array('exprs' => $2), #line); }
| T_INLINE_HTML { $$ = new PHPParser_Node_Stmt_InlineHTML(array('value' => $1), #line); }
{ $$ = new PHPParser_Node_Stmt_For(array('init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => is_array($9) ? $9 : array($9)), #line, #docComment); }
| T_SWITCH '(' expr ')' switch_case_list { $$ = new PHPParser_Node_Stmt_Switch(array('cond' => $3, 'caseList' => $5), #line, #docComment); }
| T_BREAK ';' { $$ = new PHPParser_Node_Stmt_Break(array('num' => null), #line, #docComment); }
| T_BREAK expr ';' { $$ = new PHPParser_Node_Stmt_Break(array('num' => $2), #line, #docComment); }
| T_CONTINUE ';' { $$ = new PHPParser_Node_Stmt_Continue(array('num' => null), #line, #docComment); }
| T_CONTINUE expr ';' { $$ = new PHPParser_Node_Stmt_Continue(array('num' => $2), #line, #docComment); }
| T_RETURN ';' { $$ = new PHPParser_Node_Stmt_Return(array('expr' => null), #line, #docComment); }
| T_RETURN expr ';' { $$ = new PHPParser_Node_Stmt_Return(array('expr' => $2), #line, #docComment); }
| T_GLOBAL global_var_list ';' { $$ = new PHPParser_Node_Stmt_Global(array('vars' => $2), #line, #docComment); }
| T_STATIC static_var_list ';' { $$ = new PHPParser_Node_Stmt_Static(array('vars' => $2), #line, #docComment); }
| T_ECHO expr_list ';' { $$ = new PHPParser_Node_Stmt_Echo(array('exprs' => $2), #line, #docComment); }
| T_INLINE_HTML { $$ = new PHPParser_Node_Stmt_InlineHTML(array('value' => $1), #line, #docComment); }
| expr ';' { $$ = $1; }
| T_UNSET '(' variables_list ')' ';' { $$ = new PHPParser_Node_Stmt_Unset(array('vars' => $3), #line); }
| T_UNSET '(' variables_list ')' ';' { $$ = new PHPParser_Node_Stmt_Unset(array('vars' => $3), #line, #docComment); }
| T_FOREACH '(' expr T_AS variable ')' foreach_statement
{ $$ = new PHPParser_Node_Stmt_Foreach(array('expr' => $3, 'keyVar' => null, 'byRef' => false, 'valueVar' => $5, 'stmts' => is_array($7) ? $7 : array($7)), #line); }
{ $$ = new PHPParser_Node_Stmt_Foreach(array('expr' => $3, 'keyVar' => null, 'byRef' => false, 'valueVar' => $5, 'stmts' => is_array($7) ? $7 : array($7)), #line, #docComment); }
| T_FOREACH '(' expr T_AS '&' variable ')' foreach_statement
{ $$ = new PHPParser_Node_Stmt_Foreach(array('expr' => $3, 'keyVar' => null, 'byRef' => true, 'valueVar' => $6, 'stmts' => is_array($8) ? $8 : array($8)), #line); }
{ $$ = new PHPParser_Node_Stmt_Foreach(array('expr' => $3, 'keyVar' => null, 'byRef' => true, 'valueVar' => $6, 'stmts' => is_array($8) ? $8 : array($8)), #line, #docComment); }
| T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW optional_ref variable ')' foreach_statement
{ $$ = new PHPParser_Node_Stmt_Foreach(array('expr' => $3, 'keyVar' => $5, 'byRef' => $7, 'valueVar' => $8, 'stmts' => is_array($10) ? $10 : array($10)), #line); }
| T_DECLARE '(' declare_list ')' declare_statement { $$ = new PHPParser_Node_Stmt_Declare(array('declares' => $3, 'stmts' => is_array($5) ? $5 : array($5)), #line); }
{ $$ = new PHPParser_Node_Stmt_Foreach(array('expr' => $3, 'keyVar' => $5, 'byRef' => $7, 'valueVar' => $8, 'stmts' => is_array($10) ? $10 : array($10)), #line, #docComment); }
| T_DECLARE '(' declare_list ')' declare_statement { $$ = new PHPParser_Node_Stmt_Declare(array('declares' => $3, 'stmts' => is_array($5) ? $5 : array($5)), #line, #docComment); }
| ';' { $$ = array(); /* means: no statement */ }
| T_TRY '{' inner_statement_list '}' catches { $$ = new PHPParser_Node_Stmt_TryCatch(array('stmts' => $3, 'catches' => $5), #line); }
| T_THROW expr ';' { $$ = new PHPParser_Node_Stmt_Throw(array('expr' => $2), #line); }
| T_GOTO T_STRING ';' { $$ = new PHPParser_Node_Stmt_Goto(array('name' => $2), #line); }
| T_STRING ':' { $$ = new PHPParser_Node_Stmt_Label(array('name' => $1), #line); }
| T_TRY '{' inner_statement_list '}' catches { $$ = new PHPParser_Node_Stmt_TryCatch(array('stmts' => $3, 'catches' => $5), #line, #docComment); }
| T_THROW expr ';' { $$ = new PHPParser_Node_Stmt_Throw(array('expr' => $2), #line, #docComment); }
| T_GOTO T_STRING ';' { $$ = new PHPParser_Node_Stmt_Goto(array('name' => $2), #line, #docComment); }
| T_STRING ':' { $$ = new PHPParser_Node_Stmt_Label(array('name' => $1), #line, #docComment); }
;
catches:
@ -206,7 +206,7 @@ catches:
catch:
T_CATCH '(' name T_VARIABLE ')' '{' inner_statement_list '}'
{ $$ = new PHPParser_Node_Stmt_Catch(array('type' => $3, 'var' => substr($4, 1), 'stmts' => $7), #line); }
{ $$ = new PHPParser_Node_Stmt_Catch(array('type' => $3, 'var' => substr($4, 1), 'stmts' => $7), #line, #docComment); }
;
variables_list:
@ -221,14 +221,14 @@ optional_ref:
function_declaration_statement:
T_FUNCTION optional_ref T_STRING '(' parameter_list ')' '{' inner_statement_list '}'
{ $$ = new PHPParser_Node_Stmt_Func(array('byRef' => $2, 'name' => $3, 'params' => $5, 'stmts' => $8), #line); }
{ $$ = new PHPParser_Node_Stmt_Func(array('byRef' => $2, 'name' => $3, 'params' => $5, 'stmts' => $8), #line, #docComment); }
;
class_declaration_statement:
class_entry_type T_STRING extends_from implements_list '{' class_statement_list '}'
{ $$ = new PHPParser_Node_Stmt_Class(array('type' => $1, 'name' => $2, 'extends' => $3, 'implements' => $4, 'stmts' => $6), #line); }
{ $$ = new PHPParser_Node_Stmt_Class(array('type' => $1, 'name' => $2, 'extends' => $3, 'implements' => $4, 'stmts' => $6), #line, #docComment); }
| T_INTERFACE T_STRING interface_extends_list '{' class_statement_list '}'
{ $$ = new PHPParser_Node_Stmt_Interface(array('name' => $2, 'extends' => $3, 'stmts' => $5), #line); }
{ $$ = new PHPParser_Node_Stmt_Interface(array('name' => $2, 'extends' => $3, 'stmts' => $5), #line, #docComment); }
;
class_entry_type:
@ -273,8 +273,8 @@ declare_statement:
;
declare_list:
T_STRING '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_DeclareDeclare(array('key' => $1, 'value' => $3), #line)); }
| declare_list ',' T_STRING '=' static_scalar { $1[] = new PHPParser_Node_Stmt_DeclareDeclare(array('key' => $3, 'value' => $5), #line); $$ = $1; }
T_STRING '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_DeclareDeclare(array('key' => $1, 'value' => $3), #line, #docComment)); }
| declare_list ',' T_STRING '=' static_scalar { $1[] = new PHPParser_Node_Stmt_DeclareDeclare(array('key' => $3, 'value' => $5), #line, #docComment); $$ = $1; }
;
switch_case_list:
@ -287,9 +287,9 @@ switch_case_list:
case_list:
/* empty */ { $$ = array(); }
| case_list T_CASE expr case_separator inner_statement_list
{ $1[] = new PHPParser_Node_Stmt_Case(array('cond' => $3, 'stmts' => $5), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Stmt_Case(array('cond' => $3, 'stmts' => $5), #line, #docComment); $$ = $1; }
| case_list T_DEFAULT case_separator inner_statement_list
{ $1[] = new PHPParser_Node_Stmt_Case(array('cond' => null, 'stmts' => $4), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Stmt_Case(array('cond' => null, 'stmts' => $4), #line, #docComment); $$ = $1; }
;
case_separator:
@ -304,23 +304,23 @@ while_statement:
elseif_list:
/* empty */ { $$ = array();}
| elseif_list T_ELSEIF '(' expr ')' statement { $1[] = new PHPParser_Node_Stmt_ElseIf(array('cond' => $4, 'stmts' => is_array($6) ? $6 : array($6)), #line); $$ = $1; }
| elseif_list T_ELSEIF '(' expr ')' statement { $1[] = new PHPParser_Node_Stmt_ElseIf(array('cond' => $4, 'stmts' => is_array($6) ? $6 : array($6)), #line, #docComment); $$ = $1; }
;
new_elseif_list:
/* empty */ { $$ = array(); }
| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
{ $1[] = new PHPParser_Node_Stmt_ElseIf(array('cond' => $4, 'stmts' => $7), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Stmt_ElseIf(array('cond' => $4, 'stmts' => $7), #line, #docComment); $$ = $1; }
;
else_single:
/* empty */ { $$ = null; }
| T_ELSE statement { $$ = new PHPParser_Node_Stmt_Else(array('stmts' => is_array($2) ? $2 : array($2)), #line); }
| T_ELSE statement { $$ = new PHPParser_Node_Stmt_Else(array('stmts' => is_array($2) ? $2 : array($2)), #line, #docComment); }
;
new_else_single:
/* empty */ { $$ = null; }
| T_ELSE ':' inner_statement_list { $$ = new PHPParser_Node_Stmt_Else(array('stmts' => $3), #line); }
| T_ELSE ':' inner_statement_list { $$ = new PHPParser_Node_Stmt_Else(array('stmts' => $3), #line, #docComment); }
;
parameter_list:
@ -330,13 +330,13 @@ parameter_list:
non_empty_parameter_list:
optional_class_type optional_ref T_VARIABLE
{ $$ = array(new PHPParser_Node_Stmt_FuncParam(array('type' => $1, 'name' => substr($3, 1), 'byRef' => $2, 'default' => null), #line)); }
{ $$ = array(new PHPParser_Node_Stmt_FuncParam(array('type' => $1, 'name' => substr($3, 1), 'byRef' => $2, 'default' => null), #line, #docComment)); }
| optional_class_type optional_ref T_VARIABLE '=' static_scalar
{ $$ = array(new PHPParser_Node_Stmt_FuncParam(array('type' => $1, 'name' => substr($3, 1), 'byRef' => $2, 'default' => $5), #line)); }
{ $$ = array(new PHPParser_Node_Stmt_FuncParam(array('type' => $1, 'name' => substr($3, 1), 'byRef' => $2, 'default' => $5), #line, #docComment)); }
| non_empty_parameter_list ',' optional_class_type optional_ref T_VARIABLE
{ $1[] = new PHPParser_Node_Stmt_FuncParam(array('type' => $3, 'name' => substr($5, 1), 'byRef' => $4, 'default' => null), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Stmt_FuncParam(array('type' => $3, 'name' => substr($5, 1), 'byRef' => $4, 'default' => null), #line, #docComment); $$ = $1; }
| non_empty_parameter_list ',' optional_class_type optional_ref T_VARIABLE '=' static_scalar
{ $1[] = new PHPParser_Node_Stmt_FuncParam(array('type' => $3, 'name' => substr($5, 1), 'byRef' => $4, 'default' => $7), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Stmt_FuncParam(array('type' => $3, 'name' => substr($5, 1), 'byRef' => $4, 'default' => $7), #line, #docComment); $$ = $1; }
;
optional_class_type:
@ -351,12 +351,12 @@ function_call_argument_list:
;
non_empty_function_call_argument_list:
expr { $$ = array(new PHPParser_Node_Expr_FuncCallArg(array('value' => $1, 'byRef' => false), #line)); }
| '&' variable { $$ = array(new PHPParser_Node_Expr_FuncCallArg(array('value' => $2, 'byRef' => true), #line)); }
expr { $$ = array(new PHPParser_Node_Expr_FuncCallArg(array('value' => $1, 'byRef' => false), #line, #docComment)); }
| '&' variable { $$ = array(new PHPParser_Node_Expr_FuncCallArg(array('value' => $2, 'byRef' => true), #line, #docComment)); }
| non_empty_function_call_argument_list ',' expr
{ $1[] = new PHPParser_Node_Expr_FuncCallArg(array('value' => $3, 'byRef' => false), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Expr_FuncCallArg(array('value' => $3, 'byRef' => false), #line, #docComment); $$ = $1; }
| non_empty_function_call_argument_list ',' '&' variable
{ $1[] = new PHPParser_Node_Expr_FuncCallArg(array('value' => $4, 'byRef' => true), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Expr_FuncCallArg(array('value' => $4, 'byRef' => true), #line, #docComment); $$ = $1; }
;
global_var_list:
@ -365,16 +365,16 @@ global_var_list:
;
global_var:
T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line); }
| '$' variable { $$ = new PHPParser_Node_Variable(array('name' => $2), #line); }
| '$' '{' expr '}' { $$ = new PHPParser_Node_Variable(array('name' => $3), #line); }
T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line, #docComment); }
| '$' variable { $$ = new PHPParser_Node_Variable(array('name' => $2), #line, #docComment); }
| '$' '{' expr '}' { $$ = new PHPParser_Node_Variable(array('name' => $3), #line, #docComment); }
;
static_var_list:
static_var_list ',' T_VARIABLE { $1[] = new PHPParser_Node_Stmt_StaticVar(array('name' => substr($3, 1), 'default' => null), #line); $$ = $1; }
| static_var_list ',' T_VARIABLE '=' static_scalar { $1[] = new PHPParser_Node_Stmt_StaticVar(array('name' => substr($3, 1), 'default' => $5), #line); $$ = $1; }
| T_VARIABLE { $$ = array(new PHPParser_Node_Stmt_StaticVar(array('name' => substr($1, 1), 'default' => null), #line)); }
| T_VARIABLE '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_StaticVar(array('name' => substr($1, 1), 'default' => $3), #line)); }
static_var_list ',' T_VARIABLE { $1[] = new PHPParser_Node_Stmt_StaticVar(array('name' => substr($3, 1), 'default' => null), #line, #docComment); $$ = $1; }
| static_var_list ',' T_VARIABLE '=' static_scalar { $1[] = new PHPParser_Node_Stmt_StaticVar(array('name' => substr($3, 1), 'default' => $5), #line, #docComment); $$ = $1; }
| T_VARIABLE { $$ = array(new PHPParser_Node_Stmt_StaticVar(array('name' => substr($1, 1), 'default' => null), #line, #docComment)); }
| T_VARIABLE '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_StaticVar(array('name' => substr($1, 1), 'default' => $3), #line, #docComment)); }
;
class_statement_list:
@ -383,10 +383,10 @@ class_statement_list:
;
class_statement:
variable_modifiers class_variable_declaration ';' { $$ = new PHPParser_Node_Stmt_Property(array('type' => $1, 'props' => $2), #line); }
| class_constant_declaration ';' { $$ = new PHPParser_Node_Stmt_ClassConst(array('consts' => $1), #line); }
variable_modifiers class_variable_declaration ';' { $$ = new PHPParser_Node_Stmt_Property(array('type' => $1, 'props' => $2), #line, #docComment); }
| class_constant_declaration ';' { $$ = new PHPParser_Node_Stmt_ClassConst(array('consts' => $1), #line, #docComment); }
| method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' method_body
{ $$ = new PHPParser_Node_Stmt_ClassMethod(array('type' => $1, 'byRef' => $3, 'name' => $4, 'params' => $6, 'stmts' => $8), #line); }
{ $$ = new PHPParser_Node_Stmt_ClassMethod(array('type' => $1, 'byRef' => $3, 'name' => $4, 'params' => $6, 'stmts' => $8), #line, #docComment); }
;
method_body:
@ -420,19 +420,19 @@ member_modifier:
class_variable_declaration:
class_variable_declaration ',' T_VARIABLE
{ $1[] = new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($3, 1), 'default' => null), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($3, 1), 'default' => null), #line, #docComment); $$ = $1; }
| class_variable_declaration ',' T_VARIABLE '=' static_scalar
{ $1[] = new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($3, 1), 'default' => $5), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($3, 1), 'default' => $5), #line, #docComment); $$ = $1; }
| T_VARIABLE
{ $$ = array(new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($1, 1), 'default' => null), #line)); }
{ $$ = array(new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($1, 1), 'default' => null), #line, #docComment)); }
| T_VARIABLE '=' static_scalar
{ $$ = array(new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($1, 1), 'default' => $3), #line)); }
{ $$ = array(new PHPParser_Node_Stmt_PropertyProperty(array('name' => substr($1, 1), 'default' => $3), #line, #docComment)); }
;
class_constant_declaration:
class_constant_declaration ',' T_STRING '=' static_scalar
{ $1[] = new PHPParser_Node_Stmt_ClassConstConst(array('name' => $3, 'value' => $5), #line); $$ = $1; }
| T_CONST T_STRING '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_ClassConstConst(array('name' => $2, 'value' => $4), #line)); }
{ $1[] = new PHPParser_Node_Stmt_ClassConstConst(array('name' => $3, 'value' => $5), #line, #docComment); $$ = $1; }
| T_CONST T_STRING '=' static_scalar { $$ = array(new PHPParser_Node_Stmt_ClassConstConst(array('name' => $2, 'value' => $4), #line, #docComment)); }
;
expr_list:
@ -447,83 +447,83 @@ for_expr:
expr:
variable { $$ = $1; }
| T_LIST '(' assignment_list ')' '=' expr { $$ = new PHPParser_Node_Expr_List(array('assignList' => $3, 'expr' => $6), #line); }
| variable '=' expr { $$ = new PHPParser_Node_Expr_Assign(array('var' => $1, 'expr' => $3), #line); }
| variable '=' '&' variable { $$ = new PHPParser_Node_Expr_AssignRef(array('var' => $1, 'refVar' => $4), #line); }
| T_LIST '(' assignment_list ')' '=' expr { $$ = new PHPParser_Node_Expr_List(array('assignList' => $3, 'expr' => $6), #line, #docComment); }
| variable '=' expr { $$ = new PHPParser_Node_Expr_Assign(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable '=' '&' variable { $$ = new PHPParser_Node_Expr_AssignRef(array('var' => $1, 'refVar' => $4), #line, #docComment); }
| variable '=' '&' T_NEW class_name_reference ctor_arguments
{ $$ = new PHPParser_Node_Expr_Assign(array('var' => $1, 'expr' => new PHPParser_Node_Expr_New(array('class' => $5, 'args' => $6), #line)), #line); }
{ $$ = new PHPParser_Node_Expr_Assign(array('var' => $1, 'expr' => new PHPParser_Node_Expr_New(array('class' => $5, 'args' => $6), #line, #docComment)), #line, #docComment); }
/* reference dropped intentially, TODO: Throw error? */
| T_NEW class_name_reference ctor_arguments { $$ = new PHPParser_Node_Expr_New(array('class' => $2, 'args' => $3), #line); }
| T_CLONE expr { $$ = new PHPParser_Node_Expr_Clone(array('expr' => $2), #line); }
| variable T_PLUS_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignPlus(array('var' => $1, 'expr' => $3), #line); }
| variable T_MINUS_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignMinus(array('var' => $1, 'expr' => $3), #line); }
| variable T_MUL_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignMul(array('var' => $1, 'expr' => $3), #line); }
| variable T_DIV_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignDiv(array('var' => $1, 'expr' => $3), #line); }
| variable T_CONCAT_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignConcat(array('var' => $1, 'expr' => $3), #line); }
| variable T_MOD_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignMod(array('var' => $1, 'expr' => $3), #line); }
| variable T_AND_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignBinAnd(array('var' => $1, 'expr' => $3), #line); }
| variable T_OR_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignBinOr(array('var' => $1, 'expr' => $3), #line); }
| variable T_XOR_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignBinXor(array('var' => $1, 'expr' => $3), #line); }
| variable T_SL_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignShiftLeft(array('var' => $1, 'expr' => $3), #line); }
| variable T_SR_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignShiftRight(array('var' => $1, 'expr' => $3), #line); }
| variable T_INC { $$ = new PHPParser_Node_Expr_PostInc(array('var' => $1), #line); }
| T_INC variable { $$ = new PHPParser_Node_Expr_PreInc(array('var' => $2), #line); }
| variable T_DEC { $$ = new PHPParser_Node_Expr_PostDec(array('var' => $1), #line); }
| T_DEC variable { $$ = new PHPParser_Node_Expr_PreDec(array('var' => $2), #line); }
| expr T_BOOLEAN_OR expr { $$ = new PHPParser_Node_Expr_BooleanOr(array('left' => $1, 'right' => $3), #line); }
| expr T_BOOLEAN_AND expr { $$ = new PHPParser_Node_Expr_BooleanAnd(array('left' => $1, 'right' => $3), #line); }
| expr T_LOGICAL_OR expr { $$ = new PHPParser_Node_Expr_LogicalOr(array('left' => $1, 'right' => $3), #line); }
| expr T_LOGICAL_AND expr { $$ = new PHPParser_Node_Expr_LogicalAnd(array('left' => $1, 'right' => $3), #line); }
| expr T_LOGICAL_XOR expr { $$ = new PHPParser_Node_Expr_LogicalXor(array('left' => $1, 'right' => $3), #line); }
| expr '|' expr { $$ = new PHPParser_Node_Expr_BinaryOr(array('left' => $1, 'right' => $3), #line); }
| expr '&' expr { $$ = new PHPParser_Node_Expr_BinaryAnd(array('left' => $1, 'right' => $3), #line); }
| expr '^' expr { $$ = new PHPParser_Node_Expr_BinaryXor(array('left' => $1, 'right' => $3), #line); }
| expr '.' expr { $$ = new PHPParser_Node_Expr_Concat(array('left' => $1, 'right' => $3), #line); }
| expr '+' expr { $$ = new PHPParser_Node_Expr_Plus(array('left' => $1, 'right' => $3), #line); }
| expr '-' expr { $$ = new PHPParser_Node_Expr_Minus(array('left' => $1, 'right' => $3), #line); }
| expr '*' expr { $$ = new PHPParser_Node_Expr_Mul(array('left' => $1, 'right' => $3), #line); }
| expr '/' expr { $$ = new PHPParser_Node_Expr_Div(array('left' => $1, 'right' => $3), #line); }
| expr '%' expr { $$ = new PHPParser_Node_Expr_Mod(array('left' => $1, 'right' => $3), #line); }
| expr T_SL expr { $$ = new PHPParser_Node_Expr_ShiftLeft(array('left' => $1, 'right' => $3), #line); }
| expr T_SR expr { $$ = new PHPParser_Node_Expr_ShiftRight(array('left' => $1, 'right' => $3), #line); }
| '+' expr %prec T_INC { $$ = new PHPParser_Node_Expr_UnaryPlus(array('expr' => $2), #line); }
| '-' expr %prec T_INC { $$ = new PHPParser_Node_Expr_UnaryMinus(array('expr' => $2), #line); }
| '!' expr { $$ = new PHPParser_Node_Expr_BooleanNot(array('expr' => $2), #line); }
| '~' expr { $$ = new PHPParser_Node_Expr_BinaryNot(array('expr' => $2), #line); }
| expr T_IS_IDENTICAL expr { $$ = new PHPParser_Node_Expr_Identical(array('left' => $1, 'right' => $3), #line); }
| expr T_IS_NOT_IDENTICAL expr { $$ = new PHPParser_Node_Expr_NotIdentical(array('left' => $1, 'right' => $3), #line); }
| expr T_IS_EQUAL expr { $$ = new PHPParser_Node_Expr_Equal(array('left' => $1, 'right' => $3), #line); }
| expr T_IS_NOT_EQUAL expr { $$ = new PHPParser_Node_Expr_NotEqual(array('left' => $1, 'right' => $3), #line); }
| expr '<' expr { $$ = new PHPParser_Node_Expr_Smaller(array('left' => $1, 'right' => $3), #line); }
| expr T_IS_SMALLER_OR_EQUAL expr { $$ = new PHPParser_Node_Expr_SmallerOrEqual(array('left' => $1, 'right' => $3), #line); }
| expr '>' expr { $$ = new PHPParser_Node_Expr_Greater(array('left' => $1, 'right' => $3), #line); }
| expr T_IS_GREATER_OR_EQUAL expr { $$ = new PHPParser_Node_Expr_GreaterOrEqual(array('left' => $1, 'right' => $3), #line); }
| expr T_INSTANCEOF class_name_reference { $$ = new PHPParser_Node_Expr_Instanceof(array('expr' => $1, 'class' => $3), #line); }
| T_NEW class_name_reference ctor_arguments { $$ = new PHPParser_Node_Expr_New(array('class' => $2, 'args' => $3), #line, #docComment); }
| T_CLONE expr { $$ = new PHPParser_Node_Expr_Clone(array('expr' => $2), #line, #docComment); }
| variable T_PLUS_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignPlus(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_MINUS_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignMinus(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_MUL_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignMul(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_DIV_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignDiv(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_CONCAT_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignConcat(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_MOD_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignMod(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_AND_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignBinAnd(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_OR_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignBinOr(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_XOR_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignBinXor(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_SL_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignShiftLeft(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_SR_EQUAL expr { $$ = new PHPParser_Node_Expr_AssignShiftRight(array('var' => $1, 'expr' => $3), #line, #docComment); }
| variable T_INC { $$ = new PHPParser_Node_Expr_PostInc(array('var' => $1), #line, #docComment); }
| T_INC variable { $$ = new PHPParser_Node_Expr_PreInc(array('var' => $2), #line, #docComment); }
| variable T_DEC { $$ = new PHPParser_Node_Expr_PostDec(array('var' => $1), #line, #docComment); }
| T_DEC variable { $$ = new PHPParser_Node_Expr_PreDec(array('var' => $2), #line, #docComment); }
| expr T_BOOLEAN_OR expr { $$ = new PHPParser_Node_Expr_BooleanOr(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_BOOLEAN_AND expr { $$ = new PHPParser_Node_Expr_BooleanAnd(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_LOGICAL_OR expr { $$ = new PHPParser_Node_Expr_LogicalOr(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_LOGICAL_AND expr { $$ = new PHPParser_Node_Expr_LogicalAnd(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_LOGICAL_XOR expr { $$ = new PHPParser_Node_Expr_LogicalXor(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '|' expr { $$ = new PHPParser_Node_Expr_BinaryOr(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '&' expr { $$ = new PHPParser_Node_Expr_BinaryAnd(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '^' expr { $$ = new PHPParser_Node_Expr_BinaryXor(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '.' expr { $$ = new PHPParser_Node_Expr_Concat(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '+' expr { $$ = new PHPParser_Node_Expr_Plus(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '-' expr { $$ = new PHPParser_Node_Expr_Minus(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '*' expr { $$ = new PHPParser_Node_Expr_Mul(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '/' expr { $$ = new PHPParser_Node_Expr_Div(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '%' expr { $$ = new PHPParser_Node_Expr_Mod(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_SL expr { $$ = new PHPParser_Node_Expr_ShiftLeft(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_SR expr { $$ = new PHPParser_Node_Expr_ShiftRight(array('left' => $1, 'right' => $3), #line, #docComment); }
| '+' expr %prec T_INC { $$ = new PHPParser_Node_Expr_UnaryPlus(array('expr' => $2), #line, #docComment); }
| '-' expr %prec T_INC { $$ = new PHPParser_Node_Expr_UnaryMinus(array('expr' => $2), #line, #docComment); }
| '!' expr { $$ = new PHPParser_Node_Expr_BooleanNot(array('expr' => $2), #line, #docComment); }
| '~' expr { $$ = new PHPParser_Node_Expr_BinaryNot(array('expr' => $2), #line, #docComment); }
| expr T_IS_IDENTICAL expr { $$ = new PHPParser_Node_Expr_Identical(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_IS_NOT_IDENTICAL expr { $$ = new PHPParser_Node_Expr_NotIdentical(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_IS_EQUAL expr { $$ = new PHPParser_Node_Expr_Equal(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_IS_NOT_EQUAL expr { $$ = new PHPParser_Node_Expr_NotEqual(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '<' expr { $$ = new PHPParser_Node_Expr_Smaller(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_IS_SMALLER_OR_EQUAL expr { $$ = new PHPParser_Node_Expr_SmallerOrEqual(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr '>' expr { $$ = new PHPParser_Node_Expr_Greater(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_IS_GREATER_OR_EQUAL expr { $$ = new PHPParser_Node_Expr_GreaterOrEqual(array('left' => $1, 'right' => $3), #line, #docComment); }
| expr T_INSTANCEOF class_name_reference { $$ = new PHPParser_Node_Expr_Instanceof(array('expr' => $1, 'class' => $3), #line, #docComment); }
| '(' expr ')' { $$ = $2; }
| expr '?' expr ':' expr { $$ = new PHPParser_Node_Expr_Ternary(array('cond' => $1, 'if' => $3, 'else' => $5), #line); }
| expr '?' ':' expr { $$ = new PHPParser_Node_Expr_Ternary(array('cond' => $1, 'if' => null, 'else' => $4), #line); }
| T_ISSET '(' variables_list ')' { $$ = new PHPParser_Node_Expr_Isset(array('vars' => $3), #line); }
| T_EMPTY '(' variable ')' { $$ = new PHPParser_Node_Expr_Empty(array('var' => $3), #line); }
| T_INCLUDE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_INCLUDE), #line); }
| T_INCLUDE_ONCE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_INCLUDE_ONCE), #line); }
| T_EVAL '(' expr ')' { $$ = new PHPParser_Node_Expr_Eval(array('expr' => $3), #line); }
| T_REQUIRE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_REQUIRE), #line); }
| T_REQUIRE_ONCE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_REQUIRE_ONCE), #line); }
| T_INT_CAST expr { $$ = new PHPParser_Node_Expr_IntCast(array('expr' => $2), #line); }
| T_DOUBLE_CAST expr { $$ = new PHPParser_Node_Expr_DoubleCast(array('expr' => $2), #line); }
| T_STRING_CAST expr { $$ = new PHPParser_Node_Expr_StringCast(array('expr' => $2), #line); }
| T_ARRAY_CAST expr { $$ = new PHPParser_Node_Expr_ArrayCast(array('expr' => $2), #line); }
| T_OBJECT_CAST expr { $$ = new PHPParser_Node_Expr_ObjectCast(array('expr' => $2), #line); }
| T_BOOL_CAST expr { $$ = new PHPParser_Node_Expr_BoolCast(array('expr' => $2), #line); }
| T_UNSET_CAST expr { $$ = new PHPParser_Node_Expr_UnsetCast(array('expr' => $2), #line); }
| T_EXIT exit_expr { $$ = new PHPParser_Node_Expr_Exit(array('expr' => $2), #line); }
| '@' expr { $$ = new PHPParser_Node_Expr_ErrorSuppress(array('expr' => $2), #line); }
| expr '?' expr ':' expr { $$ = new PHPParser_Node_Expr_Ternary(array('cond' => $1, 'if' => $3, 'else' => $5), #line, #docComment); }
| expr '?' ':' expr { $$ = new PHPParser_Node_Expr_Ternary(array('cond' => $1, 'if' => null, 'else' => $4), #line, #docComment); }
| T_ISSET '(' variables_list ')' { $$ = new PHPParser_Node_Expr_Isset(array('vars' => $3), #line, #docComment); }
| T_EMPTY '(' variable ')' { $$ = new PHPParser_Node_Expr_Empty(array('var' => $3), #line, #docComment); }
| T_INCLUDE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_INCLUDE), #line, #docComment); }
| T_INCLUDE_ONCE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_INCLUDE_ONCE), #line, #docComment); }
| T_EVAL '(' expr ')' { $$ = new PHPParser_Node_Expr_Eval(array('expr' => $3), #line, #docComment); }
| T_REQUIRE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_REQUIRE), #line, #docComment); }
| T_REQUIRE_ONCE expr { $$ = new PHPParser_Node_Expr_Include(array('expr' => $2, 'type' => PHPParser_Node_Expr_Include::TYPE_REQUIRE_ONCE), #line, #docComment); }
| T_INT_CAST expr { $$ = new PHPParser_Node_Expr_IntCast(array('expr' => $2), #line, #docComment); }
| T_DOUBLE_CAST expr { $$ = new PHPParser_Node_Expr_DoubleCast(array('expr' => $2), #line, #docComment); }
| T_STRING_CAST expr { $$ = new PHPParser_Node_Expr_StringCast(array('expr' => $2), #line, #docComment); }
| T_ARRAY_CAST expr { $$ = new PHPParser_Node_Expr_ArrayCast(array('expr' => $2), #line, #docComment); }
| T_OBJECT_CAST expr { $$ = new PHPParser_Node_Expr_ObjectCast(array('expr' => $2), #line, #docComment); }
| T_BOOL_CAST expr { $$ = new PHPParser_Node_Expr_BoolCast(array('expr' => $2), #line, #docComment); }
| T_UNSET_CAST expr { $$ = new PHPParser_Node_Expr_UnsetCast(array('expr' => $2), #line, #docComment); }
| T_EXIT exit_expr { $$ = new PHPParser_Node_Expr_Exit(array('expr' => $2), #line, #docComment); }
| '@' expr { $$ = new PHPParser_Node_Expr_ErrorSuppress(array('expr' => $2), #line, #docComment); }
| scalar { $$ = $1; }
| T_ARRAY '(' array_pair_list ')' { $$ = new PHPParser_Node_Expr_Array(array('items' => $3), #line); }
| '`' backticks_expr '`' { $$ = new PHPParser_Node_Expr_ShellExec(array('parts' => $2), #line); }
| T_PRINT expr { $$ = new PHPParser_Node_Expr_Print(array('expr' => $2), #line); }
| T_ARRAY '(' array_pair_list ')' { $$ = new PHPParser_Node_Expr_Array(array('items' => $3), #line, #docComment); }
| '`' backticks_expr '`' { $$ = new PHPParser_Node_Expr_ShellExec(array('parts' => $2), #line, #docComment); }
| T_PRINT expr { $$ = new PHPParser_Node_Expr_Print(array('expr' => $2), #line, #docComment); }
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
{ $$ = new PHPParser_Node_Expr_LambdaFunc(array('byRef' => $2, 'params' => $4, 'useVars' => $6, 'stmts' => $8), #line); }
{ $$ = new PHPParser_Node_Expr_LambdaFunc(array('byRef' => $2, 'params' => $4, 'useVars' => $6, 'stmts' => $8), #line, #docComment); }
;
lexical_vars:
@ -533,34 +533,34 @@ lexical_vars:
lexical_var_list:
lexical_var_list ',' optional_ref T_VARIABLE
{ $1[] = new PHPParser_Node_Expr_LambdaFuncUse(array('var' => substr($4, 1), 'byRef' => $3), #line); $$ = $1; }
{ $1[] = new PHPParser_Node_Expr_LambdaFuncUse(array('var' => substr($4, 1), 'byRef' => $3), #line, #docComment); $$ = $1; }
| optional_ref T_VARIABLE
{ $$ = array(new PHPParser_Node_Expr_LambdaFuncUse(array('var' => substr($2, 1), 'byRef' => $1), #line)); }
{ $$ = array(new PHPParser_Node_Expr_LambdaFuncUse(array('var' => substr($2, 1), 'byRef' => $1), #line, #docComment)); }
;
function_call:
name '(' function_call_argument_list ')' { $$ = new PHPParser_Node_Expr_FuncCall(array('func' => $1, 'args' => $3), #line); }
name '(' function_call_argument_list ')' { $$ = new PHPParser_Node_Expr_FuncCall(array('func' => $1, 'args' => $3), #line, #docComment); }
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
{ $$ = new PHPParser_Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5), #line); }
{ $$ = new PHPParser_Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5), #line, #docComment); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
{ $$ = new PHPParser_Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5), #line); }
{ $$ = new PHPParser_Node_Expr_StaticCall(array('class' => $1, 'func' => $3, 'args' => $5), #line, #docComment); }
| static_property_with_arrays '(' function_call_argument_list ')' {
if ($1 instanceof PHPParser_Node_Expr_StaticPropertyFetch) {
$$ = new PHPParser_Node_Expr_StaticCall(array('class' => $1->class, 'func' => $1->name, 'args' => $3), #line);
$$ = new PHPParser_Node_Expr_StaticCall(array('class' => $1->class, 'func' => $1->name, 'args' => $3), #line, #docComment);
} elseif ($1 instanceof PHPParser_Node_Expr_ArrayDimFetch) {
$2 = $1; // $2 is just a temporary variable. Nothing to do with the '('
while ($2->var instanceof PHPParser_Node_Expr_ArrayDimFetch) {
$2 = $2->var;
}
$$ = new PHPParser_Node_Expr_StaticCall(array('class' => $2->var->class, 'func' => $1, 'args' => $3), #line);
$2->var = new PHPParser_Node_Variable(array('name' => $2->var->name), #line);
$$ = new PHPParser_Node_Expr_StaticCall(array('class' => $2->var->class, 'func' => $1, 'args' => $3), #line, #docComment);
$2->var = new PHPParser_Node_Variable(array('name' => $2->var->name), #line, #docComment);
} else {
throw new Exception;
}
}
| variable_without_objects '(' function_call_argument_list ')'
{ $$ = new PHPParser_Node_Expr_FuncCall(array('func' => $1, 'args' => $3), #line); }
{ $$ = new PHPParser_Node_Expr_FuncCall(array('func' => $1, 'args' => $3), #line, #docComment); }
;
class_name:
@ -586,11 +586,11 @@ dynamic_class_name_reference:
object_access_for_dcnr:
| base_variable T_OBJECT_OPERATOR object_property
{ $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3), #line); }
{ $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3), #line, #docComment); }
| object_access_for_dcnr T_OBJECT_OPERATOR object_property
{ $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3), #line); }
| object_access_for_dcnr '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
| object_access_for_dcnr '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
{ $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3), #line, #docComment); }
| object_access_for_dcnr '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
| object_access_for_dcnr '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
;
exit_expr:
@ -611,38 +611,38 @@ ctor_arguments:
;
common_scalar:
T_LNUMBER { $$ = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $1), #line); }
| T_DNUMBER { $$ = new PHPParser_Node_Scalar_DNumber(array('value' => (double) $1), #line); }
T_LNUMBER { $$ = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $1), #line, #docComment); }
| T_DNUMBER { $$ = new PHPParser_Node_Scalar_DNumber(array('value' => (double) $1), #line, #docComment); }
| T_CONSTANT_ENCAPSED_STRING { $$ = PHPParser_Node_Scalar_String::create($1, #line); }
| T_LINE { $$ = new PHPParser_Node_Scalar_LineConst(array(), #line); }
| T_FILE { $$ = new PHPParser_Node_Scalar_FileConst(array(), #line); }
| T_DIR { $$ = new PHPParser_Node_Scalar_DirConst(array(), #line); }
| T_CLASS_C { $$ = new PHPParser_Node_Scalar_ClassConst(array(), #line); }
| T_METHOD_C { $$ = new PHPParser_Node_Scalar_MethodConst(array(), #line); }
| T_FUNC_C { $$ = new PHPParser_Node_Scalar_FuncConst(array(), #line); }
| T_NS_C { $$ = new PHPParser_Node_Scalar_NSConst(array(), #line); }
| T_LINE { $$ = new PHPParser_Node_Scalar_LineConst(array(), #line, #docComment); }
| T_FILE { $$ = new PHPParser_Node_Scalar_FileConst(array(), #line, #docComment); }
| T_DIR { $$ = new PHPParser_Node_Scalar_DirConst(array(), #line, #docComment); }
| T_CLASS_C { $$ = new PHPParser_Node_Scalar_ClassConst(array(), #line, #docComment); }
| T_METHOD_C { $$ = new PHPParser_Node_Scalar_MethodConst(array(), #line, #docComment); }
| T_FUNC_C { $$ = new PHPParser_Node_Scalar_FuncConst(array(), #line, #docComment); }
| T_NS_C { $$ = new PHPParser_Node_Scalar_NSConst(array(), #line, #docComment); }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ $$ = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($2), 'isBinary' => false, 'type' => '\'' === $1[3] ? PHPParser_Node_Scalar_String::SINGLE_QUOTED : PHPParser_Node_Scalar_String::DOUBLE_QUOTED), #line); }
{ $$ = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($2), 'isBinary' => false, 'type' => '\'' === $1[3] ? PHPParser_Node_Scalar_String::SINGLE_QUOTED : PHPParser_Node_Scalar_String::DOUBLE_QUOTED), #line, #docComment); }
| T_START_HEREDOC T_END_HEREDOC
{ $$ = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), #line); }
{ $$ = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), #line, #docComment); }
;
static_scalar: /* compile-time evaluated scalars */
common_scalar { $$ = $1; }
| name { $$ = new PHPParser_Node_Expr_ConstFetch(array('name' => $1), #line); }
| '+' static_scalar { $$ = new PHPParser_Node_Expr_UnaryPlus(array('expr' => $2), #line); }
| '-' static_scalar { $$ = new PHPParser_Node_Expr_UnaryMinus(array('expr' => $2), #line); }
| T_ARRAY '(' static_array_pair_list ')' { $$ = new PHPParser_Node_Expr_Array(array('items' => $3), #line); }
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = new PHPParser_Node_Expr_ClassConstFetch(array('class' => $1, 'name' => $3), #line); }
| name { $$ = new PHPParser_Node_Expr_ConstFetch(array('name' => $1), #line, #docComment); }
| '+' static_scalar { $$ = new PHPParser_Node_Expr_UnaryPlus(array('expr' => $2), #line, #docComment); }
| '-' static_scalar { $$ = new PHPParser_Node_Expr_UnaryMinus(array('expr' => $2), #line, #docComment); }
| T_ARRAY '(' static_array_pair_list ')' { $$ = new PHPParser_Node_Expr_Array(array('items' => $3), #line, #docComment); }
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = new PHPParser_Node_Expr_ClassConstFetch(array('class' => $1, 'name' => $3), #line, #docComment); }
;
scalar:
T_STRING_VARNAME { $$ = new PHPParser_Node_Scalar_String(array('value' => $1, 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), #line); }
T_STRING_VARNAME { $$ = new PHPParser_Node_Scalar_String(array('value' => $1, 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), #line, #docComment); }
| class_constant { $$ = $1; }
| name { $$ = new PHPParser_Node_Expr_ConstFetch(array('name' => $1), #line); }
| name { $$ = new PHPParser_Node_Expr_ConstFetch(array('name' => $1), #line, #docComment); }
| common_scalar { $$ = $1; }
| '"' encaps_list '"' { $$ = new PHPParser_Node_Scalar_Encapsed(array('parts' => $2), #line); }
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = new PHPParser_Node_Scalar_Encapsed(array('parts' => $2), #line); }
| '"' encaps_list '"' { $$ = new PHPParser_Node_Scalar_Encapsed(array('parts' => $2), #line, #docComment); }
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = new PHPParser_Node_Scalar_Encapsed(array('parts' => $2), #line, #docComment); }
;
static_array_pair_list:
@ -657,10 +657,10 @@ optional_comma:
non_empty_static_array_pair_list:
non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW static_scalar
{ $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => $3, 'value' => $5, 'byRef' => false), #line); $$ = $1; }
| non_empty_static_array_pair_list ',' static_scalar { $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $3, 'byRef' => false), #line); $$ = $1; }
| static_scalar T_DOUBLE_ARROW static_scalar { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => $1, 'value' => $3, 'byRef' => false), #line)); }
| static_scalar { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $1, 'byRef' => false), #line)); }
{ $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => $3, 'value' => $5, 'byRef' => false), #line, #docComment); $$ = $1; }
| non_empty_static_array_pair_list ',' static_scalar { $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $3, 'byRef' => false), #line, #docComment); $$ = $1; }
| static_scalar T_DOUBLE_ARROW static_scalar { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => $1, 'value' => $3, 'byRef' => false), #line, #docComment)); }
| static_scalar { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $1, 'byRef' => false), #line, #docComment)); }
;
variable:
@ -672,50 +672,50 @@ variable:
object_access:
object_access_arrayable { $$ = $1; }
| object_access_arrayable '(' function_call_argument_list ')'
{ $$ = new PHPParser_Node_Expr_FuncCall(array('func' => $1, 'args' => $3), #line); }
{ $$ = new PHPParser_Node_Expr_FuncCall(array('func' => $1, 'args' => $3), #line, #docComment); }
| variable T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = new PHPParser_Node_Expr_MethodCall(array('var' => $1, 'name' => $3, 'args' => $5), #line); }
{ $$ = new PHPParser_Node_Expr_MethodCall(array('var' => $1, 'name' => $3, 'args' => $5), #line, #docComment); }
;
object_access_arrayable:
variable T_OBJECT_OPERATOR object_property
{ $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3), #line); }
| object_access_arrayable '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
| object_access_arrayable '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
{ $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3), #line, #docComment); }
| object_access_arrayable '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
| object_access_arrayable '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
;
variable_without_objects:
reference_variable { $$ = $1; }
| '$' reference_variable { $$ = new PHPParser_Node_Variable(array('name' => $2), #line); }
| '$' reference_variable { $$ = new PHPParser_Node_Variable(array('name' => $2), #line, #docComment); }
;
base_variable:
variable_without_objects { $$ = $1; }
| class_name T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $4), #line); }
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $4), #line, #docComment); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $4), #line); }
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $4), #line, #docComment); }
| static_property_with_arrays { $$ = $1; }
;
static_property_with_arrays:
class_name T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => substr($3, 1)), #line); }
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => substr($3, 1)), #line, #docComment); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => substr($3, 1)), #line); }
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => substr($3, 1)), #line, #docComment); }
| class_name T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $5), #line); }
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $5), #line, #docComment); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $5), #line); }
| static_property_with_arrays '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
| static_property_with_arrays '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
{ $$ = new PHPParser_Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $5), #line, #docComment); }
| static_property_with_arrays '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
| static_property_with_arrays '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
;
reference_variable:
reference_variable '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
| reference_variable '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line); }
| T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line); }
| '$' '{' expr '}' { $$ = new PHPParser_Node_Variable(array('name' => $3), #line); }
reference_variable '[' dim_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
| reference_variable '{' expr '}' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3), #line, #docComment); }
| T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line, #docComment); }
| '$' '{' expr '}' { $$ = new PHPParser_Node_Variable(array('name' => $3), #line, #docComment); }
;
dim_offset:
@ -747,15 +747,15 @@ array_pair_list:
non_empty_array_pair_list:
non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
{ $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => $3, 'value' => $5, 'byRef' => false), #line); $$ = $1; }
| non_empty_array_pair_list ',' expr { $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $3, 'byRef' => false), #line); $$ = $1; }
| expr T_DOUBLE_ARROW expr { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => $1, 'value' => $3, 'byRef' => false), #line)); }
| expr { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $1, 'byRef' => false), #line)); }
{ $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => $3, 'value' => $5, 'byRef' => false), #line, #docComment); $$ = $1; }
| non_empty_array_pair_list ',' expr { $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $3, 'byRef' => false), #line, #docComment); $$ = $1; }
| expr T_DOUBLE_ARROW expr { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => $1, 'value' => $3, 'byRef' => false), #line, #docComment)); }
| expr { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $1, 'byRef' => false), #line, #docComment)); }
| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' variable
{ $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => $3, 'value' => $6, 'byRef' => true), #line); $$ = $1; }
| non_empty_array_pair_list ',' '&' variable { $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $4, 'byRef' => true), #line); $$ = $1; }
| expr T_DOUBLE_ARROW '&' variable { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => $1, 'value' => $4, 'byRef' => true), #line)); }
| '&' variable { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $2, 'byRef' => true), #line)); }
{ $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => $3, 'value' => $6, 'byRef' => true), #line, #docComment); $$ = $1; }
| non_empty_array_pair_list ',' '&' variable { $1[] = new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $4, 'byRef' => true), #line, #docComment); $$ = $1; }
| expr T_DOUBLE_ARROW '&' variable { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => $1, 'value' => $4, 'byRef' => true), #line, #docComment)); }
| '&' variable { $$ = array(new PHPParser_Node_Expr_ArrayItem(array('key' => null, 'value' => $2, 'byRef' => true), #line, #docComment)); }
;
encaps_list:
@ -766,24 +766,24 @@ encaps_list:
;
encaps_var:
T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line); }
| T_VARIABLE '[' encaps_var_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line), 'dim' => $3), #line); }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line), 'name' => $3), #line); }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = new PHPParser_Node_Variable(array('name' => $2), #line); }
T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line, #docComment); }
| T_VARIABLE '[' encaps_var_offset ']' { $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line, #docComment), 'dim' => $3), #line, #docComment); }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = new PHPParser_Node_Expr_PropertyFetch(array('var' => new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line, #docComment), 'name' => $3), #line, #docComment); }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = new PHPParser_Node_Variable(array('name' => $2), #line, #docComment); }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
{ $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => $2), #line), 'dim' => $4), #line); }
{ $$ = new PHPParser_Node_Expr_ArrayDimFetch(array('var' => new PHPParser_Node_Variable(array('name' => $2), #line, #docComment), 'dim' => $4), #line, #docComment); }
| T_CURLY_OPEN variable '}' { $$ = $2; }
;
encaps_var_offset:
T_STRING { $$ = new PHPParser_Node_Scalar_String(array('value' => $1, 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), #line); }
| T_NUM_STRING { $$ = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $1), #line); }
| T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line); }
T_STRING { $$ = new PHPParser_Node_Scalar_String(array('value' => $1, 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), #line, #docComment); }
| T_NUM_STRING { $$ = new PHPParser_Node_Scalar_LNumber(array('value' => (int) $1), #line, #docComment); }
| T_VARIABLE { $$ = new PHPParser_Node_Variable(array('name' => substr($1, 1)), #line, #docComment); }
;
class_constant:
class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = new PHPParser_Node_Expr_ClassConstFetch(array('class' => $1, 'name' => $3), #line); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = new PHPParser_Node_Expr_ClassConstFetch(array('class' => $1, 'name' => $3), #line); }
class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = new PHPParser_Node_Expr_ClassConstFetch(array('class' => $1, 'name' => $3), #line, #docComment); }
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = new PHPParser_Node_Expr_ClassConstFetch(array('class' => $1, 'name' => $3), #line, #docComment); }
;
%%

View File

@ -9,7 +9,7 @@ class PHPParser_Lexer
private static $tokenMap;
private static $dropTokens = array(
T_WHITESPACE => 1, T_COMMENT => 1, T_DOC_COMMENT => 1, T_OPEN_TAG => 1
T_WHITESPACE => 1, T_COMMENT => 1, T_OPEN_TAG => 1
);
/**
@ -53,12 +53,15 @@ class PHPParser_Lexer
/**
* Returns the next token id.
*
* @param mixed $value Variable to store token content in
* @param mixed $line Variable to store line in
* @param mixed $value Variable to store token content in
* @param mixed $line Variable to store line in
* @param mixed $docComment Variable to store doc comment in
*
* @return int Token id
*/
public function lex(&$value, &$line) {
public function lex(&$value, &$line, &$docComment) {
$docComment = null;
while (isset($this->tokens[++$this->pos])) {
$token = $this->tokens[$this->pos];
@ -66,6 +69,8 @@ class PHPParser_Lexer
$value = $token;
$line = $this->line;
return ord($token);
} elseif (T_DOC_COMMENT === $token[0]) {
$docComment = $token[1];
} elseif (!isset(self::$dropTokens[$token[0]])) {
$value = $token[1];
$line = $this->line = $token[2];

View File

@ -3,17 +3,20 @@
abstract class PHPParser_NodeAbstract extends ArrayObject
{
protected $line;
protected $docComment;
/**
* Creates a Node.
*
* @param array $subNodes Array of sub nodes
* @param int $line Line
* @param array $subNodes Array of sub nodes
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $subNodes, $line = -1) {
public function __construct(array $subNodes, $line = -1, $docComment = null) {
parent::__construct($subNodes, ArrayObject::ARRAY_AS_PROPS);
$this->line = $line;
$this->line = $line;
$this->docComment = $docComment;
}
/**
@ -36,4 +39,13 @@ abstract class PHPParser_NodeAbstract extends ArrayObject
public function getLine() {
return $this->line;
}
/**
* Gets the nearest doc comment.
*
* @return null|string Nearest doc comment or null
*/
public function getDocComment() {
return $this->docComment;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -103,7 +103,10 @@ abstract class PHPParser_PrettyPrinterAbstract
protected function pStmts(array $nodes, $indent = true) {
$pNodes = array();
foreach ($nodes as $node) {
$pNodes[] = $this->p($node)
$pNodes[] = ((null !== $docComment = $node->getDocComment())
? preg_replace('~^\s+\*~m', ' *', $docComment) . "\n"
: '')
. $this->p($node)
. (isset($this->stmtsWithoutSemicolon[$node->getType()]) ? '' : ';');
}