mirror of
https://github.com/davidhalter/parso.git
synced 2026-03-01 12:57:14 +08:00
Do proper error recover for fstrings and fix another issue there.
This commit is contained in:
@@ -840,11 +840,11 @@ class _TryStmtRule(SyntaxRule):
|
|||||||
class _FStringRule(SyntaxRule):
|
class _FStringRule(SyntaxRule):
|
||||||
_fstring_grammar = None
|
_fstring_grammar = None
|
||||||
message_empty = "f-string: empty expression not allowed" # f'{}'
|
message_empty = "f-string: empty expression not allowed" # f'{}'
|
||||||
"f-string: single '}' is not allowed" # f'}'
|
message_single_closing = "f-string: single '}' is not allowed" # f'}'
|
||||||
message_nested = "f-string: expressions nested too deeply"
|
message_nested = "f-string: expressions nested too deeply"
|
||||||
message_backslash = "f-string expression part cannot include a backslash" # f'{"\"}' or f'{"\\"}'
|
message_backslash = "f-string expression part cannot include a backslash" # f'{"\"}' or f'{"\\"}'
|
||||||
message_comment = "f-string expression part cannot include '#'" # f'{#}'
|
message_comment = "f-string expression part cannot include '#'" # f'{#}'
|
||||||
"f-string: unterminated string" # f'{"}'
|
message_string = "f-string: unterminated string" # f'{"}'
|
||||||
message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'"
|
message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'"
|
||||||
message_incomplete = "f-string: expecting '}'" # f'{'
|
message_incomplete = "f-string: expecting '}'" # f'{'
|
||||||
|
|
||||||
@@ -866,6 +866,8 @@ class _FStringRule(SyntaxRule):
|
|||||||
self._check_expression(child)
|
self._check_expression(child)
|
||||||
elif child.type == 'error_node':
|
elif child.type == 'error_node':
|
||||||
self.add_issue(child, message=self.message_incomplete)
|
self.add_issue(child, message=self.message_incomplete)
|
||||||
|
elif child.type == 'error_leaf':
|
||||||
|
self.add_issue(child, message=self.message_single_closing)
|
||||||
|
|
||||||
def _check_python_expr(self, python_expr):
|
def _check_python_expr(self, python_expr):
|
||||||
value = python_expr.value
|
value = python_expr.value
|
||||||
|
|||||||
@@ -198,9 +198,17 @@ class Parser(parser.BaseParser):
|
|||||||
add_token_callback
|
add_token_callback
|
||||||
)
|
)
|
||||||
|
|
||||||
dfa, state, (type_, nodes) = stack[1]
|
if len(stack) == 1:
|
||||||
stack[0][2][1].append(ErrorNode(nodes))
|
error_leaf = ErrorLeaf(
|
||||||
stack[1:] = []
|
TokenNamespace.token_map[typ].lower(),
|
||||||
#error_leaf = tree.PythonErrorLeaf(tok_name[typ].lower(), value, start_pos, prefix)
|
value,
|
||||||
|
start_pos,
|
||||||
|
prefix
|
||||||
|
)
|
||||||
|
stack[0][2][1].append(error_leaf)
|
||||||
|
else:
|
||||||
|
dfa, state, (type_, nodes) = stack[1]
|
||||||
|
stack[0][2][1].append(ErrorNode(nodes))
|
||||||
|
stack[1:] = []
|
||||||
|
|
||||||
add_token_callback(typ, value, start_pos, prefix)
|
add_token_callback(typ, value, start_pos, prefix)
|
||||||
|
|||||||
@@ -147,6 +147,8 @@ FAILING_EXAMPLES = [
|
|||||||
"f'{1!b}'",
|
"f'{1!b}'",
|
||||||
"f'{1:{5:{3}}}'",
|
"f'{1:{5:{3}}}'",
|
||||||
"f'{'",
|
"f'{'",
|
||||||
|
"f'{'",
|
||||||
|
"f'}'",
|
||||||
]
|
]
|
||||||
|
|
||||||
GLOBAL_NONLOCAL_ERROR = [
|
GLOBAL_NONLOCAL_ERROR = [
|
||||||
|
|||||||
Reference in New Issue
Block a user