Skip to content

Commit

Permalink
changed the operator/function map to an instance variable
Browse files Browse the repository at this point in the history
should probably be moved to a configuration file or so
  • Loading branch information
dgorissen committed Feb 21, 2012
1 parent f7c68b5 commit a438fd1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/pycel/excelcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,22 @@ def emit(self,ast,context=None):
class OperatorNode(ASTNode):
def __init__(self,*args):
super(OperatorNode,self).__init__(*args)
def emit(self,ast,context=None):
xop = self.tvalue

# Get the arguments
args = self.children(ast)

# convert the operator to python equivalents
opmap = {
self.opmap = {
"^":"**",
"=":"==",
"&":"+",
"":"+" #union
}

def emit(self,ast,context=None):
xop = self.tvalue

op = opmap.get(xop,xop)
# Get the arguments
args = self.children(ast)

op = self.opmap.get(xop,xop)

if self.ttype == "operator-prefix":
return "-" + args[0].emit(ast,context=context)
Expand Down Expand Up @@ -252,22 +253,22 @@ class FunctionNode(ASTNode):
def __init__(self,*args):
super(FunctionNode,self).__init__(*args)
self.numargs = 0

def emit(self,ast,context=None):
xfun = self.tvalue.lower()
str = ''

# map excel functions onto their python equivalents, taking care to avoid name clashes
funmap = {
self.funmap = {
"ln":"xlog",
"min":"xmin",
"min":"xmin",
"max":"xmax",
"sum":"xsum",
"gammaln":"lgamma"
}

def emit(self,ast,context=None):
xfun = self.tvalue.lower()
str = ''

fun = funmap.get(xfun,xfun)
fun = self.funmap.get(xfun,xfun)

# Get the arguments
args = self.children(ast)
Expand Down

0 comments on commit a438fd1

Please sign in to comment.