Sha256: 78ec9a40b0fddf659ef08f9d14e694f1e26116d90fbf17b8aac1f22cad1e1f42

Contents?: true

Size: 662 Bytes

Versions: 4

Compression:

Stored size: 662 Bytes

Contents

module Sexpr
  module Matcher
    class Terminal
      include Matcher

      attr_reader :value

      def initialize(value)
        @value = value
      end

      def inspect
        "(terminal #{value.inspect})"
      end

      def match?(sexp)
        terminal_match?(sexp)
      end

      def eat(sexp)
        match?(sexp.first) ? sexp[1..-1] : nil
      end

      private

      def terminal_match?(term)
        case @value
        when Regexp, Module
          @value === term rescue false
        when TrueClass, FalseClass, NilClass
          @value == term
        end
      end

    end # class Terminal
  end # module Matcher
end # module Sexpr

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sexpr-1.1.0 lib/sexpr/matcher/terminal.rb
sexpr-1.0.0 lib/sexpr/matcher/terminal.rb
sexpr-0.6.0 lib/sexpr/matcher/terminal.rb
sexpr-0.5.1 lib/sexpr/matcher/terminal.rb