[refactoring] store expr parenthesis

This commit is contained in:
Vadym Slizov 2020-08-09 22:40:55 +02:00
parent b8b4439015
commit 394092269a
12 changed files with 1439 additions and 256 deletions

View File

@ -5819,7 +5819,7 @@ func TestStmtEcho_Parenthesis(t *testing.T) {
} }
func TestStmtExpression(t *testing.T) { func TestStmtExpression(t *testing.T) {
src := `<? 1;` src := `<? ((1));`
expected := &ast.Root{ expected := &ast.Root{
Node: ast.Node{ Node: ast.Node{
@ -5827,7 +5827,7 @@ func TestStmtExpression(t *testing.T) {
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 3,
EndPos: 5, EndPos: 9,
}, },
}, },
Stmts: []ast.Vertex{ Stmts: []ast.Vertex{
@ -5837,7 +5837,7 @@ func TestStmtExpression(t *testing.T) {
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 3,
EndPos: 5, EndPos: 9,
}, },
}, },
Expr: &ast.ScalarLnumber{ Expr: &ast.ScalarLnumber{
@ -5845,8 +5845,8 @@ func TestStmtExpression(t *testing.T) {
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 5,
EndPos: 4, EndPos: 6,
}, },
}, },
Value: []byte("1"), Value: []byte("1"),
@ -13535,7 +13535,7 @@ func TestExprClone_Brackets(t *testing.T) {
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 3,
EndPos: 11, EndPos: 12,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{
@ -17177,7 +17177,7 @@ func TestExprPrint(t *testing.T) {
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 3,
EndPos: 11, EndPos: 12,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -919,36 +919,22 @@ unticked_statement:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
if len($2.GetNode().Tokens[token.OpenParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens($$, token.If, $2.GetNode().Tokens[token.OpenParenthesisToken][:len($2.GetNode().Tokens[token.OpenParenthesisToken])-1]); delete($2.GetNode().Tokens, token.OpenParenthesisToken)
}
if len($2.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $2.GetNode().Tokens[token.CloseParenthesisToken][:len($2.GetNode().Tokens[token.CloseParenthesisToken])-1]); delete($2.GetNode().Tokens, token.CloseParenthesisToken)
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_IF parenthesis_expr ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';' | T_IF parenthesis_expr ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
{ {
exprBrackets := &ast.ParserBrackets{ast.Node{}, $2}
stmts := &ast.StmtStmtList{ast.Node{}, $4} stmts := &ast.StmtStmtList{ast.Node{}, $4}
stmtsBrackets := &ast.ParserBrackets{ast.Node{}, stmts} stmtsBrackets := &ast.ParserBrackets{ast.Node{}, stmts}
$$ = &ast.StmtAltIf{ast.Node{}, exprBrackets, stmtsBrackets, $5, $6} $$ = &ast.StmtAltIf{ast.Node{}, $2, stmtsBrackets, $5, $6}
// save position // save position
exprBrackets.GetNode().Position = position.NewNodePosition($2)
stmts.GetNode().Position = position.NewNodeListPosition($4) stmts.GetNode().Position = position.NewNodeListPosition($4)
stmtsBrackets.GetNode().Position = position.NewTokenNodeListPosition($3, $4) stmtsBrackets.GetNode().Position = position.NewTokenNodeListPosition($3, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $8) $$.GetNode().Position = position.NewTokensPosition($1, $8)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
if len($2.GetNode().Tokens[token.OpenParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.GetNode().Tokens[token.OpenParenthesisToken]); delete($2.GetNode().Tokens, token.OpenParenthesisToken)
}
if len($2.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $2.GetNode().Tokens[token.CloseParenthesisToken]); delete($2.GetNode().Tokens, token.CloseParenthesisToken)
}
yylex.(*Parser).setFreeFloatingTokens(stmtsBrackets, token.Start, $3.Tokens) yylex.(*Parser).setFreeFloatingTokens(stmtsBrackets, token.Start, $3.Tokens)
if $6 != nil { if $6 != nil {
yylex.(*Parser).setFreeFloating($6.(*ast.StmtAltElse).Stmt, token.End, append($7.Tokens, $8.Tokens...)) yylex.(*Parser).setFreeFloating($6.(*ast.StmtAltElse).Stmt, token.End, append($7.Tokens, $8.Tokens...))
@ -977,12 +963,6 @@ unticked_statement:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
if len($2.GetNode().Tokens[token.OpenParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens($$, token.While, $2.GetNode().Tokens[token.OpenParenthesisToken][:len($2.GetNode().Tokens[token.OpenParenthesisToken])-1]); delete($2.GetNode().Tokens, token.OpenParenthesisToken)
}
if len($2.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $2.GetNode().Tokens[token.CloseParenthesisToken][:len($2.GetNode().Tokens[token.CloseParenthesisToken])-1]); delete($2.GetNode().Tokens, token.CloseParenthesisToken)
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -996,13 +976,7 @@ unticked_statement:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.Tokens) yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.Tokens)
if len($4.GetNode().Tokens[token.OpenParenthesisToken]) > 0 { yylex.(*Parser).setFreeFloating($4, token.End, $5.Tokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.While, $4.GetNode().Tokens[token.OpenParenthesisToken][:len($4.GetNode().Tokens[token.OpenParenthesisToken])-1]); delete($4.GetNode().Tokens, token.OpenParenthesisToken)
}
if len($4.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $4.GetNode().Tokens[token.CloseParenthesisToken][:len($4.GetNode().Tokens[token.CloseParenthesisToken])-1]); delete($4.GetNode().Tokens, token.CloseParenthesisToken)
}
yylex.(*Parser).setFreeFloating($$, token.Cond, $5.Tokens)
yylex.(*Parser).setToken($$, token.SemiColon, $5.Tokens) yylex.(*Parser).setToken($$, token.SemiColon, $5.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1052,12 +1026,6 @@ unticked_statement:
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
if len($2.GetNode().Tokens[token.OpenParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens($$, token.Switch, $2.GetNode().Tokens[token.OpenParenthesisToken][:len($2.GetNode().Tokens[token.OpenParenthesisToken])-1]); delete($2.GetNode().Tokens, token.OpenParenthesisToken)
}
if len($2.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $2.GetNode().Tokens[token.CloseParenthesisToken][:len($2.GetNode().Tokens[token.CloseParenthesisToken])-1]); delete($2.GetNode().Tokens, token.CloseParenthesisToken)
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -2163,12 +2131,6 @@ elseif_list:
// save comments // save comments
yylex.(*Parser).setFreeFloating(_elseIf, token.Start, $2.Tokens) yylex.(*Parser).setFreeFloating(_elseIf, token.Start, $2.Tokens)
if len($3.GetNode().Tokens[token.OpenParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens(_elseIf, token.ElseIf, $3.GetNode().Tokens[token.OpenParenthesisToken][:len($3.GetNode().Tokens[token.OpenParenthesisToken])-1]); delete($3.GetNode().Tokens, token.OpenParenthesisToken)
}
if len($3.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens(_elseIf, token.Expr, $3.GetNode().Tokens[token.CloseParenthesisToken][:len($3.GetNode().Tokens[token.CloseParenthesisToken])-1]); delete($3.GetNode().Tokens, token.CloseParenthesisToken)
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -2184,26 +2146,18 @@ new_elseif_list:
} }
| new_elseif_list T_ELSEIF parenthesis_expr ':' inner_statement_list | new_elseif_list T_ELSEIF parenthesis_expr ':' inner_statement_list
{ {
exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
stmts := &ast.StmtStmtList{ast.Node{}, $5} stmts := &ast.StmtStmtList{ast.Node{}, $5}
stmtsBrackets := &ast.ParserBrackets{ast.Node{}, stmts} stmtsBrackets := &ast.ParserBrackets{ast.Node{}, stmts}
_elseIf := &ast.StmtAltElseIf{ast.Node{}, exprBrackets, stmtsBrackets} _elseIf := &ast.StmtAltElseIf{ast.Node{}, $3, stmtsBrackets}
$$ = append($1, _elseIf) $$ = append($1, _elseIf)
// save position // save position
exprBrackets.GetNode().Position = position.NewNodePosition($3)
stmts.GetNode().Position = position.NewNodeListPosition($5) stmts.GetNode().Position = position.NewNodeListPosition($5)
exprBrackets.GetNode().Position = position.NewTokenNodeListPosition($4, $5) stmtsBrackets.GetNode().Position = position.NewTokenNodeListPosition($4, $5)
_elseIf.GetNode().Position = position.NewTokenNodeListPosition($2, $5) _elseIf.GetNode().Position = position.NewTokenNodeListPosition($2, $5)
// save comments // save comments
yylex.(*Parser).setFreeFloating(_elseIf, token.Start, $2.Tokens) yylex.(*Parser).setFreeFloating(_elseIf, token.Start, $2.Tokens)
if len($3.GetNode().Tokens[token.OpenParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $3.GetNode().Tokens[token.OpenParenthesisToken]); delete($3.GetNode().Tokens, token.OpenParenthesisToken)
}
if len($3.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $3.GetNode().Tokens[token.CloseParenthesisToken]); delete($3.GetNode().Tokens, token.CloseParenthesisToken)
}
yylex.(*Parser).setFreeFloatingTokens(stmtsBrackets, token.Start, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(stmtsBrackets, token.Start, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -4089,9 +4043,6 @@ expr_without_variable:
$$ = $1 $$ = $1
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
yylex.(*Parser).setFreeFloatingTokens($1, token.Start, append($1.GetNode().Tokens[token.OpenParenthesisToken], $1.GetNode().Tokens[token.Start]...)); delete($1.GetNode().Tokens, token.OpenParenthesisToken)
yylex.(*Parser).setFreeFloatingTokens($1, token.End, append($1.GetNode().Tokens[token.End], $1.GetNode().Tokens[token.CloseParenthesisToken]...)); delete($1.GetNode().Tokens, token.CloseParenthesisToken)
} }
| new_expr | new_expr
{ {
@ -4258,15 +4209,14 @@ expr_without_variable:
} }
| T_EXIT exit_expr | T_EXIT exit_expr
{ {
e := $2.(*ast.ExprExit) $$ = &ast.ExprExit{ast.Node{}, false, $2}
$$ = $2
if (bytes.EqualFold($1.Value, []byte("die"))) { if (bytes.EqualFold($1.Value, []byte("die"))) {
e.Die = true $$.(*ast.ExprExit).Die = true
} }
// save position // save position
if $2.GetNode().Position == nil { if $2 == nil {
$$.GetNode().Position = position.NewTokenPosition($1) $$.GetNode().Position = position.NewTokenPosition($1)
} else { } else {
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) $$.GetNode().Position = position.NewTokenNodePosition($1, $2)
@ -4930,39 +4880,28 @@ dynamic_class_name_variable_property:
exit_expr: exit_expr:
/* empty */ /* empty */
{ {
$$ = &ast.ExprExit{ast.Node{}, false, nil}; $$ = nil
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| '(' ')' | '(' ')'
{ {
$$ = &ast.ExprExit{ast.Node{}, false, nil}; $$ = &ast.ParserBrackets{ast.Node{}, nil}
// save position // save position
$$.GetNode().Position = position.NewTokensPosition($1, $2) $$.GetNode().Position = position.NewTokensPosition($1, $2)
// save comments // save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Exit, $1.Tokens) yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens($$, token.End, $2.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| parenthesis_expr | parenthesis_expr
{ {
$$ = &ast.ExprExit{ast.Node{}, false, $1}; $$ = $1
// save position
if bytes.Compare(yylex.(*Parser).currentToken.Value, []byte(")")) == 0 {
$$.GetNode().Position = position.NewTokenPosition(yylex.(*Parser).currentToken)
} else {
$$.GetNode().Position = position.NewNodePosition($1)
}
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
// save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Exit, $1.GetNode().Tokens[token.OpenParenthesisToken]); delete($1.GetNode().Tokens, token.OpenParenthesisToken)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $1.GetNode().Tokens[token.CloseParenthesisToken]); delete($1.GetNode().Tokens, token.CloseParenthesisToken)
} }
; ;
@ -5945,33 +5884,27 @@ expr:
parenthesis_expr: parenthesis_expr:
'(' expr ')' '(' expr ')'
{ {
$$ = $2 $$ = &ast.ParserBrackets{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
if len($2.GetNode().Tokens[token.OpenParenthesisToken]) > 0 { yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($2, token.Start, append($2.GetNode().Tokens[token.OpenParenthesisToken], $2.GetNode().Tokens[token.Start]...)) yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens)
}
if len($2.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloating($2, token.End, append($2.GetNode().Tokens[token.End], $2.GetNode().Tokens[token.CloseParenthesisToken]...))
}
yylex.(*Parser).setFreeFloatingTokens($2, token.OpenParenthesisToken, $1.Tokens)
yylex.(*Parser).setFreeFloatingTokens($2, token.CloseParenthesisToken, $3.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| '(' yield_expr ')' | '(' yield_expr ')'
{ {
$$ = $2 $$ = &ast.ParserBrackets{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
if len($2.GetNode().Tokens[token.OpenParenthesisToken]) > 0 { yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($2, token.Start, append($2.GetNode().Tokens[token.OpenParenthesisToken], $2.GetNode().Tokens[token.Start]...)) yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens)
}
if len($2.GetNode().Tokens[token.CloseParenthesisToken]) > 0 {
yylex.(*Parser).setFreeFloating($2, token.End, append($2.GetNode().Tokens[token.End], $2.GetNode().Tokens[token.CloseParenthesisToken]...))
}
yylex.(*Parser).setFreeFloatingTokens($2, token.OpenParenthesisToken, $1.Tokens)
yylex.(*Parser).setFreeFloatingTokens($2, token.CloseParenthesisToken, $3.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -6943,29 +6876,33 @@ internal_functions_in_yacc:
} }
| T_EMPTY '(' variable ')' | T_EMPTY '(' variable ')'
{ {
$$ = &ast.ExprEmpty{ast.Node{}, $3} exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
$$ = &ast.ExprEmpty{ast.Node{}, exprBrackets}
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4) $$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Empty, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_EMPTY '(' expr ')' | T_EMPTY '(' expr ')'
{ {
$$ = &ast.ExprEmpty{ast.Node{}, $3} exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
$$ = &ast.ExprEmpty{ast.Node{}, exprBrackets}
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4) $$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Empty, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -6995,15 +6932,17 @@ internal_functions_in_yacc:
} }
| T_EVAL '(' expr ')' | T_EVAL '(' expr ')'
{ {
$$ = &ast.ExprEval{ast.Node{}, $3} exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
$$ = &ast.ExprEval{ast.Node{}, exprBrackets}
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4) $$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Eval, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }

View File

@ -10048,7 +10048,7 @@ func TestPhp5(t *testing.T) {
StartLine: 175, StartLine: 175,
EndLine: 175, EndLine: 175,
StartPos: 3593, StartPos: 3593,
EndPos: 3601, EndPos: 3602,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{
@ -12426,7 +12426,7 @@ func TestPhp5(t *testing.T) {
StartLine: 223, StartLine: 223,
EndLine: 223, EndLine: 223,
StartPos: 4168, StartPos: 4168,
EndPos: 4176, EndPos: 4177,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{

View File

@ -15577,7 +15577,7 @@ func TestExprClone_Brackets(t *testing.T) {
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 3,
EndPos: 11, EndPos: 12,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{
@ -19422,7 +19422,7 @@ func TestExprPrint(t *testing.T) {
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 3, StartPos: 3,
EndPos: 11, EndPos: 12,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -993,38 +993,42 @@ statement:
} }
| T_WHILE '(' expr ')' while_statement | T_WHILE '(' expr ')' while_statement
{ {
exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
switch n := $5.(type) { switch n := $5.(type) {
case *ast.StmtWhile : case *ast.StmtWhile :
n.Cond = $3 n.Cond = exprBrackets
case *ast.StmtAltWhile : case *ast.StmtAltWhile :
n.Cond = $3 n.Cond = exprBrackets
} }
$$ = $5 $$ = $5
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokenNodePosition($1, $5) $$.GetNode().Position = position.NewTokenNodePosition($1, $5)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.While, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| T_DO statement T_WHILE '(' expr ')' ';' | T_DO statement T_WHILE '(' expr ')' ';'
{ {
$$ = &ast.StmtDo{ast.Node{}, $2, $5} exprBrackets := &ast.ParserBrackets{ast.Node{}, $5}
$$ = &ast.StmtDo{ast.Node{}, $2, exprBrackets}
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($4, $6)
$$.GetNode().Position = position.NewTokensPosition($1, $7) $$.GetNode().Position = position.NewTokensPosition($1, $7)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.Tokens) yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.Tokens)
yylex.(*Parser).setFreeFloating($$, token.While, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $4.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $6.Tokens) yylex.(*Parser).setFreeFloating(exprBrackets, token.End, append($6.Tokens, $7.Tokens...))
yylex.(*Parser).setFreeFloating($$, token.Cond, $7.Tokens)
yylex.(*Parser).setToken($$, token.SemiColon, $7.Tokens) yylex.(*Parser).setToken($$, token.SemiColon, $7.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
@ -1058,11 +1062,13 @@ statement:
} }
| T_SWITCH '(' expr ')' switch_case_list | T_SWITCH '(' expr ')' switch_case_list
{ {
exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
switch n := $5.(type) { switch n := $5.(type) {
case *ast.StmtSwitch: case *ast.StmtSwitch:
n.Cond = $3 n.Cond = exprBrackets
case *ast.StmtAltSwitch: case *ast.StmtAltSwitch:
n.Cond = $3 n.Cond = exprBrackets
default: default:
panic("unexpected node type") panic("unexpected node type")
} }
@ -1070,12 +1076,13 @@ statement:
$$ = $5 $$ = $5
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokenNodePosition($1, $5) $$.GetNode().Position = position.NewTokenNodePosition($1, $5)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Switch, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -1977,33 +1984,37 @@ while_statement:
if_stmt_without_else: if_stmt_without_else:
T_IF '(' expr ')' statement T_IF '(' expr ')' statement
{ {
$$ = &ast.StmtIf{ast.Node{}, $3, $5, nil, nil} exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
$$ = &ast.StmtIf{ast.Node{}, exprBrackets, $5, nil, nil}
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokenNodePosition($1, $5) $$.GetNode().Position = position.NewTokenNodePosition($1, $5)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.If, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
| if_stmt_without_else T_ELSEIF '(' expr ')' statement | if_stmt_without_else T_ELSEIF '(' expr ')' statement
{ {
_elseIf := &ast.StmtElseIf{ast.Node{}, $4, $6} exprBrackets := &ast.ParserBrackets{ast.Node{}, $4}
_elseIf := &ast.StmtElseIf{ast.Node{}, exprBrackets, $6}
$1.(*ast.StmtIf).ElseIf = append($1.(*ast.StmtIf).ElseIf, _elseIf) $1.(*ast.StmtIf).ElseIf = append($1.(*ast.StmtIf).ElseIf, _elseIf)
$$ = $1 $$ = $1
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($3, $5)
_elseIf.GetNode().Position = position.NewTokenNodePosition($2, $6) _elseIf.GetNode().Position = position.NewTokenNodePosition($2, $6)
$$.GetNode().Position = position.NewNodesPosition($1, $6) $$.GetNode().Position = position.NewNodesPosition($1, $6)
// save comments // save comments
yylex.(*Parser).setFreeFloating(_elseIf, token.Start, $2.Tokens) yylex.(*Parser).setFreeFloating(_elseIf, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating(_elseIf, token.ElseIf, $3.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $3.Tokens)
yylex.(*Parser).setFreeFloating(_elseIf, token.Expr, $5.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $5.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -3862,11 +3873,14 @@ expr_without_variable:
} }
| '(' expr ')' | '(' expr ')'
{ {
$$ = $2; $$ = &ast.ParserBrackets{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, append($1.Tokens, $$.GetNode().Tokens[token.Start]...)) yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($$.GetNode().Tokens[token.End], $3.Tokens...)) yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -4016,17 +4030,10 @@ expr_without_variable:
} }
| T_EXIT exit_expr | T_EXIT exit_expr
{ {
var e *ast.ExprExit; $$ = &ast.ExprExit{ast.Node{}, false, $2}
if $2 != nil {
e = $2.(*ast.ExprExit)
} else {
e = &ast.ExprExit{ast.Node{}, false, nil}
}
$$ = e
if (bytes.EqualFold($1.Value, []byte("die"))) { if (bytes.EqualFold($1.Value, []byte("die"))) {
e.Die = true $$.(*ast.ExprExit).Die = true
} }
// save position // save position
@ -4405,14 +4412,14 @@ exit_expr:
} }
| '(' optional_expr ')' | '(' optional_expr ')'
{ {
$$ = &ast.ExprExit{ast.Node{}, false, $2}; $$ = &ast.ParserBrackets{ast.Node{}, $2}
// save position // save position
$$.GetNode().Position = position.NewTokensPosition($1, $3) $$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Exit, $1.Tokens) yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.Expr, $3.Tokens) yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -4780,11 +4787,14 @@ dereferencable:
} }
| '(' expr ')' | '(' expr ')'
{ {
$$ = $2; $$ = &ast.ParserBrackets{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, append($1.Tokens, $$.GetNode().Tokens[token.Start]...)) yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($$.GetNode().Tokens[token.End], $3.Tokens...)) yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -4805,11 +4815,14 @@ callable_expr:
} }
| '(' expr ')' | '(' expr ')'
{ {
$$ = $2; $$ = &ast.ParserBrackets{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments // save comments
yylex.(*Parser).setFreeFloatingTokens($$, token.Start, append($1.Tokens, $$.GetNode().Tokens[token.Start]...)) yylex.(*Parser).setFreeFloatingTokens($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, append($$.GetNode().Tokens[token.End], $3.Tokens...)) yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -5528,15 +5541,17 @@ internal_functions_in_yacc:
} }
| T_EMPTY '(' expr ')' | T_EMPTY '(' expr ')'
{ {
$$ = &ast.ExprEmpty{ast.Node{}, $3} exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
$$ = &ast.ExprEmpty{ast.Node{}, exprBrackets}
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4) $$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Empty, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }
@ -5566,15 +5581,17 @@ internal_functions_in_yacc:
} }
| T_EVAL '(' expr ')' | T_EVAL '(' expr ')'
{ {
$$ = &ast.ExprEval{ast.Node{}, $3} exprBrackets := &ast.ParserBrackets{ast.Node{}, $3}
$$ = &ast.ExprEval{ast.Node{}, exprBrackets}
// save position // save position
exprBrackets.GetNode().Position = position.NewTokensPosition($2, $4)
$$.GetNode().Position = position.NewTokensPosition($1, $4) $$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments // save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens) yylex.(*Parser).setFreeFloating($$, token.Start, $1.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Eval, $2.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.Tokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $4.Tokens) yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.Tokens)
yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL) yylex.(*Parser).returnTokenToPool(yyDollar, &yyVAL)
} }

View File

@ -11046,7 +11046,7 @@ func TestPhp7(t *testing.T) {
StartLine: 187, StartLine: 187,
EndLine: 187, EndLine: 187,
StartPos: 3780, StartPos: 3780,
EndPos: 3788, EndPos: 3789,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{
@ -13123,7 +13123,7 @@ func TestPhp7(t *testing.T) {
StartLine: 232, StartLine: 232,
EndLine: 232, EndLine: 232,
StartPos: 4298, StartPos: 4298,
EndPos: 4306, EndPos: 4307,
}, },
}, },
Expr: &ast.ExprVariable{ Expr: &ast.ExprVariable{
@ -18632,7 +18632,7 @@ func TestPhp7(t *testing.T) {
Position: &position.Position{ Position: &position.Position{
StartLine: 332, StartLine: 332,
EndLine: 332, EndLine: 332,
StartPos: 5518, StartPos: 5517,
EndPos: 5532, EndPos: 5532,
}, },
}, },
@ -18641,7 +18641,7 @@ func TestPhp7(t *testing.T) {
Position: &position.Position{ Position: &position.Position{
StartLine: 332, StartLine: 332,
EndLine: 332, EndLine: 332,
StartPos: 5518, StartPos: 5517,
EndPos: 5531, EndPos: 5531,
}, },
}, },
@ -18696,7 +18696,7 @@ func TestPhp7(t *testing.T) {
Position: &position.Position{ Position: &position.Position{
StartLine: 333, StartLine: 333,
EndLine: 333, EndLine: 333,
StartPos: 5534, StartPos: 5533,
EndPos: 5545, EndPos: 5545,
}, },
}, },
@ -18705,7 +18705,7 @@ func TestPhp7(t *testing.T) {
Position: &position.Position{ Position: &position.Position{
StartLine: 333, StartLine: 333,
EndLine: 333, EndLine: 333,
StartPos: 5534, StartPos: 5533,
EndPos: 5544, EndPos: 5544,
}, },
}, },

File diff suppressed because it is too large Load Diff

View File

@ -1530,11 +1530,16 @@ func (p *Printer) printExprEmpty(n ast.Vertex) {
nn := n.(*ast.ExprEmpty) nn := n.(*ast.ExprEmpty)
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "empty") io.WriteString(p.w, "empty")
p.printFreeFloating(nn, token.Empty)
if _, ok := nn.Expr.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Expr) p.Print(nn.Expr)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Expr.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.printFreeFloating(nn, token.End) p.printFreeFloating(nn, token.End)
} }
@ -1551,12 +1556,18 @@ func (p *Printer) printExprErrorSuppress(n ast.Vertex) {
func (p *Printer) printExprEval(n ast.Vertex) { func (p *Printer) printExprEval(n ast.Vertex) {
nn := n.(*ast.ExprEval) nn := n.(*ast.ExprEval)
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "eval") io.WriteString(p.w, "eval")
p.printFreeFloating(nn, token.Eval)
if _, ok := nn.Expr.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Expr) p.Print(nn.Expr)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Expr.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.printFreeFloating(nn, token.End) p.printFreeFloating(nn, token.End)
} }
@ -1570,7 +1581,6 @@ func (p *Printer) printExprExit(n ast.Vertex) {
} else { } else {
io.WriteString(p.w, "exit") io.WriteString(p.w, "exit")
} }
p.printFreeFloating(nn, token.Exit)
if nn.Expr != nil && nn.Expr.GetNode().Tokens.IsEmpty() && nn.GetNode().Tokens.IsEmpty() { if nn.Expr != nil && nn.Expr.GetNode().Tokens.IsEmpty() && nn.GetNode().Tokens.IsEmpty() {
io.WriteString(p.w, " ") io.WriteString(p.w, " ")
@ -2163,11 +2173,17 @@ func (p *Printer) printStmtAltSwitch(n ast.Vertex) {
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "switch") io.WriteString(p.w, "switch")
p.printFreeFloating(nn, token.Switch)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Cond) p.Print(nn.Cond)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.printFreeFloating(nn, token.Cond) p.printFreeFloating(nn, token.Cond)
io.WriteString(p.w, ":") io.WriteString(p.w, ":")
@ -2192,11 +2208,17 @@ func (p *Printer) printStmtAltWhile(n ast.Vertex) {
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "while") io.WriteString(p.w, "while")
p.printFreeFloating(nn, token.While)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Cond) p.Print(nn.Cond)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.printFreeFloating(nn, token.Cond) p.printFreeFloating(nn, token.Cond)
io.WriteString(p.w, ":") io.WriteString(p.w, ":")
@ -2543,11 +2565,17 @@ func (p *Printer) printStmtDo(n ast.Vertex) {
p.printFreeFloating(nn, token.Stmts) p.printFreeFloating(nn, token.Stmts)
io.WriteString(p.w, "while") io.WriteString(p.w, "while")
p.printFreeFloating(nn, token.While)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Cond) p.Print(nn.Cond)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.printFreeFloating(nn, token.Cond) p.printFreeFloating(nn, token.Cond)
p.printFreeFloating(nn, token.SemiColon) p.printFreeFloating(nn, token.SemiColon)
@ -2587,11 +2615,16 @@ func (p *Printer) printStmtElseif(n ast.Vertex) {
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "elseif") io.WriteString(p.w, "elseif")
p.printFreeFloating(nn, token.ElseIf)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Cond) p.Print(nn.Cond)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.Print(nn.Stmt) p.Print(nn.Stmt)
@ -2794,11 +2827,16 @@ func (p *Printer) printStmtIf(n ast.Vertex) {
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "if") io.WriteString(p.w, "if")
p.printFreeFloating(n, token.If)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Cond) p.Print(nn.Cond)
p.printFreeFloating(n, token.Expr)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.Print(nn.Stmt) p.Print(nn.Stmt)
@ -3020,11 +3058,16 @@ func (p *Printer) printStmtSwitch(n ast.Vertex) {
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "switch") io.WriteString(p.w, "switch")
p.printFreeFloating(nn, token.Switch)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Cond) p.Print(nn.Cond)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.printFreeFloating(nn.CaseList, token.Start) p.printFreeFloating(nn.CaseList, token.Start)
io.WriteString(p.w, "{") io.WriteString(p.w, "{")
@ -3292,11 +3335,16 @@ func (p *Printer) printStmtWhile(n ast.Vertex) {
p.printFreeFloating(nn, token.Start) p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "while") io.WriteString(p.w, "while")
p.printFreeFloating(nn, token.While)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
}
p.Print(nn.Cond) p.Print(nn.Cond)
p.printFreeFloating(nn, token.Expr)
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
}
p.Print(nn.Stmt) p.Print(nn.Stmt)

View File

@ -27,28 +27,19 @@ const (
Namespace Namespace
Static Static
Class
Use Use
While
For For
Switch
Foreach Foreach
Declare Declare
Label Label
Finally Finally
List List
Default Default
If
ElseIf
Else
Function Function
Alias Alias
Equal Equal
Exit
Array Array
Isset Isset
Empty
Eval
Echo Echo
Try Try
Catch Catch
@ -68,7 +59,6 @@ const (
AdaptationList AdaptationList
LexicalVarList LexicalVarList
OpenParenthesisToken
CloseParenthesisToken CloseParenthesisToken
) )

View File

@ -30,52 +30,42 @@ func _() {
_ = x[Cond-19] _ = x[Cond-19]
_ = x[Namespace-20] _ = x[Namespace-20]
_ = x[Static-21] _ = x[Static-21]
_ = x[Class-22] _ = x[Use-22]
_ = x[Use-23] _ = x[For-23]
_ = x[While-24] _ = x[Foreach-24]
_ = x[For-25] _ = x[Declare-25]
_ = x[Switch-26] _ = x[Label-26]
_ = x[Foreach-27] _ = x[Finally-27]
_ = x[Declare-28] _ = x[List-28]
_ = x[Label-29] _ = x[Default-29]
_ = x[Finally-30] _ = x[Function-30]
_ = x[List-31] _ = x[Alias-31]
_ = x[Default-32] _ = x[Equal-32]
_ = x[If-33] _ = x[Array-33]
_ = x[ElseIf-34] _ = x[Isset-34]
_ = x[Else-35] _ = x[Echo-35]
_ = x[Function-36] _ = x[Try-36]
_ = x[Alias-37] _ = x[Catch-37]
_ = x[Equal-38] _ = x[Unset-38]
_ = x[Exit-39] _ = x[Stmts-39]
_ = x[Array-40] _ = x[VarList-40]
_ = x[Isset-41] _ = x[ConstList-41]
_ = x[Empty-42] _ = x[NameList-42]
_ = x[Eval-43] _ = x[ParamList-43]
_ = x[Echo-44] _ = x[ModifierList-44]
_ = x[Try-45] _ = x[ArrayPairList-45]
_ = x[Catch-46] _ = x[CaseListStart-46]
_ = x[Unset-47] _ = x[CaseListEnd-47]
_ = x[Stmts-48] _ = x[PropertyList-48]
_ = x[VarList-49] _ = x[ParameterList-49]
_ = x[ConstList-50] _ = x[AdaptationList-50]
_ = x[NameList-51] _ = x[LexicalVarList-51]
_ = x[ParamList-52] _ = x[CloseParenthesisToken-52]
_ = x[ModifierList-53]
_ = x[ArrayPairList-54]
_ = x[CaseListStart-55]
_ = x[CaseListEnd-56]
_ = x[PropertyList-57]
_ = x[ParameterList-58]
_ = x[AdaptationList-59]
_ = x[LexicalVarList-60]
_ = x[OpenParenthesisToken-61]
_ = x[CloseParenthesisToken-62]
} }
const _Position_name = "StartEndSemiColonAltEndAmpersandNameKeyVarReturnTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondNamespaceStaticClassUseWhileForSwitchForeachDeclareLabelFinallyListDefaultIfElseIfElseFunctionAliasEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndPropertyListParameterListAdaptationListLexicalVarListOpenParenthesisTokenCloseParenthesisToken" const _Position_name = "StartEndSemiColonAltEndAmpersandNameKeyVarReturnTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondNamespaceStaticUseForForeachDeclareLabelFinallyListDefaultFunctionAliasEqualArrayIssetEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndPropertyListParameterListAdaptationListLexicalVarListCloseParenthesisToken"
var _Position_index = [...]uint16{0, 5, 8, 17, 23, 32, 36, 39, 42, 52, 65, 76, 82, 85, 89, 93, 101, 109, 116, 120, 124, 133, 139, 144, 147, 152, 155, 161, 168, 175, 180, 187, 191, 198, 200, 206, 210, 218, 223, 228, 232, 237, 242, 247, 251, 255, 258, 263, 268, 273, 280, 289, 297, 306, 318, 331, 344, 355, 367, 380, 394, 408, 428, 449} var _Position_index = [...]uint16{0, 5, 8, 17, 23, 32, 36, 39, 42, 52, 65, 76, 82, 85, 89, 93, 101, 109, 116, 120, 124, 133, 139, 142, 145, 152, 159, 164, 171, 175, 182, 190, 195, 200, 205, 210, 214, 217, 222, 227, 232, 239, 248, 256, 265, 277, 290, 303, 314, 326, 339, 353, 367, 388}
func (i Position) String() string { func (i Position) String() string {
if i < 0 || i >= Position(len(_Position_index)-1) { if i < 0 || i >= Position(len(_Position_index)-1) {