sq/libsq/ast/arg.go
Neil O'Toole 9a1c6a7d09
Feature/173 args (#183)
- Implement --arg feature
- Refactor sqlbuilder package (now called "render").
- Bug fixes, especially around expressions.
2023-04-07 02:00:49 -06: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 {
baseNode
key string
}
// 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)
}