blob: aac7016d6c0e69765f6e58aa37ccfac579cacd0c [file] [log] [blame]
Akronb7e1f352025-05-16 15:45:23 +02001package ast
2
3// NodeType represents the type of a node in the AST
4type NodeType string
5
6const (
7 TokenNode NodeType = "token"
8 TermGroupNode NodeType = "termGroup"
9 TermNode NodeType = "term"
10)
11
12// RelationType represents the type of relation between nodes
13type RelationType string
14
15const (
16 AndRelation RelationType = "and"
17 OrRelation RelationType = "or"
18)
19
20// MatchType represents the type of match operation
21type MatchType string
22
23const (
24 MatchEqual MatchType = "eq"
25 MatchNotEqual MatchType = "ne"
26)
27
28// Node represents a node in the AST
29type Node interface {
30 Type() NodeType
31}
32
33// Token represents a token node in the query
34type Token struct {
35 Wrap Node `json:"wrap"`
36}
37
38func (t *Token) Type() NodeType {
39 return TokenNode
40}
41
42// TermGroup represents a group of terms with a relation
43type TermGroup struct {
44 Operands []Node `json:"operands"`
45 Relation RelationType `json:"relation"`
46}
47
48func (tg *TermGroup) Type() NodeType {
49 return TermGroupNode
50}
51
52// Term represents a terminal node with matching criteria
53type Term struct {
54 Foundry string `json:"foundry"`
55 Key string `json:"key"`
56 Layer string `json:"layer"`
57 Match MatchType `json:"match"`
58 Value string `json:"value,omitempty"`
59}
60
61func (t *Term) Type() NodeType {
62 return TermNode
63}
64
65// Pattern represents a pattern to match in the AST
66type Pattern struct {
67 Root Node
68}
69
70// Replacement represents a replacement pattern
71type Replacement struct {
72 Root Node
73}