Fixed bison import, code cleanup and applied pep8.

parent df45f247
graph_drawing @ a34e4894
Subproject commit ec0a7e59d3251d1e11d2efc877a77f236a7885b5 Subproject commit a34e48940a4eab2d44db8bdc61ff56648e2e087e
pybison @ 1bd7873d
Subproject commit d83b7274f5a331c7c5611974c9576495d929c234 Subproject commit 1bd7873dfad2fabac51fab8ed978374502f09034
...@@ -8,13 +8,13 @@ from sympy import Symbol ...@@ -8,13 +8,13 @@ from sympy import Symbol
import os.path import os.path
PYBISON_BUILD = os.path.realpath('build/external/pybison') 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 import sys
sys.path.insert(0, PYBISON_BUILD) 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): class Parser(BisonParser):
""" """
......
...@@ -10,13 +10,13 @@ import argparse ...@@ -10,13 +10,13 @@ import argparse
import os.path import os.path
PYBISON_BUILD = os.path.realpath('build/external/pybison') 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 import sys
sys.path.insert(0, PYBISON_BUILD) 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 # Check for n-ary operator in child nodes
...@@ -135,7 +135,7 @@ class Parser(BisonParser): ...@@ -135,7 +135,7 @@ class Parser(BisonParser):
if option in [3, 4, 5]: # rule: unary | binary | concat if option in [3, 4, 5]: # rule: unary | binary | concat
return values[0] return values[0]
raise ParserSyntaxError('Unsupported option %d in target "%s".' raise BisonSyntaxError('Unsupported option %d in target "%s".'
% (option, target)) % (option, target))
def on_unary(self, target, option, names, values): def on_unary(self, target, option, names, values):
...@@ -146,7 +146,7 @@ class Parser(BisonParser): ...@@ -146,7 +146,7 @@ class Parser(BisonParser):
if option == 0: # rule: NEG exp if option == 0: # rule: NEG exp
return Node('-', values[1]) return Node('-', values[1])
raise ParserSyntaxError('Unsupported option %d in target "%s".' raise BisonSyntaxError('Unsupported option %d in target "%s".'
% (option, target)) % (option, target))
def on_binary(self, target, option, names, values): def on_binary(self, target, option, names, values):
...@@ -176,10 +176,9 @@ class Parser(BisonParser): ...@@ -176,10 +176,9 @@ class Parser(BisonParser):
if option == 4: # rule: exp POW exp if option == 4: # rule: exp POW exp
return Node('^', values[0], values[2]) return Node('^', values[0], values[2])
raise ParserSyntaxError('Unsupported option %d in target "%s".' raise BisonSyntaxError('Unsupported option %d in target "%s".'
% (option, target)) % (option, target))
def on_concat(self, option, target, names, values): def on_concat(self, option, target, names, values):
""" """
concat : exp IDENTIFIER concat : exp IDENTIFIER
...@@ -211,7 +210,7 @@ class Parser(BisonParser): ...@@ -211,7 +210,7 @@ class Parser(BisonParser):
identifier, exponent = list(values[0]) identifier, exponent = list(values[0])
return Node('^', Leaf(identifier), Leaf(int(exponent))) return Node('^', Leaf(identifier), Leaf(int(exponent)))
raise ParserSyntaxError('Unsupported option %d in target "%s".' raise BisonSyntaxError('Unsupported option %d in target "%s".'
% (option, target)) % (option, target))
# ----------------------------------------- # -----------------------------------------
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import unittest import unittest
from src.parser import Parser from src.parser import Parser
from tests.parser import ParserWrapper, run_expressions from tests.parser import ParserWrapper
class TestException(unittest.TestCase): class TestException(unittest.TestCase):
...@@ -12,5 +12,4 @@ class TestException(unittest.TestCase): ...@@ -12,5 +12,4 @@ class TestException(unittest.TestCase):
except RuntimeError: except RuntimeError:
return return
# pragma: nocover raise AssertionError('Expected raised RuntimeError!') # pragma: nocover
raise AssertionError('Expected a raised RuntimeError!')
...@@ -18,7 +18,7 @@ class TestVariables(unittest.TestCase): ...@@ -18,7 +18,7 @@ class TestVariables(unittest.TestCase):
def test_addition_of_two_terms(self): def test_addition_of_two_terms(self):
a, b = symbols('a,b') 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) run_expressions(Parser, expressions)
#def test_short_addition_of_two_terms(self): #def test_short_addition_of_two_terms(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment