parse parses a statement from the given scanned tokens.
( query string, tokens []jsonpathSymType, )
| 63 | |
| 64 | // parse parses a statement from the given scanned tokens. |
| 65 | func (p *Parser) parse( |
| 66 | query string, tokens []jsonpathSymType, |
| 67 | ) (statements.JsonpathStatement, error) { |
| 68 | p.lexer.init(query, tokens, &p.parserImpl) |
| 69 | defer p.lexer.cleanup() |
| 70 | if p.parserImpl.Parse(&p.lexer) != 0 { |
| 71 | if p.lexer.lastError == nil { |
| 72 | // This should never happen -- there should be an error object |
| 73 | // every time Parse() returns nonzero. We're just playing safe |
| 74 | // here. |
| 75 | p.lexer.Error("syntax error") |
| 76 | } |
| 77 | err := p.lexer.lastError |
| 78 | return statements.JsonpathStatement{}, err |
| 79 | } |
| 80 | return statements.JsonpathStatement{ |
| 81 | AST: p.lexer.expr, |
| 82 | SQL: query, |
| 83 | }, nil |
| 84 | } |
| 85 | |
| 86 | func (p *Parser) Parse(jsonpath string) (statements.JsonpathStatement, error) { |
| 87 | p.scanner.Init(jsonpath) |