class SyntaxSuggest::ParseBlocksFromIndentLine
这个类负责生成初始代码块,这些代码块稍后将被扩展。
猜测代码块时,最大的问题是意外地抓取一个只包含 "end" 的代码块。在这个例子中
def dog begonn # misspelled `begin` puts "bark" end end
以下行将被匹配(从下到上)
1) end 2) puts "bark" end 3) begonn puts "bark" end
此时它没有其他地方可以扩展,它会将此内部代码生成为一个块
属性
code_lines[R]
公共类方法
new(code_lines:) 点击以切换源代码
# File syntax_suggest/parse_blocks_from_indent_line.rb, line 32 def initialize(code_lines:) @code_lines = code_lines end
公共实例方法
each_neighbor_block(target_line) { |block| ... } 点击以切换源代码
从下往上构建代码块
# File syntax_suggest/parse_blocks_from_indent_line.rb, line 37 def each_neighbor_block(target_line) scan = AroundBlockScan.new(code_lines: code_lines, block: CodeBlock.new(lines: target_line)) .force_add_empty .force_add_hidden .scan_while { |line| line.indent >= target_line.indent } neighbors = scan.code_block.lines block = CodeBlock.new(lines: neighbors) if neighbors.length <= 2 || block.valid? yield block else until neighbors.empty? lines = [neighbors.pop] while (block = CodeBlock.new(lines: lines)) && block.invalid? && neighbors.any? lines.prepend neighbors.pop end yield block if block end end end