Module: Temill::RaccHack
- Included in:
- Ruby23Parser
- Defined in:
- lib/temill/parser.rb
Class Method Summary collapse
-
.included(klass) ⇒ Object
override all actions and make them call before_reduce/after_reduce before/after each action is executed.
Instance Method Summary collapse
-
#after_reduce(val, _values, result) ⇒ Object
should return new result.
-
#before_reduce(val, _values, result) ⇒ Object
should return new val.
Class Method Details
.included(klass) ⇒ Object
override all actions and make them call before_reduce/after_reduce before/after each action is executed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/temill/parser.rb', line 58 def self.included(klass) #racc_action_table, #racc_action_check, #racc_action_default, #racc_action_pointer, #racc_goto_table, #racc_goto_check, #racc_goto_default, #racc_goto_pointer, #racc_nt_base, #racc_reduce_table, #racc_token_table, #racc_shift_n, #racc_reduce_n, #racc_use_result_var = klass::Racc_arg racc_reduce_table = klass::Racc_arg[9] racc_reduce_table.each_slice(3).map{| _,_,method_name | method_name }.uniq.each{| method_name | begin method = klass.instance_method(method_name) rescue NameError next end method.tap{| original_umethod | klass.__send__(:define_method, method_name){| val,_values,result | new_val = before_reduce(val, _values, result) new_result = original_umethod.bind(self).call(new_val, _values, result) after_reduce(val, _values, new_result) } } } end |
Instance Method Details
#after_reduce(val, _values, result) ⇒ Object
should return new result
Note that val is equal to the object passed to before_reduce, not new val returned by before_reduce
103 104 105 |
# File 'lib/temill/parser.rb', line 103 def after_reduce(val, _values, result) result end |
#before_reduce(val, _values, result) ⇒ Object
should return new val
95 96 97 |
# File 'lib/temill/parser.rb', line 95 def before_reduce(val, _values, result) val end |