Skip to content

feat: leading whitespace on first token - #12662

Merged
mhuisi merged 1 commit into
leanprover:masterfrom
mhuisi:push-qlmwuqotrxwu
Mar 6, 2026
Merged

mhuisi merged 1 commit into
leanprover:masterfrom
mhuisi:push-qlmwuqotrxwu

Conversation

@mhuisi

@mhuisi mhuisi commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

This PR adjusts the module parser to set the leading whitespace of the first token to the whitespace up to that token. If there are no actual tokens in the file, the leading whitespace is set on the final (empty) EOI token. This ensures that we do not lose the initial whitespace (e.g. comments) of a file in Syntax.

(Tests generated/adjusted by Claude)

@mhuisi mhuisi added the changelog-language Language features and metaprograms label Feb 23, 2026
@mhuisi
mhuisi requested a review from Kha February 23, 2026 19:30
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 23, 2026
@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-02-17 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-02-23 20:39:55)

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Feb 23, 2026
@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Feb 23, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 23, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Feb 23, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Feb 25, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 25, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Feb 26, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@mhuisi

mhuisi commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Mar 3, 2026 •

Copy link
Copy Markdown

Benchmark results for defcb0a against b4f768b are in! @mhuisi

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +263.2M (+0.00%)
  • 🟥 other exited with code 1

Small changes (1🟥)

  • 🟥 build/module/Lean.Parser.Module//instructions: +111.5M (+3.90%) (reduced significance based on *//lines)

@mhuisi

mhuisi commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

Copy link
Copy Markdown

Benchmark results for defcb0a against b4f768b are in! @mhuisi

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +263.2M (+0.00%)
  • 🟥 other exited with code 1

Small changes (1🟥)

  • 🟥 build/module/Lean.Parser.Module//instructions: +111.5M (+3.90%) (reduced significance based on *//lines)

@Garmelon

Garmelon commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

!bench

@leanprover-radar

leanprover-radar commented Mar 3, 2026 •

Copy link
Copy Markdown

Benchmark results for defcb0a against b4f768b are in! @Garmelon

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • ✅ build//instructions: -308.3M (-0.00%)

Large changes (1✅)

  • ✅ compiled/parser//instructions: -3.0G (-7.31%)

Small changes (1🟥)

  • 🟥 build/module/Lean.Parser.Module//instructions: +110.8M (+3.88%) (reduced significance based on *//lines)

@mhuisi
mhuisi added this pull request to the merge queue Mar 6, 2026
Merged via the queue into leanprover:master with commit 35944c3 Mar 6, 2026
15 checks passed
sgraf812 pushed a commit that referenced this pull request Mar 9, 2026
This PR adjusts the module parser to set the leading whitespace of the
first token to the whitespace up to that token. If there are no actual
tokens in the file, the leading whitespace is set on the final (empty)
EOI token. This ensures that we do not lose the initial whitespace (e.g.
comments) of a file in `Syntax`.

(Tests generated/adjusted by Claude)

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
wrenna-robson pushed a commit to wrenna-robson/lean4 that referenced this pull request Jul 15, 2026
wrenna-robson pushed a commit to wrenna-robson/lean4 that referenced this pull request Jul 17, 2026
medovina pushed a commit to medovina/verso that referenced this pull request Jul 28, 2026
… as whitespace (leanprover#924)

leanprover/lean4#12662 changed the module parser
to by default include the text preceding the first token in a Lean file
as whitespace belonging to that token. That parser infrastructure also
is used for `lean` blocks in the blog genre. The change in the PR had
the effect that the first `lean` block for an `exampleContext` always
included the whole preceding Verso file contents as leading whitespace
at the first command token.

Fixes leanprover#923.
robsimmons pushed a commit that referenced this pull request Jul 29, 2026
david-christiansen pushed a commit to leanprover/verso that referenced this pull request Aug 7, 2026
… as whitespace (#924)

leanprover/lean4#12662 changed the module parser
to by default include the text preceding the first token in a Lean file
as whitespace belonging to that token. That parser infrastructure also
is used for `lean` blocks in the blog genre. The change in the PR had
the effect that the first `lean` block for an `exampleContext` always
included the whole preceding Verso file contents as leading whitespace
at the first command token.

Fixes #923.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants