Class: SexpGrammar::Alternative

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Element

#===

Constructor Details

#initialize(terms) ⇒ Alternative

Returns a new instance of Alternative.



7
8
9
# File 'lib/sexp_grammar/alternative.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/alternative.rb', line 5

def terms
  @terms
end

Instance Method Details

#eat(sexp) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/sexp_grammar/alternative.rb', line 15

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

#inspectObject



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

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

#match?(sexp) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/sexp_grammar/alternative.rb', line 11

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