godeep constructs the subgraph from the lexed items and a GraphQuery node.
(it *lex.ItemIterator, gq *GraphQuery)
| 3102 | |
| 3103 | // godeep constructs the subgraph from the lexed items and a GraphQuery node. |
| 3104 | func 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 |
no test coverage detected