Class: SexpGrammar::Reference
- Inherits:
-
Object
- Object
- SexpGrammar::Reference
- Includes:
- Element
- Defined in:
- lib/sexp_grammar/reference.rb
Instance Attribute Summary collapse
-
#grammar ⇒ Object
readonly
Returns the value of attribute grammar.
-
#rule_name ⇒ Object
readonly
Returns the value of attribute rule_name.
Instance Method Summary collapse
- #eat(sexp) ⇒ Object
-
#initialize(rule_name, grammar) ⇒ Reference
constructor
A new instance of Reference.
- #inspect ⇒ Object
- #match?(sexp) ⇒ Boolean
- #rule ⇒ Object
Methods included from Element
Constructor Details
#initialize(rule_name, grammar) ⇒ Reference
Returns a new instance of Reference.
8 9 10 11 |
# File 'lib/sexp_grammar/reference.rb', line 8 def initialize(rule_name, grammar) @rule_name = rule_name @grammar = grammar end |
Instance Attribute Details
#grammar ⇒ Object (readonly)
Returns the value of attribute grammar.
6 7 8 |
# File 'lib/sexp_grammar/reference.rb', line 6 def grammar @grammar end |
#rule_name ⇒ Object (readonly)
Returns the value of attribute rule_name.
5 6 7 |
# File 'lib/sexp_grammar/reference.rb', line 5 def rule_name @rule_name end |
Instance Method Details
#eat(sexp) ⇒ Object
21 22 23 |
# File 'lib/sexp_grammar/reference.rb', line 21 def eat(sexp) rule && rule.eat(sexp) end |
#inspect ⇒ Object
25 26 27 |
# File 'lib/sexp_grammar/reference.rb', line 25 def inspect "(ref #{rule_name}, #{rule.inspect})" end |
#match?(sexp) ⇒ Boolean
17 18 19 |
# File 'lib/sexp_grammar/reference.rb', line 17 def match?(sexp) rule && rule.match?(sexp) end |
#rule ⇒ Object
13 14 15 |
# File 'lib/sexp_grammar/reference.rb', line 13 def rule @rule ||= @grammar[@rule_name] end |