diff options
Diffstat (limited to 'crates/ra_ssr/src/parsing.rs')
-rw-r--r-- | crates/ra_ssr/src/parsing.rs | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/crates/ra_ssr/src/parsing.rs b/crates/ra_ssr/src/parsing.rs index 5ea125616..4aee97bb2 100644 --- a/crates/ra_ssr/src/parsing.rs +++ b/crates/ra_ssr/src/parsing.rs | |||
@@ -5,17 +5,12 @@ | |||
5 | //! search patterns, we go further and parse the pattern as each kind of thing that we can match. | 5 | //! search patterns, we go further and parse the pattern as each kind of thing that we can match. |
6 | //! e.g. expressions, type references etc. | 6 | //! e.g. expressions, type references etc. |
7 | 7 | ||
8 | use crate::errors::bail; | ||
8 | use crate::{SsrError, SsrPattern, SsrRule}; | 9 | use crate::{SsrError, SsrPattern, SsrRule}; |
9 | use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind, T}; | 10 | use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind, T}; |
10 | use rustc_hash::{FxHashMap, FxHashSet}; | 11 | use rustc_hash::{FxHashMap, FxHashSet}; |
11 | use std::str::FromStr; | 12 | use std::str::FromStr; |
12 | 13 | ||
13 | /// Returns from the current function with an error, supplied by arguments as for format! | ||
14 | macro_rules! bail { | ||
15 | ($e:expr) => {return Err($crate::SsrError::new($e))}; | ||
16 | ($fmt:expr, $($arg:tt)+) => {return Err($crate::SsrError::new(format!($fmt, $($arg)+)))} | ||
17 | } | ||
18 | |||
19 | #[derive(Clone, Debug)] | 14 | #[derive(Clone, Debug)] |
20 | pub(crate) struct SsrTemplate { | 15 | pub(crate) struct SsrTemplate { |
21 | pub(crate) tokens: Vec<PatternElement>, | 16 | pub(crate) tokens: Vec<PatternElement>, |
@@ -246,7 +241,7 @@ fn parse_placeholder(tokens: &mut std::vec::IntoIter<Token>) -> Result<Placehold | |||
246 | } | 241 | } |
247 | } | 242 | } |
248 | _ => { | 243 | _ => { |
249 | bail!("Placeholders should either be $name or ${name:constraints}"); | 244 | bail!("Placeholders should either be $name or ${{name:constraints}}"); |
250 | } | 245 | } |
251 | } | 246 | } |
252 | } | 247 | } |
@@ -289,7 +284,7 @@ fn expect_token(tokens: &mut std::vec::IntoIter<Token>, expected: &str) -> Resul | |||
289 | } | 284 | } |
290 | bail!("Expected {} found {}", expected, t.text); | 285 | bail!("Expected {} found {}", expected, t.text); |
291 | } | 286 | } |
292 | bail!("Expected {} found end of stream"); | 287 | bail!("Expected {} found end of stream", expected); |
293 | } | 288 | } |
294 | 289 | ||
295 | impl NodeKind { | 290 | impl NodeKind { |
@@ -307,12 +302,6 @@ impl Placeholder { | |||
307 | } | 302 | } |
308 | } | 303 | } |
309 | 304 | ||
310 | impl SsrError { | ||
311 | fn new(message: impl Into<String>) -> SsrError { | ||
312 | SsrError(message.into()) | ||
313 | } | ||
314 | } | ||
315 | |||
316 | #[cfg(test)] | 305 | #[cfg(test)] |
317 | mod tests { | 306 | mod tests { |
318 | use super::*; | 307 | use super::*; |