<commit_before>module Docopt
  module Nodes
    class ShortOption < Option
      def initialize(value, machine)
        super
        @opt_name = @value
        @machine.type[value] ||= :singular_short_option
        if not (@machine.options[@opt_name] \
                and @machine.options[@opt_name].include? :alt) then
          if @machine.option_has_argument? @opt_name then
            @machine.data[value] = nil if not @machine.data.include? value
          else
            @machine.data[value] = false if not @machine.data.include? value
          end
        end
      end

      def move(alt, cons, args, data)
        new_data = data.clone
        args.each_with_index do |argv_elem, argv_index|
          # short option is in an argv_elem starting with dash
          next unless argv_elem[0] == "-"

          argv_elem.each_char.each_with_index do |char, elem_index|
            next if elem_index == 0 # char is the starting dash!

            cur_opt = "-#{char}"

            if @machine.option_has_argument? cur_opt then
              unless cur_opt == @opt_name
                # won't find desired short option (@opt_name) in
                # this argv_elem
                # rest of the argv_elem would be the argument of
                # cur_opt, because cur_opt has_argument
                # so skip checking other characters in current argv_elem
                # and scan the next one
                break
              end

              if elem_index == argv_elem.length-1 then
                # at the last character of argv_elem
                # look for the argument in next argv_elem

                # fail if there's no further argv_elem
                if argv_index == args.length-1
                  return alt.alt([:needs_argument, @opt_name])
                end

                # argument is supposed to be the next element in argv
                val = args[argv_index+1]
                # we should check if it's a valid value for option argument
                unless @machine.is_valid_arg_for? @opt_name, val[0]
                  return alt.alt([:needs_argument, @opt_name])
                end

                new_args = args[0...argv_index]

                #BUG: should be +=
                if argv_elem[0...elem_index] != "-"
                  new_args = [argv_elem[0...elem_index]]
                end
<commit_msg>improve comments<commit_after>module Docopt
  module Nodes
    class ShortOption < Option
      def initialize(value, machine)
        super
        @opt_name = @value
        @machine.type[value] ||= :singular_short_option
        if not (@machine.options[@opt_name] \
                and @machine.options[@opt_name].include? :alt) then
          if @machine.option_has_argument? @opt_name then
            @machine.data[value] = nil if not @machine.data.include? value
          else
            @machine.data[value] = false if not @machine.data.include? value
          end
        end
      end

      def move(alt, cons, args, data)
        new_data = data.clone
        args.each_with_index do |argv_elem, argv_index|
          # short option is in an argv_elem starting with dash
          next unless argv_elem[0] == "-"

          argv_elem.each_char.each_with_index do |char, elem_index|
            next if elem_index == 0 # char is the starting dash!

            cur_opt = "-#{char}"

            if @machine.option_has_argument? cur_opt then
              unless cur_opt == @opt_name
                # won't find desired short option (@opt_name) in this argv_elem
                # the rest of the argv_elem would be the argument of
                # cur_opt, because cur_opt has_argument
                # so skip scanning other characters in current argv_elem
                # and go to next one
                break
              end

              if elem_index == argv_elem.length-1 then
                # at the last character of argv_elem
                # look for the argument in next argv_elem

                # fail if there's no further argv_elem
                if argv_index == args.length-1
                  return alt.alt([:needs_argument, @opt_name])
                end

                # argument is supposed to be the next element in argv
                val = args[argv_index+1]
                # we should check if it's a valid value for option argument
                unless @machine.is_valid_arg_for? @opt_name, val[0]
                  return alt.alt([:needs_argument, @opt_name])
                end

                new_args = args[0...argv_index]

                #BUG: should be +=
                if argv_elem[0...elem_index] != "-"
                  new_args = [argv_elem[0...elem_index]]
                end

{'fraction_non_alphanumeric': 0.07502113271344041, 'fraction_numerical': 0.0038038884192730348, 'mean_word_length': 1.5891684901531729, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6937832', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1219, 'n_words': 392}