diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-08 15:18:57 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-08 15:18:57 +0100 |
commit | ac6ab0758731d0555fbf1b1a918abd3e12c8169d (patch) | |
tree | 05f568cbd925dbbd578f9414fd9e4ea3634b68e4 /crates/ra_mbe/src/lib.rs | |
parent | 1ca7a744eb512e6b900988cba871dcd3d90d447f (diff) | |
parent | 8ed710457875e6f580a0ddf6ab29c6b10d389a41 (diff) |
Merge #1105
1105: [WIP] Implement ra_mbe meta variables support r=matklad a=edwin0cheng
This PR implements the following meta variable support in `ra_mba` crate (issue #720):
- [x] `path`
- [ ] `expr`
- [ ] `ty`
- [ ] `pat`
- [ ] `stmt`
- [ ] `block`
- [ ] `meta`
- [ ] `item`
*Implementation Details*
In the macro expanding lhs phase, if we see a meta variable type, we try to create a `tt:TokenTree` from the remaining input. And then we use a special set of `ra_parser` to parse it to `SyntaxNode`.
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 4203929d4..a21ea4dbc 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -15,10 +15,13 @@ macro_rules! impl_froms { | |||
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | mod tt_cursor; | 18 | // mod tt_cursor; |
19 | mod mbe_parser; | 19 | mod mbe_parser; |
20 | mod mbe_expander; | 20 | mod mbe_expander; |
21 | mod syntax_bridge; | 21 | mod syntax_bridge; |
22 | mod tt_cursor; | ||
23 | mod subtree_source; | ||
24 | mod subtree_parser; | ||
22 | 25 | ||
23 | use ra_syntax::SmolStr; | 26 | use ra_syntax::SmolStr; |
24 | 27 | ||
@@ -379,4 +382,54 @@ SOURCE_FILE@[0; 40) | |||
379 | // [let] [s] [=] ["rust1"] [;] | 382 | // [let] [s] [=] ["rust1"] [;] |
380 | assert_eq!(to_literal(&stm_tokens[15 + 3]).text, "\"rust1\""); | 383 | assert_eq!(to_literal(&stm_tokens[15 + 3]).text, "\"rust1\""); |
381 | } | 384 | } |
385 | |||
386 | #[test] | ||
387 | fn test_two_idents() { | ||
388 | let rules = create_rules( | ||
389 | r#" | ||
390 | macro_rules! foo { | ||
391 | ($ i:ident, $ j:ident) => { | ||
392 | fn foo() { let a = $ i; let b = $j; } | ||
393 | } | ||
394 | } | ||
395 | "#, | ||
396 | ); | ||
397 | assert_expansion(&rules, "foo! { foo, bar }", "fn foo () {let a = foo ; let b = bar ;}"); | ||
398 | } | ||
399 | |||
400 | // The following tests are port from intellij-rust directly | ||
401 | // https://github.com/intellij-rust/intellij-rust/blob/c4e9feee4ad46e7953b1948c112533360b6087bb/src/test/kotlin/org/rust/lang/core/macros/RsMacroExpansionTest.kt | ||
402 | |||
403 | #[test] | ||
404 | fn test_path() { | ||
405 | let rules = create_rules( | ||
406 | r#" | ||
407 | macro_rules! foo { | ||
408 | ($ i:path) => { | ||
409 | fn foo() { let a = $ i; } | ||
410 | } | ||
411 | } | ||
412 | "#, | ||
413 | ); | ||
414 | assert_expansion(&rules, "foo! { foo }", "fn foo () {let a = foo ;}"); | ||
415 | assert_expansion( | ||
416 | &rules, | ||
417 | "foo! { bar::<u8>::baz::<u8> }", | ||
418 | "fn foo () {let a = bar ::< u8 > ::baz ::< u8 > ;}", | ||
419 | ); | ||
420 | } | ||
421 | |||
422 | #[test] | ||
423 | fn test_two_paths() { | ||
424 | let rules = create_rules( | ||
425 | r#" | ||
426 | macro_rules! foo { | ||
427 | ($ i:path, $ j:path) => { | ||
428 | fn foo() { let a = $ i; let b = $j; } | ||
429 | } | ||
430 | } | ||
431 | "#, | ||
432 | ); | ||
433 | assert_expansion(&rules, "foo! { foo, bar }", "fn foo () {let a = foo ; let b = bar ;}"); | ||
434 | } | ||
382 | } | 435 | } |