Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
graph_drawing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
graph_drawing
Commits
c8ecf708
Commit
c8ecf708
authored
12 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Multiplication sign is not omitted anymore for multiplication of equal identifiers
parent
0e6c5e55
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
line.py
+16
-12
16 additions, 12 deletions
line.py
tests/test_line.py
+5
-0
5 additions, 0 deletions
tests/test_line.py
with
21 additions
and
12 deletions
line.py
+
16
−
12
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
'
*
'
...
...
This diff is collapsed.
Click to expand it.
tests/test_line.py
+
5
−
0
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment