Class: SexpGrammar::Alternative
- Inherits:
-
Object
- Object
- SexpGrammar::Alternative
- Includes:
- Element
- Defined in:
- lib/sexp_grammar/alternative.rb
Instance Attribute Summary collapse
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
- #eat(sexp) ⇒ Object
-
#initialize(terms) ⇒ Alternative
constructor
A new instance of Alternative.
- #inspect ⇒ Object
- #match?(sexp) ⇒ Boolean
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
#terms ⇒ Object (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 |
#inspect ⇒ Object
23 24 25 |
# File 'lib/sexp_grammar/alternative.rb', line 23 def inspect "(alt #{terms.inspect})" end |
#match?(sexp) ⇒ Boolean
11 12 13 |
# File 'lib/sexp_grammar/alternative.rb', line 11 def match?(sexp) terms.any?{|t| t.match?(sexp)} end |