code: def commentdoc(text):
      
      if not text:
          raise ValueError(
              'Expected non-empty comment str, got {}'.format(repr(text))
          )
  
      commentlines = []
      for line in text.splitlines():
          alternating_words_ws = list(filter(None, WHITESPACE_PATTERN_TEXT.split(line)))
          starts_with_whitespace = bool(
              WHITESPACE_PATTERN_TEXT.match(alternating_words_ws[0])
          )
  
          if starts_with_whitespace:
              prefix = alternating_words_ws[0]
              alternating_words_ws = alternating_words_ws[1:]
          else:
              prefix = NIL
  
          if len(alternating_words_ws) % 2 == 0:
              # The last part must be whitespace.
              alternating_words_ws = alternating_words_ws[:-1]
  
          for idx, tup in enumerate(zip(alternating_words_ws, cycle([False, True]))):
              part, is_ws = tup
              if is_ws:
                  alternating_words_ws[idx] = flat_choice(
                      when_flat=part,
                      when_broken=always_break(
                          concat([
                              HARDLINE,
                              '# ',
                          ])
                      )
                  )
  
          commentlines.append(
              concat([
                  '# ',
                  prefix,
                  fill(alternating_words_ws)
              ])
          )
  
      outer = identity
  
      if len(commentlines) > 1:
          outer = always_break
  
      return annotate(
          Token.COMMENT_SINGLE,
          outer(concat(intersperse(HARDLINE, commentlines)))
      )
docs: Returns a Doc representing a comment `text`. `text` is
      treated as words, and any whitespace may be used to break
      the comment to multiple lines.