Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST improvements to support conversion to rustc AST #3838

Closed
wants to merge 7 commits into from

Conversation

luca-barbieri
Copy link
Contributor

This is a set of improvements that I done while creating a rustc branch that can use rust-analyzer to parse code and convert the rust-analyzer AST to rustc's internal AST format, found at rust-lang/rust#70745

The goal is to extend the helper classes implementing AstNode and similar classes so that the AST can be examined solely using them.

@bjorn3
Copy link
Member

bjorn3 commented Apr 3, 2020

The last four commits are committed by Your Name.

- Adds a new AstElement trait that is implemented by all generated
  node, token and enum structs

- Overhauls the code generators to code-generate all tokens, and
  also enhances enums to support including tokens, node, and nested
  enums
We used to parse it as T: Fn() -> (u8 + Send), which is different from
the rustc behavior of T: (Fn() -> u8) + Send
This allows to mark subnodes with #[sep], which will result in
"splitting" the node using them, allowing to match other fields only
if found in the proper separation.

For instance, this will work:

Addition {
  lhs: Expr,
  #[sep] Plus,
  rhs: Expr
}
This requires the #[sep] support, since the MacroCall node can either
be a Pat or an Expr.
@matklad
Copy link
Member

matklad commented Apr 7, 2020

I'll try to merge most of these during the next few days! I'd rather do this myself manually, as this'll conflict with everything!

@matklad
Copy link
Member

matklad commented Apr 9, 2020

I've merged most of the things here into master. Most notable things not merged:

  • the AstNode and AstToken traits are left as is. No new AstElement traits is added. I would like to separatenly consider the most perfect interface here
  • no support for #[sep]: this needs to be examined on a case-by-case basis, but my hunch is that we actually just want to add some extra wrappers to the AST. Like, the problem with pat macro_call being confused with an expr macro call was solved by introduction of ast::MacroPat

Thanks for putting this together @luca-barbieri !

@matklad matklad closed this Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants