aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/parsing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ssr/src/parsing.rs')
-rw-r--r--crates/ra_ssr/src/parsing.rs17
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
8use crate::errors::bail;
8use crate::{SsrError, SsrPattern, SsrRule}; 9use crate::{SsrError, SsrPattern, SsrRule};
9use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind, T}; 10use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind, T};
10use rustc_hash::{FxHashMap, FxHashSet}; 11use rustc_hash::{FxHashMap, FxHashSet};
11use std::str::FromStr; 12use std::str::FromStr;
12 13
13/// Returns from the current function with an error, supplied by arguments as for format!
14macro_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)]
20pub(crate) struct SsrTemplate { 15pub(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
295impl NodeKind { 290impl NodeKind {
@@ -307,12 +302,6 @@ impl Placeholder {
307 } 302 }
308} 303}
309 304
310impl SsrError {
311 fn new(message: impl Into<String>) -> SsrError {
312 SsrError(message.into())
313 }
314}
315
316#[cfg(test)] 305#[cfg(test)]
317mod tests { 306mod tests {
318 use super::*; 307 use super::*;