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

Consider using rustc_lexer #201

Open
CAD97 opened this issue Oct 7, 2019 · 2 comments · May be fixed by #202
Open

Consider using rustc_lexer #201

CAD97 opened this issue Oct 7, 2019 · 2 comments · May be fixed by #202

Comments

@CAD97
Copy link

CAD97 commented Oct 7, 2019

rustc_lexer

rustc_lexer is now the lexer used by rustc and is on crates for reuse. rust-analyzer is already using it. It would make sense for proc-macro2 to also use rustc_lexer and only have to do bracket matching and trivia stripping.

I spent a little time trying to do so, but I'm not familiar enough with the current fallback parser to do so. I can attempt just ripping everything out and building from scratch on rustc_lexer, but I'd prefer to have a go-ahead before putting time into that.

@mystor
Copy link
Contributor

mystor commented Oct 7, 2019

That's good to know! This would probably help fix #126 and related issues as well.

FWIW you probably wouldn't need to rip out the entire fallback parser as it exists today. The only entry-point to it (if I remember correctly), which is the FromStr impl for TokenStream.

This code then goes on to lex the entire input string & generate a TokenStream out of it. With the new API, you'd iterate over the tokenize output and generate the corresponding TokenTree instances. Once it's gone you can drop the strnom module and about ~600 lines of fallback.

@CAD97 CAD97 linked a pull request Oct 7, 2019 that will close this issue
@CAD97
Copy link
Author

CAD97 commented Oct 7, 2019

Unfortunate news: rustc_lexer uses std::iter::from_fn, which was stabilized in 1.34.0, which is later than the current MSRV of 1.31.0.

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 a pull request may close this issue.

2 participants