mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
debug impls
This commit is contained in:
parent
82cf0185c3
commit
2980508ad2
3 changed files with 47 additions and 2 deletions
|
@ -250,3 +250,29 @@ fn convert_tt(tt: &SyntaxNode) -> Option<tt::Subtree> {
|
||||||
};
|
};
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_convert_tt() {
|
||||||
|
let text = r#"
|
||||||
|
macro_rules! impl_froms {
|
||||||
|
($e:ident: $($v:ident), *) => {
|
||||||
|
$(
|
||||||
|
impl From<$v> for $e {
|
||||||
|
fn from(it: $v) -> $e {
|
||||||
|
$e::$v(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
let source_file = ast::SourceFile::parse(text);
|
||||||
|
let maco_call = source_file
|
||||||
|
.syntax()
|
||||||
|
.descendants()
|
||||||
|
.find_map(ast::MacroCall::cast)
|
||||||
|
.unwrap();
|
||||||
|
let tt = macro_call_to_tt(maco_call).unwrap();
|
||||||
|
let tt = mbe::parse(&tt);
|
||||||
|
dbg!(tt);
|
||||||
|
}
|
||||||
|
|
|
@ -2,21 +2,25 @@ use ra_syntax::SmolStr;
|
||||||
|
|
||||||
use crate::macros::tt;
|
use crate::macros::tt;
|
||||||
|
|
||||||
struct MacroRules {
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct MacroRules {
|
||||||
rules: Vec<Rule>,
|
rules: Vec<Rule>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Rule {
|
struct Rule {
|
||||||
lhs: TokenTree,
|
lhs: TokenTree,
|
||||||
rhs: TokenTree,
|
rhs: TokenTree,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
enum TokenTree {
|
enum TokenTree {
|
||||||
Leaf(Leaf),
|
Leaf(Leaf),
|
||||||
Subtree(Subtree),
|
Subtree(Subtree),
|
||||||
Repeat(Repeat),
|
Repeat(Repeat),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
enum Leaf {
|
enum Leaf {
|
||||||
Literal(Literal),
|
Literal(Literal),
|
||||||
Punct(Punct),
|
Punct(Punct),
|
||||||
|
@ -24,11 +28,13 @@ enum Leaf {
|
||||||
Var(Var),
|
Var(Var),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Subtree {
|
struct Subtree {
|
||||||
delimiter: Delimiter,
|
delimiter: Delimiter,
|
||||||
token_trees: Vec<TokenTree>,
|
token_trees: Vec<TokenTree>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
enum Delimiter {
|
enum Delimiter {
|
||||||
Parenthesis,
|
Parenthesis,
|
||||||
Brace,
|
Brace,
|
||||||
|
@ -36,33 +42,39 @@ enum Delimiter {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Repeat {
|
struct Repeat {
|
||||||
subtree: Subtree,
|
subtree: Subtree,
|
||||||
kind: RepeatKind,
|
kind: RepeatKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
enum RepeatKind {
|
enum RepeatKind {
|
||||||
ZeroOrMore,
|
ZeroOrMore,
|
||||||
OneOrMore,
|
OneOrMore,
|
||||||
ZeroOrOne,
|
ZeroOrOne,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Literal {
|
struct Literal {
|
||||||
text: SmolStr,
|
text: SmolStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Punct {
|
struct Punct {
|
||||||
char: char,
|
char: char,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Ident {
|
struct Ident {
|
||||||
text: SmolStr,
|
text: SmolStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct Var {
|
struct Var {
|
||||||
text: SmolStr,
|
text: SmolStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(tt: tt::TokenTree) -> MacroRules {
|
pub(crate) fn parse(tt: &tt::Subtree) -> MacroRules {
|
||||||
MacroRules { rules: Vec::new() }
|
MacroRules { rules: Vec::new() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::SmolStr;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) enum TokenTree {
|
pub(crate) enum TokenTree {
|
||||||
Leaf(Leaf),
|
Leaf(Leaf),
|
||||||
Subtree(Subtree),
|
Subtree(Subtree),
|
||||||
}
|
}
|
||||||
impl_froms!(TokenTree: Leaf, Subtree);
|
impl_froms!(TokenTree: Leaf, Subtree);
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) enum Leaf {
|
pub(crate) enum Leaf {
|
||||||
Literal(Literal),
|
Literal(Literal),
|
||||||
Punct(Punct),
|
Punct(Punct),
|
||||||
|
@ -13,11 +15,13 @@ pub(crate) enum Leaf {
|
||||||
}
|
}
|
||||||
impl_froms!(Leaf: Literal, Punct, Ident);
|
impl_froms!(Leaf: Literal, Punct, Ident);
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct Subtree {
|
pub(crate) struct Subtree {
|
||||||
pub(crate) delimiter: Delimiter,
|
pub(crate) delimiter: Delimiter,
|
||||||
pub(crate) token_trees: Vec<TokenTree>,
|
pub(crate) token_trees: Vec<TokenTree>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) enum Delimiter {
|
pub(crate) enum Delimiter {
|
||||||
Parenthesis,
|
Parenthesis,
|
||||||
Brace,
|
Brace,
|
||||||
|
@ -25,14 +29,17 @@ pub(crate) enum Delimiter {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct Literal {
|
pub(crate) struct Literal {
|
||||||
pub(crate) text: SmolStr,
|
pub(crate) text: SmolStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct Punct {
|
pub(crate) struct Punct {
|
||||||
pub(crate) char: char,
|
pub(crate) char: char,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct Ident {
|
pub(crate) struct Ident {
|
||||||
pub(crate) text: SmolStr,
|
pub(crate) text: SmolStr,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue