Class: SexpGrammar::Rule
- Inherits:
-
Object
- Object
- SexpGrammar::Rule
- Includes:
- Element
- Defined in:
- lib/sexp_grammar/rule.rb
Instance Attribute Summary collapse
-
#defn ⇒ Object
readonly
Returns the value of attribute defn.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #eat(sexp) ⇒ Object
-
#initialize(name, defn) ⇒ Rule
constructor
A new instance of Rule.
- #inspect ⇒ Object
- #match?(sexp) ⇒ Boolean
Methods included from Element
Constructor Details
#initialize(name, defn) ⇒ Rule
Returns a new instance of Rule.
8 9 10 11 |
# File 'lib/sexp_grammar/rule.rb', line 8 def initialize(name, defn) @name = name @defn = defn end |
Instance Attribute Details
#defn ⇒ Object (readonly)
Returns the value of attribute defn.
6 7 8 |
# File 'lib/sexp_grammar/rule.rb', line 6 def defn @defn end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/sexp_grammar/rule.rb', line 5 def name @name end |
Instance Method Details
#eat(sexp) ⇒ Object
19 20 21 22 |
# File 'lib/sexp_grammar/rule.rb', line 19 def eat(sexp) return nil unless match?(sexp.first) sexp[1..-1] end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/sexp_grammar/rule.rb', line 24 def inspect "(rule #{name}, #{defn.inspect})" end |
#match?(sexp) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/sexp_grammar/rule.rb', line 13 def match?(sexp) return nil unless sexp.is_a?(Array) return false unless sexp.first && (sexp.first == name) defn.match?(sexp[1..-1]) end |