Skip to content

Improve TokenTree variants #18229

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

Merged
merged 7 commits into from
Oct 28, 2014
Merged

Improve TokenTree variants #18229

merged 7 commits into from
Oct 28, 2014

Conversation

brendanzab
Copy link
Member

I have renamed the TokenTree variants to be longer and clearer, and to use standard capitalisation. They should also fit in better with the existing TTNonterminal variant.

The new definition of TtDelimited adds an associated Span that covers the whole token tree, and moves the opening and closing delimiters out of the vector of delimited token trees. This came up when working on the gl-rs generator plugin.

The bool in TtSequence has been replaced with a KleeneOp enum. This should make the intent of the code clearer (I had trouble understanding it).

A get_span method has also been added to TokenTree type to make it easier to implement better error messages for syntax extensions.

[breaking-change]

Renamed:

  • TTTok -> TtToken
  • TTDelim -> TtDelimited
  • TTSeq -> TtSequence
  • TTNonterminal -> TtNonterminal

New definition of TtDelimited:

TtDelimited(Span, Rc<(Delimiter, Vec<TokenTree>, Delimiter)>)

New definition of TtSequence:

TtSequence(Span, Rc<Vec<TokenTree>>, Option<::parse::token::Token>, KleeneOp)

@brendanzab brendanzab changed the title Add Span and separate open/close delims to TTDelim Rename TokenTree variants for Clarity, and solidify delimeter invariants Oct 22, 2014
@brendanzab brendanzab changed the title Rename TokenTree variants for Clarity, and solidify delimeter invariants Rename TokenTree variants for clarity and solidify delimeter invariants Oct 22, 2014
@brendanzab brendanzab changed the title Rename TokenTree variants for clarity and solidify delimeter invariants Rename TokenTree variants for clarity and solidify delimiter invariants Oct 22, 2014
@brendanzab brendanzab added the A-parser Area: The lexing & parsing of Rust source code to an AST label Oct 22, 2014
@brendanzab brendanzab force-pushed the ttdelim branch 3 times, most recently from 448b25d to 7580e84 Compare October 22, 2014 14:47
@pczarn
Copy link
Contributor

pczarn commented Oct 22, 2014

Could you rename TTTok to TtToken etc. as per convention?

Don't you think the new TTDelimited will increase memory usage? The size of each TokenTree will be 1+2+(2+1+1+2)*2+1 = 16 words, in contrast to 10 words thus far on x64.

cc #17830.

@brendanzab
Copy link
Member Author

Ah, this is true... Would boxing the delimiters help? That would take us to 12 words if my calculations are correct...

@pczarn
Copy link
Contributor

pczarn commented Oct 22, 2014

Very nice. Isn't it 6 words? TtSequence looks larger. Ideally, TtDelimited would contain Rc<(Delimiter, Vec<TokenTree>, Delimiter)> (not considering DST). But this won't change the size in practice.

@brendanzab
Copy link
Member Author

Unfortunately with this you lose the nice patten matching... but I guess that is not the biggest issue.

@brendanzab
Copy link
Member Author

Ok, updated with your suggestion.

@brendanzab brendanzab changed the title Rename TokenTree variants for clarity and solidify delimiter invariants Improve TokenTree variants Oct 23, 2014
@brendanzab
Copy link
Member Author

I've also just made a change to TtSequence to make it a bit clearer.

This came up when working [on the gl-rs generator extension](https://github.com/bjz/gl-rs/blob/990383de801bd2e233159d5be07c9b5622827620/src/gl_generator/lib.rs#L135-L146).

The new definition of  `TTDelim` adds an associated `Span` that covers the whole token tree and enforces the invariant that a delimited sequence of token trees must have an opening and closing delimiter.

A `get_span` method has also been added to `TokenTree` type to make it easier to implement better error messages for syntax extensions.
This should be clearer, and fits in better with the `TTNonterminal` variant.

Renames:

- `TTTok` -> `TTToken`
- `TTDelim` -> `TTDelimited`
- `TTSeq` -> `TTSequence`
@brendanzab
Copy link
Member Author

Rebased

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 27, 2014
@bors bors merged commit 6598d33 into rust-lang:master Oct 28, 2014
@brendanzab brendanzab deleted the ttdelim branch October 28, 2014 01:17
lnicola pushed a commit to lnicola/rust that referenced this pull request Oct 17, 2024
fix: Join rustfmt overrideCommand with project root

When providing a custom rustfmt command, join it with the project root instead of the workspace root. This fixes rust-analyzer getting the wrong invocation path in projects containing subprojects.

This makes the behaviour consistent with how a custom path provided in rust-analyzer.procMacro.server behaves already.

Resolves issue rust-lang#18222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants