Class: Sexpr::Matcher::Sequence

Inherits:
Object
  • Object
show all
Includes:
Sexpr::Matcher
Defined in:
lib/sexpr/matcher/sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sexpr::Matcher

#===

Constructor Details

#initialize(terms) ⇒ Sequence

Returns a new instance of Sequence.



8
9
10
# File 'lib/sexpr/matcher/sequence.rb', line 8

def initialize(terms)
  @terms = terms
end

Instance Attribute Details

#termsObject (readonly)

Returns the value of attribute terms.



6
7
8
# File 'lib/sexpr/matcher/sequence.rb', line 6

def terms
  @terms
end

Instance Method Details

#eat(sexp) ⇒ Object



18
19
20
21
22
# File 'lib/sexpr/matcher/sequence.rb', line 18

def eat(sexp)
  @terms.inject sexp do |rest,rule|
    rest && rule.eat(rest)
  end
end

#inspectObject



24
25
26
# File 'lib/sexpr/matcher/sequence.rb', line 24

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

#match?(sexp) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/sexpr/matcher/sequence.rb', line 12

def match?(sexp)
  return nil unless sexp.is_a?(Array)
  eat = eat(sexp)
  eat && eat.empty?
end