Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
a746a9ad
Commit
a746a9ad
authored
Jun 10, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of unused code
parent
83f1f9c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
24 deletions
+20
-24
common/lib/calc/calc.py
+20
-24
No files found.
common/lib/calc/calc.py
View file @
a746a9ad
...
...
@@ -21,7 +21,7 @@ from pyparsing import (Word, nums, Literal,
ZeroOrMore
,
MatchFirst
,
Optional
,
Forward
,
CaselessLiteral
,
NoMatch
,
stringEnd
,
Suppress
,
Combine
)
stringEnd
,
Suppress
,
Combine
)
DEFAULT_FUNCTIONS
=
{
'sin'
:
numpy
.
sin
,
'cos'
:
numpy
.
cos
,
...
...
@@ -258,31 +258,27 @@ def evaluator(variables, functions, string, cs=False):
# Predefine recursive variables
expr
=
Forward
()
# Handle variables passed in. E.g. if we have {'R':0.5}, we make the substitution.
# Special case for no variables because of how we understand PyParsing is put together
if
len
(
all_variables
)
>
0
:
# We sort the list so that var names (like "e2") match before
# mathematical constants (like "e"). This is kind of a hack.
all_variables_keys
=
sorted
(
all_variables
.
keys
(),
key
=
len
,
reverse
=
True
)
varnames
=
MatchFirst
([
CasedLiteral
(
k
)
for
k
in
all_variables_keys
])
varnames
.
setParseAction
(
lambda
x
:
[
all_variables
[
k
]
for
k
in
x
]
)
else
:
# all_variables includes DEFAULT_VARIABLES, which isn't empty
# this is unreachable. Get rid of it?
varnames
=
NoMatch
()
# Handle variables passed in.
# E.g. if we have {'R':0.5}, we make the substitution.
# We sort the list so that var names (like "e2") match before
# mathematical constants (like "e"). This is kind of a hack.
all_variables_keys
=
sorted
(
all_variables
.
keys
(),
key
=
len
,
reverse
=
True
)
varnames
=
MatchFirst
([
CasedLiteral
(
k
)
for
k
in
all_variables_keys
])
varnames
.
setParseAction
(
lambda
x
:
[
all_variables
[
k
]
for
k
in
x
]
)
# if all_variables were empty, then pyparsing wants
# varnames = NoMatch()
# this is not the case, as all_variables contains the defaults
# Same thing for functions.
if
len
(
all_functions
)
>
0
:
funcnames
=
MatchFirst
([
CasedLiteral
(
k
)
for
k
in
all_functions
.
keys
()])
function
=
funcnames
+
Suppress
(
"("
)
+
expr
+
Suppress
(
")"
)
function
.
setParseAction
(
lambda
x
:
[
all_functions
[
x
[
0
]](
x
[
1
])]
)
else
:
# see note above (this is unreachable)
function
=
NoMatch
()
all_functions_keys
=
sorted
(
all_functions
.
keys
(),
key
=
len
,
reverse
=
True
)
funcnames
=
MatchFirst
([
CasedLiteral
(
k
)
for
k
in
all_functions_keys
])
function
=
funcnames
+
Suppress
(
"("
)
+
expr
+
Suppress
(
")"
)
function
.
setParseAction
(
lambda
x
:
[
all_functions
[
x
[
0
]](
x
[
1
])]
)
atom
=
number
|
function
|
varnames
|
Suppress
(
"("
)
+
expr
+
Suppress
(
")"
)
...
...
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