<commit_before>module Tritium
  module Parser
    module Instructions
      require_relative "block"

      class Invocation < Block
        attr :kwd_args
        attr :pos_args
        attr :name
        def initialize(filename, line_num,
                       name = nil, pos_args = [], kwd_args = {}, statements = [])
          super(filename, line_num, statements)
          @name, @pos_args, @kwd_args = name.intern, pos_args, kwd_args
        end
        
        def spec
          scope[@name.to_s]
        end
        
        def base?
          spec.base?
        end
        
        def opens
          spec.opens
        end

        def function_stub(depth = 0)
          name = @name.to_s.gsub(/\$/, "select")
          if name == "else" 
            name = "else_do"
          end
          if name == "not"
            name = "not_matcher"
          end
          result = ruby_debug_line(depth) + "#{@@tab * depth}#{name}("
          @pos_args.each { |arg| result << "#{arg}, " }
          @kwd_args.each { |kwd, arg| result << "#{kwd.inspect} => #{arg}, " }
          result[-2,2] = "" if result.end_with? ", "
          result << ")"
          return result
        end
        
        def to_s(depth = 0)
          result = function_stub(depth)
          if @statements.any?
            result << " {\n"
            depth += 1
            @statements.each { |stm| result << stm.to_s(depth) << "\n" }
            depth -= 1
            result << "#{@@tab * depth}}"
          end
          return result
        end
      end
    end
  end
end<commit_msg>Throw an error if an invalid function is used<commit_after>module Tritium
  module Parser
    module Instructions
      require_relative "block"

      class Invocation < Block
        attr :kwd_args
        attr :pos_args
        attr :name
        def initialize(filename, line_num,
                       name = nil, pos_args = [], kwd_args = {}, statements = [])
          super(filename, line_num, statements)
          @name, @pos_args, @kwd_args = name.intern, pos_args, kwd_args
        end
        
        def spec
          spec = scope[@name.to_s]
          if spec.nil?
            throw "Invalid #{@name.to_s} in #{scope.name} scope"
          end
          spec
        end
        
        def base?
          spec.base?
        end
        
        def opens
          spec.opens
        end

        def function_stub(depth = 0)
          name = @name.to_s.gsub(/\$/, "select")
          if name == "else" 
            name = "else_do"
          end
          if name == "not"
            name = "not_matcher"
          end
          result = ruby_debug_line(depth) + "#{@@tab * depth}#{name}("
          @pos_args.each { |arg| result << "#{arg}, " }
          @kwd_args.each { |kwd, arg| result << "#{kwd.inspect} => #{arg}, " }
          result[-2,2] = "" if result.end_with? ", "
          result << ")"
          return result
        end
        
        def to_s(depth = 0)
          result = function_stub(depth)
          if @statements.any?
            result << " {\n"
            depth += 1
            @statements.each { |stm| result << stm.to_s(depth) << "\n" }
            depth -= 1
            result << "#{@@tab * depth}}"
          end
          return result
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11949305974652988, 'fraction_numerical': 0.003621001810500905, 'mean_word_length': 1.3411016949152543, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 5, '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': '665738', 'n_tokens_mistral': 1007, 'n_tokens_neox': 990, 'n_words': 248}