Class: Dry::Transformer::Compiler Private
- Inherits:
-
Object
- Object
- Dry::Transformer::Compiler
- Defined in:
- lib/dry/transformer/compiler.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- InvalidFunctionNameError =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Class.new(StandardError)
Instance Attribute Summary collapse
- #registry ⇒ Object readonly private
- #transformer ⇒ Object readonly private
Instance Method Summary collapse
- #call(ast) ⇒ Object private
-
#initialize(registry, transformer = nil) ⇒ Compiler
constructor
private
A new instance of Compiler.
- #visit(node) ⇒ Object private
- #visit_arg(arg) ⇒ Object private
- #visit_fn(node) ⇒ Object private
- #visit_t(node) ⇒ Object private
Constructor Details
#initialize(registry, transformer = nil) ⇒ Compiler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Compiler.
11 12 13 14 |
# File 'lib/dry/transformer/compiler.rb', line 11 def initialize(registry, transformer = nil) @registry = registry @transformer = transformer end |
Instance Attribute Details
#registry ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/dry/transformer/compiler.rb', line 9 def registry @registry end |
#transformer ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/dry/transformer/compiler.rb', line 9 def transformer @transformer end |
Instance Method Details
#call(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/dry/transformer/compiler.rb', line 16 def call(ast) ast.map(&method(:visit)).reduce(:>>) end |
#visit(node) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 |
# File 'lib/dry/transformer/compiler.rb', line 20 def visit(node) id, *rest = node public_send(:"visit_#{id}", *rest) end |
#visit_arg(arg) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/dry/transformer/compiler.rb', line 38 def visit_arg(arg) arg end |
#visit_fn(node) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dry/transformer/compiler.rb', line 25 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/dry/transformer/compiler.rb', line 42 def visit_t(node) call(node) end |