(c context.Context)
| 39 | } |
| 40 | |
| 41 | func (p *parser) parsePath(c context.Context) error { |
| 42 | switch p.Scan() { |
| 43 | case '.': |
| 44 | return p.parseSelect(c) |
| 45 | case '[': |
| 46 | keys, seperator, err := p.parseBracket(c) |
| 47 | |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | switch seperator { |
| 53 | case ':': |
| 54 | if len(keys) > 3 { |
| 55 | return fmt.Errorf("range query has at least the parameter [min:max:step]") |
| 56 | } |
| 57 | keys = append(keys, []gval.Evaluable{ |
| 58 | p.Const(0), p.Const(float64(math.MaxInt32)), p.Const(1)}[len(keys):]...) |
| 59 | p.appendAmbiguousSelector(rangeSelector(keys[0], keys[1], keys[2])) |
| 60 | case '?': |
| 61 | if len(keys) != 1 { |
| 62 | return fmt.Errorf("filter needs exactly one key") |
| 63 | } |
| 64 | p.appendAmbiguousSelector(filterSelector(keys[0])) |
| 65 | default: |
| 66 | if len(keys) == 1 { |
| 67 | p.appendPlainSelector(directSelector(keys[0])) |
| 68 | } else { |
| 69 | p.appendAmbiguousSelector(multiSelector(keys)) |
| 70 | } |
| 71 | } |
| 72 | return p.parsePath(c) |
| 73 | case '(': |
| 74 | return p.parseScript(c) |
| 75 | default: |
| 76 | p.Camouflage("jsonpath", '.', '[', '(') |
| 77 | return nil |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func (p *parser) parseSelect(c context.Context) error { |
| 82 | scan := p.Scan() |
no test coverage detected