Sha256: 0e4eff65e46f34541bb601c14e3521ada0f059d08e9b1b07489ac7501ca20f85

Contents?: true

Size: 891 Bytes

Versions: 9

Compression:

Stored size: 891 Bytes

Contents

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

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

    def self.matcher(symbol)
      @matchers ||= [
        :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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dentaku-2.0.10 lib/dentaku/token_matchers.rb
dentaku-2.0.9 lib/dentaku/token_matchers.rb
dentaku-2.0.8 lib/dentaku/token_matchers.rb
dentaku-2.0.7 lib/dentaku/token_matchers.rb
dentaku-2.0.6 lib/dentaku/token_matchers.rb
dentaku-2.0.5 lib/dentaku/token_matchers.rb
dentaku-2.0.4 lib/dentaku/token_matchers.rb
dentaku-2.0.3 lib/dentaku/token_matchers.rb
dentaku-2.0.2 lib/dentaku/token_matchers.rb