mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
add tt matcher
This commit is contained in:
parent
762819864f
commit
59b6cc780b
2 changed files with 28 additions and 0 deletions
|
@ -762,4 +762,28 @@ MACRO_ITEMS@[0; 40)
|
||||||
r#"# [cfg (target_os = "windows")] fn bar () {}"#,
|
r#"# [cfg (target_os = "windows")] fn bar () {}"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tt_block() {
|
||||||
|
let rules = create_rules(
|
||||||
|
r#"
|
||||||
|
macro_rules! foo {
|
||||||
|
($ i:tt) => { fn foo() $ i }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
assert_expansion(&rules, r#"foo! { { 1; } }"#, r#"fn foo () {1 ;}"#);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tt_group() {
|
||||||
|
let rules = create_rules(
|
||||||
|
r#"
|
||||||
|
macro_rules! foo {
|
||||||
|
($($ i:tt)*) => { $($ i)* }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
assert_expansion(&rules, r#"foo! { fn foo() {} }"#, r#"fn foo () {}"#);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,6 +171,10 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
|
||||||
input.eat_meta().ok_or(ExpandError::UnexpectedToken)?.clone();
|
input.eat_meta().ok_or(ExpandError::UnexpectedToken)?.clone();
|
||||||
res.inner.insert(text.clone(), Binding::Simple(meta.into()));
|
res.inner.insert(text.clone(), Binding::Simple(meta.into()));
|
||||||
}
|
}
|
||||||
|
"tt" => {
|
||||||
|
let token = input.eat().ok_or(ExpandError::UnexpectedToken)?.clone();
|
||||||
|
res.inner.insert(text.clone(), Binding::Simple(token.into()));
|
||||||
|
}
|
||||||
"item" => {
|
"item" => {
|
||||||
let item =
|
let item =
|
||||||
input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone();
|
input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue