Skip to content

Commit 79837fc

Browse files
committed
Condense byte literal parser into one function
1 parent 8637d88 commit 79837fc

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/parse.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,6 @@ fn raw_string(input: Cursor) -> Result<Cursor, LexError> {
444444

445445
fn byte(input: Cursor) -> Result<Cursor, LexError> {
446446
let input = input.expect("b'")?;
447-
let input = cooked_byte(input)?;
448-
let input = input.expect("'")?;
449-
Ok(input)
450-
}
451-
452-
fn cooked_byte(input: Cursor) -> Result<Cursor, LexError> {
453447
let mut bytes = input.bytes().enumerate();
454448
let ok = match bytes.next().map(|(_, b)| b) {
455449
Some(b'\\') => match bytes.next().map(|(_, b)| b) {
@@ -460,20 +454,14 @@ fn cooked_byte(input: Cursor) -> Result<Cursor, LexError> {
460454
},
461455
b => b.is_some(),
462456
};
463-
if ok {
464-
match bytes.next() {
465-
Some((offset, _)) => {
466-
if input.chars().as_str().is_char_boundary(offset) {
467-
Ok(input.advance(offset))
468-
} else {
469-
Err(LexError)
470-
}
471-
}
472-
None => Ok(input.advance(input.len())),
473-
}
474-
} else {
475-
Err(LexError)
457+
if !ok {
458+
return Err(LexError);
459+
}
460+
let (offset, _) = bytes.next().ok_or(LexError)?;
461+
if !input.chars().as_str().is_char_boundary(offset) {
462+
return Err(LexError);
476463
}
464+
input.advance(offset).expect("'")
477465
}
478466

479467
fn character(input: Cursor) -> Result<Cursor, LexError> {

0 commit comments

Comments
 (0)