module Delorean class SNode < Treetop::Runtime::SyntaxNode end class Line < SNode def check(context, *a) f.check(context, *a) end def rewrite(context) f.rewrite(context) end end class Parameter < SNode def check(context, *) context.parse_define_param(i.text_value, []) end def rewrite(context) # Adds a parameter to the current node. Parameters are # implemented as functions (just like attrs). The environment # arg (_e) is a Hash. To find a param (aname) in node (cname), # we first check to see if cname.aname has already been computed # in _e. If not, to compute it we check for the value in _e # (i.e. check for aname). Otherwise, we use the default value # if any. aname, cname = i.text_value, context.last_node exc = "raise UndefinedParamError, 'undefined parameter #{aname}'" < " + e1.rewrite(context) + (defined?(args_rest.al) && !args_rest.al.text_value.empty? ? ", " + args_rest.al.rewrite(context) : "") end end class ScriptCall < SNode def check(context, *) i.check(context) unless i.text_value.empty? al.check(context) if defined?(al) [] end def rewrite(context) node_name = i.text_value.empty? ? "nil" : i.rewrite(context) do_rewrite(context, node_name) end def do_rewrite(context, node_name, mname="nil") args, kw = al.rewrite(context) args_str = '[' + args.reverse.join(',') + ']' kw_str = '{' + kw.map {|k, v| "'#{k}' => #{v}" }.join(',') + '}' "_script_call(#{node_name}, #{mname}, _e, #{args_str}, #{kw_str})" end end class ScriptCallNode < ScriptCall def check(context, *) # FIXME: for both this and when node_name is nil, should check # to see if attributes exist on the node before allowing the # call. Also, can check parameters. mname = mod.m.text_value if defined?(mod.m) context.parse_check_defined_mod_node(c.text_value, mname) al.check(context) if defined?(al) [] end def rewrite(context) node_name = c.text_value.inspect mname = defined?(mod.m) ? mod.m.text_value.inspect : "nil" do_rewrite(context, node_name, mname) end end end