Class: Ryac::Pipeline::CharShorten

Inherits:
Stage
  • Object
show all
Defined in:
lib/ryac/pipeline/char_shorten.rb,
sig/ryac/pipeline/char_shorten.rbs

Instance Method Summary collapse

Methods inherited from Stage

#analysis, #analysis_options, #call, #finish, #fixpoint?, #needs_analysis?, new

Methods included from SourcePatcher

#apply_patches, #mk, #src, #verify_parses

Instance Method Details

#collect(ctx, patches) ⇒ void

This method returns an undefined value.

Parameters:



6
7
8
# File 'lib/ryac/pipeline/char_shorten.rb', line 6

def collect(ctx, patches)
  walk(ctx.ast, patches)
end

#walk(node, patches) ⇒ void

This method returns an undefined value.

Parameters:

  • node (Prism::Node)
  • patches (Array[patch_entry])


12
13
14
15
16
17
# File 'lib/ryac/pipeline/char_shorten.rb', line 12

def walk(node, patches)
  if node.is_a?(Prism::StringNode) && node.opening_loc && node.content.match?(/\A[a-zA-Z0-9_]\z/)
    patches << mk(node, "?#{node.content}")
  end
  node.compact_child_nodes.each { |child| walk(child, patches) }
end