[refactoring] update ast structure of "Goto" and "Label" nodes
This commit is contained in:
parent
48aaa7cc47
commit
94aa9cf829
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -829,15 +829,19 @@ statement:
|
||||
| T_STRING ':'
|
||||
{
|
||||
label := &ast.Identifier{ast.Node{}, $1.Value}
|
||||
$$ = &ast.StmtLabel{ast.Node{}, label}
|
||||
$$ = &ast.StmtLabel{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $2),
|
||||
},
|
||||
LabelName: label,
|
||||
ColonTkn: $2,
|
||||
}
|
||||
|
||||
// save position
|
||||
label.GetNode().Position = position.NewTokenPosition($1)
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Label, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating(label, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
@ -1179,17 +1183,21 @@ unticked_statement:
|
||||
| T_GOTO T_STRING ';'
|
||||
{
|
||||
label := &ast.Identifier{ast.Node{}, $2.Value}
|
||||
$$ = &ast.StmtGoto{ast.Node{}, label}
|
||||
|
||||
$$ = &ast.StmtGoto{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $3),
|
||||
},
|
||||
GotoTkn: $1,
|
||||
Label: label,
|
||||
SemiColonTkn: $3,
|
||||
}
|
||||
|
||||
// save position
|
||||
label.GetNode().Position = position.NewTokenPosition($2)
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating(label, token.Start, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Label, $3.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -1089,30 +1089,38 @@ statement:
|
||||
| T_GOTO T_STRING ';'
|
||||
{
|
||||
label := &ast.Identifier{ast.Node{}, $2.Value}
|
||||
$$ = &ast.StmtGoto{ast.Node{}, label}
|
||||
|
||||
$$ = &ast.StmtGoto{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $3),
|
||||
},
|
||||
GotoTkn: $1,
|
||||
Label: label,
|
||||
SemiColonTkn: $3,
|
||||
}
|
||||
|
||||
// save position
|
||||
label.GetNode().Position = position.NewTokenPosition($2)
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating(label, token.Start, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Label, $3.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
||||
}
|
||||
| T_STRING ':'
|
||||
{
|
||||
label := &ast.Identifier{ast.Node{}, $1.Value}
|
||||
$$ = &ast.StmtLabel{ast.Node{}, label}
|
||||
$$ = &ast.StmtLabel{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $2),
|
||||
},
|
||||
LabelName: label,
|
||||
ColonTkn: $2,
|
||||
}
|
||||
|
||||
// save position
|
||||
label.GetNode().Position = position.NewTokenPosition($1)
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Label, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating(label, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
|
||||
catch_list:
|
||||
|
@ -505,7 +505,9 @@ func (n *StmtGlobal) Accept(v NodeVisitor) {
|
||||
// StmtGoto node
|
||||
type StmtGoto struct {
|
||||
Node
|
||||
GotoTkn *token.Token
|
||||
Label Vertex
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtGoto) Accept(v NodeVisitor) {
|
||||
@ -582,6 +584,7 @@ func (n *StmtInterfaceExtends) Accept(v NodeVisitor) {
|
||||
type StmtLabel struct {
|
||||
Node
|
||||
LabelName Vertex
|
||||
ColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtLabel) Accept(v NodeVisitor) {
|
||||
|
@ -265,3 +265,12 @@ func (v *FilterTokens) StmtThrow(n *ast.StmtThrow) {
|
||||
n.ThrowTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtGoto(n *ast.StmtGoto) {
|
||||
n.GotoTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtLabel(n *ast.StmtLabel) {
|
||||
n.ColonTkn = nil
|
||||
}
|
||||
|
@ -2425,23 +2425,11 @@ func (p *Printer) printStmtGlobal(n *ast.StmtGlobal) {
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtGoto(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtGoto)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
p.write([]byte("goto"))
|
||||
if nn.Label.GetNode().Tokens.IsEmpty() {
|
||||
p.write([]byte(" "))
|
||||
}
|
||||
p.Print(nn.Label)
|
||||
p.printFreeFloating(nn, token.Label)
|
||||
|
||||
p.printFreeFloating(nn, token.SemiColon)
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
p.write([]byte(";"))
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
func (p *Printer) printStmtGoto(n *ast.StmtGoto) {
|
||||
p.printToken(n.GotoTkn, "goto")
|
||||
p.bufStart = " "
|
||||
p.Print(n.Label)
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtHaltCompiler(n *ast.StmtHaltCompiler) {
|
||||
@ -2527,16 +2515,9 @@ func (p *Printer) printStmtInterface(n ast.Vertex) {
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtLabel(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtLabel)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
p.Print(nn.LabelName)
|
||||
p.printFreeFloating(nn, token.Label)
|
||||
|
||||
p.write([]byte(":"))
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
func (p *Printer) printStmtLabel(n *ast.StmtLabel) {
|
||||
p.Print(n.LabelName)
|
||||
p.printToken(n.ColonTkn, ":")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtNamespace(n *ast.StmtNamespace) {
|
||||
|
Loading…
Reference in New Issue
Block a user