fix declare do if else else_if nodes

This commit is contained in:
vadim
2017-12-07 11:35:45 +02:00
parent 9608147c51
commit bb188f0637
8 changed files with 50 additions and 60 deletions

View File

@@ -12,15 +12,15 @@ type Declare struct {
node.SimpleNode
token token.Token
consts []node.Node
stmts []node.Node
stmt node.Node
}
func NewDeclare(token token.Token, consts []node.Node, stmts []node.Node) node.Node {
func NewDeclare(token token.Token, consts []node.Node, stmt node.Node) node.Node {
return Declare{
node.SimpleNode{Name: "Declare", Attributes: make(map[string]string)},
token,
consts,
stmts,
stmt,
}
}
@@ -34,10 +34,8 @@ func (n Declare) Print(out io.Writer, indent string) {
}
}
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
if n.stmt != nil {
fmt.Fprintf(out, "\n%vstmt:", indent+" ")
n.stmt.Print(out, indent+" ")
}
}

View File

@@ -11,15 +11,15 @@ import (
type Do struct {
node.SimpleNode
token token.Token
stmts []node.Node
stmt node.Node
cond node.Node
}
func NewDo(token token.Token, stmts []node.Node, cond node.Node) node.Node {
func NewDo(token token.Token, stmt node.Node, cond node.Node) node.Node {
return Do{
node.SimpleNode{Name: "Do", Attributes: make(map[string]string)},
token,
stmts,
stmt,
cond,
}
}
@@ -32,10 +32,8 @@ func (n Do) Print(out io.Writer, indent string) {
n.cond.Print(out, indent+" ")
}
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
if n.stmt != nil {
fmt.Fprintf(out, "\n%vstmt:", indent+" ")
n.stmt.Print(out, indent+" ")
}
}

View File

@@ -11,23 +11,23 @@ import (
type Echo struct {
node.SimpleNode
token token.Token
stmts []node.Node
exprs []node.Node
}
func NewEcho(token token.Token, stmts []node.Node) node.Node {
func NewEcho(token token.Token, exprs []node.Node) node.Node {
return Echo{
node.SimpleNode{Name: "Echo", Attributes: make(map[string]string)},
token,
stmts,
exprs,
}
}
func (n Echo) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value)
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
if n.exprs != nil {
fmt.Fprintf(out, "\n%vexprs:", indent+" ")
for _, nn := range n.exprs {
nn.Print(out, indent+" ")
}
}

View File

@@ -11,24 +11,22 @@ import (
type Else struct {
node.SimpleNode
token token.Token
stmts []node.Node
stmt node.Node
}
func NewElse(token token.Token, stmts []node.Node) node.Node {
func NewElse(token token.Token, stmt node.Node) node.Node {
return Else{
node.SimpleNode{Name: "Else", Attributes: make(map[string]string)},
token,
stmts,
stmt,
}
}
func (n Else) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value)
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
if n.stmt != nil {
fmt.Fprintf(out, "\n%vstmt:", indent+" ")
n.stmt.Print(out, indent+" ")
}
}

View File

@@ -12,15 +12,15 @@ type ElseIf struct {
node.SimpleNode
token token.Token
cond node.Node
stmts []node.Node
stmt node.Node
}
func NewElseIf(token token.Token, cond node.Node, stmts []node.Node) node.Node {
func NewElseIf(token token.Token, cond node.Node, stmt node.Node) node.Node {
return ElseIf{
node.SimpleNode{Name: "ElseIf", Attributes: make(map[string]string)},
token,
cond,
stmts,
stmt,
}
}
@@ -32,10 +32,8 @@ func (n ElseIf) Print(out io.Writer, indent string) {
n.cond.Print(out, indent+" ")
}
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
if n.stmt != nil {
fmt.Fprintf(out, "\n%vstmt:", indent+" ")
n.stmt.Print(out, indent+" ")
}
}

View File

@@ -12,24 +12,24 @@ type If struct {
node.SimpleNode
token token.Token
cond node.Node
stmts []node.Node
stmt node.Node
elseIf []node.Node
_else node.Node
}
func NewIf(token token.Token, cond node.Node, stmts []node.Node) node.Node {
func NewIf(token token.Token, cond node.Node, stmt node.Node) node.Node {
return If{
node.SimpleNode{Name: "If", Attributes: make(map[string]string)},
token,
cond,
stmts,
stmt,
nil,
nil,
}
}
func (n If) AddElseIf(elseIf node.Node) node.Node {
if (n.elseIf == nil) {
if n.elseIf == nil {
n.elseIf = make([]node.Node, 0)
}
@@ -52,13 +52,11 @@ func (n If) Print(out io.Writer, indent string) {
n.cond.Print(out, indent+" ")
}
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
if n.stmt != nil {
fmt.Fprintf(out, "\n%vstmt:", indent+" ")
n.stmt.Print(out, indent+" ")
}
if n.elseIf != nil {
fmt.Fprintf(out, "\n%velseIfs:", indent+" ")
for _, nn := range n.elseIf {