parse if stmt

This commit is contained in:
z7zmey 2017-11-28 21:47:12 +02:00
parent fea39723b8
commit 668a6ed287
2 changed files with 878 additions and 805 deletions

1638
parser.go

File diff suppressed because it is too large Load Diff

View File

@ -81,6 +81,7 @@ func (n node) attribute(key string, value string) node {
%right T_POW %right T_POW
%right '[' %right '['
%nonassoc T_NEW T_CLONE %nonassoc T_NEW T_CLONE
%left T_NOELSE
%left T_ELSEIF %left T_ELSEIF
%left T_ELSE %left T_ELSE
%left T_ENDIF %left T_ENDIF
@ -197,6 +198,8 @@ func (n node) attribute(key string, value string) node {
%type <node> callable_variable %type <node> callable_variable
%type <node> variable %type <node> variable
%type <node> simple_variable %type <node> simple_variable
%type <node> if_stmt_without_else
%type <node> if_stmt
%% %%
@ -266,9 +269,28 @@ inner_statement:
statement: statement:
'{' inner_statement_list '}' { $$ = $2; } '{' inner_statement_list '}' { $$ = $2; }
| if_stmt { $$ = $1; }
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = Node("Do While").append($2).append($5)} | T_DO statement T_WHILE '(' expr ')' ';' { $$ = Node("Do While").append($2).append($5)}
| expr ';' { $$ = $1; } | expr ';' { $$ = $1; }
if_stmt_without_else:
T_IF '(' expr ')' statement
{
$$ = Node("if").append(Node("expr").append($3)).append(Node("stmt").append($5))
}
| if_stmt_without_else T_ELSEIF '(' expr ')' statement
{
$$ = $1.append(Node("elseif").append(Node("expr").append($4)).append(Node("stmt").append($6)))
}
;
if_stmt:
if_stmt_without_else %prec T_NOELSE { $$ = $1; }
| if_stmt_without_else T_ELSE statement
{
$$ = $1.append(Node("else").append(Node("stmt").append($3)))
}
;
class_declaration_statement: class_declaration_statement:
class_modifiers T_CLASS T_STRING '{' '}' { $$ = $1.attribute("name", $3) } class_modifiers T_CLASS T_STRING '{' '}' { $$ = $1.attribute("name", $3) }
| T_CLASS T_STRING '{' '}' { $$ = Node("Class").attribute("name", $2) } | T_CLASS T_STRING '{' '}' { $$ = Node("Class").attribute("name", $2) }
@ -461,15 +483,14 @@ simple_variable:
%% %%
const src = `<? const src = `<?
namespace foo\bar\test;
+$b++; if ($a > $b) {
$b=$c;
} elseif ($a === $b) {
do { } else {
function test(string $a, \bar\baz $b = $t) {
yield $a => $b; }
}
} while($a = $b = $c);
` `