1313
1414
1515class FilterStack (object ):
16-
1716 def __init__ (self ):
1817 self .preprocess = []
1918 self .stmtprocess = []
2019 self .postprocess = []
21- self .split_statements = False
2220 self ._grouping = False
2321
2422 def enable_grouping (self ):
@@ -27,42 +25,20 @@ def enable_grouping(self):
2725 def run (self , sql , encoding = None ):
2826 stream = lexer .tokenize (sql , encoding )
2927 # Process token stream
30- if self .preprocess :
31- for filter_ in self .preprocess :
32- stream = filter_ .process (stream )
33-
34- if (self .stmtprocess or self .postprocess or
35- self .split_statements or self ._grouping ):
36- splitter = StatementFilter ()
37- stream = splitter .process (stream )
38-
39- if self ._grouping :
40-
41- def _group (stream ):
42- for stmt in stream :
43- grouping .group (stmt )
44- yield stmt
45- stream = _group (stream )
28+ for filter_ in self .preprocess :
29+ stream = filter_ .process (stream )
4630
47- if self . stmtprocess :
31+ stream = StatementFilter (). process ( stream )
4832
49- def _run1 (stream ):
50- ret = []
51- for stmt in stream :
52- for filter_ in self .stmtprocess :
53- filter_ .process (stmt )
54- ret .append (stmt )
55- return ret
56- stream = _run1 (stream )
33+ # Output: Stream processed Statements
34+ for stmt in stream :
35+ if self ._grouping :
36+ stmt = grouping .group (stmt )
5737
58- if self .postprocess :
38+ for filter_ in self .stmtprocess :
39+ filter_ .process (stmt )
5940
60- def _run2 (stream ):
61- for stmt in stream :
62- stmt .tokens = list (stmt .flatten ())
63- for filter_ in self .postprocess :
64- stmt = filter_ .process (stmt )
65- yield stmt
66- stream = _run2 (stream )
41+ for filter_ in self .postprocess :
42+ stmt = filter_ .process (stmt )
6743
68- return stream
44+ yield stmt
0 commit comments