فهرست منبع

Fixed bison import, code cleanup and applied pep8.

Sander Mathijs van Veen 14 سال پیش
والد
کامیت
b878620d47
6فایلهای تغییر یافته به همراه19 افزوده شده و 21 حذف شده
  1. 1 1
      external/graph_drawing
  2. 1 1
      external/pybison
  3. 3 3
      src/calc.py
  4. 11 12
      src/parser.py
  5. 2 3
      tests/test_exception.py
  6. 1 1
      tests/test_variables.py

+ 1 - 1
external/graph_drawing

@@ -1 +1 @@
-Subproject commit ec0a7e59d3251d1e11d2efc877a77f236a7885b5
+Subproject commit a34e48940a4eab2d44db8bdc61ff56648e2e087e

+ 1 - 1
external/pybison

@@ -1 +1 @@
-Subproject commit d83b7274f5a331c7c5611974c9576495d929c234
+Subproject commit 1bd7873dfad2fabac51fab8ed978374502f09034

+ 3 - 3
src/calc.py

@@ -8,13 +8,13 @@ from sympy import Symbol
 
 import os.path
 PYBISON_BUILD = os.path.realpath('build/external/pybison')
-PYBISON_PYREX = os.path.realpath('external/pybison/src/pyrex')
+EXTERNAL_MODS = os.path.realpath('external')
 
 import sys
 sys.path.insert(0, PYBISON_BUILD)
-sys.path.insert(1, PYBISON_PYREX)
+sys.path.insert(1, EXTERNAL_MODS)
 
-from bison import BisonParser
+from pybison import BisonParser
 
 class Parser(BisonParser):
     """

+ 11 - 12
src/parser.py

@@ -10,13 +10,13 @@ import argparse
 
 import os.path
 PYBISON_BUILD = os.path.realpath('build/external/pybison')
-PYBISON_PYREX = os.path.realpath('external/pybison/src/pyrex')
+EXTERNAL_MODS = os.path.realpath('external')
 
 import sys
 sys.path.insert(0, PYBISON_BUILD)
-sys.path.insert(1, PYBISON_PYREX)
+sys.path.insert(1, EXTERNAL_MODS)
 
-from bison import BisonParser, ParserSyntaxError
+from pybison import BisonParser, BisonSyntaxError
 
 
 # Check for n-ary operator in child nodes
@@ -135,8 +135,8 @@ class Parser(BisonParser):
         if option in [3, 4, 5]:  # rule: unary | binary | concat
             return values[0]
 
-        raise ParserSyntaxError('Unsupported option %d in target "%s".'
-                                % (option, target))
+        raise BisonSyntaxError('Unsupported option %d in target "%s".'
+                               % (option, target))
 
     def on_unary(self, target, option, names, values):
         """
@@ -146,8 +146,8 @@ class Parser(BisonParser):
         if option == 0:  # rule: NEG exp
             return Node('-', values[1])
 
-        raise ParserSyntaxError('Unsupported option %d in target "%s".'
-                                % (option, target))
+        raise BisonSyntaxError('Unsupported option %d in target "%s".'
+                               % (option, target))
 
     def on_binary(self, target, option, names, values):
         """
@@ -176,9 +176,8 @@ class Parser(BisonParser):
         if option == 4:  # rule: exp POW exp
             return Node('^', values[0], values[2])
 
-        raise ParserSyntaxError('Unsupported option %d in target "%s".'
-                                % (option, target))
-
+        raise BisonSyntaxError('Unsupported option %d in target "%s".'
+                               % (option, target))
 
     def on_concat(self, option, target, names, values):
         """
@@ -211,8 +210,8 @@ class Parser(BisonParser):
             identifier, exponent = list(values[0])
             return Node('^', Leaf(identifier), Leaf(int(exponent)))
 
-        raise ParserSyntaxError('Unsupported option %d in target "%s".'
-                                % (option, target))
+        raise BisonSyntaxError('Unsupported option %d in target "%s".'
+                               % (option, target))
 
     # -----------------------------------------
     # raw lex script, verbatim here

+ 2 - 3
tests/test_exception.py

@@ -2,7 +2,7 @@
 import unittest
 
 from src.parser import Parser
-from tests.parser import ParserWrapper, run_expressions
+from tests.parser import ParserWrapper
 
 
 class TestException(unittest.TestCase):
@@ -12,5 +12,4 @@ class TestException(unittest.TestCase):
         except RuntimeError:
             return
 
-        # pragma: nocover
-        raise AssertionError('Expected a raised RuntimeError!')
+        raise AssertionError('Expected raised RuntimeError!') # pragma: nocover

+ 1 - 1
tests/test_variables.py

@@ -18,7 +18,7 @@ class TestVariables(unittest.TestCase):
 
     def test_addition_of_two_terms(self):
         a, b = symbols('a,b')
-        expressions = [('4*a + 5*b', 4*a + 5*b)]
+        expressions = [('4*a + 5*b', 4 * a + 5 * b)]
         run_expressions(Parser, expressions)
 
     #def test_short_addition_of_two_terms(self):