package ast
import (
"time"
)
type Node interface {
Location() *Location
}
type Position struct {
Line int
Column int
}
type Location struct {
Start Position `json:"start"`
End Position `json:"end"`
Source *string `json:"source,omitempty"`
}
type Base struct {
Loc *Location
}
func (b *Base) Location() *Location { return b.Loc }
type Ast struct {
*Base
Nodes []Node `json:"body"`
}
type StringNode struct {
*Base
Key string
Value string
Exact bool
CaseInsensitive bool
}
type BooleanNode struct {
*Base
Key string
Value bool
}
type DateTimeNode struct {
*Base
Key string
Operator *OperatorNode
Value time.Time
}
type NumberNode struct {
*Base
Key string
Operator *OperatorNode
Value float64
}
type OperatorNode struct {
*Base
Value string
}
type GroupNode struct {
*Base
Key string
Nodes []Node
}
func NodeKey(n Node) string {
switch node := n.(type) {
case *StringNode:
return node.Key
case *DateTimeNode:
return node.Key
case *BooleanNode:
return node.Key
case *GroupNode:
return node.Key
default:
return ""
}
}
func NodeValue(n Node) any {
switch node := n.(type) {
case *StringNode:
return node.Value
case *DateTimeNode:
return node.Value
case *BooleanNode:
return node.Value
case *GroupNode:
return node.Nodes
default:
return ""
}
}