[refactoring] update ast structure of "Nop" node

This commit is contained in:
Vadym Slizov 2020-09-14 19:34:02 +03:00
parent e78f0dc650
commit 33af1df9c4
7 changed files with 43 additions and 53 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -1141,14 +1141,12 @@ unticked_statement:
} }
| ';' | ';'
{ {
$$ = &ast.StmtNop{ast.Node{}, } $$ = &ast.StmtNop{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
SemiColonTkn: $1,
// save comments }
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $1.SkippedTokens)
} }
| T_TRY '{' inner_statement_list '}' catch_statement finally_statement | T_TRY '{' inner_statement_list '}' catch_statement finally_statement
{ {
@ -2420,13 +2418,12 @@ trait_list:
trait_adaptations: trait_adaptations:
';' ';'
{ {
$$ = &ast.StmtNop{ast.Node{}, } $$ = &ast.StmtNop{
Node: ast.Node{
$$.GetNode().Position = position.NewTokenPosition($1) Position: position.NewTokenPosition($1),
},
// save comments SemiColonTkn: $1,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.SemiColon, $1.SkippedTokens)
} }
| '{' trait_adaptation_list '}' | '{' trait_adaptation_list '}'
{ {
@ -2587,14 +2584,12 @@ trait_modifiers:
method_body: method_body:
';' /* abstract method */ ';' /* abstract method */
{ {
$$ = &ast.StmtNop{ast.Node{}, } $$ = &ast.StmtNop{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
SemiColonTkn: $1,
// save comments }
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $1.SkippedTokens)
} }
| '{' inner_statement_list '}' | '{' inner_statement_list '}'
{ {

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -1051,14 +1051,12 @@ statement:
} }
| ';' | ';'
{ {
$$ = &ast.StmtNop{ast.Node{}, } $$ = &ast.StmtNop{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
SemiColonTkn: $1,
// save comments }
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $1.SkippedTokens)
} }
| T_TRY '{' inner_statement_list '}' catch_list finally_statement | T_TRY '{' inner_statement_list '}' catch_list finally_statement
{ {
@ -2203,13 +2201,12 @@ name_list:
trait_adaptations: trait_adaptations:
';' ';'
{ {
$$ = &ast.StmtNop{ast.Node{}, } $$ = &ast.StmtNop{
Node: ast.Node{
$$.GetNode().Position = position.NewTokenPosition($1) Position: position.NewTokenPosition($1),
},
// save comments SemiColonTkn: $1,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setToken($$, token.SemiColon, $1.SkippedTokens)
} }
| '{' '}' | '{' '}'
{ {
@ -2372,14 +2369,12 @@ absolute_trait_method_reference:
method_body: method_body:
';' /* abstract method */ ';' /* abstract method */
{ {
$$ = &ast.StmtNop{ast.Node{}, } $$ = &ast.StmtNop{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
$$.GetNode().Position = position.NewTokenPosition($1) },
SemiColonTkn: $1,
// save comments }
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $1.SkippedTokens)
} }
| '{' inner_statement_list '}' | '{' inner_statement_list '}'
{ {

View File

@ -597,6 +597,7 @@ func (n *StmtNamespace) Accept(v NodeVisitor) {
// StmtNop node // StmtNop node
type StmtNop struct { type StmtNop struct {
Node Node
SemiColonTkn *token.Token
} }
func (n *StmtNop) Accept(v NodeVisitor) { func (n *StmtNop) Accept(v NodeVisitor) {

View File

@ -235,3 +235,7 @@ func (v *FilterTokens) StmtDeclare(n *ast.StmtDeclare) {
n.EndDeclareTkn = nil n.EndDeclareTkn = nil
n.SemiColonTkn = nil n.SemiColonTkn = nil
} }
func (v *FilterTokens) StmtNop(n *ast.StmtNop) {
n.SemiColonTkn = nil
}

View File

@ -2581,13 +2581,8 @@ func (p *Printer) printStmtNamespace(n *ast.StmtNamespace) {
p.printToken(n.SemiColonTkn, ";") p.printToken(n.SemiColonTkn, ";")
} }
func (p *Printer) printStmtNop(n ast.Vertex) { func (p *Printer) printStmtNop(n *ast.StmtNop) {
p.printFreeFloatingOrDefault(n, token.Start, p.bufStart) p.printToken(n.SemiColonTkn, ";")
p.printFreeFloating(n, token.SemiColon)
if n.GetNode().Tokens.IsEmpty() {
p.write([]byte(";"))
}
p.printFreeFloating(n, token.End)
} }
func (p *Printer) printStmtPropertyList(n ast.Vertex) { func (p *Printer) printStmtPropertyList(n ast.Vertex) {