-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Reserved Prefixes RFC: How to handle TokenStream::from_str
?
#84979
Comments
cc @dtolnay @petrochenkov @rust-lang/lang |
Note that we're about to add |
@nikomatsakis said in rust-lang/rfcs#3101 (comment):
I think @dtolnay can answer that question. |
So, a few thoughts:
|
Isn't the prefix reservation supposed to be edition-independent based on the crater results? I hope that's true because the lexer library (the one shared with rust-analyzer) doesn't currently have any knowledge about editions, it also isn't supposed to have access to any global data (including "global edition") by design. |
@petrochenkov The generalized form of the RFC was not edition independent, as far as I know, and included things like prefixed literals ( |
@matklad @petrochenkov We discussed this a little in the T-lang meeting on 2021-05-18, and were interested in getting a bit more information about what the specific implications of introducing edition-dependent lexing are, and the extent to which this is a large problem. There's definitely a tradeoff here between simplicity (just reserve across all editions or don't do anything) and the relative desire to introduce new lexing rules. We're interested in your opinions on the downsides so that we can better evaluate that tradeoff. |
I wouldn't worry about rustc_lexer interface, I think it can support edition-dependent lexing in a rather clean way: // rustc_lexer
pub struct LexerConfig {
allow_string_prefixes: bool,
}
/// Parses the first token from the provided input string.
pub fn first_token(config: &LexerConfig, input: &str) -> Token {
debug_assert!(!input.is_empty());
Cursor::new(input).advance_token()
}
// Call-site in rustc/rust-analyzer
let lexer_config = if edition >= 2021 {
LexerConfig { allow_string_prefixes: true }
} else {
LexerConfig { allow_string_prefixes: false }
}
first_token(&lexer_config, token_text); I do worry about overall "erosion" of the nice token tree model. I think the original design was that token trees are a narrow public interface for macros. Tokens are simple, so we can just expose them and never need to redesign, right? Since then, we tweaked the design a number of times:
All of the above would be totally fine if tokens were a private impl detail of a particular compiler, but they are a part of public API. I can't say what problem exactly this creates (maybe it doesn't?), but I have a feeling of un-elegantness. |
I think there was a plan for suffixes/prefixes was to expose jointness not only for punctuation, but also for idents? Such that |
Are there similar issues, besides prefixes, which might require changes to the lexer? One thing that comes to mind is that we want to have |
We specifically wanted to make these things a lexer error, so we don't have to decide on the lexing rules for that literal yet. E.g. is |
@m-ou-se raised a point on rust-lang/rfcs#3101 that needs to be resolved in some way:
The text was updated successfully, but these errors were encountered: