[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:
|
||||
top_statement_list
|
||||
{
|
||||
yylex.(*Parser).rootNode = &ast.Root{ast.Node{}, $1}
|
||||
yylex.(*Parser).rootNode.GetNode().Position = position.NewNodeListPosition($1)
|
||||
|
||||
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, token.End, yylex.(*Parser).currentToken.SkippedTokens)
|
||||
yylex.(*Parser).rootNode = &ast.Root{
|
||||
Node: ast.Node{
|
||||
Position: position.NewNodeListPosition($1),
|
||||
},
|
||||
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:
|
||||
top_statement_list
|
||||
{
|
||||
yylex.(*Parser).rootNode = &ast.Root{ast.Node{}, $1}
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).rootNode.GetNode().Position = position.NewNodeListPosition($1)
|
||||
|
||||
yylex.(*Parser).setFreeFloating(yylex.(*Parser).rootNode, token.End, yylex.(*Parser).currentToken.SkippedTokens)
|
||||
yylex.(*Parser).rootNode = &ast.Root{
|
||||
Node: ast.Node{
|
||||
Position: position.NewNodeListPosition($1),
|
||||
},
|
||||
Stmts: $1,
|
||||
EndTkn: yylex.(*Parser).currentToken,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@ -2754,13 +2755,15 @@ anonymous_class:
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $8),
|
||||
},
|
||||
ClassTkn: $1,
|
||||
ArgumentList: $2,
|
||||
Extends: $3,
|
||||
Implements: $4,
|
||||
OpenCurlyBracket: $6,
|
||||
Stmts: $7,
|
||||
CloseCurlyBracket: $8,
|
||||
ClassTkn: $1,
|
||||
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||
Arguments: $2.(*ast.ArgumentList).Arguments,
|
||||
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||
Extends: $3,
|
||||
Implements: $4,
|
||||
OpenCurlyBracket: $6,
|
||||
Stmts: $7,
|
||||
CloseCurlyBracket: $8,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
@ -24,7 +24,6 @@ type NodeVisitor interface {
|
||||
Variadic(n *Variadic)
|
||||
Parameter(n *Parameter)
|
||||
Identifier(n *Identifier)
|
||||
ArgumentList(n *ArgumentList)
|
||||
Argument(n *Argument)
|
||||
|
||||
StmtBreak(n *StmtBreak)
|
||||
|
@ -23,7 +23,8 @@ func (n *Node) GetPosition() *position.Position {
|
||||
// Root node
|
||||
type Root struct {
|
||||
Node
|
||||
Stmts []Vertex
|
||||
Stmts []Vertex
|
||||
EndTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *Root) Accept(v NodeVisitor) {
|
||||
@ -87,19 +88,6 @@ func (n *Identifier) Accept(v NodeVisitor) {
|
||||
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
|
||||
type Argument struct {
|
||||
Node
|
||||
@ -238,15 +226,17 @@ func (n *StmtCatch) Accept(v NodeVisitor) {
|
||||
// StmtClass node
|
||||
type StmtClass struct {
|
||||
Node
|
||||
Modifiers []Vertex
|
||||
ClassTkn *token.Token
|
||||
ClassName Vertex
|
||||
ArgumentList Vertex
|
||||
Extends Vertex
|
||||
Implements Vertex
|
||||
OpenCurlyBracket *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracket *token.Token
|
||||
Modifiers []Vertex
|
||||
ClassTkn *token.Token
|
||||
ClassName Vertex
|
||||
OpenParenthesisTkn *token.Token
|
||||
Arguments []Vertex
|
||||
CloseParenthesisTkn *token.Token
|
||||
Extends Vertex
|
||||
Implements Vertex
|
||||
OpenCurlyBracket *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracket *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtClass) Accept(v NodeVisitor) {
|
||||
@ -2098,6 +2088,19 @@ func (n *ParserSeparatedList) Accept(v NodeVisitor) {
|
||||
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 {
|
||||
Node
|
||||
ColonTkn *token.Token
|
||||
|
@ -93,20 +93,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
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:
|
||||
if nn == nil {
|
||||
return
|
||||
@ -195,10 +181,12 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
}
|
||||
t.visitor.Leave("Modifiers", false)
|
||||
}
|
||||
if nn.ArgumentList != nil {
|
||||
t.visitor.Enter("ArgumentList", true)
|
||||
t.Traverse(nn.ArgumentList)
|
||||
t.visitor.Leave("ArgumentList", true)
|
||||
if nn.Arguments != nil {
|
||||
t.visitor.Enter("Arguments", false)
|
||||
for _, c := range nn.Arguments {
|
||||
t.Traverse(c)
|
||||
}
|
||||
t.visitor.Leave("Arguments", false)
|
||||
}
|
||||
if nn.Extends != nil {
|
||||
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))
|
||||
}
|
||||
|
||||
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) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.Argument{\n")
|
||||
|
@ -46,10 +46,6 @@ func (v *Null) Identifier(_ *ast.Identifier) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) ArgumentList(_ *ast.ArgumentList) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) Argument(_ *ast.Argument) {
|
||||
// do nothing
|
||||
}
|
||||
|
@ -1450,9 +1450,9 @@ func (p *PrettyPrinter) printStmtClass(n ast.Vertex) {
|
||||
p.Print(nn.ClassName)
|
||||
}
|
||||
|
||||
if nn.ArgumentList != nil {
|
||||
if nn.Arguments != nil {
|
||||
io.WriteString(p.w, "(")
|
||||
p.joinPrint(", ", nn.ArgumentList.(*ast.ArgumentList).Arguments)
|
||||
p.joinPrint(", ", nn.Arguments)
|
||||
io.WriteString(p.w, ")")
|
||||
}
|
||||
|
||||
|
@ -2067,10 +2067,10 @@ func (p *Printer) printStmtClass(n ast.Vertex) {
|
||||
p.Print(nn.ClassName)
|
||||
}
|
||||
|
||||
if nn.ArgumentList != nil {
|
||||
p.printFreeFloatingOrDefault(nn.ArgumentList, token.Start, "(")
|
||||
p.joinPrint(",", nn.ArgumentList.(*ast.ArgumentList).Arguments)
|
||||
p.printFreeFloatingOrDefault(nn.ArgumentList, token.End, ")")
|
||||
if nn.Arguments != nil {
|
||||
p.printToken(nn.OpenParenthesisTkn, "(")
|
||||
p.joinPrint(",", nn.Arguments)
|
||||
p.printToken(nn.CloseParenthesisTkn, ")")
|
||||
}
|
||||
|
||||
if nn.Extends != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user