# File lib/scrubyt/core/shared/extractor.rb, line 12
    def self.define(mode=nil, &extractor_definition)
      backtrace = SharedUtils.get_backtrace
      parts = backtrace[1].split(':')
      source_file = parts[0]
      
      @@mode = mode
      #We are keeping the relations between the detail patterns and their root patterns
      @@detail_extractor_to_pattern_name = {}
      @@detail_pattern_relations = {} 
      #root pattern -> URIBuilder mapping
      @@next_patterns = {}
      mode_name = (mode == :production ? 'Production' : 'Learning')
      
      Scrubyt.log :MODE, mode_name

      @@evaluation_context = EvaluationContext.new
      #Hack up an artificial root pattern (i.e. do not return the pattern which 
      #is the root one in the user's definition, but rather the real (invisible)
      #root pattern
      @@evaluation_context.evaluating_extractor_definition = true
      class_eval(&extractor_definition)
      @@evaluation_context.evaluating_extractor_definition = false
      root_pattern = @@evaluation_context.root_pattern

      if root_pattern.nil?
        # TODO: this should be an exception
        Scrubyt.log :ERROR, 'No extractor defined, exiting...'
        exit
      end

      root_pattern.source_file = source_file
      root_pattern.source_proc = extractor_definition
      #Once all is set up, evaluate the extractor from the root pattern!
      root_results = evaluate_extractor(root_pattern)

      scrubyt_result = ScrubytResult.new('root')
      scrubyt_result.push(*root_results)
      scrubyt_result.root_pattern = root_pattern
            
      #Return the root pattern
      Scrubyt.log :INFO, 'Extraction finished succesfully!'
      scrubyt_result
    end