测试gitnore
This commit is contained in:
@@ -13,7 +13,6 @@ class TokenBase:
|
||||
Base class for operators and literals, mainly for debugging and for throwing
|
||||
syntax errors.
|
||||
"""
|
||||
|
||||
id = None # node/token type name
|
||||
value = None # used by literals
|
||||
first = second = None # used by tree nodes
|
||||
@@ -46,7 +45,6 @@ def infix(bp, func):
|
||||
Create an infix operator, given a binding power and a function that
|
||||
evaluates the node.
|
||||
"""
|
||||
|
||||
class Operator(TokenBase):
|
||||
lbp = bp
|
||||
|
||||
@@ -72,7 +70,6 @@ def prefix(bp, func):
|
||||
Create a prefix operator, given a binding power and a function that
|
||||
evaluates the node.
|
||||
"""
|
||||
|
||||
class Operator(TokenBase):
|
||||
lbp = bp
|
||||
|
||||
@@ -94,19 +91,19 @@ def prefix(bp, func):
|
||||
# We defer variable evaluation to the lambda to ensure that terms are
|
||||
# lazily evaluated using Python's boolean parsing logic.
|
||||
OPERATORS = {
|
||||
"or": infix(6, lambda context, x, y: x.eval(context) or y.eval(context)),
|
||||
"and": infix(7, lambda context, x, y: x.eval(context) and y.eval(context)),
|
||||
"not": prefix(8, lambda context, x: not x.eval(context)),
|
||||
"in": infix(9, lambda context, x, y: x.eval(context) in y.eval(context)),
|
||||
"not in": infix(9, lambda context, x, y: x.eval(context) not in y.eval(context)),
|
||||
"is": infix(10, lambda context, x, y: x.eval(context) is y.eval(context)),
|
||||
"is not": infix(10, lambda context, x, y: x.eval(context) is not y.eval(context)),
|
||||
"==": infix(10, lambda context, x, y: x.eval(context) == y.eval(context)),
|
||||
"!=": infix(10, lambda context, x, y: x.eval(context) != y.eval(context)),
|
||||
">": infix(10, lambda context, x, y: x.eval(context) > y.eval(context)),
|
||||
">=": infix(10, lambda context, x, y: x.eval(context) >= y.eval(context)),
|
||||
"<": infix(10, lambda context, x, y: x.eval(context) < y.eval(context)),
|
||||
"<=": infix(10, lambda context, x, y: x.eval(context) <= y.eval(context)),
|
||||
'or': infix(6, lambda context, x, y: x.eval(context) or y.eval(context)),
|
||||
'and': infix(7, lambda context, x, y: x.eval(context) and y.eval(context)),
|
||||
'not': prefix(8, lambda context, x: not x.eval(context)),
|
||||
'in': infix(9, lambda context, x, y: x.eval(context) in y.eval(context)),
|
||||
'not in': infix(9, lambda context, x, y: x.eval(context) not in y.eval(context)),
|
||||
'is': infix(10, lambda context, x, y: x.eval(context) is y.eval(context)),
|
||||
'is not': infix(10, lambda context, x, y: x.eval(context) is not y.eval(context)),
|
||||
'==': infix(10, lambda context, x, y: x.eval(context) == y.eval(context)),
|
||||
'!=': infix(10, lambda context, x, y: x.eval(context) != y.eval(context)),
|
||||
'>': infix(10, lambda context, x, y: x.eval(context) > y.eval(context)),
|
||||
'>=': infix(10, lambda context, x, y: x.eval(context) >= y.eval(context)),
|
||||
'<': infix(10, lambda context, x, y: x.eval(context) < y.eval(context)),
|
||||
'<=': infix(10, lambda context, x, y: x.eval(context) <= y.eval(context)),
|
||||
}
|
||||
|
||||
# Assign 'id' to each:
|
||||
@@ -118,7 +115,6 @@ class Literal(TokenBase):
|
||||
"""
|
||||
A basic self-resolvable object similar to a Django template variable.
|
||||
"""
|
||||
|
||||
# IfParser uses Literal in create_var, but TemplateIfParser overrides
|
||||
# create_var so that a proper implementation that actually resolves
|
||||
# variables, filters etc. is used.
|
||||
@@ -194,9 +190,8 @@ class IfParser:
|
||||
retval = self.expression()
|
||||
# Check that we have exhausted all the tokens
|
||||
if self.current_token is not EndToken:
|
||||
raise self.error_class(
|
||||
"Unused '%s' at end of if expression." % self.current_token.display()
|
||||
)
|
||||
raise self.error_class("Unused '%s' at end of if expression." %
|
||||
self.current_token.display())
|
||||
return retval
|
||||
|
||||
def expression(self, rbp=0):
|
||||
|
||||
Reference in New Issue
Block a user