Class: Delorean::Formula

Inherits:
SNode
  • Object
show all
Defined in:
lib/delorean/nodes.rb

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/delorean/nodes.rb', line 125

def check(context, *)
  if i.text_value.include?('?')
    raise Delorean::ParseError.new(
      '? in formula names not supported',
      context.module_name,
      context.line_no
    )
  end

  context.parse_define_attr(i.text_value, e.check(context))
end

#rewrite(context) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/delorean/nodes.rb', line 137

def rewrite(context)
  dname = [context.module_name, context.last_node, i.text_value].join('.')
  debug = Debug.debug_set.member?(dname)

  # an attr is defined as a class function on the node class.
  "class #{context.last_node}; " \
    "def self.#{i.text_value}#{POST}(_e); " +
    (debug ? '_debug =' : '') +
    "_e[self.name+'.#{i.text_value}'] ||= #{e.rewrite(context)};" +
    (debug ? 'Delorean::Debug.log(_debug); _debug;' : '') +
    'end; end;'
end