mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Add parse_to_token_tree
This commit is contained in:
parent
013e908056
commit
e7206467d5
5 changed files with 213 additions and 37 deletions
|
@ -1499,12 +1499,20 @@ impl MacroFixture {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_macro(macro_definition: &str) -> MacroFixture {
|
||||
let source_file = ast::SourceFile::parse(macro_definition).ok().unwrap();
|
||||
pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture {
|
||||
let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap();
|
||||
let macro_definition =
|
||||
source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
|
||||
|
||||
let (definition_tt, _) = ast_to_token_tree(¯o_definition.token_tree().unwrap()).unwrap();
|
||||
|
||||
let parsed = parse_to_token_tree(
|
||||
&ra_fixture[macro_definition.token_tree().unwrap().syntax().text_range()],
|
||||
)
|
||||
.unwrap()
|
||||
.0;
|
||||
assert_eq!(definition_tt, parsed);
|
||||
|
||||
let rules = MacroRules::parse(&definition_tt).unwrap();
|
||||
MacroFixture { rules }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue