fix: keep the space before a hygieneInfo antiquotation - #15025
Open
mhuisi wants to merge 1 commit into
Open
Conversation
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>
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
|
The adaptation PR for this PR is leanprover/downstream-lean4#45. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR stops the parser from dropping the space in front of a
hygieneInfoantiquotation. 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).hygieneInfoFndoes 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.restoreonly shrinks the stack, so this edit is not undone by backtracking.hygieneInfowas wrapped inwithAntiquot, which keeps whichever alternative matches further and so runshygieneInfoFneven once the antiquotation has already matched. The result ofhygieneInfoFnwas then thrown away, but the space it had taken from·was not given back.Add
withAntiquotAcceptLhs, a variant ofwithAntiquotthat returns as soon as the antiquotation matches and never runs the second parser, and use it forhygieneInfo. SkippinghygieneInfoFncosts nothing here: it matches the empty string, so the antiquotation always matched further anyway.