Skip to content

Commit

Permalink
Add a bit more to the term rule in the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgoldstein committed Sep 27, 2023
1 parent ca08a95 commit dd3880c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/lib/search_query_parser.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class SearchQueryParser < Parslet::Parser
rule(:term) { match('[^\s":]').repeat(1).as(:term) }
rule(:term) { match('[^\s":+-]').repeat(1).as(:term) }
rule(:quote) { str('"') }
rule(:colon) { str(':') }
rule(:space) { match('\s').repeat(1) }
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/search_query_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
expect(parser.clause).to parse('foo:bar')
end

it 'consumes "+:foo:"' do
expect(parser.clause).to parse('+:foo:')
end

it 'consumes "-foo:bar"' do
expect(parser.clause).to parse('-foo:bar')
end
Expand Down Expand Up @@ -94,5 +98,13 @@
it 'consumes "foo:bar bar: hello"' do
expect(parser.query).to parse('foo:bar bar: hello')
end

it 'consumes "foo +:bar:"' do
expect(parser.query).to parse('foo +:bar:')
end

it 'consumes "foo+:bar:"' do
expect(parser.query).to parse('foo+:bar:')
end
end
end

0 comments on commit dd3880c

Please sign in to comment.