Class: Query::Parser::Operator

Inherits:
Language
  • Object
show all
Defined in:
lib/query/parser/operator.rb

Constant Summary collapse

PREFIXES =
%w[- + !]
OPERATORS =
%w[^ $ >= => <= =< < > !]
MODIFIERS =
[":::", "::", ":", "===", "==", "=", ""]

Instance Method Summary collapse

Instance Method Details

#rootObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/query/parser/operator.rb', line 12

def root
  (
    PREFIXES
      .map { |prefix| str(prefix) }
      .reduce(&:|)
      .aka(:prefix)
      .maybe << (
      OPERATORS
        .flat_map do |operator|
          MODIFIERS
            .map do |modifier|
              str("#{operator}#{modifier}") |
                str("#{modifier}#{operator}") | str(operator)
            end
            .reduce(&:|)
            .then { operator }
        end
        .reduce(&:|) |
        MODIFIERS
          .compact_blank
          .map { |modifier| str(modifier) }
          .reduce(&:|)
    ).aka(:suffix)
  ).aka(:operator)
end