File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,16 @@ impl<'input> Lexer<'input> {
139139 let mut string_content = String :: new ( ) ;
140140 let start_pos = self . location ;
141141
142+ // If the next two characters are also the quote character, then we have a triple-quoted
143+ // string; consume those two characters and ensure that we require a triple-quote to close
144+ let triple_quoted = if self . chr0 == Some ( quote_char) && self . chr1 == Some ( quote_char) {
145+ self . next_char ( ) ;
146+ self . next_char ( ) ;
147+ true
148+ } else {
149+ false
150+ } ;
151+
142152 loop {
143153 match self . next_char ( ) {
144154 Some ( '\\' ) => {
@@ -198,7 +208,19 @@ impl<'input> Lexer<'input> {
198208 }
199209 Some ( c) => {
200210 if c == quote_char {
201- break ;
211+ if triple_quoted {
212+ // Look ahead at the next two characters; if we have two more
213+ // quote_chars, it's the end of the string; consume the remaining
214+ // closing quotes and break the loop
215+ if self . chr0 == Some ( quote_char) && self . chr1 == Some ( quote_char) {
216+ self . next_char ( ) ;
217+ self . next_char ( ) ;
218+ break ;
219+ }
220+ string_content. push ( c) ;
221+ } else {
222+ break ;
223+ }
202224 } else {
203225 string_content. push ( c) ;
204226 }
Original file line number Diff line number Diff line change 1+ assert "a" == 'a'
2+ assert """a""" == "a"
3+ assert len (""" " "" " "" """ ) == 11
4+ assert "\" " == '"'
5+ assert "\" " == """\" """
6+
7+ assert "\n " == """
8+ """
9+
10+ assert len (""" " \" """ ) == 5
You can’t perform that action at this time.
0 commit comments