Module: Spectre::DynVarMixin
- Included in:
- Grammar
- Defined in:
- lib/spectre/base/grammar.rb
Overview
Provides the functionality of dynamically defining rules inside Grammars. Must be mixed into a Parser.
Instance Method Summary collapse
-
#close(node) ⇒ Object
Closes over the specified
node
with a newly constructed Closure. -
#rule(hash) ⇒ Object
Stores the Parsers referenced by
symbol
=>parser
from thehash
so they can be used later on. -
#start_with(parser) ⇒ Object
Sets the
parser
with which the Grammar should start parsing.
Instance Method Details
#close(node) ⇒ Object
Closes over the specified node
with a newly constructed Closure.
62 63 64 65 66 |
# File 'lib/spectre/base/grammar.rb', line 62 def close node node = node.to_p node.closure = Closure.new node end |
#rule(hash) ⇒ Object
Stores the Parsers referenced by symbol
=> parser
from the hash
so they can be used later on.
72 73 74 75 76 |
# File 'lib/spectre/base/grammar.rb', line 72 def rule hash hash.each do |getter,node| @node.symbols[getter] = node.to_p end end |
#start_with(parser) ⇒ Object
Sets the parser
with which the Grammar should start parsing. Does auto-conversion on parser
.
82 83 84 |
# File 'lib/spectre/base/grammar.rb', line 82 def start_with parser @start_rule = parser.to_p end |