@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/jonbodner/proteus/logger"
16
16
"github.com/jonbodner/proteus/mapper"
17
+ "github.com/jonbodner/stackerr"
17
18
)
18
19
19
20
func buildNameOrderMap (paramOrder string , startPos int ) map [string ]int {
@@ -87,7 +88,7 @@ func buildFixedQueryAndParamOrder(c context.Context, query string, nameOrderMap
87
88
if inVar {
88
89
if len (curVar ) == 0 {
89
90
//error! must have a something
90
- return nil , nil , fmt .Errorf ("empty variable declaration at position %d" , k )
91
+ return nil , nil , stackerr .Errorf ("empty variable declaration at position %d" , k )
91
92
}
92
93
curVarS := string (curVar )
93
94
id , err := validIdentifier (c , curVarS )
@@ -103,7 +104,7 @@ func buildFixedQueryAndParamOrder(c context.Context, query string, nameOrderMap
103
104
//if it's a slice, then we put in the slice template syntax instead.
104
105
105
106
//get just the first part of the name, before any .
106
- path := strings .SplitN (id , "." , 2 )
107
+ path := strings .Split (id , "." )
107
108
paramName := path [0 ]
108
109
if paramPos , ok := nameOrderMap [paramName ]; ok {
109
110
//if the path has more than one part, make sure that the type of the function parameter is map or struct
@@ -113,7 +114,7 @@ func buildFixedQueryAndParamOrder(c context.Context, query string, nameOrderMap
113
114
case reflect .Map , reflect .Struct :
114
115
//do nothing
115
116
default :
116
- return nil , nil , fmt .Errorf ("query Parameter %s has a path, but the incoming parameter is not a map or a struct" , paramName )
117
+ return nil , nil , stackerr .Errorf ("query Parameter %s has a path, but the incoming parameter is not a map or a struct" , paramName )
117
118
}
118
119
}
119
120
pathType , err := mapper .ExtractType (c , paramType , path )
@@ -129,7 +130,7 @@ func buildFixedQueryAndParamOrder(c context.Context, query string, nameOrderMap
129
130
}
130
131
paramOrder = append (paramOrder , paramInfo {id , paramPos , isSlice })
131
132
} else {
132
- return nil , nil , fmt .Errorf ("query Parameter %s cannot be found in the incoming parameters" , paramName )
133
+ return nil , nil , stackerr .Errorf ("query Parameter %s cannot be found in the incoming parameters" , paramName )
133
134
}
134
135
135
136
inVar = false
@@ -146,7 +147,7 @@ func buildFixedQueryAndParamOrder(c context.Context, query string, nameOrderMap
146
147
}
147
148
}
148
149
if inVar {
149
- return nil , nil , fmt .Errorf ("missing a closing : somewhere: %s" , query )
150
+ return nil , nil , stackerr .Errorf ("missing a closing : somewhere: %s" , query )
150
151
}
151
152
152
153
queryString := out .String ()
@@ -230,7 +231,7 @@ func addSlice(sliceName string) string {
230
231
231
232
func validIdentifier (c context.Context , curVar string ) (string , error ) {
232
233
if strings .Contains (curVar , ";" ) {
233
- return "" , fmt .Errorf ("; is not allowed in an identifier: %s" , curVar )
234
+ return "" , stackerr .Errorf ("; is not allowed in an identifier: %s" , curVar )
234
235
}
235
236
curVarB := []byte (curVar )
236
237
@@ -251,7 +252,7 @@ loop:
251
252
switch tok {
252
253
case token .EOF :
253
254
if first || lastPeriod {
254
- return "" , fmt .Errorf ("identifiers cannot be empty or end with a .: %s" , curVar )
255
+ return "" , stackerr .Errorf ("identifiers cannot be empty or end with a .: %s" , curVar )
255
256
}
256
257
break loop
257
258
case token .SEMICOLON :
@@ -260,15 +261,15 @@ loop:
260
261
continue
261
262
case token .IDENT :
262
263
if ! first && ! lastPeriod && ! lastFloat {
263
- return "" , fmt .Errorf (". missing between parts of an identifier: %s" , curVar )
264
+ return "" , stackerr .Errorf (". missing between parts of an identifier: %s" , curVar )
264
265
}
265
266
first = false
266
267
lastPeriod = false
267
268
lastFloat = false
268
269
identifier += lit
269
270
case token .PERIOD :
270
271
if first || lastPeriod {
271
- return "" , fmt .Errorf ("identifier cannot start with . or have two . in a row: %s" , curVar )
272
+ return "" , stackerr .Errorf ("identifier cannot start with . or have two . in a row: %s" , curVar )
272
273
}
273
274
lastPeriod = true
274
275
identifier += "."
@@ -280,28 +281,35 @@ loop:
280
281
first = false
281
282
continue
282
283
}
283
- return "" , fmt .Errorf ("invalid character found in identifier: %s" , curVar )
284
+ return "" , stackerr .Errorf ("invalid character found in identifier: %s" , curVar )
284
285
case token .INT :
285
- if ! dollar {
286
- return "" , fmt .Errorf ("invalid character found in identifier: %s" , curVar )
286
+ if ! dollar || first {
287
+ return "" , stackerr .Errorf ("invalid character found in identifier: %s" , curVar )
287
288
}
288
289
identifier += lit
289
- dollar = false
290
+ if dollar {
291
+ dollar = false
292
+ }
290
293
case token .FLOAT :
291
294
//this is weird. If we have $1.NAME, it will think that there's a FLOAT token with value 1.
292
295
//due to float support for exponents, if we have an E after the decimal point, the FLOAT token
293
- //will include the E and any subsequent digits. Obviously, only valid for $ notation
294
- if ! dollar {
295
- return "" , fmt .Errorf ("invalid character found in identifier: %s" , curVar )
296
+ //will include the E and any subsequent digits.
297
+ // also a problem when walking array or slice references (values.0 is the 0th element in array values). This
298
+ // returns .0 as the lit value
299
+ //Only valid for $ notation and array/slice references.
300
+ if first {
301
+ return "" , stackerr .Errorf ("invalid character found in identifier: %s" , curVar )
296
302
}
297
303
identifier += lit
298
- dollar = false
304
+ if dollar {
305
+ dollar = false
306
+ }
299
307
lastFloat = true
300
308
if lit [len (lit )- 1 ] == '.' {
301
309
lastPeriod = true
302
310
}
303
311
default :
304
- return "" , fmt .Errorf ("invalid character found in identifier: %s" , curVar )
312
+ return "" , stackerr .Errorf ("invalid character found in identifier: %s" , curVar )
305
313
}
306
314
}
307
315
return identifier , nil
0 commit comments