Sha256: 0528e9ae7d982afb2bab850434166da5314d0ef9c308e20e9fdd73906e2bc8c3

Contents?: true

Size: 429 Bytes

Versions: 1

Compression:

Stored size: 429 Bytes

Contents

module Sexpr
  class Alternative
    include Element

    attr_reader :terms

    def initialize(terms)
      @terms = terms
    end

    def match?(sexp)
      terms.any?{|t| t.match?(sexp)}
    end

    def eat(sexp)
      @terms.each do |alt|
        res = alt.eat(sexp)
        return res if res
      end
      nil
    end

    def inspect
      "(alt #{terms.inspect})"
    end

  end # class Alternative
end # module Sexpr

Version data entries

1 entries across 1 versions & 1 rubygems

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