Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lbp = 0
def __init__(self, id, expression, advance, value):
super(LiteralToken, self).__init__(id, expression, advance)
self.value = value
def nud(self):
return ConstantExpression(self.value)
class NameToken(BaseToken):
def __init__(self, id, expression, advance, value):
super(NameToken, self).__init__(id, expression, advance)
self.value = value
def nud(self):
return NameExpression(self.value)
class OperatorAddToken(BaseToken):
lbp = 110
def led(self, left):
return BinaryExpression(BinaryExpression.Add, left, self.expression(self.lbp))
class OperatorSubToken(BaseToken):
lbp = 110
def nud(self):
return UnaryExpression(UnaryExpression.Negate, self.expression(self.lbp+20))
def led(self, left):
return BinaryExpression(BinaryExpression.Subtract, left, self.expression(self.lbp))
class OperatorMulToken(BaseToken):
lbp = 120
def led(self, left):
return BinaryExpression(BinaryExpression.Multiply, left, self.expression(self.lbp))
def nud(self):
return UnaryExpression(UnaryExpression.Negate, self.expression(self.lbp+20))
def led(self, left):
return BinaryExpression(BinaryExpression.Subtract, left, self.expression(self.lbp))
class OperatorMulToken(BaseToken):
lbp = 120
def led(self, left):
return BinaryExpression(BinaryExpression.Multiply, left, self.expression(self.lbp))
class OperatorDivToken(BaseToken):
lbp = 120
def led(self, left):
return BinaryExpression(BinaryExpression.Divide, left, self.expression(self.lbp))
class OperatorModToken(BaseToken):
lbp = 130
def led(self, left):
return BinaryExpression(BinaryExpression.Modulo, left, self.expression(self.lbp))
class OperatorPowerToken(BaseToken):
lbp = 140
def led(self, left):
return BinaryExpression(BinaryExpression.Power, left, self.expression(self.lbp-1))
class OperatorAndToken(BaseToken):
lbp = 40
def led(self, left):
return BinaryExpression(BinaryExpression.And, left, self.expression(self.lbp-1))
class OperatorOrToken(BaseToken):
lbp = 30
class OperatorGreaterThanToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThan, left, self.expression(self.lbp))
class OperatorGreaterThanOrEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThanOrEqual, left, self.expression(self.lbp))
class OperatorLessThanToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.LessThan, left, self.expression(self.lbp))
class OperatorLessThanOrEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.LessThanOrEqual, left, self.expression(self.lbp))
class OperatorNotToken(BaseToken):
lbp = 60
def nud(self):
return UnaryExpression(UnaryExpression.Not, self.expression(self.lbp))
class DotToken(BaseToken):
global token
lbp = 150
def led(self, left):
first = left
second = token
if not isinstance(second, NameToken):
class OperatorPowerToken(BaseToken):
lbp = 140
def led(self, left):
return BinaryExpression(BinaryExpression.Power, left, self.expression(self.lbp-1))
class OperatorAndToken(BaseToken):
lbp = 40
def led(self, left):
return BinaryExpression(BinaryExpression.And, left, self.expression(self.lbp-1))
class OperatorOrToken(BaseToken):
lbp = 30
def led(self, left):
return BinaryExpression(BinaryExpression.Or, left, self.expression(self.lbp-1))
class OperatorEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.Equal, left, self.expression(self.lbp))
class OperatorNotEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.NotEqual, left, self.expression(self.lbp))
class OperatorGreaterThanToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThan, left, self.expression(self.lbp))
class OperatorGreaterThanOrEqualToken(BaseToken):
lbp = 60
if t[0] == tokenize.NAME and t[1] in special_operators:
yield type_map[tokenize.OP], t[1]
else:
yield type_map[t[0]], t[1]
except KeyError:
if t[0] == tokenize.ENDMARKER:
break
yield "(end)", "(end)"
class BaseToken(object):
def __init__(self, id, expression, advance):
self.id = id
self.expression = expression
self.advance = advance
class LiteralToken(BaseToken):
lbp = 0
def __init__(self, id, expression, advance, value):
super(LiteralToken, self).__init__(id, expression, advance)
self.value = value
def nud(self):
return ConstantExpression(self.value)
class NameToken(BaseToken):
def __init__(self, id, expression, advance, value):
super(NameToken, self).__init__(id, expression, advance)
self.value = value
def nud(self):
return NameExpression(self.value)
class OperatorAddToken(BaseToken):
def nud(self):
return NameExpression(self.value)
class OperatorAddToken(BaseToken):
lbp = 110
def led(self, left):
return BinaryExpression(BinaryExpression.Add, left, self.expression(self.lbp))
class OperatorSubToken(BaseToken):
lbp = 110
def nud(self):
return UnaryExpression(UnaryExpression.Negate, self.expression(self.lbp+20))
def led(self, left):
return BinaryExpression(BinaryExpression.Subtract, left, self.expression(self.lbp))
class OperatorMulToken(BaseToken):
lbp = 120
def led(self, left):
return BinaryExpression(BinaryExpression.Multiply, left, self.expression(self.lbp))
class OperatorDivToken(BaseToken):
lbp = 120
def led(self, left):
return BinaryExpression(BinaryExpression.Divide, left, self.expression(self.lbp))
class OperatorModToken(BaseToken):
lbp = 130
def led(self, left):
return BinaryExpression(BinaryExpression.Modulo, left, self.expression(self.lbp))
class OperatorPowerToken(BaseToken):
lbp = 140
class OperatorGreaterThanOrEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThanOrEqual, left, self.expression(self.lbp))
class OperatorLessThanToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.LessThan, left, self.expression(self.lbp))
class OperatorLessThanOrEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.LessThanOrEqual, left, self.expression(self.lbp))
class OperatorNotToken(BaseToken):
lbp = 60
def nud(self):
return UnaryExpression(UnaryExpression.Not, self.expression(self.lbp))
class DotToken(BaseToken):
global token
lbp = 150
def led(self, left):
first = left
second = token
if not isinstance(second, NameToken):
error = u"Each part of a given get attribute expression (some.variable.value) needs to be a NameExpression."
raise ValueError(error)
second = NameExpression(second.value)
self.advance()
class OperatorAndToken(BaseToken):
lbp = 40
def led(self, left):
return BinaryExpression(BinaryExpression.And, left, self.expression(self.lbp-1))
class OperatorOrToken(BaseToken):
lbp = 30
def led(self, left):
return BinaryExpression(BinaryExpression.Or, left, self.expression(self.lbp-1))
class OperatorEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.Equal, left, self.expression(self.lbp))
class OperatorNotEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.NotEqual, left, self.expression(self.lbp))
class OperatorGreaterThanToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThan, left, self.expression(self.lbp))
class OperatorGreaterThanOrEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThanOrEqual, left, self.expression(self.lbp))
class OperatorLessThanToken(BaseToken):
lbp = 60
class OperatorNotEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.NotEqual, left, self.expression(self.lbp))
class OperatorGreaterThanToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThan, left, self.expression(self.lbp))
class OperatorGreaterThanOrEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.GreaterThanOrEqual, left, self.expression(self.lbp))
class OperatorLessThanToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.LessThan, left, self.expression(self.lbp))
class OperatorLessThanOrEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.LessThanOrEqual, left, self.expression(self.lbp))
class OperatorNotToken(BaseToken):
lbp = 60
def nud(self):
return UnaryExpression(UnaryExpression.Not, self.expression(self.lbp))
class DotToken(BaseToken):
global token
class OperatorDivToken(BaseToken):
lbp = 120
def led(self, left):
return BinaryExpression(BinaryExpression.Divide, left, self.expression(self.lbp))
class OperatorModToken(BaseToken):
lbp = 130
def led(self, left):
return BinaryExpression(BinaryExpression.Modulo, left, self.expression(self.lbp))
class OperatorPowerToken(BaseToken):
lbp = 140
def led(self, left):
return BinaryExpression(BinaryExpression.Power, left, self.expression(self.lbp-1))
class OperatorAndToken(BaseToken):
lbp = 40
def led(self, left):
return BinaryExpression(BinaryExpression.And, left, self.expression(self.lbp-1))
class OperatorOrToken(BaseToken):
lbp = 30
def led(self, left):
return BinaryExpression(BinaryExpression.Or, left, self.expression(self.lbp-1))
class OperatorEqualToken(BaseToken):
lbp = 60
def led(self, left):
return BinaryExpression(BinaryExpression.Equal, left, self.expression(self.lbp))
class OperatorNotEqualToken(BaseToken):
lbp = 60