sq/libsq/ast/arg.go
Neil O'Toole 7c56377b40
Struct alignment (#369)
* Field alignment
2024-01-27 00:11:24 -07:00

38 lines
775 B
Go

package ast
import (
"strings"
"github.com/neilotoole/sq/libsq/ast/internal/slq"
)
// ArgNode implements the SQL "DISTINCT" clause.
type ArgNode struct {
key string
baseNode
}
// String returns a log/debug-friendly representation.
func (n *ArgNode) String() string {
return nodeString(n)
}
// Key returns the arg key. If the arg is "$name", the key is "name".
func (n *ArgNode) Key() string {
return n.key
}
// VisitArg implements slq.SLQVisitor.
func (v *parseTreeVisitor) VisitArg(ctx *slq.ArgContext) interface{} {
node := &ArgNode{}
node.ctx = ctx
node.text = ctx.GetText()
if ctx.ARG() != nil {
// The node text will be "$key". We need to trim the $ prefix.
node.key = strings.TrimPrefix(ctx.ARG().GetText(), "$")
}
return v.cur.AddChild(node)
}