Skip to content

Commit 3571b0a

Browse files
authored
Merge pull request #277 from alexcrichton/lexerror
Simplify `Err(LexError) => Err(LexError)` arms in parser
2 parents 51608bb + 2dd9e63 commit 3571b0a

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/parse.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,9 @@ fn ident_not_raw(input: Cursor) -> PResult<&str> {
287287
}
288288

289289
fn literal(input: Cursor) -> PResult<Literal> {
290-
match literal_nocapture(input) {
291-
Ok(a) => {
292-
let end = input.len() - a.len();
293-
Ok((a, Literal::_new(input.rest[..end].to_string())))
294-
}
295-
Err(LexError) => Err(LexError),
296-
}
290+
let rest = literal_nocapture(input)?;
291+
let end = input.len() - rest.len();
292+
Ok((rest, Literal::_new(input.rest[..end].to_string())))
297293
}
298294

299295
fn literal_nocapture(input: Cursor) -> Result<Cursor, LexError> {
@@ -730,22 +726,19 @@ fn digits(mut input: Cursor) -> Result<Cursor, LexError> {
730726
}
731727

732728
fn punct(input: Cursor) -> PResult<Punct> {
733-
match punct_char(input) {
734-
Ok((rest, '\'')) => {
735-
if ident_any(rest)?.0.starts_with("'") {
736-
Err(LexError)
737-
} else {
738-
Ok((rest, Punct::new('\'', Spacing::Joint)))
739-
}
740-
}
741-
Ok((rest, ch)) => {
742-
let kind = match punct_char(rest) {
743-
Ok(_) => Spacing::Joint,
744-
Err(LexError) => Spacing::Alone,
745-
};
746-
Ok((rest, Punct::new(ch, kind)))
729+
let (rest, ch) = punct_char(input)?;
730+
if ch == '\'' {
731+
if ident_any(rest)?.0.starts_with("'") {
732+
Err(LexError)
733+
} else {
734+
Ok((rest, Punct::new('\'', Spacing::Joint)))
747735
}
748-
Err(LexError) => Err(LexError),
736+
} else {
737+
let kind = match punct_char(rest) {
738+
Ok(_) => Spacing::Joint,
739+
Err(LexError) => Spacing::Alone,
740+
};
741+
Ok((rest, Punct::new(ch, kind)))
749742
}
750743
}
751744

0 commit comments

Comments
 (0)