Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
b878620d
Commit
b878620d
authored
Dec 09, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bison import, code cleanup and applied pep8.
parent
df45f247
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
21 deletions
+19
-21
external/graph_drawing
external/graph_drawing
+1
-1
external/pybison
external/pybison
+1
-1
src/calc.py
src/calc.py
+3
-3
src/parser.py
src/parser.py
+11
-12
tests/test_exception.py
tests/test_exception.py
+2
-3
tests/test_variables.py
tests/test_variables.py
+1
-1
No files found.
graph_drawing
@
a34e4894
Subproject commit
ec0a7e59d3251d1e11d2efc877a77f236a7885b5
Subproject commit
a34e48940a4eab2d44db8bdc61ff56648e2e087e
pybison
@
1bd7873d
Subproject commit
d83b7274f5a331c7c5611974c9576495d929c2
34
Subproject commit
1bd7873dfad2fabac51fab8ed978374502f090
34
src/calc.py
View file @
b878620d
...
...
@@ -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
py
bison
import
BisonParser
class
Parser
(
BisonParser
):
"""
...
...
src/parser.py
View file @
b878620d
...
...
@@ -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
,
Parser
SyntaxError
from
pybison
import
BisonParser
,
Bison
SyntaxError
# 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
Parser
SyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
raise
Bison
SyntaxError
(
'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
Parser
SyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
raise
Bison
SyntaxError
(
'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
Parser
SyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
raise
Bison
SyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# -----------------------------------------
# raw lex script, verbatim here
...
...
tests/test_exception.py
View file @
b878620d
...
...
@@ -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
tests/test_variables.py
View file @
b878620d
...
...
@@ -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):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment