aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-01 12:55:37 +0100
committerAleksey Kladov <[email protected]>2018-08-01 12:55:37 +0100
commit1954df63364ab07b99f6b6eaf228a14bae61e81e (patch)
treeaae09111d6166bc27da0ccf1393911bea00e21e6
parentecd5da5b0cae5b3af95f5b86a8157a1f57a944c5 (diff)
drop the bombs
-rw-r--r--Cargo.toml1
-rw-r--r--src/drop_bomb.rs21
-rw-r--r--src/lib.rs2
-rw-r--r--src/parser_api.rs20
4 files changed, 7 insertions, 37 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d61613352..8af8f825b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,6 +11,7 @@ members = [ "tools", "cli", "libeditor" ]
11unicode-xid = "0.1.0" 11unicode-xid = "0.1.0"
12text_unit = "0.1.2" 12text_unit = "0.1.2"
13itertools = "0.7.5" 13itertools = "0.7.5"
14drop_bomb = "0.1.4"
14 15
15[dev-dependencies] 16[dev-dependencies]
16testutils = { path = "./tests/testutils" } 17testutils = { path = "./tests/testutils" }
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 @@
1use std::borrow::Cow;
2
3pub struct DropBomb {
4 msg: Cow<'static, str>,
5 defused: bool,
6}
7
8impl 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
15impl 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 @@
23extern crate itertools; 23extern crate itertools;
24extern crate text_unit; 24extern crate text_unit;
25extern crate unicode_xid; 25extern crate unicode_xid;
26extern crate drop_bomb;
26 27
27pub mod algo; 28pub mod algo;
28pub mod ast; 29pub mod ast;
@@ -31,7 +32,6 @@ mod lexer;
31mod parser_api; 32mod parser_api;
32mod grammar; 33mod grammar;
33mod parser_impl; 34mod parser_impl;
34mod drop_bomb;
35 35
36mod syntax_kinds; 36mod 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]
20macro_rules! token_set { 20macro_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]
31macro_rules! token_set_union { 26macro_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