Class: SeeingIsBelieving::Binary::CommentableLines

Inherits:
Object
  • Object
show all
Includes:
ParserHelpers
Defined in:
lib/seeing_is_believing/binary/commentable_lines.rb

Overview

could possibly be sped up by just reflecting on the tokens instead of the whole ast

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ParserHelpers

#comments_from, #heredoc?, #heredoc_hack, #initialize_parser, #void_value?

Constructor Details

#initialize(code) ⇒ CommentableLines

Returns a new instance of CommentableLines.



15
16
17
18
19
# File 'lib/seeing_is_believing/binary/commentable_lines.rb', line 15

def initialize(code)
  self.code = code
  self.buffer, self.parser, self.rewriter = initialize_parser(code, 'finding_commentable_lines')
  self.root, self.comments = parser.parse_with_comments(buffer)
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



32
33
34
# File 'lib/seeing_is_believing/binary/commentable_lines.rb', line 32

def buffer
  @buffer
end

#rewriterObject

Returns the value of attribute rewriter.



32
33
34
# File 'lib/seeing_is_believing/binary/commentable_lines.rb', line 32

def rewriter
  @rewriter
end

Class Method Details

.call(code) ⇒ Object



11
12
13
# File 'lib/seeing_is_believing/binary/commentable_lines.rb', line 11

def self.call(code)
  new(code).call
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/seeing_is_believing/binary/commentable_lines.rb', line 21

def call
  @call ||= begin
    line_num_to_indexes = line_nums_to_last_index_and_col(buffer)
    remove_lines_after_data_segment           line_num_to_indexes
    remove_lines_whose_newline_is_escaped     line_num_to_indexes
    remove_lines_ending_in_comments           line_num_to_indexes, comments
    remove_lines_inside_of_strings_and_things line_num_to_indexes, root
    line_num_to_indexes
  end
end