sq/libsq/ast/handle.go
Neil O'Toole f07edef14d
Add flag --src.schema (#326)
* Support for --src.schema in commands "slq", "sql", and "inspect"
2023-11-18 17:05:48 -07:00

50 lines
1.1 KiB
Go

package ast
import (
"github.com/neilotoole/sq/libsq/ast/internal/slq"
"github.com/neilotoole/sq/libsq/core/tablefq"
)
// HandleNode models a source handle such as "@sakila".
type HandleNode struct {
baseNode
}
// Handle returns the handle value, e.g. "@sakila".
func (d *HandleNode) Handle() string {
return d.text
}
// String returns a log/debug-friendly representation.
func (d *HandleNode) String() string {
return nodeString(d)
}
// VisitHandle implements slq.SLQVisitor.
func (v *parseTreeVisitor) VisitHandle(ctx *slq.HandleContext) any {
node := &HandleNode{}
node.text = ctx.GetText()
node.parent = v.cur
node.ctx = ctx.HANDLE()
return v.cur.AddChild(node)
}
// VisitHandleTable implements slq.SLQVisitor.
func (v *parseTreeVisitor) VisitHandleTable(ctx *slq.HandleTableContext) any {
node := &TblSelectorNode{}
node.parent = v.cur
node.ctx = ctx
node.text = ctx.GetText()
node.handle = ctx.HANDLE().GetText()
var err error
selTbl, err := extractSelVal(ctx.NAME())
if err != nil {
return err
}
node.tbl = tablefq.From(selTbl)
return v.cur.AddChild(node)
}