Commit a746a9ad by Peter Baratta

Get rid of unused code

parent 83f1f9c2
...@@ -21,7 +21,7 @@ from pyparsing import (Word, nums, Literal, ...@@ -21,7 +21,7 @@ from pyparsing import (Word, nums, Literal,
ZeroOrMore, MatchFirst, ZeroOrMore, MatchFirst,
Optional, Forward, Optional, Forward,
CaselessLiteral, CaselessLiteral,
NoMatch, stringEnd, Suppress, Combine) stringEnd, Suppress, Combine)
DEFAULT_FUNCTIONS = {'sin': numpy.sin, DEFAULT_FUNCTIONS = {'sin': numpy.sin,
'cos': numpy.cos, 'cos': numpy.cos,
...@@ -258,31 +258,27 @@ def evaluator(variables, functions, string, cs=False): ...@@ -258,31 +258,27 @@ def evaluator(variables, functions, string, cs=False):
# Predefine recursive variables # Predefine recursive variables
expr = Forward() expr = Forward()
# Handle variables passed in. E.g. if we have {'R':0.5}, we make the substitution. # Handle variables passed in.
# Special case for no variables because of how we understand PyParsing is put together # E.g. if we have {'R':0.5}, we make the substitution.
if len(all_variables) > 0: # We sort the list so that var names (like "e2") match before
# We sort the list so that var names (like "e2") match before # mathematical constants (like "e"). This is kind of a hack.
# mathematical constants (like "e"). This is kind of a hack. all_variables_keys = sorted(all_variables.keys(), key=len, reverse=True)
all_variables_keys = sorted(all_variables.keys(), key=len, reverse=True) varnames = MatchFirst([CasedLiteral(k) for k in all_variables_keys])
varnames = MatchFirst([CasedLiteral(k) for k in all_variables_keys]) varnames.setParseAction(
varnames.setParseAction( lambda x: [all_variables[k] for k in x]
lambda x: [all_variables[k] for k in x] )
)
else: # if all_variables were empty, then pyparsing wants
# all_variables includes DEFAULT_VARIABLES, which isn't empty # varnames = NoMatch()
# this is unreachable. Get rid of it? # this is not the case, as all_variables contains the defaults
varnames = NoMatch()
# Same thing for functions. # Same thing for functions.
if len(all_functions) > 0: all_functions_keys = sorted(all_functions.keys(), key=len, reverse=True)
funcnames = MatchFirst([CasedLiteral(k) for k in all_functions.keys()]) funcnames = MatchFirst([CasedLiteral(k) for k in all_functions_keys])
function = funcnames + Suppress("(") + expr + Suppress(")") function = funcnames + Suppress("(") + expr + Suppress(")")
function.setParseAction( function.setParseAction(
lambda x: [all_functions[x[0]](x[1])] lambda x: [all_functions[x[0]](x[1])]
) )
else:
# see note above (this is unreachable)
function = NoMatch()
atom = number | function | varnames | Suppress("(") + expr + Suppress(")") atom = number | function | varnames | Suppress("(") + expr + Suppress(")")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment