Skip to content

Commit 042cf85

Browse files
committed
Un-generalize tuple parser down to pair
1 parent 12c1a7a commit 042cf85

File tree

2 files changed

+8
-42
lines changed

2 files changed

+8
-42
lines changed

src/fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ named!(doc_comment_contents -> (&str, bool), alt!(
14581458
|
14591459
do_parse!(
14601460
option!(whitespace) >>
1461-
peek!(tuple!(tag!("/**"), not!(tag!("*")))) >>
1461+
peek!(pair!(tag!("/**"), not!(tag!("*")))) >>
14621462
s: block_comment >>
14631463
((s, false))
14641464
)

src/strnom.rs

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -274,50 +274,16 @@ macro_rules! take_until_newline_or_eof {
274274
}};
275275
}
276276

277-
macro_rules! tuple {
278-
($i:expr, $($rest:tt)*) => {
279-
tuple_parser!($i, (), $($rest)*)
280-
};
281-
}
282-
283-
/// Do not use directly. Use `tuple!`.
284-
macro_rules! tuple_parser {
285-
($i:expr, ($($parsed:tt),*), $e:ident, $($rest:tt)*) => {
286-
tuple_parser!($i, ($($parsed),*), call!($e), $($rest)*)
287-
};
288-
289-
($i:expr, (), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => {
290-
match $submac!($i, $($args)*) {
277+
macro_rules! pair {
278+
($i:expr, $first:ident!( $($arg1:tt)* ), $second:ident!( $($arg2:tt)* )) => {
279+
match $first!($i, $($arg1)*) {
291280
Err(LexError) => Err(LexError),
292-
Ok((i, o)) => tuple_parser!(i, (o), $($rest)*),
293-
}
294-
};
295-
296-
($i:expr, ($($parsed:tt)*), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => {
297-
match $submac!($i, $($args)*) {
298-
Err(LexError) => Err(LexError),
299-
Ok((i, o)) => tuple_parser!(i, ($($parsed)* , o), $($rest)*),
300-
}
301-
};
302-
303-
($i:expr, ($($parsed:tt),*), $e:ident) => {
304-
tuple_parser!($i, ($($parsed),*), call!($e))
305-
};
306-
307-
($i:expr, (), $submac:ident!( $($args:tt)* )) => {
308-
$submac!($i, $($args)*)
309-
};
310-
311-
($i:expr, ($($parsed:expr),*), $submac:ident!( $($args:tt)* )) => {
312-
match $submac!($i, $($args)*) {
313-
Err(LexError) => Err(LexError),
314-
Ok((i, o)) => Ok((i, ($($parsed),*, o)))
281+
Ok((i, o1)) => match $second!(i, $($arg2)*) {
282+
Err(LexError) => Err(LexError),
283+
Ok((i, o2)) => Ok((i, (o1, o2))),
284+
},
315285
}
316286
};
317-
318-
($i:expr, ($($parsed:expr),*)) => {
319-
Ok(($i, ($($parsed),*)))
320-
};
321287
}
322288

323289
macro_rules! not {

0 commit comments

Comments
 (0)