Skip to content

parser: replace internal frontmatter lex with rustc_lexer::tokenize - #23289

Open
dimxy wants to merge 5 commits into
rust-lang:masterfrom
dimxy:eliminate-internal-frontmatter-lex
Open

dimxy wants to merge 5 commits into
rust-lang:masterfrom
dimxy:eliminate-internal-frontmatter-lex

Conversation

@dimxy

@dimxy dimxy commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Currently RA has its own shebang and frontmatter tokenizing code while the rustc tokenizer also does this job.
This PR eliminates internal frontmatter lex code and uses rustc_lexer::tokenize instead.
There are important notes about this code though:

  • Rustc performs its frontmatter validation in the parser (not in the tokenizer) so this PR has to borrow and implement those checks from the rustc parser.
  • Unlike RA, rustc_lexer::tokenize receives only normalized input (CRLF -> LF), so when used inside RA, it may return '\r' suffix in the frontmatter token and treat some infostrings with ending '\r' as invalid. Both these cases are processed in the PR's validate_frontmatter code. A test was added for CRLF input as well.

Fixes #23144. Added a test case.

Disclaimer: used Claude Code to help with code analysis and reviewing changes.

@dimxy
dimxy marked this pull request as ready for review September 14, 2026 10:14
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FP Syntax Error: expected an item

2 participants