Skip to content

Commit 8637d88

Browse files
committed
Parse close quotes just once
1 parent f7bcad3 commit 8637d88

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/parse.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,7 @@ fn literal_suffix(input: Cursor) -> Cursor {
311311

312312
fn string(input: Cursor) -> Result<Cursor, LexError> {
313313
if let Ok(input) = input.expect("\"") {
314-
let input = cooked_string(input)?;
315-
let input = input.expect("\"")?;
316-
Ok(literal_suffix(input))
314+
cooked_string(input)
317315
} else if let Ok(input) = input.expect("r") {
318316
raw_string(input)
319317
} else {
@@ -326,7 +324,8 @@ fn cooked_string(input: Cursor) -> Result<Cursor, LexError> {
326324
while let Some((byte_offset, ch)) = chars.next() {
327325
match ch {
328326
'"' => {
329-
return Ok(input.advance(byte_offset));
327+
let input = input.advance(byte_offset + 1);
328+
return Ok(literal_suffix(input));
330329
}
331330
'\r' => {
332331
if let Some((_, '\n')) = chars.next() {
@@ -367,12 +366,9 @@ fn cooked_string(input: Cursor) -> Result<Cursor, LexError> {
367366

368367
fn byte_string(input: Cursor) -> Result<Cursor, LexError> {
369368
if let Ok(input) = input.expect("b\"") {
370-
let input = cooked_byte_string(input)?;
371-
let input = input.expect("\"")?;
372-
Ok(input)
369+
cooked_byte_string(input)
373370
} else if let Ok(input) = input.expect("br") {
374-
let input = raw_string(input)?;
375-
Ok(input)
371+
raw_string(input)
376372
} else {
377373
Err(LexError)
378374
}
@@ -383,7 +379,7 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, LexError> {
383379
'outer: while let Some((offset, b)) = bytes.next() {
384380
match b {
385381
b'"' => {
386-
return Ok(input.advance(offset));
382+
return Ok(input.advance(offset + 1));
387383
}
388384
b'\r' => {
389385
if let Some((_, b'\n')) = bytes.next() {

0 commit comments

Comments
 (0)