Akron | b7e1f35 | 2025-05-16 15:45:23 +0200 | [diff] [blame^] | 1 | package ast |
| 2 | |
| 3 | // NodeType represents the type of a node in the AST |
| 4 | type NodeType string |
| 5 | |
| 6 | const ( |
| 7 | TokenNode NodeType = "token" |
| 8 | TermGroupNode NodeType = "termGroup" |
| 9 | TermNode NodeType = "term" |
| 10 | ) |
| 11 | |
| 12 | // RelationType represents the type of relation between nodes |
| 13 | type RelationType string |
| 14 | |
| 15 | const ( |
| 16 | AndRelation RelationType = "and" |
| 17 | OrRelation RelationType = "or" |
| 18 | ) |
| 19 | |
| 20 | // MatchType represents the type of match operation |
| 21 | type MatchType string |
| 22 | |
| 23 | const ( |
| 24 | MatchEqual MatchType = "eq" |
| 25 | MatchNotEqual MatchType = "ne" |
| 26 | ) |
| 27 | |
| 28 | // Node represents a node in the AST |
| 29 | type Node interface { |
| 30 | Type() NodeType |
| 31 | } |
| 32 | |
| 33 | // Token represents a token node in the query |
| 34 | type Token struct { |
| 35 | Wrap Node `json:"wrap"` |
| 36 | } |
| 37 | |
| 38 | func (t *Token) Type() NodeType { |
| 39 | return TokenNode |
| 40 | } |
| 41 | |
| 42 | // TermGroup represents a group of terms with a relation |
| 43 | type TermGroup struct { |
| 44 | Operands []Node `json:"operands"` |
| 45 | Relation RelationType `json:"relation"` |
| 46 | } |
| 47 | |
| 48 | func (tg *TermGroup) Type() NodeType { |
| 49 | return TermGroupNode |
| 50 | } |
| 51 | |
| 52 | // Term represents a terminal node with matching criteria |
| 53 | type 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 | |
| 61 | func (t *Term) Type() NodeType { |
| 62 | return TermNode |
| 63 | } |
| 64 | |
| 65 | // Pattern represents a pattern to match in the AST |
| 66 | type Pattern struct { |
| 67 | Root Node |
| 68 | } |
| 69 | |
| 70 | // Replacement represents a replacement pattern |
| 71 | type Replacement struct { |
| 72 | Root Node |
| 73 | } |