Class: Walrus::Grammar::MultilineComment

Inherits:
Comment
  • Object
show all
Defined in:
lib/walrus/grammar/multiline_comment.rb

Instance Method Summary collapse

Instance Method Details

#compile(options = {}) ⇒ Object

Multiline comments may contain nested Comments/Multiline comments or normal text, so must compile recursively.

TODO: anchor comments that appear immediately before #def and #block directives to their corresponding methods (for the timebeing should note in the documentation that if you want your comments to appear adjacent to the blocks which follow them then you must put your comments inside the blocks)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/walrus/grammar/multiline_comment.rb', line 36

def compile options = {}
  compiled = ''
  if @content.respond_to? :each
    @content.each do |item|
      if item.kind_of? Comment
        compiled << '# (nested) ' + item.compile
      else
        first = true
        item.to_s.each do |line|
          if first
            first = false
            compiled << '# MultilineComment:' + line.to_s.chomp + "\n"
          else
            compiled << '# MultilineComment (continued):' + line.to_s.chomp + "\n"
          end
        end
      end
    end
  else
    # no nesting, just raw text, but still must check for multiple lines
    first = true
    @content.to_s.each do |line|
      if first
        first = false
        compiled << '# MultilineComment:' + line.to_s.chomp + "\n"
      else
        compiled << '# MultilineComment (continued):' + line.to_s.chomp + "\n"
      end
    end
  end
  compiled
end