module Tweezer::ASTHelper
Public Class Methods
append_block_child(block, node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 46 def append_block_child(block, node) new_children = block.children[0..1] old_child = block.children[2] if old_child.type == :begin new_children << old_child.append(node) else new_children << s(:begin, old_child, node) end block.updated(nil, new_children) end
block?(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 11 def block?(node) node.type == :block end
block_children(node) { |c| ... }
click to toggle source
# File lib/tweezer/ast_helper.rb, line 27 def block_children(node) child = node.children[2] children = child.type == :begin ? child.children : [child] return children unless block_given? children.each { |c| yield c } end
group_block?(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 21 def group_block?(node) block?(node) && node.children[0].type == :send && node.children[0].children[1] == :group end
groups_from_group_block(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 34 def groups_from_group_block(node) node.children[0].children[2..-1].flat_map(&:children) end
s(type, *children)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 3 def s(type, *children) Parser::AST::Node.new(type, children) end
source_block?(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 15 def source_block?(node) block?(node) && node.children[0].type == :send && node.children[0].children[1] == :source end
unparse_hash_node(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 38 def unparse_hash_node(node) return {} unless node fail ArgumentError unless node.type == :hash Hash[node.children.map do |child| [child.children[0].children[0], child.children[1]] end] end
Public Instance Methods
blank_line()
click to toggle source
# File lib/tweezer/ast_helper.rb, line 7 def blank_line Parser::AST::Node.new(:blank_line) end
Private Instance Methods
append_block_child(block, node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 46 def append_block_child(block, node) new_children = block.children[0..1] old_child = block.children[2] if old_child.type == :begin new_children << old_child.append(node) else new_children << s(:begin, old_child, node) end block.updated(nil, new_children) end
block?(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 11 def block?(node) node.type == :block end
block_children(node) { |c| ... }
click to toggle source
# File lib/tweezer/ast_helper.rb, line 27 def block_children(node) child = node.children[2] children = child.type == :begin ? child.children : [child] return children unless block_given? children.each { |c| yield c } end
group_block?(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 21 def group_block?(node) block?(node) && node.children[0].type == :send && node.children[0].children[1] == :group end
groups_from_group_block(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 34 def groups_from_group_block(node) node.children[0].children[2..-1].flat_map(&:children) end
s(type, *children)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 3 def s(type, *children) Parser::AST::Node.new(type, children) end
source_block?(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 15 def source_block?(node) block?(node) && node.children[0].type == :send && node.children[0].children[1] == :source end
unparse_hash_node(node)
click to toggle source
# File lib/tweezer/ast_helper.rb, line 38 def unparse_hash_node(node) return {} unless node fail ArgumentError unless node.type == :hash Hash[node.children.map do |child| [child.children[0].children[0], child.children[1]] end] end