Class: SexpGrammar::Sequence

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/sexp_grammar/sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#termsObject (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

#inspectObject



23
24
25
# File 'lib/sexp_grammar/sequence.rb', line 23

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

#match?(sexp) ⇒ Boolean

Returns:

  • (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