From b285c57dc62caac2c1f09e74eeece406b0e7cc00 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 20 Aug 2020 12:00:34 +0200 Subject: query: expand the tokenizer/parser to parse arbitrary search terms --- query/parser.go | 73 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 33 deletions(-) (limited to 'query/parser.go') diff --git a/query/parser.go b/query/parser.go index a379f750..762a47e5 100644 --- a/query/parser.go +++ b/query/parser.go @@ -24,42 +24,49 @@ func Parse(query string) (*Query, error) { sortingDone := false for _, t := range tokens { - switch t.qualifier { - case "status", "state": - status, err := bug.StatusFromString(t.value) - if err != nil { - return nil, err - } - q.Status = append(q.Status, status) - case "author": - q.Author = append(q.Author, t.value) - case "actor": - q.Actor = append(q.Actor, t.value) - case "participant": - q.Participant = append(q.Participant, t.value) - case "label": - q.Label = append(q.Label, t.value) - case "title": - q.Title = append(q.Title, t.value) - case "no": - switch t.value { + switch t.kind { + case tokenKindSearch: + q.Search = append(q.Search, t.term) + break + + case tokenKindKV: + switch t.qualifier { + case "status", "state": + status, err := bug.StatusFromString(t.value) + if err != nil { + return nil, err + } + q.Status = append(q.Status, status) + case "author": + q.Author = append(q.Author, t.value) + case "actor": + q.Actor = append(q.Actor, t.value) + case "participant": + q.Participant = append(q.Participant, t.value) case "label": - q.NoLabel = true + q.Label = append(q.Label, t.value) + case "title": + q.Title = append(q.Title, t.value) + case "no": + switch t.value { + case "label": + q.NoLabel = true + default: + return nil, fmt.Errorf("unknown \"no\" filter \"%s\"", t.value) + } + case "sort": + if sortingDone { + return nil, fmt.Errorf("multiple sorting") + } + err = parseSorting(q, t.value) + if err != nil { + return nil, err + } + sortingDone = true + default: - return nil, fmt.Errorf("unknown \"no\" filter \"%s\"", t.value) + return nil, fmt.Errorf("unknown qualifier \"%s\"", t.qualifier) } - case "sort": - if sortingDone { - return nil, fmt.Errorf("multiple sorting") - } - err = parseSorting(q, t.value) - if err != nil { - return nil, err - } - sortingDone = true - - default: - return nil, fmt.Errorf("unknown qualifier \"%s\"", t.qualifier) } } return q, nil -- cgit