Commits

Maciej Fijalkowski committed 498d5cb

multiple statements

  • Participants
  • Parent commits 0152866

Comments (0)

Files changed (2)

File kermit/sourceparser.py

     to something easier to work with
     """
     def visit_main(self, node):
-        return Block([self.visit_stmt(node.children[0].children[0])])
+        star = node.children[0]
+        stmts = []
+        while len(star.children) == 2:
+            stmts.append(self.visit_stmt(star.children[0]))
+            star = star.children[1]
+        stmts.append(self.visit_stmt(star.children[0]))
+        return Block(stmts)
 
     def visit_stmt(self, node):
         return Stmt(self.visit_expr(node.children[0]))

File kermit/test/test_parser.py

     assert parse('1 + a;') == Block([Stmt(BinOp('+', ConstantInt(1),
                                                 Variable('a')))])
 
+def test_multiple_statements():
+    assert parse('''
+    1 + 2;
+    c;
+    e;
+    ''') == Block([Stmt(BinOp("+", ConstantInt(1), ConstantInt(2))),
+                   Stmt(Variable('c')),
+                   Stmt(Variable('e'))])