Class: Pione::Lang::RuleBindingDeclaration

Inherits:
Declaration
  • Object
show all
Defined in:
lib/pione/lang/declaration.rb

Overview

RuleBindingDeclaration is a declaration for rule binding stentences.

Instance Method Summary collapse

Methods inherited from Declaration

#eval!, inherited

Methods included from Util::Positionable

#line_and_column, #pos, #set_source_position

Instance Method Details

#eval(env) ⇒ Object

Update rule table with the rule name and reference definition. e.g. "rule A := B"



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/pione/lang/declaration.rb', line 177

def eval(env)
  # rule name
  refs = get_reference(env, expr1, RuleExprSequence)

  refs.pieces.each do |ref|
    referents = expr2.eval!(env)
    referents.pieces.each do |referent|
      # merge param sets
      definition = env.rule_get_value(referent)
      param_sets = definition.param_sets.merge(referent.param_sets)
      _referent = referent.set(param_sets: param_sets)

      # update rule table
      env.rule_set(ref, _referent)
    end
  end
end