1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Fix line numbers for some list structures

When defining a list in the grammar the list elements have to get a separate
rule, otherwise they'll all be assigned the same line number.
This commit is contained in:
nikic 2012-04-19 00:52:44 +02:00
parent e2a9745bf1
commit 5b27fb40ce
3 changed files with 1279 additions and 1129 deletions

View File

@ -279,8 +279,12 @@ declare_statement:
;
declare_list:
T_STRING '=' static_scalar { init(Stmt_DeclareDeclare[$1, $3]); }
| declare_list ',' T_STRING '=' static_scalar { push($1, Stmt_DeclareDeclare[$3, $5]); }
declare_list_element { init($1); }
| declare_list ',' declare_list_element { push($1, $3); }
;
declare_list_element:
T_STRING '=' static_scalar { $$ = Stmt_DeclareDeclare[$1, $3]; }
;
switch_case_list:
@ -292,10 +296,12 @@ switch_case_list:
case_list:
/* empty */ { init(); }
| case_list T_CASE expr case_separator inner_statement_list
{ push($1, Stmt_Case[$3, $5]); }
| case_list T_DEFAULT case_separator inner_statement_list
{ push($1, Stmt_Case[null, $4]); }
| case_list case { push($1, $2); }
;
case:
T_CASE expr case_separator inner_statement_list { $$ = Stmt_Case[$2, $4]; }
| T_DEFAULT case_separator inner_statement_list { $$ = Stmt_Case[null, $3]; }
;
case_separator:
@ -309,14 +315,21 @@ while_statement:
;
elseif_list:
/* empty */ { init();}
| elseif_list T_ELSEIF '(' expr ')' statement { push($1, Stmt_ElseIf[$4, toArray($6)]); }
/* empty */ { init(); }
| elseif_list elseif { push($1, $2); }
;
elseif:
T_ELSEIF '(' expr ')' statement { $$ = Stmt_ElseIf[$3, toArray($5)]; }
;
new_elseif_list:
/* empty */ { init(); }
| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
{ push($1, Stmt_ElseIf[$4, $7]); }
| new_elseif_list new_elseif { push($1, $2); }
;
new_elseif:
T_ELSEIF '(' expr ')' ':' inner_statement_list { $$ = Stmt_ElseIf[$3, $6]; }
;
else_single:
@ -572,14 +585,16 @@ lexical_vars:
;
lexical_var_list:
lexical_var_list ',' optional_ref T_VARIABLE
{ push($1, Expr_ClosureUse[parseVar($4), $3]); }
| optional_ref T_VARIABLE
{ init(Expr_ClosureUse[parseVar($2), $1]); }
lexical_var { init($1); }
| lexical_var_list ',' lexical_var { push($1, $3); }
;
lexical_var:
optional_ref T_VARIABLE { $$ = Expr_ClosureUse[parseVar($2), $1]; }
;
function_call:
name '(' argument_list ')' { $$ = Expr_FuncCall[$1, $3]; }
name '(' argument_list ')' { $$ = Expr_FuncCall[$1, $3]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' argument_list ')'
{ $$ = Expr_StaticCall[$1, $3, $5]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' '(' argument_list ')'

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,112 @@
Blockless statements for if/for/etc
-----
<?php
if ($a) $A;
elseif ($b) $B;
else $C;
for (;;) $foo;
foreach ($a as $b) $AB;
while ($a) $A;
do $A; while ($a);
declare (a='b') $C;
-----
array(
0: Stmt_If(
stmts: array(
0: Expr_Variable(
name: A
)
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Variable(
name: b
)
stmts: array(
0: Expr_Variable(
name: B
)
)
)
)
else: Stmt_Else(
stmts: array(
0: Expr_Variable(
name: C
)
)
)
cond: Expr_Variable(
name: a
)
)
1: Stmt_For(
init: array(
)
cond: array(
)
loop: array(
)
stmts: array(
0: Expr_Variable(
name: foo
)
)
)
2: Stmt_Foreach(
keyVar: null
byRef: false
stmts: array(
0: Expr_Variable(
name: AB
)
)
expr: Expr_Variable(
name: a
)
valueVar: Expr_Variable(
name: b
)
)
3: Stmt_While(
cond: Expr_Variable(
name: a
)
stmts: array(
0: Expr_Variable(
name: A
)
)
)
4: Stmt_Do(
cond: Expr_Variable(
name: a
)
stmts: array(
0: Expr_Variable(
name: A
)
)
)
5: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: a
value: Scalar_String(
value: b
)
)
)
stmts: array(
0: Expr_Variable(
name: C
)
)
)
)