MCPcopy
hub / github.com/dgraph-io/dgraph / parseFunction

Function parseFunction

dql/parser.go:1735–2111  ·  view source on GitHub ↗
(it *lex.ItemIterator, gq *GraphQuery)

Source from the content-addressed store, hash-verified

1733}
1734
1735func parseFunction(it *lex.ItemIterator, gq *GraphQuery) (*Function, error) {
1736 function := &Function{}
1737 var expectArg, seenFuncArg, expectLang, isDollar bool
1738L:
1739 for it.Next() {
1740 item := it.Item()
1741 if item.Typ != itemName {
1742 return nil, item.Errorf("Expected a function but got %q", item.Val)
1743
1744 }
1745
1746 name := collectName(it, item.Val)
1747 function.Name = strings.ToLower(name)
1748 var similarToOptSeen map[string]struct{}
1749 if function.Name == similarToFn {
1750 similarToOptSeen = make(map[string]struct{})
1751 }
1752 if _, ok := tryParseItemType(it, itemLeftRound); !ok {
1753 return nil, it.Errorf("Expected ( after func name [%s]", function.Name)
1754 }
1755
1756 attrItemsAgo := -1
1757 expectArg = true
1758 for it.Next() {
1759 itemInFunc := it.Item()
1760 if attrItemsAgo >= 0 {
1761 attrItemsAgo++
1762 }
1763 var val string
1764 switch itemInFunc.Typ {
1765 case itemRightRound:
1766 break L
1767 case itemComma:
1768 if expectArg {
1769 return nil, itemInFunc.Errorf("Invalid use of comma.")
1770 }
1771 if isDollar {
1772 return nil, itemInFunc.Errorf("Invalid use of comma after dollar.")
1773 }
1774 expectArg = true
1775 continue
1776 case itemLeftRound:
1777 // Function inside a function.
1778 if seenFuncArg {
1779 return nil, itemInFunc.Errorf("Multiple functions as arguments not allowed")
1780 }
1781 it.Prev()
1782 it.Prev()
1783 nestedFunc, err := parseFunction(it, gq)
1784 if err != nil {
1785 return nil, err
1786 }
1787 seenFuncArg = true
1788 switch nestedFunc.Name {
1789 case valueFunc:
1790 if len(nestedFunc.NeedsVar) > 1 {
1791 return nil, itemInFunc.Errorf("Multiple variables not allowed in a function")
1792 }

Callers 3

parseFilterFunction · 0.70
getRootFunction · 0.70
godeepFunction · 0.70

Calls 15

collectNameFunction · 0.85
tryParseItemTypeFunction · 0.85
IsInequalityFnFunction · 0.85
parseRegexArgsFunction · 0.85
isGeoFuncFunction · 0.85
parseGeoArgsFunction · 0.85
parseFuncArgsFunction · 0.85
trySkipItemTypFunction · 0.85
parseVarNameFunction · 0.85
unquoteIfQuotedFunction · 0.85
ItemMethod · 0.80
PrevMethod · 0.80

Tested by

no test coverage detected