Skip to content

Commit 832b234

Browse files
committed
Rewrite byte_string parser without macros
1 parent 0954dcf commit 832b234

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

src/fallback.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,20 +1040,19 @@ fn cooked_string(input: Cursor) -> PResult<()> {
10401040
Err(LexError)
10411041
}
10421042

1043-
named!(byte_string -> (), alt!(
1044-
do_parse!(
1045-
punct!("b\"") >>
1046-
cooked_byte_string >>
1047-
tag!("\"") >>
1048-
(())
1049-
)
1050-
|
1051-
do_parse!(
1052-
punct!("br") >>
1053-
raw_string >>
1054-
(())
1055-
)
1056-
));
1043+
fn byte_string(input: Cursor) -> PResult<()> {
1044+
let input = skip_whitespace(input);
1045+
if let Ok(input) = input.expect("b\"") {
1046+
let (input, ()) = cooked_byte_string(input)?;
1047+
let input = input.expect("\"")?;
1048+
Ok((input, ()))
1049+
} else if let Ok(input) = input.expect("br") {
1050+
let (input, ()) = raw_string(input)?;
1051+
Ok((input, ()))
1052+
} else {
1053+
Err(LexError)
1054+
}
1055+
}
10571056

10581057
fn cooked_byte_string(mut input: Cursor) -> PResult<()> {
10591058
let mut bytes = input.bytes().enumerate();

src/strnom.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,6 @@ macro_rules! call {
251251
};
252252
}
253253

254-
macro_rules! tag {
255-
($i:expr, $tag:expr) => {
256-
if $i.starts_with($tag) {
257-
Ok(($i.advance($tag.len()), ()))
258-
} else {
259-
Err(LexError)
260-
}
261-
};
262-
}
263-
264254
macro_rules! punct {
265255
($i:expr, $punct:expr) => {
266256
$crate::strnom::punct($i, $punct)

0 commit comments

Comments
 (0)