2015-01-11 21:38:45 +01:00
|
|
|
package ast
|
|
|
|
|
2015-01-11 22:59:24 +01:00
|
|
|
import (
|
2015-01-14 21:18:51 +01:00
|
|
|
"bytes"
|
2015-01-11 22:59:24 +01:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2015-01-11 21:38:45 +01:00
|
|
|
// Concat represents a node where the result of two or more expressions are
|
|
|
|
// concatenated. The result of all expressions must be a string.
|
|
|
|
type Concat struct {
|
|
|
|
Exprs []Node
|
2015-01-12 09:28:47 +01:00
|
|
|
Posx Pos
|
2015-01-11 21:38:45 +01:00
|
|
|
}
|
2015-01-11 22:59:24 +01:00
|
|
|
|
2015-01-15 01:36:01 +01:00
|
|
|
func (n *Concat) Accept(v Visitor) Node {
|
|
|
|
for i, expr := range n.Exprs {
|
|
|
|
n.Exprs[i] = expr.Accept(v)
|
2015-01-12 00:26:54 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 01:36:01 +01:00
|
|
|
return v(n)
|
2015-01-12 00:26:54 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 09:28:47 +01:00
|
|
|
func (n *Concat) Pos() Pos {
|
|
|
|
return n.Posx
|
|
|
|
}
|
|
|
|
|
2015-01-11 22:59:24 +01:00
|
|
|
func (n *Concat) GoString() string {
|
|
|
|
return fmt.Sprintf("*%#v", *n)
|
|
|
|
}
|
2015-01-14 21:18:51 +01:00
|
|
|
|
|
|
|
func (n *Concat) String() string {
|
|
|
|
var b bytes.Buffer
|
|
|
|
for _, expr := range n.Exprs {
|
|
|
|
b.WriteString(fmt.Sprintf("%s", expr))
|
|
|
|
}
|
|
|
|
|
|
|
|
return b.String()
|
|
|
|
}
|
2015-01-15 05:13:35 +01:00
|
|
|
|
|
|
|
func (n *Concat) Type(Scope) (Type, error) {
|
|
|
|
return TypeString, nil
|
|
|
|
}
|