Class: Pegarus::Grammar
Instance Attribute Summary collapse
-
#start ⇒ Object
Returns the value of attribute start.
Instance Method Summary collapse
- #get_variable(name) ⇒ Object
-
#initialize(variable = nil) ⇒ Grammar
constructor
A new instance of Grammar.
- #method_missing(sym, *args) ⇒ Object
- #set_variable(name, pattern) ⇒ Object
Methods inherited from Pattern
#*, #+, #+@, #-, #-@, #/, engine, #graph, #match, select_engine, #visit
Constructor Details
#initialize(variable = nil) ⇒ Grammar
Returns a new instance of Grammar.
21 22 23 24 25 26 |
# File 'lib/pegarus/ast/grammar.rb', line 21 def initialize(variable=nil) if variable @start = variable.name set_variable variable.name, variable.pattern end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/pegarus/ast/grammar.rb', line 46 def method_missing(sym, *args) name = sym.to_s if name[-1] == ?= and args.size == 1 set_variable name[0..-2], args.first else get_variable name end end |
Instance Attribute Details
#start ⇒ Object
Returns the value of attribute start.
19 20 21 |
# File 'lib/pegarus/ast/grammar.rb', line 19 def start @start end |
Instance Method Details
#get_variable(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pegarus/ast/grammar.rb', line 34 def get_variable(name) if .method_defined? name variable = send name else vname = name.to_sym variable = Variable.new vname .thunk_method vname, variable end variable end |
#set_variable(name, pattern) ⇒ Object
28 29 30 31 32 |
# File 'lib/pegarus/ast/grammar.rb', line 28 def set_variable(name, pattern) variable = get_variable name variable.pattern = pattern variable end |