diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/drop_bomb.rs | 21 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/parser_api.rs | 20 |
3 files changed, 6 insertions, 37 deletions
diff --git a/src/drop_bomb.rs b/src/drop_bomb.rs deleted file mode 100644 index 750904a01..000000000 --- a/src/drop_bomb.rs +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | use std::borrow::Cow; | ||
2 | |||
3 | pub struct DropBomb { | ||
4 | msg: Cow<'static, str>, | ||
5 | defused: bool, | ||
6 | } | ||
7 | |||
8 | impl DropBomb { | ||
9 | pub fn new(msg: impl Into<Cow<'static, str>>) -> DropBomb { | ||
10 | DropBomb { msg: msg.into(), defused: false } | ||
11 | } | ||
12 | pub fn defuse(&mut self) { self.defused = true } | ||
13 | } | ||
14 | |||
15 | impl Drop for DropBomb { | ||
16 | fn drop(&mut self) { | ||
17 | if !self.defused && !::std::thread::panicking() { | ||
18 | panic!("{}", self.msg) | ||
19 | } | ||
20 | } | ||
21 | } | ||
diff --git a/src/lib.rs b/src/lib.rs index d9572912c..a7705ab66 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
@@ -23,6 +23,7 @@ | |||
23 | extern crate itertools; | 23 | extern crate itertools; |
24 | extern crate text_unit; | 24 | extern crate text_unit; |
25 | extern crate unicode_xid; | 25 | extern crate unicode_xid; |
26 | extern crate drop_bomb; | ||
26 | 27 | ||
27 | pub mod algo; | 28 | pub mod algo; |
28 | pub mod ast; | 29 | pub mod ast; |
@@ -31,7 +32,6 @@ mod lexer; | |||
31 | mod parser_api; | 32 | mod parser_api; |
32 | mod grammar; | 33 | mod grammar; |
33 | mod parser_impl; | 34 | mod parser_impl; |
34 | mod drop_bomb; | ||
35 | 35 | ||
36 | mod syntax_kinds; | 36 | mod syntax_kinds; |
37 | /// Utilities for simple uses of the parser. | 37 | /// Utilities for simple uses of the parser. |
diff --git a/src/parser_api.rs b/src/parser_api.rs index 3cad91976..95394e39d 100644 --- a/src/parser_api.rs +++ b/src/parser_api.rs | |||
@@ -18,24 +18,14 @@ impl TokenSet { | |||
18 | 18 | ||
19 | #[macro_export] | 19 | #[macro_export] |
20 | macro_rules! token_set { | 20 | macro_rules! token_set { |
21 | ($($t:ident),*) => { | 21 | ($($t:ident),*) => { TokenSet($(1u128 << ($t as usize))|*) }; |
22 | TokenSet($(1u128 << ($t as usize))|*) | 22 | ($($t:ident),* ,) => { token_set!($($t),*) }; |
23 | }; | ||
24 | |||
25 | ($($t:ident),* ,) => { | ||
26 | token_set!($($t),*) | ||
27 | }; | ||
28 | } | 23 | } |
29 | 24 | ||
30 | #[macro_export] | 25 | #[macro_export] |
31 | macro_rules! token_set_union { | 26 | macro_rules! token_set_union { |
32 | ($($ts:expr),*) => { | 27 | ($($ts:expr),*) => { TokenSet($($ts.0)|*) }; |
33 | TokenSet($($ts.0)|*) | 28 | ($($ts:expr),* ,) => { token_set_union!($($ts),*) }; |
34 | }; | ||
35 | |||
36 | ($($ts:expr),* ,) => { | ||
37 | token_set_union!($($ts),*) | ||
38 | }; | ||
39 | } | 29 | } |
40 | 30 | ||
41 | /// `Parser` struct provides the low-level API for | 31 | /// `Parser` struct provides the low-level API for |
@@ -141,7 +131,7 @@ impl Marker { | |||
141 | fn new(pos: u32) -> Marker { | 131 | fn new(pos: u32) -> Marker { |
142 | Marker { | 132 | Marker { |
143 | pos, | 133 | pos, |
144 | bomb: DropBomb::new("Marker must be either completed or abandoned") | 134 | bomb: DropBomb::new("Marker must be either completed or abandoned"), |
145 | } | 135 | } |
146 | } | 136 | } |
147 | 137 | ||