diff options
Diffstat (limited to 'crates/ra_ssr')
-rw-r--r-- | crates/ra_ssr/src/parsing.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/ra_ssr/src/parsing.rs b/crates/ra_ssr/src/parsing.rs index 0f4f88b7c..5ea125616 100644 --- a/crates/ra_ssr/src/parsing.rs +++ b/crates/ra_ssr/src/parsing.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | //! e.g. expressions, type references etc. | 6 | //! e.g. expressions, type references etc. |
7 | 7 | ||
8 | use crate::{SsrError, SsrPattern, SsrRule}; | 8 | use crate::{SsrError, SsrPattern, SsrRule}; |
9 | use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind}; | 9 | use ra_syntax::{ast, AstNode, SmolStr, SyntaxKind, T}; |
10 | use rustc_hash::{FxHashMap, FxHashSet}; | 10 | use rustc_hash::{FxHashMap, FxHashSet}; |
11 | use std::str::FromStr; | 11 | use std::str::FromStr; |
12 | 12 | ||
@@ -161,7 +161,7 @@ fn parse_pattern(pattern_str: &str) -> Result<Vec<PatternElement>, SsrError> { | |||
161 | let mut placeholder_names = FxHashSet::default(); | 161 | let mut placeholder_names = FxHashSet::default(); |
162 | let mut tokens = tokenize(pattern_str)?.into_iter(); | 162 | let mut tokens = tokenize(pattern_str)?.into_iter(); |
163 | while let Some(token) = tokens.next() { | 163 | while let Some(token) = tokens.next() { |
164 | if token.kind == SyntaxKind::DOLLAR { | 164 | if token.kind == T![$] { |
165 | let placeholder = parse_placeholder(&mut tokens)?; | 165 | let placeholder = parse_placeholder(&mut tokens)?; |
166 | if !placeholder_names.insert(placeholder.ident.clone()) { | 166 | if !placeholder_names.insert(placeholder.ident.clone()) { |
167 | bail!("Name `{}` repeats more than once", placeholder.ident); | 167 | bail!("Name `{}` repeats more than once", placeholder.ident); |
@@ -226,7 +226,7 @@ fn parse_placeholder(tokens: &mut std::vec::IntoIter<Token>) -> Result<Placehold | |||
226 | SyntaxKind::IDENT => { | 226 | SyntaxKind::IDENT => { |
227 | name = Some(token.text); | 227 | name = Some(token.text); |
228 | } | 228 | } |
229 | SyntaxKind::L_CURLY => { | 229 | T!['{'] => { |
230 | let token = | 230 | let token = |
231 | tokens.next().ok_or_else(|| SsrError::new("Unexpected end of placeholder"))?; | 231 | tokens.next().ok_or_else(|| SsrError::new("Unexpected end of placeholder"))?; |
232 | if token.kind == SyntaxKind::IDENT { | 232 | if token.kind == SyntaxKind::IDENT { |
@@ -237,10 +237,10 @@ fn parse_placeholder(tokens: &mut std::vec::IntoIter<Token>) -> Result<Placehold | |||
237 | .next() | 237 | .next() |
238 | .ok_or_else(|| SsrError::new("Placeholder is missing closing brace '}'"))?; | 238 | .ok_or_else(|| SsrError::new("Placeholder is missing closing brace '}'"))?; |
239 | match token.kind { | 239 | match token.kind { |
240 | SyntaxKind::COLON => { | 240 | T![:] => { |
241 | constraints.push(parse_constraint(tokens)?); | 241 | constraints.push(parse_constraint(tokens)?); |
242 | } | 242 | } |
243 | SyntaxKind::R_CURLY => break, | 243 | T!['}'] => break, |
244 | _ => bail!("Unexpected token while parsing placeholder: '{}'", token.text), | 244 | _ => bail!("Unexpected token while parsing placeholder: '{}'", token.text), |
245 | } | 245 | } |
246 | } | 246 | } |
@@ -330,24 +330,24 @@ mod tests { | |||
330 | result.pattern.raw.tokens, | 330 | result.pattern.raw.tokens, |
331 | vec![ | 331 | vec![ |
332 | token(SyntaxKind::IDENT, "foo"), | 332 | token(SyntaxKind::IDENT, "foo"), |
333 | token(SyntaxKind::L_PAREN, "("), | 333 | token(T!['('], "("), |
334 | placeholder("a"), | 334 | placeholder("a"), |
335 | token(SyntaxKind::COMMA, ","), | 335 | token(T![,], ","), |
336 | token(SyntaxKind::WHITESPACE, " "), | 336 | token(SyntaxKind::WHITESPACE, " "), |
337 | placeholder("b"), | 337 | placeholder("b"), |
338 | token(SyntaxKind::R_PAREN, ")"), | 338 | token(T![')'], ")"), |
339 | ] | 339 | ] |
340 | ); | 340 | ); |
341 | assert_eq!( | 341 | assert_eq!( |
342 | result.template.tokens, | 342 | result.template.tokens, |
343 | vec![ | 343 | vec![ |
344 | token(SyntaxKind::IDENT, "bar"), | 344 | token(SyntaxKind::IDENT, "bar"), |
345 | token(SyntaxKind::L_PAREN, "("), | 345 | token(T!['('], "("), |
346 | placeholder("b"), | 346 | placeholder("b"), |
347 | token(SyntaxKind::COMMA, ","), | 347 | token(T![,], ","), |
348 | token(SyntaxKind::WHITESPACE, " "), | 348 | token(SyntaxKind::WHITESPACE, " "), |
349 | placeholder("a"), | 349 | placeholder("a"), |
350 | token(SyntaxKind::R_PAREN, ")"), | 350 | token(T![')'], ")"), |
351 | ] | 351 | ] |
352 | ); | 352 | ); |
353 | } | 353 | } |