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

Function godeep

dql/parser.go:3104–3494  ·  view source on GitHub ↗

godeep constructs the subgraph from the lexed items and a GraphQuery node.

(it *lex.ItemIterator, gq *GraphQuery)

Source from the content-addressed store, hash-verified

3102
3103// godeep constructs the subgraph from the lexed items and a GraphQuery node.
3104func godeep(it *lex.ItemIterator, gq *GraphQuery) error {
3105 if gq == nil {
3106 return it.Errorf("Bad nesting of predicates or functions")
3107 }
3108 var count countType
3109 var alias, varName string
3110 curp := gq // Used to track current node, for nesting.
3111 for it.Next() {
3112 item := it.Item()
3113 switch item.Typ {
3114 case lex.ItemEOF:
3115 return nil
3116 case itemRightCurl:
3117 return nil
3118 case itemPeriod:
3119 // looking for ...
3120 dots := 1
3121 for range 2 {
3122 if it.Next() && it.Item().Typ == itemPeriod {
3123 dots++
3124 }
3125 }
3126 if dots == 3 {
3127 it.Next()
3128 item = it.Item()
3129 if item.Typ == itemName {
3130 // item.Val is expected to start with "..." and to have len >3.
3131 gq.Children = append(gq.Children, &GraphQuery{fragment: item.Val})
3132 // Unlike itemName, there is no nesting, so do not change "curp".
3133 }
3134 } else {
3135 return item.Errorf("Expected 3 periods (\"...\"), got %d.", dots)
3136 }
3137 case itemName:
3138 peekIt, err := it.Peek(1)
3139 if err != nil {
3140 return item.Errorf("Invalid query")
3141 }
3142 if peekIt[0].Typ == itemName && strings.ToLower(peekIt[0].Val) == "as" {
3143 varName = item.Val
3144 it.Next() // "As" was checked before.
3145 continue
3146 }
3147
3148 val := collectName(it, item.Val)
3149 valLower := strings.ToLower(val)
3150
3151 peekIt, err = it.Peek(1)
3152 if err != nil {
3153 return err
3154 }
3155 if peekIt[0].Typ == itemColon {
3156 if len(alias) > 0 {
3157 return item.Errorf("Invalid colon after alias declaration")
3158 }
3159 alias = val
3160 it.Next() // Consume the itemcolon
3161 continue

Callers 2

getQueryFunction · 0.85
getFragmentFunction · 0.85

Calls 15

collectNameFunction · 0.85
isAggregatorFunction · 0.85
validateEmptyBlockItemFunction · 0.85
parseLanguageListFunction · 0.85
parseVarListFunction · 0.85
isMathBlockFunction · 0.85
parseMathFuncFunction · 0.85
isExpandFuncFunction · 0.85
parseTypeListFunction · 0.85
parseArgumentsFunction · 0.85
validKeyFunction · 0.85
attrAndLangFunction · 0.85

Tested by

no test coverage detected