@@ -9,33 +9,50 @@ const (
9
9
10
10
// Node represents a node in the JSONPath AST.
11
11
type Node interface {
12
- Pos () TokenInfo // position of the first token belonging to the node
13
- End () TokenInfo // position of the first token immediately after the node
14
- String () string // print pretty.
12
+ Kind () Kind // The Kind of the node
15
13
}
16
14
15
+ type Segment = Node
16
+
17
17
// JSONPath expression built from segments that have
18
18
// been syntactically restricted in a certain way (Section 2.3.5.1)
19
19
type Query struct {
20
20
RootNode TokenInfo
21
21
Segments []Segment
22
22
}
23
23
24
+ var _ Node = DescendantSegment {}
25
+
26
+ type DescendantKind int
27
+
28
+ const (
29
+ DescendantWildcardSelector = iota
30
+ DescendantDotNameSelector
31
+ DescendantLongSelector
32
+ )
33
+
34
+ var _ Segment = DescendantSegment {}
35
+
36
+ type DescendantSegment struct {
37
+ SubKind DescendantKind
38
+ LongFormInner Segment
39
+ }
40
+
41
+ func (d DescendantSegment ) Kind () Kind {
42
+ return DescendantSegmentKind
43
+ }
44
+
24
45
// One of the constructs that selects children ([<selectors>])
25
46
// or descendants (..[<selectors>]) of an input value
26
47
// segment = child-segment / descendant-segment
27
- type Segment struct {
28
- Kind Kind
29
- ChildSegment ChildSegment
30
- DescendantSegment DescendantSegment
31
- }
32
48
33
49
// child-segment = bracketed-selection /
34
50
//
35
51
// ("."
36
52
// (wildcard-selector /
37
53
// member-name-shorthand))
38
54
type ChildSegment struct {
55
+ Kind Kind
39
56
}
40
57
41
58
// Expr represents a JSONPath expression.
@@ -60,110 +77,13 @@ type CurrentNode struct {
60
77
At TokenInfo // position of "@"
61
78
}
62
79
63
- func (n * CurrentNode ) Pos () TokenInfo { return n .At }
64
- func (n * CurrentNode ) End () TokenInfo {
65
- return TokenInfo {Token : n .At .Token , Line : n .At .Line , Column : n .At .Column + 1 }
66
- }
67
- func (n * CurrentNode ) exprNode () {}
68
-
69
- // IdentifierNode represents an identifier in a JSONPath expression.
70
- type IdentifierNode struct {
71
- Name TokenInfo // identifier name
72
- }
73
-
74
- func (n * IdentifierNode ) Pos () TokenInfo { return n .Name }
75
- func (n * IdentifierNode ) End () TokenInfo {
76
- return TokenInfo {Token : n .Name .Token , Line : n .Name .Line , Column : n .Name .Column + len (n .Name .Literal )}
77
- }
78
- func (n * IdentifierNode ) exprNode () {}
79
-
80
- // WildcardNode represents a wildcard in a JSONPath expression.
81
- type WildcardNode struct {
82
- Star TokenInfo // position of "*"
83
- }
84
-
85
- func (n * WildcardNode ) Pos () TokenInfo { return n .Star }
86
- func (n * WildcardNode ) End () TokenInfo {
87
- return TokenInfo {Token : n .Star .Token , Line : n .Star .Line , Column : n .Star .Column + 1 }
88
- }
89
- func (n * WildcardNode ) exprNode () {}
90
-
91
- // RecursiveDescentNode represents a recursive descent operator in a JSONPath expression.
92
- type RecursiveDescentNode struct {
93
- DoubleDot TokenInfo // position of ".."
94
- }
95
-
96
- func (n * RecursiveDescentNode ) Pos () TokenInfo { return n .DoubleDot }
97
- func (n * RecursiveDescentNode ) End () TokenInfo {
98
- return TokenInfo {Token : n .DoubleDot .Token , Line : n .DoubleDot .Line , Column : n .DoubleDot .Column + 2 }
99
- }
100
- func (n * RecursiveDescentNode ) exprNode () {}
101
-
102
- // SubscriptNode represents a subscript operator in a JSONPath expression.
103
- type SubscriptNode struct {
104
- Lbrack TokenInfo // position of "["
105
- Index Expr // subscript index expression
106
- Rbrack TokenInfo // position of "]"
107
- }
108
-
109
- func (n * SubscriptNode ) Pos () TokenInfo { return n .Lbrack }
110
- func (n * SubscriptNode ) End () TokenInfo {
111
- return TokenInfo {Token : n .Rbrack .Token , Line : n .Rbrack .Line , Column : n .Rbrack .Column + 1 }
112
- }
113
- func (n * SubscriptNode ) exprNode () {}
114
-
115
- // SliceNode represents a slice operator in a JSONPath expression.
116
- type SliceNode struct {
117
- Lbrack TokenInfo // position of "["
118
- Start Expr // start index expression
119
- Colon1 TokenInfo // position of first ":"
120
- Finish Expr // end index expression
121
- Colon2 TokenInfo // position of second ":", if any
122
- Step Expr // step expression
123
- Rbrack TokenInfo // position of "]"
124
- }
125
-
126
- func (n * SliceNode ) Pos () TokenInfo { return n .Lbrack }
127
- func (n * SliceNode ) End () TokenInfo {
128
- return TokenInfo {Token : n .Rbrack .Token , Line : n .Rbrack .Line , Column : n .Rbrack .Column + 1 }
129
- }
130
- func (n * SliceNode ) exprNode () {}
131
-
132
- // UnionNode represents a union operator in a JSONPath expression.
133
- type UnionNode struct {
134
- Lhs Expr // left-hand side expression
135
- Comma TokenInfo // position of ","
136
- Rhs Expr // right-hand side expression
137
- }
138
-
139
- func (n * UnionNode ) Pos () TokenInfo { return n .Lhs .Pos () }
140
- func (n * UnionNode ) End () TokenInfo { return n .Rhs .End () }
141
- func (n * UnionNode ) exprNode () {}
142
-
143
- // FilterNode represents a filter expression in a JSONPath expression.
144
- type FilterNode struct {
145
- Lbrack TokenInfo // position of "["
146
- Expr Expr // filter expression
147
- Rbrack TokenInfo // position of "]"
148
- }
149
-
150
- func (n * FilterNode ) Pos () TokenInfo { return n .Lbrack }
151
- func (n * FilterNode ) End () TokenInfo {
152
- return TokenInfo {Token : n .Rbrack .Token , Line : n .Rbrack .Line , Column : n .Rbrack .Column + 1 }
153
- }
154
- func (n * FilterNode ) exprNode () {}
155
-
156
80
// ComparisonNode represents a comparison expression in a JSONPath filter.
157
81
type ComparisonNode struct {
158
82
Lhs Expr // left-hand side expression
159
83
Operator TokenInfo // comparison operator
160
84
Rhs Expr // right-hand side expression
161
85
}
162
86
163
- func (n * ComparisonNode ) Pos () TokenInfo { return n .Lhs .Pos () }
164
- func (n * ComparisonNode ) End () TokenInfo { return n .Rhs .End () }
165
- func (n * ComparisonNode ) exprNode () {}
166
-
167
87
// BooleanNode represents a boolean literal in a JSONPath expression.
168
88
type BooleanNode struct {
169
89
Value TokenInfo // boolean value
0 commit comments