Sha256: 2c0dcd820ba54fc20e1c9f7dcf5591238d04146d5c4ebb5f6ef70276334ac7cf

Contents?: true

Size: 564 Bytes

Versions: 1

Compression:

Stored size: 564 Bytes

Contents

module Sexpr
  class Terminal
    include Element

    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
        @value === term rescue false
      when TrueClass, FalseClass, NilClass
        @value == term
      end
    end

  end # class Terminal
end # module Sexpr

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sexpr-0.2.0 lib/sexpr/terminal.rb