[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 ':'
|
| T_STRING ':'
|
||||||
{
|
{
|
||||||
label := &ast.Identifier{ast.Node{}, $1.Value}
|
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
|
// save position
|
||||||
label.GetNode().Position = position.NewTokenPosition($1)
|
label.GetNode().Position = position.NewTokenPosition($1)
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
yylex.(*Parser).setFreeFloating(label, token.Start, $1.SkippedTokens)
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Label, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -1179,17 +1183,21 @@ unticked_statement:
|
|||||||
| T_GOTO T_STRING ';'
|
| T_GOTO T_STRING ';'
|
||||||
{
|
{
|
||||||
label := &ast.Identifier{ast.Node{}, $2.Value}
|
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
|
// save position
|
||||||
label.GetNode().Position = position.NewTokenPosition($2)
|
label.GetNode().Position = position.NewTokenPosition($2)
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating(label, token.Start, $2.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 ';'
|
| T_GOTO T_STRING ';'
|
||||||
{
|
{
|
||||||
label := &ast.Identifier{ast.Node{}, $2.Value}
|
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
|
// save position
|
||||||
label.GetNode().Position = position.NewTokenPosition($2)
|
label.GetNode().Position = position.NewTokenPosition($2)
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating(label, token.Start, $2.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 ':'
|
| T_STRING ':'
|
||||||
{
|
{
|
||||||
label := &ast.Identifier{ast.Node{}, $1.Value}
|
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
|
// save position
|
||||||
label.GetNode().Position = position.NewTokenPosition($1)
|
label.GetNode().Position = position.NewTokenPosition($1)
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
yylex.(*Parser).setFreeFloating(label, token.Start, $1.SkippedTokens)
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Label, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch_list:
|
catch_list:
|
||||||
|
@ -505,7 +505,9 @@ func (n *StmtGlobal) Accept(v NodeVisitor) {
|
|||||||
// StmtGoto node
|
// StmtGoto node
|
||||||
type StmtGoto struct {
|
type StmtGoto struct {
|
||||||
Node
|
Node
|
||||||
Label Vertex
|
GotoTkn *token.Token
|
||||||
|
Label Vertex
|
||||||
|
SemiColonTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StmtGoto) Accept(v NodeVisitor) {
|
func (n *StmtGoto) Accept(v NodeVisitor) {
|
||||||
@ -582,6 +584,7 @@ func (n *StmtInterfaceExtends) Accept(v NodeVisitor) {
|
|||||||
type StmtLabel struct {
|
type StmtLabel struct {
|
||||||
Node
|
Node
|
||||||
LabelName Vertex
|
LabelName Vertex
|
||||||
|
ColonTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StmtLabel) Accept(v NodeVisitor) {
|
func (n *StmtLabel) Accept(v NodeVisitor) {
|
||||||
|
@ -265,3 +265,12 @@ func (v *FilterTokens) StmtThrow(n *ast.StmtThrow) {
|
|||||||
n.ThrowTkn = nil
|
n.ThrowTkn = nil
|
||||||
n.SemiColonTkn = 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, ";")
|
p.printToken(n.SemiColonTkn, ";")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtGoto(n ast.Vertex) {
|
func (p *Printer) printStmtGoto(n *ast.StmtGoto) {
|
||||||
nn := n.(*ast.StmtGoto)
|
p.printToken(n.GotoTkn, "goto")
|
||||||
p.printFreeFloating(nn, token.Start)
|
p.bufStart = " "
|
||||||
|
p.Print(n.Label)
|
||||||
p.write([]byte("goto"))
|
p.printToken(n.SemiColonTkn, ";")
|
||||||
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) printStmtHaltCompiler(n *ast.StmtHaltCompiler) {
|
func (p *Printer) printStmtHaltCompiler(n *ast.StmtHaltCompiler) {
|
||||||
@ -2527,16 +2515,9 @@ func (p *Printer) printStmtInterface(n ast.Vertex) {
|
|||||||
p.printFreeFloating(nn, token.End)
|
p.printFreeFloating(nn, token.End)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtLabel(n ast.Vertex) {
|
func (p *Printer) printStmtLabel(n *ast.StmtLabel) {
|
||||||
nn := n.(*ast.StmtLabel)
|
p.Print(n.LabelName)
|
||||||
p.printFreeFloating(nn, token.Start)
|
p.printToken(n.ColonTkn, ":")
|
||||||
|
|
||||||
p.Print(nn.LabelName)
|
|
||||||
p.printFreeFloating(nn, token.Label)
|
|
||||||
|
|
||||||
p.write([]byte(":"))
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.End)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtNamespace(n *ast.StmtNamespace) {
|
func (p *Printer) printStmtNamespace(n *ast.StmtNamespace) {
|
||||||
|
Loading…
Reference in New Issue
Block a user