def parse(data)
      sections = []
      docs, code = [], []
      lines = data.split("\n")

      # Skip shebang and encoding information
      lines.shift if lines[0] =~ /^\#\!/
      lines.shift if lines[0] =~ /coding[:=]\s*[-\w.]+/

      in_comment_block = false
      lines.each do |line|
        # If we're currently in a comment block, check whether the line matches
        # the _end_ of a comment block
        if in_comment_block
          if line.match(@@block_comment_end)
            in_comment_block = false
          else
            docs << line
          end
        # Otherwise, check whether the line matches the beginning of a block, or
        # a single-line comment all on it's lonesome. In either case, if there's
        # code, start a new section
        else
          if line.match(@@block_comment_start)
            in_comment_block = true
            if code.any?
              sections << [docs, code]
              docs, code = [], []
            end
          elsif line.match(@@comment_pattern)
            if code.any?
              sections << [docs, code]
              docs, code = [], []
            end
            docs << line.sub(@@comment_pattern, '')
          else
            code << line
          end
        end
      end

      sections << [docs, code] if docs.any? || code.any?
      normalize_leading_spaces(sections)
    end
def parse(data)
      sections = []
      docs, code = [], []
      lines = data.split("\n")

      # Skip shebang and encoding information
      lines.shift if lines[0] =~ /^\#\!/
      lines.shift if lines[0] =~ /coding[:=]\s*[-\w.]+/

      in_comment_block = false
      lines.each do |line|
        # If we're currently in a comment block, check whether the line matches
        # the _end_ of a comment block
        if in_comment_block
          if line.match(@@block_comment_end)
            in_comment_block = false
          else
            docs << line
          end
        # Otherwise, check whether the line matches the beginning of a block, or
        # a single-line comment all on it's lonesome. In either case, if there's
        # code, start a new section
        else
          if line.match(@@block_comment_start)
            in_comment_block = true
            if code.any?
              sections << [docs, code]
              docs, code = [], []
            end
          elsif line.match(@@comment_pattern)
            if code.any?
              sections << [docs, code]
              docs, code = [], []
            end
            docs << line.sub(@@comment_pattern, '')
          else
            code << line
          end
        end
      end

      sections << [docs, code] if docs.any? || code.any?
      normalize_leading_spaces(sections)
    end
Parse the raw file data into a list of two-tuples. Each tuple has the form
 `[docs, code]` where both elements are arrays containing the raw lines
 parsed from the input file, comment characters stripped.