11package godata
22
33import (
4+ "context"
45 "strconv"
56)
67
@@ -50,8 +51,8 @@ func ExpandTokenizer() *Tokenizer {
5051 return & t
5152}
5253
53- func ParseExpandString (expand string ) (* GoDataExpandQuery , error ) {
54- tokens , err := GlobalExpandTokenizer .Tokenize (expand )
54+ func ParseExpandString (ctx context. Context , expand string ) (* GoDataExpandQuery , error ) {
55+ tokens , err := GlobalExpandTokenizer .Tokenize (ctx , expand )
5556
5657 if err != nil {
5758 return nil , err
@@ -74,7 +75,7 @@ func ParseExpandString(expand string) (*GoDataExpandQuery, error) {
7475 } else if token .Value == "," {
7576 if stack .Empty () {
7677 // no paren on the stack, parse this item and start a new queue
77- item , err := ParseExpandItem (queue )
78+ item , err := ParseExpandItem (ctx , queue )
7879 if err != nil {
7980 return nil , err
8081 }
@@ -93,7 +94,7 @@ func ParseExpandString(expand string) (*GoDataExpandQuery, error) {
9394 return nil , BadRequestError ("Mismatched parentheses in expand clause." )
9495 }
9596
96- item , err := ParseExpandItem (queue )
97+ item , err := ParseExpandItem (ctx , queue )
9798 if err != nil {
9899 return nil , err
99100 }
@@ -102,7 +103,7 @@ func ParseExpandString(expand string) (*GoDataExpandQuery, error) {
102103 return & GoDataExpandQuery {ExpandItems : items }, nil
103104}
104105
105- func ParseExpandItem (input tokenQueue ) (* ExpandItem , error ) {
106+ func ParseExpandItem (ctx context. Context , input tokenQueue ) (* ExpandItem , error ) {
106107
107108 item := & ExpandItem {}
108109 item .Path = []* Token {}
@@ -128,7 +129,7 @@ func ParseExpandItem(input tokenQueue) (*ExpandItem, error) {
128129 queue .Enqueue (token )
129130 } else {
130131 // top level slash means we're done parsing the options
131- err := ParseExpandOption (queue , item )
132+ err := ParseExpandOption (ctx , queue , item )
132133 if err != nil {
133134 return nil , err
134135 }
@@ -140,7 +141,7 @@ func ParseExpandItem(input tokenQueue) (*ExpandItem, error) {
140141 item .Path = append (item .Path , queue .Dequeue ())
141142 } else if token .Value == ";" && stack .Size == 1 {
142143 // semicolons only split expand options at the first level
143- err := ParseExpandOption (queue , item )
144+ err := ParseExpandOption (ctx , queue , item )
144145 if err != nil {
145146 return nil , err
146147 }
@@ -162,7 +163,7 @@ func ParseExpandItem(input tokenQueue) (*ExpandItem, error) {
162163 return item , nil
163164}
164165
165- func ParseExpandOption (queue * tokenQueue , item * ExpandItem ) error {
166+ func ParseExpandOption (ctx context. Context , queue * tokenQueue , item * ExpandItem ) error {
166167 head := queue .Dequeue ().Value
167168 if queue .Head == nil {
168169 return BadRequestError ("Invalid expand clause." )
@@ -171,7 +172,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
171172 body := queue .GetValue ()
172173
173174 if head == "$filter" {
174- filter , err := ParseFilterString (body )
175+ filter , err := ParseFilterString (ctx , body )
175176 if err == nil {
176177 item .Filter = filter
177178 } else {
@@ -180,7 +181,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
180181 }
181182
182183 if head == "at" {
183- at , err := ParseFilterString (body )
184+ at , err := ParseFilterString (ctx , body )
184185 if err == nil {
185186 item .At = at
186187 } else {
@@ -189,7 +190,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
189190 }
190191
191192 if head == "$search" {
192- search , err := ParseSearchString (body )
193+ search , err := ParseSearchString (ctx , body )
193194 if err == nil {
194195 item .Search = search
195196 } else {
@@ -198,7 +199,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
198199 }
199200
200201 if head == "$orderby" {
201- orderby , err := ParseOrderByString (body )
202+ orderby , err := ParseOrderByString (ctx , body )
202203 if err == nil {
203204 item .OrderBy = orderby
204205 } else {
@@ -207,7 +208,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
207208 }
208209
209210 if head == "$skip" {
210- skip , err := ParseSkipString (body )
211+ skip , err := ParseSkipString (ctx , body )
211212 if err == nil {
212213 item .Skip = skip
213214 } else {
@@ -216,7 +217,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
216217 }
217218
218219 if head == "$top" {
219- top , err := ParseTopString (body )
220+ top , err := ParseTopString (ctx , body )
220221 if err == nil {
221222 item .Top = top
222223 } else {
@@ -225,7 +226,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
225226 }
226227
227228 if head == "$select" {
228- sel , err := ParseSelectString (body )
229+ sel , err := ParseSelectString (ctx , body )
229230 if err == nil {
230231 item .Select = sel
231232 } else {
@@ -234,7 +235,7 @@ func ParseExpandOption(queue *tokenQueue, item *ExpandItem) error {
234235 }
235236
236237 if head == "$expand" {
237- expand , err := ParseExpandString (body )
238+ expand , err := ParseExpandString (ctx , body )
238239 if err == nil {
239240 item .Expand = expand
240241 } else {
0 commit comments