class SyntaxTree::Index::EntryComments

This class handles parsing comments from Ruby source code in the case that we use the instruction sequence backend. Because the instruction sequence backend doesn’t provide comments (since they are dropped) we provide this interface to lazily parse them out.

Attributes

file_comments[R]
location[R]

Public Class Methods

new(file_comments, location) click to toggle source
# File lib/syntax_tree/index.rb, line 156
def initialize(file_comments, location)
  @file_comments = file_comments
  @location = location
end

Public Instance Methods

each(&block) click to toggle source
# File lib/syntax_tree/index.rb, line 161
def each(&block)
  line = location.line - 1
  result = []

  while line >= 0 && (comment = file_comments.comments[line])
    result.unshift(comment)
    line -= 1
  end

  result.each(&block)
end