[refactoring] update ast structure of "While" node

This commit is contained in:
Vadym Slizov
2020-09-04 10:33:47 +03:00
parent 6976388a82
commit 3b85f5e82b
21 changed files with 1066 additions and 1162 deletions

View File

@@ -12762,7 +12762,7 @@ func TestStmtBreak(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtAltWhile{
&ast.StmtWhile{
Node: ast.Node{
Position: &position.Position{
StartLine: 1,
@@ -12771,6 +12771,7 @@ func TestStmtBreak(t *testing.T) {
EndPos: 34,
},
},
Alt: true,
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{

1094
internal/php5/php5.go generated

File diff suppressed because it is too large Load Diff

View File

@@ -901,20 +901,13 @@ unticked_statement:
}
| T_WHILE parenthesis_expr while_statement
{
switch n := $3.(type) {
case *ast.StmtWhile :
n.Cond = $2
case *ast.StmtAltWhile :
n.Cond = $2
}
$3.(*ast.StmtWhile).WhileTkn = $1
$3.(*ast.StmtWhile).OpenParenthesisTkn = $2.(*ast.ParserBrackets).OpenBracketTkn
$3.(*ast.StmtWhile).Cond = $2.(*ast.ParserBrackets).Child
$3.(*ast.StmtWhile).CloseParenthesisTkn = $2.(*ast.ParserBrackets).CloseBracketTkn
$3.(*ast.StmtWhile).Node.Position = position.NewTokenNodePosition($1, $3)
$$ = $3
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
}
| T_DO statement T_WHILE parenthesis_expr ';'
{
@@ -1914,29 +1907,30 @@ case_separator:
while_statement:
statement
{
$$ = &ast.StmtWhile{ast.Node{}, nil, $1}
// save position
$$.GetNode().Position = position.NewNodePosition($1)
$$ = &ast.StmtWhile{
Node: ast.Node{
Position: position.NewNodePosition($1),
},
Stmt: $1,
}
}
| ':' inner_statement_list T_ENDWHILE ';'
{
stmtList := &ast.StmtStmtList{
$$ = &ast.StmtWhile{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
Position: position.NewTokensPosition($1, $4),
},
Stmts: $2,
Alt: true,
ColonTkn: $1,
Stmt: &ast.StmtStmtList{
Node: ast.Node{
Position: position.NewNodeListPosition($2),
},
Stmts: $2,
},
EndWhileTkn: $3,
SemiColonTkn: $4,
}
$$ = &ast.StmtAltWhile{ast.Node{}, nil, stmtList}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Cond, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.AltEnd, $4.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $4.SkippedTokens)
}
;

View File

@@ -3049,7 +3049,7 @@ func TestPhp5(t *testing.T) {
},
},
},
&ast.StmtAltWhile{
&ast.StmtWhile{
Node: ast.Node{
Position: &position.Position{
StartLine: 57,
@@ -3058,6 +3058,7 @@ func TestPhp5(t *testing.T) {
EndPos: 1046,
},
},
Alt: true,
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{