Skip to content

Commit 5975a61

Browse files
committed
Condense character literal parser into one function
1 parent 79837fc commit 5975a61

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/parse.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,6 @@ fn byte(input: Cursor) -> Result<Cursor, LexError> {
466466

467467
fn character(input: Cursor) -> Result<Cursor, LexError> {
468468
let input = input.expect("'")?;
469-
let input = cooked_char(input)?;
470-
let input = input.expect("'")?;
471-
Ok(input)
472-
}
473-
474-
fn cooked_char(input: Cursor) -> Result<Cursor, LexError> {
475469
let mut chars = input.char_indices();
476470
let ok = match chars.next().map(|(_, ch)| ch) {
477471
Some('\\') => match chars.next().map(|(_, ch)| ch) {
@@ -484,14 +478,11 @@ fn cooked_char(input: Cursor) -> Result<Cursor, LexError> {
484478
},
485479
ch => ch.is_some(),
486480
};
487-
if ok {
488-
match chars.next() {
489-
Some((idx, _)) => Ok(input.advance(idx)),
490-
None => Ok(input.advance(input.len())),
491-
}
492-
} else {
493-
Err(LexError)
481+
if !ok {
482+
return Err(LexError);
494483
}
484+
let (idx, _) = chars.next().ok_or(LexError)?;
485+
input.advance(idx).expect("'")
495486
}
496487

497488
macro_rules! next_ch {

0 commit comments

Comments
 (0)