Skip to content

fix: keep the space before a hygieneInfo antiquotation - #15025

Open
mhuisi wants to merge 1 commit into
leanprover:masterfrom
mhuisi:push-vnppputzlnsn
Open

fix: keep the space before a hygieneInfo antiquotation#15025
mhuisi wants to merge 1 commit into
leanprover:masterfrom
mhuisi:push-vnppputzlnsn

Conversation

@mhuisi

@mhuisi mhuisi commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This PR stops the parser from dropping the space in front of a hygieneInfo antiquotation. The quotation `(· $h:hygieneInfo) was parsed into a tree in which the · token had lost its trailing space, so anything that rebuilds source text from that tree read it back as `(·$h:hygieneInfo).

hygieneInfoFn does more than push its own node. It also reaches back to the token already on the parser stack, takes that token's trailing whitespace away, and puts it on the node it builds. ParserState.restore only shrinks the stack, so this edit is not undone by backtracking.

hygieneInfo was wrapped in withAntiquot, which keeps whichever alternative matches further and so runs hygieneInfoFn even once the antiquotation has already matched. The result of hygieneInfoFn was then thrown away, but the space it had taken from · was not given back.

Add withAntiquotAcceptLhs, a variant of withAntiquot that returns as soon as the antiquotation matches and never runs the second parser, and use it for hygieneInfo. Skipping hygieneInfoFn costs nothing here: it matches the empty string, so the antiquotation always matched further anyway.

This PR stops the parser from dropping the space in front of a `hygieneInfo` antiquotation. The quotation `` `(· $h:hygieneInfo) `` was parsed into a tree in which the `·` token had lost its trailing space, so anything that rebuilds source text from that tree read it back as `` `(·$h:hygieneInfo) ``.

`hygieneInfoFn` does more than push its own node. It also reaches back to the token already on the parser stack, takes that token's trailing whitespace away, and puts it on the node it builds. `ParserState.restore` only shrinks the stack, so this edit is not undone by backtracking.

`hygieneInfo` was wrapped in `withAntiquot`, which keeps whichever alternative matches further and so runs `hygieneInfoFn` even once the antiquotation has already matched. The result of `hygieneInfoFn` was then thrown away, but the space it had taken from `·` was not given back.

Add `withAntiquotAcceptLhs`, a variant of `withAntiquot` that returns as soon as the antiquotation matches and never runs the second parser, and use it for `hygieneInfo`. Skipping `hygieneInfoFn` costs nothing here: it matches the empty string, so the antiquotation always matched further anyway.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mhuisi
mhuisi requested a review from kmill as a code owner September 4, 2026 12:55
@mhuisi mhuisi added the changelog-no Do not include this PR in the release changelog label Sep 4, 2026
@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 Sep 4, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-09-03 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-09-04 13:12:09)

@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Sep 4, 2026
@leanprover-bot

leanprover-bot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

@downstream-lean4

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#45.

@mhuisi
mhuisi requested a review from Kha September 4, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-manual CI has verified that the Lean Language Reference builds against this PR changelog-no Do not include this PR in the release changelog downstream Request a downstream-lean4 adaptation PR. 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.

2 participants