+ self.encoding = encoding
+
+ def process_line(self, line):
+ self.lines.append(line)
+ self.process_lines()
+
+ def process_lines(self):
+ statements = parse(''.join(self.lines), encoding=self.encoding)
+ last_stmt = statements[-1]
+ for i in xrange(len(last_stmt.tokens) - 1, 0, -1):
+ token = last_stmt.tokens[i]
+ if token.ttype in (Comment.Single, Comment.Multiline,
+ Newline, Whitespace):
+ continue
+ if token.ttype is Punctuation and token.value == ';':
+ break # The last statement is complete
+ # The last statement is still incomplete - wait for the next line
+ return
+ self.lines = []
+ self.statements = statements