After determining that raw_line is is not empty, I clean it up a bit, copy it to line and call _Parse().
while True:
if len(self.line) == 0:
# Read next line.
self.raw_line = self.file.readline()
if len(self.raw_line) == 0:
return False
# Remove trailing whitespace.
self.raw_line = self.raw_line.rstrip()
self.lineNumber = self.lineNumber + 1
# Convert tabs to spaces and remove leading whitespace.
self.line = self.raw_line.replace('\t', ' ').strip()
# Tokens are removed from self.line as they are parsed.
self._Parse()
if self.tokenType == None: # This happens if a line ends in a comment.
continue
return True
Parse() parses the next token on self.line and removes the token from self.line. When self.line becomes empty, it is time to read a new line from the file.
(Note that the two-stage line reading is so that I can print the entire source line in an error message if there is a parsing problem midway through the line.)
--Mark