From 5c3c2b869085a26187c0f7c7bcd4ee58bc1075a9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 19 Dec 2019 14:43:19 +0100 Subject: Fix parsing of interpolated expressions --- crates/ra_mbe/src/tests.rs | 18 ++++++++++++++++++ crates/ra_parser/src/grammar/expressions/atom.rs | 1 + 2 files changed, 19 insertions(+) (limited to 'crates') diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index ff225f0db..b5a10a9d2 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs @@ -1450,6 +1450,24 @@ macro_rules! delegate_impl { ); } +#[test] +fn expr_interpolation() { + let rules = create_rules( + r#" + macro_rules! id { + ($expr:expr) => { + map($expr) + } + } + "#, + ); + + let expanded = expand(&rules, "id!(x + foo);"); + let expanded = + token_tree_to_syntax_node(&expanded, FragmentKind::Expr).unwrap().0.syntax_node(); + assert_eq!(expanded.to_string(), "map(x+foo)"); +} + pub(crate) fn create_rules(macro_definition: &str) -> MacroRules { let source_file = ast::SourceFile::parse(macro_definition).ok().unwrap(); let macro_definition = diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 09f0a2d98..6f5545a83 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -43,6 +43,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = T!['('], T!['{'], T!['['], + L_DOLLAR, T![|], T![move], T![box], -- cgit v1.2.3