[refactoring] update ast structure of "Root" and "Class" nodes
This commit is contained in:
parent
d19b3f609e
commit
df1626b7dc
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -267,10 +267,13 @@ import (
|
|||||||
start:
|
start:
|
||||||
top_statement_list
|
top_statement_list
|
||||||
{
|
{
|
||||||
yylex.(*Parser).rootNode = &ast.Root{ast.Node{}, $1}
|
yylex.(*Parser).rootNode = &ast.Root{
|
||||||
yylex.(*Parser).rootNode.GetNode().Position = position.NewNodeListPosition($1)
|
Node: ast.Node{
|
||||||
|
Position: position.NewNodeListPosition($1),
|
||||||
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, token.End, yylex.(*Parser).currentToken.SkippedTokens)
|
},
|
||||||
|
Stmts: $1,
|
||||||
|
EndTkn: yylex.(*Parser).currentToken,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -288,12 +288,13 @@ import (
|
|||||||
start:
|
start:
|
||||||
top_statement_list
|
top_statement_list
|
||||||
{
|
{
|
||||||
yylex.(*Parser).rootNode = &ast.Root{ast.Node{}, $1}
|
yylex.(*Parser).rootNode = &ast.Root{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeListPosition($1),
|
||||||
yylex.(*Parser).rootNode.GetNode().Position = position.NewNodeListPosition($1)
|
},
|
||||||
|
Stmts: $1,
|
||||||
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, token.End, yylex.(*Parser).currentToken.SkippedTokens)
|
EndTkn: yylex.(*Parser).currentToken,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2755,7 +2756,9 @@ anonymous_class:
|
|||||||
Position: position.NewTokensPosition($1, $8),
|
Position: position.NewTokensPosition($1, $8),
|
||||||
},
|
},
|
||||||
ClassTkn: $1,
|
ClassTkn: $1,
|
||||||
ArgumentList: $2,
|
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
|
Arguments: $2.(*ast.ArgumentList).Arguments,
|
||||||
|
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
Extends: $3,
|
Extends: $3,
|
||||||
Implements: $4,
|
Implements: $4,
|
||||||
OpenCurlyBracket: $6,
|
OpenCurlyBracket: $6,
|
||||||
|
@ -24,7 +24,6 @@ type NodeVisitor interface {
|
|||||||
Variadic(n *Variadic)
|
Variadic(n *Variadic)
|
||||||
Parameter(n *Parameter)
|
Parameter(n *Parameter)
|
||||||
Identifier(n *Identifier)
|
Identifier(n *Identifier)
|
||||||
ArgumentList(n *ArgumentList)
|
|
||||||
Argument(n *Argument)
|
Argument(n *Argument)
|
||||||
|
|
||||||
StmtBreak(n *StmtBreak)
|
StmtBreak(n *StmtBreak)
|
||||||
|
@ -24,6 +24,7 @@ func (n *Node) GetPosition() *position.Position {
|
|||||||
type Root struct {
|
type Root struct {
|
||||||
Node
|
Node
|
||||||
Stmts []Vertex
|
Stmts []Vertex
|
||||||
|
EndTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Root) Accept(v NodeVisitor) {
|
func (n *Root) Accept(v NodeVisitor) {
|
||||||
@ -87,19 +88,6 @@ func (n *Identifier) Accept(v NodeVisitor) {
|
|||||||
v.Identifier(n)
|
v.Identifier(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArgumentList node
|
|
||||||
type ArgumentList struct {
|
|
||||||
Node
|
|
||||||
OpenParenthesisTkn *token.Token
|
|
||||||
Arguments []Vertex
|
|
||||||
SeparatorTkns []*token.Token
|
|
||||||
CloseParenthesisTkn *token.Token
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *ArgumentList) Accept(v NodeVisitor) {
|
|
||||||
v.ArgumentList(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Argument node
|
// Argument node
|
||||||
type Argument struct {
|
type Argument struct {
|
||||||
Node
|
Node
|
||||||
@ -241,7 +229,9 @@ type StmtClass struct {
|
|||||||
Modifiers []Vertex
|
Modifiers []Vertex
|
||||||
ClassTkn *token.Token
|
ClassTkn *token.Token
|
||||||
ClassName Vertex
|
ClassName Vertex
|
||||||
ArgumentList Vertex
|
OpenParenthesisTkn *token.Token
|
||||||
|
Arguments []Vertex
|
||||||
|
CloseParenthesisTkn *token.Token
|
||||||
Extends Vertex
|
Extends Vertex
|
||||||
Implements Vertex
|
Implements Vertex
|
||||||
OpenCurlyBracket *token.Token
|
OpenCurlyBracket *token.Token
|
||||||
@ -2098,6 +2088,19 @@ func (n *ParserSeparatedList) Accept(v NodeVisitor) {
|
|||||||
v.ParserSeparatedList(n)
|
v.ParserSeparatedList(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArgumentList node
|
||||||
|
type ArgumentList struct {
|
||||||
|
Node
|
||||||
|
OpenParenthesisTkn *token.Token
|
||||||
|
Arguments []Vertex
|
||||||
|
SeparatorTkns []*token.Token
|
||||||
|
CloseParenthesisTkn *token.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *ArgumentList) Accept(v NodeVisitor) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
type ReturnType struct {
|
type ReturnType struct {
|
||||||
Node
|
Node
|
||||||
ColonTkn *token.Token
|
ColonTkn *token.Token
|
||||||
|
@ -93,20 +93,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
|||||||
if !t.visitor.EnterNode(nn) {
|
if !t.visitor.EnterNode(nn) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case *ast.ArgumentList:
|
|
||||||
if nn == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !t.visitor.EnterNode(nn) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if nn.Arguments != nil {
|
|
||||||
t.visitor.Enter("Arguments", false)
|
|
||||||
for _, c := range nn.Arguments {
|
|
||||||
t.Traverse(c)
|
|
||||||
}
|
|
||||||
t.visitor.Leave("Arguments", false)
|
|
||||||
}
|
|
||||||
case *ast.Argument:
|
case *ast.Argument:
|
||||||
if nn == nil {
|
if nn == nil {
|
||||||
return
|
return
|
||||||
@ -195,10 +181,12 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
|||||||
}
|
}
|
||||||
t.visitor.Leave("Modifiers", false)
|
t.visitor.Leave("Modifiers", false)
|
||||||
}
|
}
|
||||||
if nn.ArgumentList != nil {
|
if nn.Arguments != nil {
|
||||||
t.visitor.Enter("ArgumentList", true)
|
t.visitor.Enter("Arguments", false)
|
||||||
t.Traverse(nn.ArgumentList)
|
for _, c := range nn.Arguments {
|
||||||
t.visitor.Leave("ArgumentList", true)
|
t.Traverse(c)
|
||||||
|
}
|
||||||
|
t.visitor.Leave("Arguments", false)
|
||||||
}
|
}
|
||||||
if nn.Extends != nil {
|
if nn.Extends != nil {
|
||||||
t.visitor.Enter("Extends", true)
|
t.visitor.Enter("Extends", true)
|
||||||
|
@ -230,12 +230,6 @@ func (v *Dump) Identifier(n *ast.Identifier) {
|
|||||||
v.print(fmt.Sprintf("Value: []byte(%q),\n", n.Value))
|
v.print(fmt.Sprintf("Value: []byte(%q),\n", n.Value))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Dump) ArgumentList(n *ast.ArgumentList) {
|
|
||||||
v.printIndentIfNotSingle(v.indent - 1)
|
|
||||||
v.print("&ast.ArgumentList{\n")
|
|
||||||
v.printNode(n.GetNode())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Dump) Argument(n *ast.Argument) {
|
func (v *Dump) Argument(n *ast.Argument) {
|
||||||
v.printIndentIfNotSingle(v.indent - 1)
|
v.printIndentIfNotSingle(v.indent - 1)
|
||||||
v.print("&ast.Argument{\n")
|
v.print("&ast.Argument{\n")
|
||||||
|
@ -46,10 +46,6 @@ func (v *Null) Identifier(_ *ast.Identifier) {
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Null) ArgumentList(_ *ast.ArgumentList) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Null) Argument(_ *ast.Argument) {
|
func (v *Null) Argument(_ *ast.Argument) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -1450,9 +1450,9 @@ func (p *PrettyPrinter) printStmtClass(n ast.Vertex) {
|
|||||||
p.Print(nn.ClassName)
|
p.Print(nn.ClassName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nn.ArgumentList != nil {
|
if nn.Arguments != nil {
|
||||||
io.WriteString(p.w, "(")
|
io.WriteString(p.w, "(")
|
||||||
p.joinPrint(", ", nn.ArgumentList.(*ast.ArgumentList).Arguments)
|
p.joinPrint(", ", nn.Arguments)
|
||||||
io.WriteString(p.w, ")")
|
io.WriteString(p.w, ")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2067,10 +2067,10 @@ func (p *Printer) printStmtClass(n ast.Vertex) {
|
|||||||
p.Print(nn.ClassName)
|
p.Print(nn.ClassName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nn.ArgumentList != nil {
|
if nn.Arguments != nil {
|
||||||
p.printFreeFloatingOrDefault(nn.ArgumentList, token.Start, "(")
|
p.printToken(nn.OpenParenthesisTkn, "(")
|
||||||
p.joinPrint(",", nn.ArgumentList.(*ast.ArgumentList).Arguments)
|
p.joinPrint(",", nn.Arguments)
|
||||||
p.printFreeFloatingOrDefault(nn.ArgumentList, token.End, ")")
|
p.printToken(nn.CloseParenthesisTkn, ")")
|
||||||
}
|
}
|
||||||
|
|
||||||
if nn.Extends != nil {
|
if nn.Extends != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user