Module: Dentaku::TokenMatchers

Defined in:
lib/dentaku/token_matchers.rb

Class Method Summary collapse

Class Method Details

.function_token_matchers(function_name, *symbols) ⇒ Object



7
8
9
10
11
# File 'lib/dentaku/token_matchers.rb', line 7

def self.function_token_matchers(function_name, *symbols)
  token_matchers(:open, *symbols, :close).unshift(
    TokenMatcher.send(function_name)
  )
end

.matcher(symbol) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dentaku/token_matchers.rb', line 13

def self.matcher(symbol)
  @matchers ||= [
    :datetime, :numeric, :string, :addsub, :subtract, :muldiv, :pow, :mod,
    :comparator, :comp_gt, :comp_lt, :open, :close, :comma,
    :non_close_plus, :non_group, :non_group_star, :arguments,
    :logical, :combinator, :if, :round, :roundup, :rounddown, :not,
    :anchored_minus, :math_neg_pow, :math_neg_mul
  ].each_with_object({}) do |name, matchers|
    matchers[name] = TokenMatcher.send(name)
  end

  @matchers.fetch(symbol) do
    raise "Unknown token symbol #{ symbol }"
  end
end

.token_matchers(*symbols) ⇒ Object



3
4
5
# File 'lib/dentaku/token_matchers.rb', line 3

def self.token_matchers(*symbols)
  symbols.map { |s| matcher(s) }
end