Class: SexpGrammar::Sequence
- Inherits:
-
Object
- Object
- SexpGrammar::Sequence
- Includes:
- Element
- Defined in:
- lib/sexp_grammar/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 Element
Constructor Details
#initialize(terms) ⇒ Sequence
Returns a new instance of Sequence.
7 8 9 |
# File 'lib/sexp_grammar/sequence.rb', line 7 def initialize(terms) @terms = terms end |
Instance Attribute Details
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
5 6 7 |
# File 'lib/sexp_grammar/sequence.rb', line 5 def terms @terms end |
Instance Method Details
#eat(sexp) ⇒ Object
17 18 19 20 21 |
# File 'lib/sexp_grammar/sequence.rb', line 17 def eat(sexp) @terms.inject sexp do |rest,rule| rest && rule.eat(rest) end end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/sexp_grammar/sequence.rb', line 23 def inspect "(seq #{terms.inspect})" end |
#match?(sexp) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/sexp_grammar/sequence.rb', line 11 def match?(sexp) return nil unless sexp.is_a?(Array) eat = eat(sexp) eat && eat.empty? end |