dsl-fixes/fix.rb
# Generates node class and fix_xyz method
Generates node class and fix_xyz method
Generates node class and fix_xyz method
def gen
    expected_symbol = gen_expected_symbol
    fix_method_name = gen_fix_method_name
    unless @node_class
      aliases = @aliases
      class_target = @class_target
      expected_len = @expected_len
      named = @named
      node_class_name = gen_node_class_name
      if const_defined? node_class_name
        cls = const_get node_class_name
      else
        cls = Object.const_set node_class_name, Class.new(Node)
      end
      cls.class_eval do
        define_method :initialize do
          |ruby_node, children|
          super()
          @ruby_node = ruby_node
          expect_len(expected_len, children) if expected_len
          if respond_to? :transform_children
            children = transform_children children
          end
          assign_children children
        end
        if named
          define_method :to_s do
            "#{node_class_name}(#{name})"
          end
        else
          define_method :to_s do
            node_class_name
          end
        end
        aliases.each do
          |a|
          self.send :define_method, a.new_name do
            self.send a.old_name
          end
          self.send :define_method, (a.new_name.to_s + '=') do
            |value|
            self.send a.old_name.to_s + '=', value
          end
        end
        if class_target
          define_method :cls do
            self
          end
        end
        if named
          define_method :name do
            child.load_name
          end
          define_method :load_name do
            child.load_name
          end
        end
      end
    end
    node_class = gen_node_class
    UnprocessedNode.send :define_method, fix_method_name do
      return self unless symbol? expected_symbol.to_s
      return node_class.new @ruby_node, children
    end
  end
def gen expected_symbol = gen_expected_symbol fix_method_name = gen_fix_method_name unless @node_class aliases = @aliases class_target = @class_target expected_len = @expected_len named = @named node_class_name = gen_node_class_name if const_defined? node_class_name cls = const_get node_class_name else cls = Object . const_set node_class_name , Class . new ( Node ) end cls . class_eval do define_method :initialize do | ruby_node , children | super ( ) @ruby_node = ruby_node expect_len ( expected_len , children ) if expected_len if respond_to? :transform_children children = transform_children children end assign_children children end if named define_method :to_s do "#{node_class_name}(#{name})" end else define_method :to_s do node_class_name end end aliases . each do | a | self . send :define_method , a . new_name do self . send a . old_name end self . send :define_method , ( a . new_name . to_s + '=' ) do | value | self . send a . old_name . to_s + '=' , value end end if class_target define_method :cls do self end end if named define_method :name do child . load_name end define_method :load_name do child . load_name end end end end node_class = gen_node_class UnprocessedNode . send :define_method , fix_method_name do return self unless symbol? expected_symbol . to_s return node_class . new @ruby_node , children end end
Generates node class and fix_xyz method
Generates node class and fix_xyz method
# Skip node class generation if defined explicitly # Add to existing node class # Completely new node class # Constructor # For named methods add name to to_s() # Getters and setters for aliases # Generate the UnprocessedNode#fix_xyz()