File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -2156,8 +2156,14 @@ def test_error_parenthesis(self):
2156
2156
2157
2157
def test_error_string_literal (self ):
2158
2158
2159
- self ._check_error ("'blech" , "unterminated string literal" )
2160
- self ._check_error ('"blech' , "unterminated string literal" )
2159
+ self ._check_error ("'blech" , r"unterminated string literal \(.*\)$" )
2160
+ self ._check_error ('"blech' , r"unterminated string literal \(.*\)$" )
2161
+ self ._check_error (
2162
+ r'"blech\"' , r"unterminated string literal \(.*\); perhaps you escaped the end quote"
2163
+ )
2164
+ self ._check_error (
2165
+ r'r"blech\"' , r"unterminated string literal \(.*\); perhaps you escaped the end quote"
2166
+ )
2161
2167
self ._check_error ("'''blech" , "unterminated triple-quoted string literal" )
2162
2168
self ._check_error ('"""blech' , "unterminated triple-quoted string literal" )
2163
2169
Original file line number Diff line number Diff line change @@ -2009,6 +2009,7 @@ tok_get(struct tok_state *tok, struct token *token)
2009
2009
int quote = c ;
2010
2010
int quote_size = 1 ; /* 1 or 3 */
2011
2011
int end_quote_size = 0 ;
2012
+ int has_escaped_quote = 0 ;
2012
2013
2013
2014
/* Nodes of type STRING, especially multi line strings
2014
2015
must be handled differently in order to get both
@@ -2056,8 +2057,13 @@ tok_get(struct tok_state *tok, struct token *token)
2056
2057
return MAKE_TOKEN (ERRORTOKEN );
2057
2058
}
2058
2059
else {
2059
- syntaxerror (tok , "unterminated string literal (detected at"
2060
- " line %d)" , start );
2060
+ if (has_escaped_quote ) {
2061
+ syntaxerror (tok , "unterminated string literal (detected at"
2062
+ " line %d); perhaps you escaped the end quote?" , start );
2063
+ } else {
2064
+ syntaxerror (tok , "unterminated string literal (detected at"
2065
+ " line %d)" , start );
2066
+ }
2061
2067
if (c != '\n' ) {
2062
2068
tok -> done = E_EOLS ;
2063
2069
}
@@ -2070,7 +2076,11 @@ tok_get(struct tok_state *tok, struct token *token)
2070
2076
else {
2071
2077
end_quote_size = 0 ;
2072
2078
if (c == '\\' ) {
2073
- tok_nextc (tok ); /* skip escaped char */
2079
+ // skip escaped char, but record whether the escaped char
2080
+ // was a quote
2081
+ if (tok_nextc (tok ) == quote ) {
2082
+ has_escaped_quote = 1 ;
2083
+ }
2074
2084
}
2075
2085
}
2076
2086
}
You can’t perform that action at this time.
0 commit comments