@@ -22,7 +22,7 @@ import (
2222// TSLNode represents a tree search language AST (Abstract Syntax Tree) node
2323// This provides the public interface for TSL parsing results
2424type TSLNode struct {
25- node * Node
25+ Node * Node
2626}
2727
2828// TSLExpressionOp represents both unary and binary operations
@@ -40,7 +40,7 @@ type TSLArrayLiteral struct {
4040func ParseTSL (input string ) (* TSLNode , error ) {
4141 parserNode , err := parser .Parse (input )
4242 if err != nil {
43- // Convert parser error to TSL error type
43+ // Return a TSL-specific error with position information
4444 if parseErr , ok := err .(* parser.ParseError ); ok {
4545 return nil , & SyntaxError {
4646 Message : parseErr .Message ,
@@ -52,64 +52,64 @@ func ParseTSL(input string) (*TSLNode, error) {
5252 return nil , err
5353 }
5454
55- // Convert parser node to TSL node
55+ // Create TSL node from parsed input
5656 tslNode := wrapParserNode (parserNode )
57- return & TSLNode {node : tslNode }, nil
57+ return & TSLNode {Node : tslNode }, nil
5858}
5959
6060// Clone creates a deep copy of the TSLNode and its children
6161func (n * TSLNode ) Clone () * TSLNode {
62- if n == nil || n .node == nil {
62+ if n == nil || n .Node == nil {
6363 return nil
6464 }
65- return & TSLNode {node : n .node .Clone ()}
65+ return & TSLNode {Node : n .Node .Clone ()}
6666}
6767
6868// Type returns the type of the node
6969func (n * TSLNode ) Type () Kind {
70- if n == nil || n .node == nil {
70+ if n == nil || n .Node == nil {
7171 return Kind (- 1 )
7272 }
73- return n .node .Kind
73+ return n .Node .Kind
7474}
7575
7676// Value returns the node's value based on its type
7777func (n * TSLNode ) Value () interface {} {
78- if n == nil || n .node == nil {
78+ if n == nil || n .Node == nil {
7979 return nil
8080 }
8181
82- switch n .node .Kind {
82+ switch n .Node .Kind {
8383 case KindBooleanLiteral , KindNumericLiteral , KindStringLiteral ,
8484 KindIdentifier , KindDateLiteral , KindTimestampLiteral :
85- return n .node .Value
85+ return n .Node .Value
8686 case KindBinaryExpr :
8787 var left , right * TSLNode
88- if n .node .Left != nil {
89- left = & TSLNode {node : n .node .Left }
88+ if n .Node .Left != nil {
89+ left = & TSLNode {Node : n .Node .Left }
9090 }
91- if n .node .Right != nil {
92- right = & TSLNode {node : n .node .Right }
91+ if n .Node .Right != nil {
92+ right = & TSLNode {Node : n .Node .Right }
9393 }
9494 return TSLExpressionOp {
95- Operator : n .node .Operator ,
95+ Operator : n .Node .Operator ,
9696 Left : left ,
9797 Right : right ,
9898 }
9999 case KindUnaryExpr :
100100 var right * TSLNode
101- if n .node .Right != nil {
102- right = & TSLNode {node : n .node .Right }
101+ if n .Node .Right != nil {
102+ right = & TSLNode {Node : n .Node .Right }
103103 }
104104 return TSLExpressionOp {
105- Operator : n .node .Operator ,
105+ Operator : n .Node .Operator ,
106106 Left : nil ,
107107 Right : right ,
108108 }
109109 case KindArrayLiteral :
110- values := make ([]* TSLNode , len (n .node .Children ))
111- for i , child := range n .node .Children {
112- values [i ] = & TSLNode {node : child }
110+ values := make ([]* TSLNode , len (n .Node .Children ))
111+ for i , child := range n .Node .Children {
112+ values [i ] = & TSLNode {Node : child }
113113 }
114114 return TSLArrayLiteral {Values : values }
115115 case KindNullLiteral :
@@ -118,63 +118,3 @@ func (n *TSLNode) Value() interface{} {
118118 return nil
119119 }
120120}
121-
122- // DetachLeft safely detaches and returns the left child of a binary expression node
123- func (n * TSLNode ) DetachLeft () * TSLNode {
124- if n == nil || n .node == nil || n .node .Kind != KindBinaryExpr || n .node .Left == nil {
125- return nil
126- }
127- left := n .node .Left
128- n .node .Left = nil
129- return & TSLNode {node : left }
130- }
131-
132- // DetachRight safely detaches and returns the right child of a binary expression node
133- func (n * TSLNode ) DetachRight () * TSLNode {
134- if n == nil || n .node == nil || n .node .Kind != KindBinaryExpr || n .node .Right == nil {
135- return nil
136- }
137- right := n .node .Right
138- n .node .Right = nil
139- return & TSLNode {node : right }
140- }
141-
142- // DetachChild safely detaches and returns the child of a unary expression node
143- func (n * TSLNode ) DetachChild () * TSLNode {
144- if n == nil || n .node == nil || n .node .Kind != KindUnaryExpr || n .node .Right == nil {
145- return nil
146- }
147- child := n .node .Right
148- n .node .Right = nil
149- return & TSLNode {node : child }
150- }
151-
152- // AttachLeft safely attaches a child node as the left child of a binary expression node
153- func (n * TSLNode ) AttachLeft (child * TSLNode ) bool {
154- if n == nil || n .node == nil || child == nil || child .node == nil ||
155- n .node .Kind != KindBinaryExpr {
156- return false
157- }
158- n .node .Left = child .node
159- return true
160- }
161-
162- // AttachRight safely attaches a child node as the right child of a binary expression node
163- func (n * TSLNode ) AttachRight (child * TSLNode ) bool {
164- if n == nil || n .node == nil || child == nil || child .node == nil ||
165- n .node .Kind != KindBinaryExpr {
166- return false
167- }
168- n .node .Right = child .node
169- return true
170- }
171-
172- // AttachChild safely attaches a child node to a unary expression node
173- func (n * TSLNode ) AttachChild (child * TSLNode ) bool {
174- if n == nil || n .node == nil || child == nil || child .node == nil ||
175- n .node .Kind != KindUnaryExpr {
176- return false
177- }
178- n .node .Right = child .node
179- return true
180- }
0 commit comments