feat: forbid non-reserved identifiers via withForbidden#14432
Conversation
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
675571f to
44667e1
Compare
|
!bench |
|
Benchmark results for 44667e1 against a104164 are in. No significant results found. @sgraf812
Small changes (1✅, 2🟥)
|
|
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.
44667e1 to
79bbf4e
Compare
70fb0ea to
648cffa
Compare
|
Thanks for the review. Yes, we should do it on the raw string; the new test case tests for that now. While doing the check in |
|
!bench |
|
Benchmark results for 648cffa against a104164 are in. No significant results found. @sgraf812
Small changes (1✅, 2🟥)
|
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.We considered putting a unified check in
tokenFnormkIdResult, but decided against that. The former would move the check outside the cache and regress some benchmarks by ~1%. The latter forces a flag onmkIdResultandidentFnAuxbecausenameLitAuxandrawLitFnmust not forbid any tokens.