Class: Parser::Source::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_cover/parser_ext/range.rb

Instance Method Summary collapse

Instance Method Details

#succObject



4
5
6
# File 'lib/deep_cover/parser_ext/range.rb', line 4

def succ
  adjust(begin_pos: +1, end_pos: +1)
end

#wrap_final_commentObject

Only wraps anything if there is a comment to wrap on the last line Will wrap the whitespace before the comment



24
25
26
27
28
29
30
31
32
# File 'lib/deep_cover/parser_ext/range.rb', line 24

def wrap_final_comment
  current = wrap_rwhitespace(whitespaces: /\A[ \t\r\f]+/)
  if @source_buffer.slice(current.end_pos) != '#'
    # No comment, do nothing
    return self
  end
  comment = @source_buffer.slice(current.end_pos..-1)[/\A[^\n]+/] || ''
  current.adjust(end_pos: comment.size)
end

#wrap_rwhitespace(whitespaces: /\A\s+/) ⇒ Object



8
9
10
11
# File 'lib/deep_cover/parser_ext/range.rb', line 8

def wrap_rwhitespace(whitespaces: /\A\s+/)
  whitespace = @source_buffer.slice(end_pos..-1)[whitespaces] || ''
  adjust(end_pos: whitespace.size)
end

#wrap_rwhitespace_and_comments(whitespaces: /\A\s+/) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/deep_cover/parser_ext/range.rb', line 13

def wrap_rwhitespace_and_comments(whitespaces: /\A\s+/)
  current = wrap_rwhitespace(whitespaces: whitespaces)
  while @source_buffer.slice(current.end_pos) == '#'
    comment = @source_buffer.slice(current.end_pos..-1)[/\A[^\n]+/] || ''
    current = current.adjust(end_pos: comment.size).wrap_rwhitespace(whitespaces: whitespaces)
  end
  current
end