gh-88535: Improve syntax error for wrongly closed strings (#26633)

This commit is contained in:
Pablo Galindo Salgado 2025-02-13 01:30:20 +00:00 committed by GitHub
parent 56eda25633
commit 6fb5138776
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1098 additions and 930 deletions

View file

@ -1178,6 +1178,9 @@ invalid_type_param:
}
invalid_expression:
| STRING a=(!STRING expression_without_invalid)+ STRING {
RAISE_SYNTAX_ERROR_KNOWN_RANGE( PyPegen_first_item(a, expr_ty), PyPegen_last_item(a, expr_ty),
"invalid syntax. Is this intended to be part of the string?") }
# !(NAME STRING) is not matched so we don't show this error with some invalid string prefixes like: kf"dsfsdf"
# Soft keywords need to also be ignored because they can be parsed as NAME NAME
| !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid {