class Transproc::Compiler
@api private
Constants
- InvalidFunctionNameError
Attributes
registry[R]
transformer[R]
Public Class Methods
new(registry, transformer = nil)
click to toggle source
# File lib/transproc/compiler.rb, line 10 def initialize(registry, transformer = nil) @registry = registry @transformer = transformer end
Public Instance Methods
call(ast)
click to toggle source
# File lib/transproc/compiler.rb, line 15 def call(ast) ast.map(&method(:visit)).reduce(:>>) end
visit(node)
click to toggle source
# File lib/transproc/compiler.rb, line 19 def visit(node) id, *rest = node public_send(:"visit_#{id}", *rest) end
visit_arg(arg)
click to toggle source
# File lib/transproc/compiler.rb, line 37 def visit_arg(arg) arg end
visit_fn(node)
click to toggle source
# File lib/transproc/compiler.rb, line 24 def visit_fn(node) name, rest = node args = rest.map { |arg| visit(arg) } if registry.contain?(name) registry[name, *args] elsif transformer.respond_to?(name) Function.new(transformer.method(name), name: name, args: args) else raise InvalidFunctionNameError, "function name +#{name}+ is not valid" end end
visit_t(node)
click to toggle source
# File lib/transproc/compiler.rb, line 41 def visit_t(node) call(node) end