parseFuncArgs will try to parse the arguments inside an array ([]). If the values are prefixed with $ they are treated as Dql variables, otherwise they are used as scalar values. Returns nil on success while appending arguments to the function Args slice. Otherwise returns an error, which can be a p
(it *lex.ItemIterator, g *Function)
| 1643 | // Returns nil on success while appending arguments to the function Args slice. Otherwise |
| 1644 | // returns an error, which can be a parsing or value error. |
| 1645 | func parseFuncArgs(it *lex.ItemIterator, g *Function) error { |
| 1646 | var expectArg, isDollar bool |
| 1647 | |
| 1648 | expectArg = true |
| 1649 | for it.Next() { |
| 1650 | item := it.Item() |
| 1651 | switch item.Typ { |
| 1652 | case itemRightSquare: |
| 1653 | return nil |
| 1654 | case itemDollar: |
| 1655 | if !expectArg { |
| 1656 | return item.Errorf("Missing comma in argument list declaration") |
| 1657 | } |
| 1658 | if item, ok := it.PeekOne(); !ok || item.Typ != itemName { |
| 1659 | return item.Errorf("Expecting a variable name. Got: %v", item) |
| 1660 | } |
| 1661 | isDollar = true |
| 1662 | continue |
| 1663 | case itemName: |
| 1664 | // This is not a $variable, just add the value. |
| 1665 | if !isDollar { |
| 1666 | val, err := getValueArg(item.Val) |
| 1667 | if err != nil { |
| 1668 | return err |
| 1669 | } |
| 1670 | g.Args = append(g.Args, Arg{Value: val}) |
| 1671 | break |
| 1672 | } |
| 1673 | // This is a $variable that must be expanded later. |
| 1674 | val := "$" + item.Val |
| 1675 | g.Args = append(g.Args, Arg{Value: val, IsDQLVar: true}) |
| 1676 | case itemComma: |
| 1677 | if expectArg { |
| 1678 | return item.Errorf("Invalid comma in argument list") |
| 1679 | } |
| 1680 | expectArg = true |
| 1681 | continue |
| 1682 | default: |
| 1683 | return item.Errorf("Invalid arg list") |
| 1684 | } |
| 1685 | expectArg = false |
| 1686 | isDollar = false |
| 1687 | } |
| 1688 | return it.Errorf("Expecting ] to end list but got %v instead", it.Item().Val) |
| 1689 | } |
| 1690 | |
| 1691 | // getValueArg returns a space-trimmed and unquoted version of val. |
| 1692 | // Returns the cleaned string, otherwise empty string and an error. |
no test coverage detected