feat: forbid non-reserved identifiers via withForbidden#14432
Open
sgraf812 wants to merge 2 commits into
Open
Conversation
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
sgraf812
force-pushed
the
sg/parser-forbid-idents
branch
from
July 17, 2026 12:52
675571f to
44667e1
Compare
Contributor
Author
|
!bench |
sgraf812
marked this pull request as ready for review
July 17, 2026 13:39
|
Benchmark results for 44667e1 against a104164 are in. No significant results found. @sgraf812
Small changes (1✅, 2🟥)
|
Contributor
|
Shouldn't this be something handled directly in |
This PR makes `withForbidden` stop a term at a non-reserved word used as an identifier, not just at a registered token. A parser like `withForbidden "invariant" termParser` now ends the term when it reaches a bare `invariant`, while `invariant` remains usable as an identifier everywhere else. `identFn` rejects an identifier whose text is in `forbiddenTks`, mirroring the forbidden-token check in `mkTokenAndFixPos`. The check is guarded by `forbiddenTks.isEmpty`, so the common identifier path is unchanged, and it does not affect `rawIdent` (field projections), the parenthesized escape via `withoutForbidden`, or reserved-token forbidding.
sgraf812
force-pushed
the
sg/parser-forbid-idents
branch
from
July 17, 2026 14:54
44667e1 to
79bbf4e
Compare
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 makes
withForbiddenstop a term at a non-reserved word used as an identifier, not just at a registered token. A parser likewithForbidden "invariant" termParsernow ends the term when it reaches a bareinvariant, whileinvariantremains usable as an identifier everywhere else.identFnrejects an identifier whose text is inforbiddenTks, mirroring the forbidden-token check inmkTokenAndFixPos. The check is guarded byforbiddenTks.isEmpty, so the common identifier path is unchanged, and it does not affectrawIdent(field projections), the parenthesized escape viawithoutForbidden, or reserved-token forbidding.Preparatory for
for … invariant … dodo-notation andrequire/ensurescontract clauses, whose clause keywords are deliberately non-reserved.