[refactoring] update ast structure of "Eval", "Exit", "FunctionCall", "Include" and "IncludeOnce" nodes

This commit is contained in:
Vadym Slizov
2020-12-01 11:58:09 +02:00
parent 2d240e9475
commit 9b122de8bf
9 changed files with 1333 additions and 1335 deletions

View File

@@ -1114,7 +1114,10 @@ func (n *ExprErrorSuppress) Accept(v NodeVisitor) {
// ExprEval node
type ExprEval struct {
Node
Expr Vertex
EvalTkn *token.Token
OpenParenthesisTkn *token.Token
Expr Vertex
CloseParenthesisTkn *token.Token
}
func (n *ExprEval) Accept(v NodeVisitor) {
@@ -1124,8 +1127,10 @@ func (n *ExprEval) Accept(v NodeVisitor) {
// ExprExit node
type ExprExit struct {
Node
Die bool
Expr Vertex
DieTkn *token.Token
OpenParenthesisTkn *token.Token
Expr Vertex
CloseParenthesisTkn *token.Token
}
func (n *ExprExit) Accept(v NodeVisitor) {
@@ -1135,8 +1140,10 @@ func (n *ExprExit) Accept(v NodeVisitor) {
// ExprFunctionCall node
type ExprFunctionCall struct {
Node
Function Vertex
ArgumentList *ArgumentList
Function Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
CloseParenthesisTkn *token.Token
}
func (n *ExprFunctionCall) Accept(v NodeVisitor) {
@@ -1146,7 +1153,8 @@ func (n *ExprFunctionCall) Accept(v NodeVisitor) {
// ExprInclude node
type ExprInclude struct {
Node
Expr Vertex
IncludeTkn *token.Token
Expr Vertex
}
func (n *ExprInclude) Accept(v NodeVisitor) {
@@ -1156,7 +1164,8 @@ func (n *ExprInclude) Accept(v NodeVisitor) {
// ExprIncludeOnce node
type ExprIncludeOnce struct {
Node
Expr Vertex
IncludeTkn *token.Token
Expr Vertex
}
func (n *ExprIncludeOnce) Accept(v NodeVisitor) {

View File

@@ -1303,10 +1303,12 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.Function)
t.visitor.Leave("Function", true)
}
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)
}
case *ast.ExprInclude:
if nn == nil {

View File

@@ -692,11 +692,6 @@ func (v *Dump) ExprExit(n *ast.ExprExit) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.ExprExit{\n")
v.printNode(n.GetNode())
if n.Die {
v.printIndent(v.indent)
v.print("Die: true,\n")
}
}
func (v *Dump) ExprFunctionCall(n *ast.ExprFunctionCall) {

View File

@@ -1074,11 +1074,7 @@ func (p *PrettyPrinter) printExprEval(n ast.Vertex) {
func (p *PrettyPrinter) printExprExit(n ast.Vertex) {
nn := n.(*ast.ExprExit)
if nn.Die {
io.WriteString(p.w, "die(")
} else {
io.WriteString(p.w, "exit(")
}
io.WriteString(p.w, "exit(")
p.Print(nn.Expr)
io.WriteString(p.w, ")")
}
@@ -1088,7 +1084,7 @@ func (p *PrettyPrinter) printExprFunctionCall(n ast.Vertex) {
p.Print(nn.Function)
io.WriteString(p.w, "(")
p.joinPrint(", ", nn.ArgumentList.Arguments)
p.joinPrint(", ", nn.Arguments)
io.WriteString(p.w, ")")
}

View File

@@ -1590,8 +1590,8 @@ func (p *Printer) printExprExit(n ast.Vertex) {
nn := n.(*ast.ExprExit)
p.printFreeFloating(nn, token.Start)
if nn.Die {
p.write([]byte("die"))
if nn.DieTkn != nil {
p.write(nn.DieTkn.Value)
} else {
p.write([]byte("exit"))
}
@@ -1611,9 +1611,9 @@ func (p *Printer) printExprFunctionCall(n ast.Vertex) {
p.Print(nn.Function)
p.printFreeFloatingOrDefault(nn.ArgumentList, token.Start, "(")
p.joinPrint(",", nn.ArgumentList.Arguments)
p.printFreeFloatingOrDefault(nn.ArgumentList, token.End, ")")
p.printToken(nn.OpenParenthesisTkn, "(")
p.joinPrint(",", nn.Arguments)
p.printToken(nn.CloseParenthesisTkn, ")")
p.printFreeFloating(nn, token.End)
}