lib/unparser/emitter.rb in unparser-0.1.13 vs lib/unparser/emitter.rb in unparser-0.1.14
- old
+ new
@@ -4,11 +4,21 @@
# Emitter base class
class Emitter
include Adamantium::Flat, AbstractType, Constants, NodeHelpers
include Concord.new(:node, :parent)
+ extend DSL
+ # Registry for node emitters
+ REGISTRY = {}
+
+ NOINDENT = [:rescue, :ensure].to_set.freeze
+
+ DEFAULT_DELIMITER = ', '.freeze
+
+ CURLY_BRACKETS = IceNine.deep_freeze(%w({ }))
+
module LocalVariableRoot
# Return local variable root
#
# @return [Parser::AST::Node]
@@ -23,11 +33,11 @@
descendant.class_eval do
memoize :local_variable_scope
end
end
- end
+ end # LocalVariableRoot
# Return local variable root
#
# @return [Parser::AST::Node]
#
@@ -35,19 +45,10 @@
#
def local_variable_scope
parent.local_variable_scope
end
- # Registry for node emitters
- REGISTRY = {}
-
- NOINDENT = [:rescue, :ensure].to_set.freeze
-
- DEFAULT_DELIMITER = ', '.freeze
-
- CURLY_BRACKETS = IceNine.deep_freeze(%w({ }))
-
# Return assigned lvars
#
# @return [Array<Symbol>]
#
# @api private
@@ -62,58 +63,10 @@
#
def node_type
node.type
end
- # Define remaining children
- #
- # @param [Enumerable<Symbol>] names
- #
- # @return [undefined]
- #
- # @api private
- #
- def self.define_remaining_children(names)
- define_method(:remaining_children) do
- children[names.length..-1]
- end
- private :remaining_children
- end
- private_class_method :define_remaining_children
-
- # Define named child
- #
- # @param [Symbol] name
- # @param [Fixnum] index
- #
- # @return [undefined]
- #
- # @api private
- #
- def self.define_child(name, index)
- define_method(name) do
- children.at(index)
- end
- protected name
- end
- private_class_method :define_child
-
- # Create name helpers
- #
- # @return [undefined]
- #
- # @api private
- #
- def self.children(*names)
- define_remaining_children(names)
-
- names.each_with_index do |name, index|
- define_child(name, index)
- end
- end
- private_class_method :children
-
# Register emitter for type
#
# @param [Symbol] type
#
# @return [undefined]
@@ -174,13 +127,10 @@
#
abstract_method :dispatch
# Test if node is emitted as terminated expression
#
- # @return [false]
- # if emitted node is unambigous
- #
- # @return [true]
+ # @return [Boolean]
#
# @api private
#
def terminated?
TERMINATED.include?(node.type)