app/controllers/preprocessor/python/python_preprocessor.rb
# Given a line number from an error message, try to find out which line number it would
# correspond to in the user's original code. If we're in the syntax check phase, we haven't
# done anything to the code yet, so the original line number equals the new line number.
# If we are in the augmentation phase, this method shouldn't be called. If we're in the
# execution phase, what we do depends on whether we're running augmented code or not. If
# so, we look for a line number comment in the augmented code. Otherwise, we won't find
# an original line number, but all we've done to the user's code was prepend a few lines,
# so we subtract the number of prepended lines.
Given a line number from an error message, try to find out which line number it would
correspond to in the user's original code. If we're in the syntax check phase, we haven't
done anything to the code yet, so the original line number equals the new line number.
If we are in the augmentation phase, this method shouldn't be called. If we're in the
execution phase, what we do depends on whether we're running augmented code or not. If
so, we look for a line number comment in the augmented code. Otherwise, we won't find
an original line number, but all we've done to the user's code was prepend a few lines,
so we subtract the number of prepended lines.
Given a line number from an error message try to find out which line number it would correspond to in the user ' s original code . If we ' re in the syntax check phase we haven ' t done anything to the code yet so the original line number equals the new line number . If we are in the augmentation phase this method shouldn ' t be called . If we ' re in the execution phase what we do depends on whether we ' re running augmented code or not . If so we look for a line number comment in the augmented code . Otherwise we won ' t find an original line number but all we ' ve done to the user ' s code was prepend a few lines so we subtract the number of prepended lines .
def original_line_number(new_line)
    new_line = new_line.to_i
    if @phase == :execute
      if @augmented_code.nil?
        number_of_prepended_lines = make_runnable("").count("\n")
        return new_line - number_of_prepended_lines
      else
        augmented_code_lines = @augmented_code.lines
        if new_line > augmented_code_lines.length
          return "<unbekannt>"
        else
          ln = PythonCodeAugmenter.extract_line_number(augmented_code_lines[new_line - 1])
          if ln.nil?
            return "<unbekannt>"
          else
            return ln
          end
        end
      end
    else
      return new_line
    end
  end
def original_line_number ( new_line ) new_line = new_line . to_i if @phase == :execute if @augmented_code . nil? number_of_prepended_lines = make_runnable ( "" ) . count ( "\n" ) return new_line - number_of_prepended_lines else augmented_code_lines = @augmented_code . lines if new_line > augmented_code_lines . length return "<unbekannt>" else ln = PythonCodeAugmenter . extract_line_number ( augmented_code_lines [ new_line - 1 ] ) if ln . nil? return "<unbekannt>" else return ln end end end else return new_line end end
Given a line number from an error message, try to find out which line number it would
correspond to in the user's original code.
Given a line number from an error message try to find out which line number it would correspond to in the user ' s original code .
# First of all, convert the line number to an integer # It's the execute phase, so we have more to do # We haven't augmented the code with line numbers or anything # Pull the offending line out of the augmented code # We were not able to find the line the error message refers to. Shouldn't happen. # Check if the line has a line number comment # It's not the execute phase, so we can simply return the line number
new_line