parseArguments parses the arguments part of the DQL query root.
(it *lex.ItemIterator, gq *GraphQuery)
| 1358 | |
| 1359 | // parseArguments parses the arguments part of the DQL query root. |
| 1360 | func parseArguments(it *lex.ItemIterator, gq *GraphQuery) (result []pair, rerr error) { |
| 1361 | expectArg := true |
| 1362 | orderCount := 0 |
| 1363 | loop: |
| 1364 | for it.Next() { |
| 1365 | var p pair |
| 1366 | // Get key. |
| 1367 | item := it.Item() |
| 1368 | switch item.Typ { |
| 1369 | case itemName: |
| 1370 | if !expectArg { |
| 1371 | return result, item.Errorf("Expecting a comma. But got: %v", item.Val) |
| 1372 | } |
| 1373 | p.Key = collectName(it, item.Val) |
| 1374 | if isSortkey(p.Key) { |
| 1375 | orderCount++ |
| 1376 | } |
| 1377 | expectArg = false |
| 1378 | case itemRightRound: |
| 1379 | if expectArg { |
| 1380 | return result, item.Errorf("Expected argument but got ')'.") |
| 1381 | } |
| 1382 | break loop |
| 1383 | case itemComma: |
| 1384 | if expectArg { |
| 1385 | return result, item.Errorf("Expected Argument but got comma.") |
| 1386 | } |
| 1387 | expectArg = true |
| 1388 | continue |
| 1389 | default: |
| 1390 | return result, item.Errorf("Expecting argument name. Got: %v", item) |
| 1391 | } |
| 1392 | |
| 1393 | it.Next() |
| 1394 | item = it.Item() |
| 1395 | if item.Typ != itemColon { |
| 1396 | return result, item.Errorf("Expecting a colon. Got: %v in %v", item, gq.Attr) |
| 1397 | } |
| 1398 | |
| 1399 | // Get value. |
| 1400 | it.Next() |
| 1401 | item = it.Item() |
| 1402 | var val string |
| 1403 | if item.Val == valueFunc { |
| 1404 | count, err := parseVarList(it, gq) |
| 1405 | if err != nil { |
| 1406 | return result, err |
| 1407 | } |
| 1408 | if count != 1 { |
| 1409 | return result, item.Errorf("Only one variable expected. Got %d", count) |
| 1410 | } |
| 1411 | gq.NeedsVar[len(gq.NeedsVar)-1].Typ = ValueVar |
| 1412 | p.Val = gq.NeedsVar[len(gq.NeedsVar)-1].Name |
| 1413 | result = append(result, p) |
| 1414 | if isSortkey(p.Key) && orderCount > 1 { |
| 1415 | return result, item.Errorf("Multiple sorting only allowed by predicates. Got: %+v", |
| 1416 | p.Val) |
| 1417 | } |
no test coverage detected