Class: Sexpr::Matcher::Sequence
- Inherits:
-
Object
- Object
- Sexpr::Matcher::Sequence
- Includes:
- Sexpr::Matcher
- Defined in:
- lib/sexpr/matcher/sequence.rb
Instance Attribute Summary collapse
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
- #eat(sexp) ⇒ Object
-
#initialize(terms) ⇒ Sequence
constructor
A new instance of Sequence.
- #inspect ⇒ Object
- #match?(sexp) ⇒ Boolean
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
#terms ⇒ Object (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 |
#inspect ⇒ Object
24 25 26 |
# File 'lib/sexpr/matcher/sequence.rb', line 24 def inspect "(seq #{terms.inspect})" end |
#match?(sexp) ⇒ 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 |