evalIdentifier evaluates IdentifierNode
(input []reflect.Value, node *IdentifierNode)
| 209 | |
| 210 | // evalIdentifier evaluates IdentifierNode |
| 211 | func (j *JSONPath) evalIdentifier(input []reflect.Value, node *IdentifierNode) ([]reflect.Value, error) { |
| 212 | results := []reflect.Value{} |
| 213 | switch node.Name { |
| 214 | case "range": |
| 215 | j.stack = append(j.stack, j.cur) |
| 216 | j.beginRange++ |
| 217 | results = input |
| 218 | case "end": |
| 219 | if j.endRange < j.inRange { // inside a loop, break the current block |
| 220 | j.endRange++ |
| 221 | break |
| 222 | } |
| 223 | // the loop is about to end, pop value and continue the following execution |
| 224 | if len(j.stack) > 0 { |
| 225 | j.cur, j.stack = j.stack[len(j.stack)-1], j.stack[:len(j.stack)-1] |
| 226 | } else { |
| 227 | return results, fmt.Errorf("not in range, nothing to end") |
| 228 | } |
| 229 | default: |
| 230 | return input, fmt.Errorf("unrecognized identifier %v", node.Name) |
| 231 | } |
| 232 | return results, nil |
| 233 | } |
| 234 | |
| 235 | // evalArray evaluates ArrayNode |
| 236 | func (j *JSONPath) evalArray(input []reflect.Value, node *ArrayNode) ([]reflect.Value, error) { |