]> git.phdru.name Git - sqlconvert.git/commitdiff
Do not test statements in StatementGrouper
authorOleg Broytman <phd@phdru.name>
Sun, 25 Sep 2016 01:36:23 +0000 (04:36 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 25 Sep 2016 01:36:23 +0000 (04:36 +0300)
StatementGrouper simply raises StopIteration if there are no statements.

demo/demo-group.py
demo/demo-process.py
scripts/mysql2sql
sqlconvert/process_tokens.py

index 888cb9749339af20dc9567dcb7931590b112b193..00daf43c97468ac02c7e366056ab6ba5a4d84e59 100755 (executable)
@@ -10,14 +10,13 @@ def group_lines(*lines):
     grouper = StatementGrouper(encoding='utf-8')
     for line in lines:
         grouper.process_line(line)
-        if grouper.statements:
-            for statement in grouper.get_statements():
-                print("----- -----")
-                if find_error(statement):
-                    print("ERRORS IN QUERY")
-                print_tokens(statement, encoding='utf-8')
-                print()
-                statement._pprint_tree()
+        for statement in grouper.get_statements():
+            print("----- -----")
+            if find_error(statement):
+                print("ERRORS IN QUERY")
+            print_tokens(statement, encoding='utf-8')
+            print()
+            statement._pprint_tree()
             print("-----/-----")
     tokens = grouper.close()
     if tokens:
index 8d3ee5d686d84b000083e868fc17c98110b4c532..2c93338c8e454064cb3b8d4747d0c5d38ea5bce9 100755 (executable)
@@ -11,15 +11,14 @@ def process_lines(*lines):
     grouper = StatementGrouper(encoding='utf-8')
     for line in lines:
         grouper.process_line(line)
-        if grouper.statements:
-            for statement in grouper.get_statements():
-                print("----- -----")
-                if find_error(statement):
-                    print("ERRORS IN QUERY")
-                process_statement(statement)
-                print_tokens(statement, encoding='utf-8')
-                print()
-                statement._pprint_tree()
+        for statement in grouper.get_statements():
+            print("----- -----")
+            if find_error(statement):
+                print("ERRORS IN QUERY")
+            process_statement(statement)
+            print_tokens(statement, encoding='utf-8')
+            print()
+            statement._pprint_tree()
             print("-----/-----")
     tokens = grouper.close()
     if tokens:
index 98c5f10e6eeee216120facaa3b53250ab47decdb..112130ea398c707878d6e78e16088a8e6a3628ba 100755 (executable)
@@ -48,18 +48,17 @@ def main(infile, encoding, outfile, output_encoding, use_pbar):
                 cur_pos += len(line)
             pbar.display(cur_pos)
         grouper.process_line(line)
-        if grouper.statements:
-            for statement in grouper.get_statements():
-                if got_directive and is_newline_statement(statement):
-                    # Condense a sequence of newlines after a /*! directive */;
-                    got_directive = False
-                    continue
-                got_directive = is_directive_statement(statement)
-                if got_directive:
-                    continue
-                process_statement(statement)
-                print_tokens(statement, outfile=outfile,
-                             encoding=output_encoding)
+        for statement in grouper.get_statements():
+            if got_directive and is_newline_statement(statement):
+                # Condense a sequence of newlines after a /*! directive */;
+                got_directive = False
+                continue
+            got_directive = is_directive_statement(statement)
+            if got_directive:
+                continue
+            process_statement(statement)
+            print_tokens(statement, outfile=outfile,
+                         encoding=output_encoding)
     tokens = grouper.close()
     if tokens:
         for token in tokens:
index 924ba4abd7ce2f00c8b5ecb477a081c023cc674d..b1c26022f7ad2adbecaf943fee47cd74c7794a7d 100644 (file)
@@ -54,6 +54,7 @@ class StatementGrouper(object):
         for stmt in self.statements:
             yield stmt
         self.statements = []
+        raise StopIteration
 
     def close(self):
         if not self.lines: