app/controllers/preprocessor/python/augmentation.rb
# Parses a line starting at the given index under the assumption that the start index is inside a
# string. Returns the index of the next character to be parsed. This method parses either until the end
# of the line is reached (in which case the returned index is equal to the line's length) or until it
# finds the end of the string (in which case the returned index points to the character after the
# string's closing delimiter(s)).
#
# We almost completely disregard escape characters, except for when they precede the current string
# delimiter. This is because all other escapes are of no concern to us. We don't even need to check
# whether a single-quoted string ends with an escape character to continue at the next line, because
# if the escape character weren't there, the code wouldn't have passed syntax validation in the first
# place.
#
# Note: This method expects to be called on a line that has had trailing whitespace removed.
Parses a line starting at the given index under the assumption that the start index is inside a
string. Returns the index of the next character to be parsed. This method parses either until the end
of the line is reached (in which case the returned index is equal to the line's length) or until it
finds the end of the string (in which case the returned index points to the character after the
string's closing delimiter(s)).

We almost completely disregard escape characters, except for when they precede the current string
delimiter. This is because all other escapes are of no concern to us. We don't even need to check
whether a single-quoted string ends with an escape character to continue at the next line, because
if the escape character weren't there, the code wouldn't have passed syntax validation in the first
place.

This method expects to be called on a line that has had trailing whitespace removed.
Parses a line starting at the given index under the assumption that the start index is inside a string . Returns the index of the next character to be parsed . This method parses either until the end of the line is reached ( in which case the returned index is equal to the line ' s length ) or until it finds the end of the string ( in which case the returned index points to the character after the string ' s closing delimiter ( s )) . We almost completely disregard escape characters except for when they precede the current string delimiter . This is because all other escapes are of no concern to us . We don ' t even need to check whether a single - quoted string ends with an escape character to continue at the next line because if the escape character weren ' t there the code wouldn ' t have passed syntax validation in the first place . This method expects to be called on a line that has had trailing whitespace removed .
def parse_characters_in_string(line, start_index)
    index = start_index
    delim = @state[:in_string]
    while index < line.length
      if line[index] == delim[0]
        if index > 0 && line[index - 1] == "\\"
          index += 1
        else
          if line[index...index + delim.length] == delim
            @state[:in_string] = nil
            index += delim.length
            break
          else
            index += 1
          end
        end
      else
        index += 1
      end
    end
    return index
  end
def parse_characters_in_string ( line , start_index ) index = start_index delim = @state [ :in_string ] while index < line . length if line [ index ] == delim [ 0 ] if index > 0 && line [ index - 1 ] == "\\" index += 1 else if line [ index ... index + delim . length ] == delim @state [ :in_string ] = nil index += delim . length break else index += 1 end end else index += 1 end end return index end
Parses a line starting at the given index under the assumption that the start index is inside a
string.
Parses a line starting at the given index under the assumption that the start index is inside a string .
# The delimiter that would end the current string # We have encountered the string's delimiter character. Check whether the user has escaped it # It was escaped, so simply advance one character # It was not escaped. Check whether we have as many delimiting characters as we need # We have indeed reached the end of the string # We have not reached the end of the string yet. Advance to the next character # Advance a character
line
start_index