Procházet zdrojové kódy

Merge branch 'master' of kompiler.org:trs

Taddeus Kroes před 14 roky
rodič
revize
fc77458239
6 změnil soubory, kde provedl 28 přidání a 8 odebrání
  1. 1 1
      external/graph_drawing
  2. 1 1
      external/pybison
  3. 1 0
      external/rules.mk
  4. 8 5
      src/parser.py
  5. 1 1
      tests/parser.py
  6. 16 0
      tests/test_exception.py

+ 1 - 1
external/graph_drawing

@@ -1 +1 @@
-Subproject commit 45bee0e4fe53619176d85fc0bc5ae3b40d99716d
+Subproject commit ec0a7e59d3251d1e11d2efc877a77f236a7885b5

+ 1 - 1
external/pybison

@@ -1 +1 @@
-Subproject commit 260359e31ceeaa46d26a26303e08cda37c7578f5
+Subproject commit d83b7274f5a331c7c5611974c9576495d929c234

+ 1 - 0
external/rules.mk

@@ -28,4 +28,5 @@ endif
 
 
 $(b)pybison/%.c: $(d)pybison/src/pyrex/%.pyx
 $(b)pybison/%.c: $(d)pybison/src/pyrex/%.pyx
 	$(py2c) -o $@ $<
 	$(py2c) -o $@ $<
+	$(RM) $(@D)/*.so
 
 

+ 8 - 5
src/parser.py

@@ -63,6 +63,9 @@ class Parser(BisonParser):
     # override default read method with a version that prompts for input
     # override default read method with a version that prompts for input
     # ------------------------------------------------------------------
     # ------------------------------------------------------------------
     def read(self, nbytes):
     def read(self, nbytes):
+        if self.file == sys.stdin and self.file.closed:
+            return ''
+
         try:
         try:
             return raw_input('>>> ') + '\n'
             return raw_input('>>> ') + '\n'
         except EOFError:
         except EOFError:
@@ -187,24 +190,24 @@ class Parser(BisonParser):
         """
         """
 
 
         if option in [0, 1]:  # rule: exp IDENTIFIER | exp NUMBER
         if option in [0, 1]:  # rule: exp IDENTIFIER | exp NUMBER
-            # NOTE: xy -> x*y
-            # NOTE: (x)4 -> x*4
+            # example: xy -> x*y
+            # example: (x)4 -> x*4
             val = int(values[1]) if option == 1 else values[1]
             val = int(values[1]) if option == 1 else values[1]
             return Node('*', *(combine('*', values[0]) + [Leaf(val)]))
             return Node('*', *(combine('*', values[0]) + [Leaf(val)]))
 
 
         if option == 2:  # rule: exp LPAREN exp RPAREN
         if option == 2:  # rule: exp LPAREN exp RPAREN
-            # NOTE: x(y) -> x*(y)
+            # example: x(y) -> x*(y)
             return Node('*', *(combine('*', values[0])
             return Node('*', *(combine('*', values[0])
                               + combine('*', values[2])))
                               + combine('*', values[2])))
 
 
         if option == 3:
         if option == 3:
-            # NOTE: x4 -> x^4
+            # example: xy4 -> x*y^4
             identifier, exponent = list(values[1])
             identifier, exponent = list(values[1])
             node = Node('^', Leaf(identifier), Leaf(int(exponent)))
             node = Node('^', Leaf(identifier), Leaf(int(exponent)))
             return Node('*', values[0], node)
             return Node('*', values[0], node)
 
 
         if option == 4:
         if option == 4:
-            # NOTE: x4 -> x^4
+            # example: x4 -> x^4
             identifier, exponent = list(values[0])
             identifier, exponent = list(values[0])
             return Node('^', Leaf(identifier), Leaf(int(exponent)))
             return Node('^', Leaf(identifier), Leaf(int(exponent)))
 
 

+ 1 - 1
tests/parser.py

@@ -83,7 +83,7 @@ def run_expressions(base_class, expressions, keepfiles=1, fail=True,
         try:
         try:
             res = parser.run([exp])
             res = parser.run([exp])
             assert res == out
             assert res == out
-        except:
+        except:  # pragma: nocover
             if not silent:
             if not silent:
                 print >>sys.stderr, 'error: %s = %s, but expected: %s' \
                 print >>sys.stderr, 'error: %s = %s, but expected: %s' \
                                     % (exp, str(res), str(out))
                                     % (exp, str(res), str(out))

+ 16 - 0
tests/test_exception.py

@@ -0,0 +1,16 @@
+# vim: set fileencoding=utf-8 :
+import unittest
+
+from src.parser import Parser
+from tests.parser import ParserWrapper, run_expressions
+
+
+class TestException(unittest.TestCase):
+    def test_raise(self):
+        try:
+            ParserWrapper(Parser).run(['raise'])
+        except RuntimeError:
+            return
+
+        # pragma: nocover
+        raise AssertionError('Expected a raised RuntimeError!')