<commit_before>require 'tomparse'

module YARD

  module TomDoc
    #
    def self.metadata
      @metadata ||= (
        require 'yaml'
        YAML.load_file(File.dirname(__FILE__) + '/yard-tomdoc.yml')
      )
    end

    #
    def self.const_missing(name)
      metadata[name.to_s.downcase] || super(name)
    end
  end

  class Docstring
    # Parse comments with TomDoc and then provide YARD with results. 
    #
    # comments - [Array] of comment strings.
    #
    # Returns parsed comments description [String].
    def parse_comments(comments)
      comment = [comments].flatten.join("\n")

      tomdoc = TomParse.parse(comment)

      tomdoc.examples.each {|ex| create_tag(:example, "\n" + ex) }

      tomdoc.arguments.each {|arg| create_tag(:param, "#{arg.name} #{arg.description}") }

      last_argument = tomdoc.arguments.last
      last_argument.options.each do |opt|
        create_tag(:option, "#{last_argument.name} #{opt.description}")
      end

      tomdoc.raises.each {|r| create_tag(:raise, r.sub(/\ARaises\s+/, '')) }

      tomdoc.returns.each do |r|
        if md = /\AReturns\s+([A-Z].*?)\s+/.match(r)
          klass = md[1]
          desc  = md.post_match
          create_tag(:return, "[#{klass}] #{desc}")
        else
          desc = r.sub(/\AReturns\s+/, '')
          create_tag(:return, desc)
        end
      end

      create_tag(:yield, tomdoc.yields) if tomdoc.yields

      create_tag(:deprecated) if tomdoc.deprecated?

      create_tag(:private) if tomdoc.internal?

      # notice we return the modified comment
      tomdoc.description.to_s
    end
  end

end
<commit_msg>There are no options if no last argument.<commit_after>require 'tomparse'

module YARD

  module TomDoc
    #
    def self.metadata
      @metadata ||= (
        require 'yaml'
        YAML.load_file(File.dirname(__FILE__) + '/yard-tomdoc.yml')
      )
    end

    #
    def self.const_missing(name)
      metadata[name.to_s.downcase] || super(name)
    end
  end

  class Docstring
    # Parse comments with TomDoc and then provide YARD with results. 
    #
    # comments - [Array] of comment strings.
    #
    # Returns parsed comments description [String].
    def parse_comments(comments)
      comment = [comments].flatten.join("\n")

      tomdoc = TomParse.parse(comment)

      tomdoc.examples.each {|ex| create_tag(:example, "\n" + ex) }

      tomdoc.arguments.each {|arg| create_tag(:param, "#{arg.name} #{arg.description}") }

      if last_argument = tomdoc.arguments.last
        last_argument.options.each do |opt|
          create_tag(:option, "#{last_argument.name} #{opt.description}")
        end
      end

      tomdoc.raises.each {|r| create_tag(:raise, r.sub(/\ARaises\s+/, '')) }
#p tomdoc.returns
      tomdoc.returns.each do |r|
        if md = /\AReturns\s+([A-Z].*?)\s+/.match(r)
          klass = md[1]
          desc  = md.post_match
          create_tag(:return, "[#{klass}] #{desc}")
        else
          desc = r.sub(/\AReturns\s+/, '')
          create_tag(:return, desc)
        end
      end

      create_tag(:yield, tomdoc.yields) if tomdoc.yields

      create_tag(:deprecated) if tomdoc.deprecated?

      create_tag(:private) if tomdoc.internal?

      # notice we return the modified comment
      tomdoc.description.to_s
    end
  end

end

{'fraction_non_alphanumeric': 0.13435990338164253, 'fraction_numerical': 0.0006038647342995169, 'mean_word_length': 2.3634517766497463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '721999', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1085, 'n_words': 233}