Class: Metal::Generator::Rule
- Inherits:
-
Object
- Object
- Metal::Generator::Rule
- Defined in:
- lib/metal/generator.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #generate(ctx, source) ⇒ Object
-
#initialize(name, or_set) ⇒ Rule
constructor
A new instance of Rule.
- #preprocess(ctx) ⇒ Object
- #with_lambda(source, &block) ⇒ Object
Constructor Details
#initialize(name, or_set) ⇒ Rule
Returns a new instance of Rule.
181 182 183 184 185 186 |
# File 'lib/metal/generator.rb', line 181 def initialize(name, or_set) @name = name @or_set = or_set @serial = 0 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
196 197 198 |
# File 'lib/metal/generator.rb', line 196 def name @name end |
Instance Method Details
#generate(ctx, source) ⇒ Object
191 192 193 194 195 |
# File 'lib/metal/generator.rb', line 191 def generate(ctx, source) ctx.rule = self source << "Env env;\n" @or_set.generate(ctx, source) end |
#preprocess(ctx) ⇒ Object
187 188 189 190 |
# File 'lib/metal/generator.rb', line 187 def preprocess(ctx) ctx.rule = self @or_set.preprocess(ctx) end |
#with_lambda(source, &block) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/metal/generator.rb', line 198 def with_lambda(source, &block) obj = "rule_#{@name}_#{@serial+=1}" source << "struct #{obj}_t : Lambda {\n" source << "#{obj}_t(Context* _ctx, Env& _env) : Lambda(_ctx, _env) {}\n" source << "VALUE call() {\n" source << "return ({\n" yield source << "});\n" source << "}\n" source << "} #{obj}(ctx, env);\n" obj end |