class Riml::Compiler::DefNodeVisitor
Public Instance Methods
compile(node)
click to toggle source
# File lib/riml/compiler.rb, line 468 def compile(node) set_modifier(node) bang = node.bang params = process_parameters!(node) declaration = "function#{bang} #{node.sid}#{node.scope_modifier}" declaration << if node.name.respond_to?(:variable) node.name.accept(visitor_for_node(node.name)) node.name.compiled_output else node.name end << "(#{params.join(', ')})" declaration << (node.keywords.empty? ? "\n" : " #{node.keywords.join(' ')}\n") node.expressions.parent_node = node node.expressions.accept NodesVisitor.new(:propagate_up_tree => false) body = "" unless node.expressions.compiled_output.empty? node.expressions.compiled_output.each_line do |line| body << node.indent + line end end node.compiled_output = declaration << body << "endfunction\n" if current_compiler(node).readable node.compiled_output << "\n" else node.compiled_output end end
visit(node)
click to toggle source
Calls superclass method
Riml::Compiler::Visitor#visit
# File lib/riml/compiler.rb, line 459 def visit(node) options = {} if node.nested_function? options[:nested_function] = true end setup_local_scope_for_descendants(node, options) super end
Private Instance Methods
process_parameters!(node)
click to toggle source
# File lib/riml/compiler.rb, line 504 def process_parameters!(node) splat = node.splat return node.parameters unless splat node.parameters.map {|p| p == splat ? '...' : p} end
setup_local_scope_for_descendants(node, options)
click to toggle source
# File lib/riml/compiler.rb, line 499 def setup_local_scope_for_descendants(node, options) options.merge!(:scope => node.to_scope) node.expressions.accept(EstablishScopeVisitor.new(options)) end