parseDqlVariables parses the DQL variable declaration.
(it *lex.ItemIterator, vmap varMap)
| 1234 | |
| 1235 | // parseDqlVariables parses the DQL variable declaration. |
| 1236 | func parseDqlVariables(it *lex.ItemIterator, vmap varMap) error { |
| 1237 | expectArg := true |
| 1238 | if item, ok := it.PeekOne(); ok && item.Typ == itemRightRound { |
| 1239 | return nil |
| 1240 | } |
| 1241 | loop: |
| 1242 | for it.Next() { |
| 1243 | var varName string |
| 1244 | // Get variable name. |
| 1245 | item := it.Item() |
| 1246 | switch item.Typ { |
| 1247 | case itemDollar: |
| 1248 | if !expectArg { |
| 1249 | return item.Errorf("Missing comma in var declaration") |
| 1250 | } |
| 1251 | it.Next() |
| 1252 | item = it.Item() |
| 1253 | if item.Typ == itemName { |
| 1254 | varName = fmt.Sprintf("$%s", item.Val) |
| 1255 | } else { |
| 1256 | return item.Errorf("Expecting a variable name. Got: %v", item) |
| 1257 | } |
| 1258 | case itemRightRound: |
| 1259 | if expectArg { |
| 1260 | return item.Errorf("Invalid comma in var block") |
| 1261 | } |
| 1262 | break loop |
| 1263 | case itemComma: |
| 1264 | if expectArg { |
| 1265 | return item.Errorf("Invalid comma in var block") |
| 1266 | } |
| 1267 | expectArg = true |
| 1268 | continue |
| 1269 | default: |
| 1270 | return item.Errorf("Unexpected item in place of variable. Got: %v %v", item, |
| 1271 | item.Typ == itemDollar) |
| 1272 | } |
| 1273 | |
| 1274 | it.Next() |
| 1275 | item = it.Item() |
| 1276 | if item.Typ != itemColon { |
| 1277 | return item.Errorf("Expecting a colon. Got: %v", item) |
| 1278 | } |
| 1279 | |
| 1280 | // Get variable type. |
| 1281 | it.Next() |
| 1282 | item = it.Item() |
| 1283 | if item.Typ != itemName { |
| 1284 | return item.Errorf("Expecting a variable type. Got: %v", item) |
| 1285 | } |
| 1286 | |
| 1287 | // Ensure that the type is not nil. |
| 1288 | varType := item.Val |
| 1289 | if varType == "" { |
| 1290 | return item.Errorf("Type of a variable can't be empty") |
| 1291 | } |
| 1292 | it.Next() |
| 1293 | item = it.Item() |
no test coverage detected