Skip to content

Commit f7a6201

Browse files
committed
Rewrite byte parser without macros
1 parent 79a15ac commit f7a6201

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/fallback.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,13 +1125,13 @@ fn raw_string(input: Cursor) -> PResult<()> {
11251125
Err(LexError)
11261126
}
11271127

1128-
named!(byte -> (), do_parse!(
1129-
punct!("b") >>
1130-
tag!("'") >>
1131-
cooked_byte >>
1132-
tag!("'") >>
1133-
(())
1134-
));
1128+
fn byte(input: Cursor) -> PResult<()> {
1129+
let input = skip_whitespace(input);
1130+
let input = input.expect("b'")?;
1131+
let (input, ()) = cooked_byte(input)?;
1132+
let input = input.expect("'")?;
1133+
Ok((input, ()))
1134+
}
11351135

11361136
fn cooked_byte(input: Cursor) -> PResult<()> {
11371137
let mut bytes = input.bytes().enumerate();

src/strnom.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ impl<'a> Cursor<'a> {
5757
pub fn char_indices(&self) -> CharIndices<'a> {
5858
self.rest.char_indices()
5959
}
60+
61+
pub fn expect(&self, tag: &str) -> Result<Cursor<'a>, LexError> {
62+
if self.starts_with(tag) {
63+
Ok(self.advance(tag.len()))
64+
} else {
65+
Err(LexError)
66+
}
67+
}
6068
}
6169

6270
pub(crate) type PResult<'a, O> = Result<(Cursor<'a>, O), LexError>;

0 commit comments

Comments
 (0)