Sha256: e6a163d8196d986d933304fb75cf0a0296f3ab17c7c9f0b0c8baedbf19d2af87
Contents?: true
Size: 1.21 KB
Versions: 2
Compression:
Stored size: 1.21 KB
Contents
# encoding: utf-8 module Unparser class Emitter # Emitter control flow modifiers class FlowModifier < self MAP = { return: K_RETURN, next: K_NEXT, break: K_BREAK, } handle(*MAP.keys) private # Perform dispatch # # @return [undefined] # # @api private # def dispatch conditional_parentheses((parent_type == :or || parent_type == :and) && children.any?) do write(MAP.fetch(node.type)) emit_arguments if children.any? end end # Emit break or return arguments # # @return [undefined] # # @api private # def emit_arguments ws head, *tail = children emit_argument(head) tail.each do |node| write(DEFAULT_DELIMITER) emit_argument(node) end end PARENS = [:if, :case, :begin].to_set.freeze # Emit argument # # @param [Parser::AST::Node] node # # @api private # def emit_argument(node) conditional_parentheses(PARENS.include?(node.type)) do visit(node) end end end # Return end # Emitter end # Unparser
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unparser-0.1.9 | lib/unparser/emitter/flow_modifier.rb |
unparser-0.1.8 | lib/unparser/emitter/flow_modifier.rb |