Sha256: e0f9b7b53fcda006d07b66232e832c2c1edb83e5130d49def8e508ddbf681a41
Contents?: true
Size: 1.13 KB
Versions: 27
Compression:
Stored size: 1.13 KB
Contents
module Parser class Lexer::Dedenter def initialize(dedent_level) @dedent_level = dedent_level @at_line_begin = true @indent_level = 0 end def dedent(string) space_begin = space_end = offset = 0 last_index = string.length - 1 string.chars.each_with_index do |char, index| if @at_line_begin if char == ?\n || @indent_level >= @dedent_level string.slice!(space_begin...space_end) offset += space_end - space_begin - 1 @at_line_begin = false redo if char == ?\n end case char when ?\s @indent_level += 1 space_end += 1 when ?\t @indent_level += 8 - @indent_level % 8 space_end += 1 end elsif char == ?\n && index == last_index @at_line_begin = true @indent_level = 0 space_begin = space_end = index - offset + 1 end end if @at_line_begin string.slice!(space_begin..space_end) end nil end def interrupt @at_line_begin = false end end end
Version data entries
27 entries across 27 versions & 4 rubygems