mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-08 16:54:31 +00:00
Move supported prefixes to a constant
This commit is contained in:
parent
e5caa462c1
commit
64c6adcc58
|
@ -1,6 +1,17 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SearchQueryParser < Parslet::Parser
|
class SearchQueryParser < Parslet::Parser
|
||||||
|
SUPPORTED_PREFIXES = %w(
|
||||||
|
has
|
||||||
|
is
|
||||||
|
language
|
||||||
|
from
|
||||||
|
before
|
||||||
|
after
|
||||||
|
during
|
||||||
|
in
|
||||||
|
).freeze
|
||||||
|
|
||||||
# Efficiently matches disjoint strings
|
# Efficiently matches disjoint strings
|
||||||
class StrList < Parslet::Atoms::Base
|
class StrList < Parslet::Atoms::Base
|
||||||
attr_reader :strings
|
attr_reader :strings
|
||||||
|
@ -41,7 +52,7 @@ class SearchQueryParser < Parslet::Parser
|
||||||
rule(:colon) { str(':') }
|
rule(:colon) { str(':') }
|
||||||
rule(:space) { match('\s').repeat(1) }
|
rule(:space) { match('\s').repeat(1) }
|
||||||
rule(:operator) { (str('+') | str('-')).as(:operator) }
|
rule(:operator) { (str('+') | str('-')).as(:operator) }
|
||||||
rule(:prefix_operator) { StrList.new(%w(has is language from before after during in)) }
|
rule(:prefix_operator) { StrList.new(SUPPORTED_PREFIXES) }
|
||||||
rule(:prefix) { prefix_operator.as(:prefix_operator) >> colon }
|
rule(:prefix) { prefix_operator.as(:prefix_operator) >> colon }
|
||||||
rule(:phrase) do
|
rule(:phrase) do
|
||||||
(str('"') >> match('[^"]').repeat.as(:phrase) >> str('"')) |
|
(str('"') >> match('[^"]').repeat.as(:phrase) >> str('"')) |
|
||||||
|
|
Loading…
Reference in a new issue