类 SyntaxSuggest::ParseBlocksFromIndentLine
此类负责生成初始代码块,这些代码块随后将被扩展。
在猜测代码块时,最大的问题是意外地抓取了一个只包含“end”的代码块。在这个例子中
def dog begonn # mispelled `begin` puts "bark" end end
以下行将被匹配(从下到上)
1) end 2) puts "bark" end 3) begonn puts "bark" end
此时它没有其他地方可以扩展,它将生成此内部代码作为块
属性
code_lines[R]
公共类方法
new(code_lines:) 点击切换源代码
# File lib/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 lib/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