| 325 | } |
| 326 | |
| 327 | func parseExpression(ctx context.Context, exp string) (*SearchQuery, error) { |
| 328 | base := &Constraint{ |
| 329 | Permanode: &PermanodeConstraint{ |
| 330 | SkipHidden: true, |
| 331 | }, |
| 332 | } |
| 333 | sq := &SearchQuery{ |
| 334 | Constraint: base, |
| 335 | } |
| 336 | |
| 337 | exp = strings.TrimSpace(exp) |
| 338 | if exp == "" { |
| 339 | return sq, nil |
| 340 | } |
| 341 | p := newParser(ctx, exp) |
| 342 | |
| 343 | c, err := p.parseExp() |
| 344 | if err != nil { |
| 345 | return nil, err |
| 346 | } |
| 347 | lastToken := p.next() |
| 348 | if lastToken.typ != tokenEOF { |
| 349 | switch lastToken.typ { |
| 350 | case tokenClose: |
| 351 | return nil, newParseExpError(noMatchingOpening, *lastToken) |
| 352 | } |
| 353 | return nil, newParseExpError(trailingTokens, *lastToken) |
| 354 | } |
| 355 | if c != nil { |
| 356 | sq.Constraint = andConst(base, c) |
| 357 | } |
| 358 | return sq, nil |
| 359 | } |