def run(self, sql, encoding=None): stream = lexer.tokenize(sql, encoding) # Process token stream if self.preprocess: for filter_ in self.preprocess: stream = filter_.process(self, stream) if (self.stmtprocess or self.postprocess or self.split_statements or self._grouping): splitter = StatementFilter() stream = splitter.process(self, stream) if self._grouping: def _group(stream): for stmt in stream: grouping.group(stmt) yield stmt stream = _group(stream) if self.stmtprocess: def _run1(stream): ret = [] for stmt in stream: for filter_ in self.stmtprocess: filter_.process(self, stmt) ret.append(stmt) return ret stream = _run1(stream) if self.postprocess: def _run2(stream): for stmt in stream: stmt.tokens = list(self._flatten(stmt.tokens)) for filter_ in self.postprocess: stmt = filter_.process(self, stmt) yield stmt stream = _run2(stream) return stream
def split2(stream): splitter = StatementFilter() return list(splitter.process(None, stream))