Fix strange regression in inlinefunc. Resolve #1307.
This commit is contained in:
parent
a7d7917995
commit
ef95726be6
1 changed files with 55 additions and 55 deletions
|
|
@ -283,64 +283,64 @@ def parse_inlinefunc(string, strip=False, **kwargs):
|
||||||
# no cached stack; build a new stack and continue
|
# no cached stack; build a new stack and continue
|
||||||
stack = ParseStack()
|
stack = ParseStack()
|
||||||
|
|
||||||
# process string on stack
|
# process string on stack
|
||||||
ncallable = 0
|
ncallable = 0
|
||||||
for match in _RE_TOKEN.finditer(string):
|
for match in _RE_TOKEN.finditer(string):
|
||||||
gdict = match.groupdict()
|
gdict = match.groupdict()
|
||||||
if gdict["singlequote"]:
|
if gdict["singlequote"]:
|
||||||
stack.append(gdict["singlequote"])
|
stack.append(gdict["singlequote"])
|
||||||
elif gdict["doublequote"]:
|
elif gdict["doublequote"]:
|
||||||
stack.append(gdict["doublequote"])
|
stack.append(gdict["doublequote"])
|
||||||
elif gdict["end"]:
|
elif gdict["end"]:
|
||||||
if ncallable <= 0:
|
if ncallable <= 0:
|
||||||
stack.append(")")
|
stack.append(")")
|
||||||
continue
|
continue
|
||||||
args = []
|
args = []
|
||||||
while stack:
|
while stack:
|
||||||
operation = stack.pop()
|
operation = stack.pop()
|
||||||
if callable(operation):
|
if callable(operation):
|
||||||
if not strip:
|
if not strip:
|
||||||
stack.append((operation, [arg for arg in reversed(args)]))
|
stack.append((operation, [arg for arg in reversed(args)]))
|
||||||
ncallable -= 1
|
ncallable -= 1
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
args.append(operation)
|
||||||
|
elif gdict["start"]:
|
||||||
|
funcname = _RE_STARTTOKEN.match(gdict["start"]).group(1)
|
||||||
|
try:
|
||||||
|
# try to fetch the matching inlinefunc from storage
|
||||||
|
stack.append(_INLINE_FUNCS[funcname])
|
||||||
|
except KeyError:
|
||||||
|
stack.append(_INLINE_FUNCS["nomatch"])
|
||||||
|
stack.append(funcname)
|
||||||
|
ncallable += 1
|
||||||
|
elif gdict["escaped"]:
|
||||||
|
# escaped tokens
|
||||||
|
token = gdict["escaped"].lstrip("\\")
|
||||||
|
stack.append(token)
|
||||||
|
elif gdict["comma"]:
|
||||||
|
if ncallable > 0:
|
||||||
|
# commas outside strings and inside a callable are
|
||||||
|
# used to mark argument separation - we use None
|
||||||
|
# in the stack to indicate such a separation.
|
||||||
|
stack.append(None)
|
||||||
else:
|
else:
|
||||||
args.append(operation)
|
# no callable active - just a string
|
||||||
elif gdict["start"]:
|
stack.append(",")
|
||||||
funcname = _RE_STARTTOKEN.match(gdict["start"]).group(1)
|
|
||||||
try:
|
|
||||||
# try to fetch the matching inlinefunc from storage
|
|
||||||
stack.append(_INLINE_FUNCS[funcname])
|
|
||||||
except KeyError:
|
|
||||||
stack.append(_INLINE_FUNCS["nomatch"])
|
|
||||||
stack.append(funcname)
|
|
||||||
ncallable += 1
|
|
||||||
elif gdict["escaped"]:
|
|
||||||
# escaped tokens
|
|
||||||
token = gdict["escaped"].lstrip("\\")
|
|
||||||
stack.append(token)
|
|
||||||
elif gdict["comma"]:
|
|
||||||
if ncallable > 0:
|
|
||||||
# commas outside strings and inside a callable are
|
|
||||||
# used to mark argument separation - we use None
|
|
||||||
# in the stack to indicate such a separation.
|
|
||||||
stack.append(None)
|
|
||||||
else:
|
else:
|
||||||
# no callable active - just a string
|
# the rest
|
||||||
stack.append(",")
|
stack.append(gdict["rest"])
|
||||||
|
|
||||||
|
if ncallable > 0:
|
||||||
|
# this means not all inlinefuncs were complete
|
||||||
|
return string
|
||||||
|
|
||||||
|
if _STACK_MAXSIZE > 0 and _STACK_MAXSIZE < len(stack):
|
||||||
|
# if stack is larger than limit, throw away parsing
|
||||||
|
return string + gdict["stackfull"](*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
# the rest
|
# cache the stack
|
||||||
stack.append(gdict["rest"])
|
_PARSING_CACHE[string] = stack
|
||||||
|
|
||||||
if ncallable > 0:
|
|
||||||
# this means not all inlinefuncs were complete
|
|
||||||
return string
|
|
||||||
|
|
||||||
if _STACK_MAXSIZE > 0 and _STACK_MAXSIZE < len(stack):
|
|
||||||
# if stack is larger than limit, throw away parsing
|
|
||||||
return string + gdict["stackfull"](*args, **kwargs)
|
|
||||||
else:
|
|
||||||
# cache the stack
|
|
||||||
_PARSING_CACHE[string] = stack
|
|
||||||
|
|
||||||
# run the stack recursively
|
# run the stack recursively
|
||||||
def _run_stack(item, depth=0):
|
def _run_stack(item, depth=0):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue