Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_fn_in_fn():
"""Test function declarations being impossible inside a function body."""
decl = emptyfn(emptyfn(""))
with raises(FailedParse):
parse_source(decl)
return self.nested.message
class FailedChoice(FailedParse):
@property
def message(self):
return 'no viable option'
class FailedLookahead(FailedParse):
@property
def message(self):
return 'failed lookahead'
class FailedLeftRecursion(FailedParse):
@property
def message(self):
return 'infinite left recursion'
class FailedExpectingEndOfText(FailedParse):
pass
return 'no viable option'
class FailedLookahead(FailedParse):
@property
def message(self):
return 'failed lookahead'
class FailedLeftRecursion(FailedParse):
@property
def message(self):
return 'infinite left recursion'
class FailedExpectingEndOfText(FailedParse):
pass
leading,
'\n'.join(reversed(self.stack))
)
class FailedToken(FailedParse):
def __init__(self, tokenizer, stack, token):
super().__init__(tokenizer, stack, token)
self.token = token
@property
def message(self):
return "expecting %s" % repr(self.token).lstrip('u')
class FailedPattern(FailedParse):
def __init__(self, tokenizer, stack, pattern):
super().__init__(tokenizer, stack, pattern)
self.pattern = pattern
@property
def message(self):
return "expecting /%s/" % self.pattern
class FailedRef(FailedParse):
def __init__(self, tokenizer, stack, name):
super().__init__(tokenizer, stack, name)
self.name = name
@property
def message(self):
self._push_ast()
try:
try:
self._next_token(ruleinfo)
ruleinfo.impl(self)
node = self._get_node(key.pos, ruleinfo)
node = self._invoke_semantic_rule(ruleinfo, node)
result = self._mkresult(node)
self._memoize(key, result)
return result
except FailedSemantics as e:
self._error(str(e))
finally:
self._pop_ast()
except FailedParse as e:
self._memoize(key, e)
self._goto(key.pos)
raise
@property
def message(self):
return "expecting %s" % repr(self.token).lstrip('u')
class FailedPattern(FailedParse):
def __init__(self, tokenizer, stack, pattern):
super().__init__(tokenizer, stack, pattern)
self.pattern = pattern
@property
def message(self):
return "expecting /%s/" % self.pattern
class FailedRef(FailedParse):
def __init__(self, tokenizer, stack, name):
super().__init__(tokenizer, stack, name)
self.name = name
@property
def message(self):
return "could not resolve reference to rule '%s'" % self.name
class FailedCut(FailedParse):
def __init__(self, nested):
super().__init__(nested.tokenizer, nested.stack, nested.item)
self.pos = nested.pos
self.nested = nested
@property
def _error(self, item, exclass=FailedParse):
raise self._make_exception(item, exclass=exclass)
super().__init__(nested.tokenizer, nested.stack, nested.item)
self.pos = nested.pos
self.nested = nested
@property
def message(self):
return self.nested.message
class FailedChoice(FailedParse):
@property
def message(self):
return 'no viable option'
class FailedLookahead(FailedParse):
@property
def message(self):
return 'failed lookahead'
class FailedLeftRecursion(FailedParse):
@property
def message(self):
return 'infinite left recursion'
class FailedExpectingEndOfText(FailedParse):
pass
def message(self):
return "could not resolve reference to rule '%s'" % self.name
class FailedCut(FailedParse):
def __init__(self, nested):
super().__init__(nested.tokenizer, nested.stack, nested.item)
self.pos = nested.pos
self.nested = nested
@property
def message(self):
return self.nested.message
class FailedChoice(FailedParse):
@property
def message(self):
return 'no viable option'
class FailedLookahead(FailedParse):
@property
def message(self):
return 'failed lookahead'
class FailedLeftRecursion(FailedParse):
@property
def message(self):
return 'infinite left recursion'
template = "{}({}:{}) {} :\n{}\n{}^\n{}"
text = info.text.rstrip()
leading = re.sub(r'[^\t]', ' ', text)[:info.col]
text = text.expandtabs()
leading = leading.expandtabs()
return template.format(info.filename,
info.line + 1, info.col + 1,
self.message.rstrip(),
text,
leading,
'\n'.join(reversed(self.stack))
)
class FailedToken(FailedParse):
def __init__(self, tokenizer, stack, token):
super().__init__(tokenizer, stack, token)
self.token = token
@property
def message(self):
return "expecting %s" % repr(self.token).lstrip('u')
class FailedPattern(FailedParse):
def __init__(self, tokenizer, stack, pattern):
super().__init__(tokenizer, stack, pattern)
self.pattern = pattern
@property
def message(self):