Skip to content

Commit 2af6bdb

Browse files
committed
Consolidate delimited! and do_parse! macros
1 parent 697510d commit 2af6bdb

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

src/fallback.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -896,23 +896,26 @@ named!(token_kind -> TokenTree, alt!(
896896
));
897897

898898
named!(group -> Group, alt!(
899-
delimited!(
900-
punct!("("),
901-
token_stream,
902-
punct!(")")
903-
) => { |ts| Group::new(Delimiter::Parenthesis, ts) }
899+
do_parse!(
900+
punct!("(") >>
901+
ts: token_stream >>
902+
punct!(")") >>
903+
(Group::new(Delimiter::Parenthesis, ts))
904+
)
904905
|
905-
delimited!(
906-
punct!("["),
907-
token_stream,
908-
punct!("]")
909-
) => { |ts| Group::new(Delimiter::Bracket, ts) }
906+
do_parse!(
907+
punct!("[") >>
908+
ts: token_stream >>
909+
punct!("]") >>
910+
(Group::new(Delimiter::Bracket, ts))
911+
)
910912
|
911-
delimited!(
912-
punct!("{"),
913-
token_stream,
914-
punct!("}")
915-
) => { |ts| Group::new(Delimiter::Brace, ts) }
913+
do_parse!(
914+
punct!("{") >>
915+
ts: token_stream >>
916+
punct!("}") >>
917+
(Group::new(Delimiter::Brace, ts))
918+
)
916919
));
917920

918921
fn symbol(input: Cursor) -> PResult<TokenTree> {
@@ -1039,11 +1042,12 @@ fn cooked_string(input: Cursor) -> PResult<()> {
10391042
}
10401043

10411044
named!(byte_string -> (), alt!(
1042-
delimited!(
1043-
punct!("b\""),
1044-
cooked_byte_string,
1045-
tag!("\"")
1046-
) => { |_| () }
1045+
do_parse!(
1046+
punct!("b\"") >>
1047+
cooked_byte_string >>
1048+
tag!("\"") >>
1049+
(())
1050+
)
10471051
|
10481052
preceded!(
10491053
punct!("br"),

src/strnom.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,6 @@ macro_rules! preceded {
368368
};
369369
}
370370

371-
macro_rules! delimited {
372-
($i:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)+) => {
373-
match tuple_parser!($i, (), $submac!($($args)*), $($rest)*) {
374-
Err(LexError) => Err(LexError),
375-
Ok((i1, (_, o, _))) => Ok((i1, o))
376-
}
377-
};
378-
}
379-
380371
macro_rules! map {
381372
($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => {
382373
match $submac!($i, $($args)*) {

0 commit comments

Comments
 (0)