Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
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
trs
Commits
358e632e
Commit
358e632e
authored
12 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Moved n-ary operator definition to a constant list.
parent
dfd85838
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
src/node.py
+5
-2
5 additions, 2 deletions
src/node.py
src/strategy.py
+3
-2
3 additions, 2 deletions
src/strategy.py
with
8 additions
and
4 deletions
src/node.py
+
5
−
2
View file @
358e632e
...
...
@@ -31,6 +31,9 @@ OP_SUBSCRIPT = 8
OP_AND
=
9
OP_OR
=
10
# Binary operators that are considered n-ary
NARY_OPERATORS
=
[
OP_ADD
,
OP_SUB
,
OP_MUL
]
# N-ary (functions)
OP_INT
=
11
OP_INT_INDEF
=
12
...
...
@@ -200,7 +203,7 @@ class ExpressionBase(object):
return
exponent
==
None
or
self
[
1
]
==
exponent
def
is_nary
(
self
):
return
not
self
.
is_leaf
and
self
.
op
in
[
OP_ADD
,
OP_SUB
,
OP_MUL
]
return
not
self
.
is_leaf
and
self
.
op
in
NARY_OPERATORS
def
is_identifier
(
self
,
identifier
=
None
):
return
self
.
type
==
TYPE_IDENTIFIER
\
...
...
@@ -457,7 +460,7 @@ class ExpressionNode(Node, ExpressionBase):
if
not
isinstance
(
other
,
ExpressionNode
)
or
other
.
op
!=
self
.
op
:
return
False
if
self
.
op
in
(
OP_ADD
,
OP_MUL
)
:
if
self
.
op
in
NARY_OPERATORS
:
s0
=
Scope
(
self
)
s1
=
set
(
Scope
(
other
))
...
...
This diff is collapsed.
Click to expand it.
src/strategy.py
+
3
−
2
View file @
358e632e
from
node
import
OP_NEG
from
node
import
OP_NEG
,
NARY_OPERATORS
from
rules
import
RULES
from
rules.precedences
import
HIGH
,
LOW
,
RELATIVE
...
...
@@ -70,7 +70,8 @@ def depth_possibilities(node, depth=0, parent_op=None):
# Add operator-specific handlers. Prevent duplicate possibilities in
# n-ary nodes by only executing the handlers on the outermost node of
# related nodes with the same operator
if
node
.
op
!=
parent_op
and
node
.
op
in
RULES
:
if
node
.
op
in
RULES
and
(
node
.
op
!=
parent_op
\
or
node
.
op
not
in
NARY_OPERATORS
):
handlers
+=
RULES
[
node
.
op
]
# Add negation handlers after operator-specific handlers to obtain an
...
...
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