Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
graph_drawing
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
graph_drawing
Commits
c8ecf708
Commit
c8ecf708
authored
Nov 17, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Multiplication sign is not omitted anymore for multiplication of equal identifiers
parent
0e6c5e55
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
line.py
line.py
+16
-12
tests/test_line.py
tests/test_line.py
+5
-0
No files found.
line.py
View file @
c8ecf708
...
...
@@ -173,6 +173,7 @@ def generate_line(root):
left
=
rightmost_node
(
left
)
# a * b -> ab
# a * a -> a * a
# a * 2 -> a * 2
# a * (b) -> a(b)
# (a) * b -> (a)b
...
...
@@ -181,18 +182,21 @@ def generate_line(root):
# a * sin(b) -> a sin(b)
left_char
=
content
[
left
][
-
1
]
right_char
=
content
[
right
][
0
]
left_paren
=
lparens
or
left_char
in
')]}'
right_paren
=
rparens
or
right_char
in
'([{'
right_alpha
=
right_char
.
isalpha
()
left_simple
=
is_id
(
left
)
or
is_int
(
left
)
if
left_paren
or
(
right_paren
and
left_simple
)
\
or
(
is_id
(
left
)
and
is_id
(
right
))
\
or
(
is_int
(
left
)
and
right_alpha
):
return
''
if
is_id
(
left
)
and
right_alpha
:
return
' '
if
lparens
or
rparens
or
left_char
!=
right_char
:
left_paren
=
lparens
or
left_char
in
')]}'
right_paren
=
rparens
or
right_char
in
'([{'
left_alpha
=
left_char
.
isalpha
()
right_alpha
=
right_char
.
isalpha
()
left_simple
=
is_id
(
left
)
or
is_int
(
left
)
if
left_paren
or
(
right_paren
and
left_simple
)
\
or
(
is_id
(
left
)
and
is_id
(
right
))
\
or
(
is_int
(
left
)
and
right_alpha
):
return
''
if
is_id
(
left
)
and
right_alpha
:
return
' '
return
' * '
...
...
tests/test_line.py
View file @
c8ecf708
...
...
@@ -138,6 +138,11 @@ class TestLine(unittest.TestCase):
mul
=
N
(
'*'
,
N
(
'*'
,
a
,
l2
),
b
)
self
.
assertEquals
(
generate_line
(
mul
),
'a * 2b'
)
mul
=
N
(
'*'
,
a
,
a
)
self
.
assertEquals
(
generate_line
(
mul
),
'a * a'
)
mul
=
N
(
'*'
,
N
(
'+'
,
a
,
b
),
N
(
'+'
,
b
,
a
))
self
.
assertEquals
(
generate_line
(
mul
),
'(a + b)(b + a)'
)
mul
=
-
N
(
'*'
,
N
(
'*'
,
a
,
b
),
c
)
self
.
assertEquals
(
generate_line
(
mul
),
'-abc'
)
mul
=
N
(
'*'
,
N
(
'*'
,
-
a
,
b
),
c
)
...
...
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