-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: validate atoms modulo leading and trailing whitespace #6012
fix: validate atoms modulo leading and trailing whitespace #6012
Conversation
The failing test defines this operator: /-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image Should this be allowed? I would think not, because deleting the leading space makes current versions of Lean reject it, and I would expect that pretty printing instructions were orthogonal to token rules. On that assumption, I'll update the test. |
This notation is also used in Mathlib. |
Why wouldn't this be allowed? Whitespace aside, it seems like a perfectly reasonable infix declaration. (Well, I do recall there was a hack added specifically to allow |
If it should be allowed, then shouldn't it be allowed whether or not the pretty-printer is instructed to insert whitespace before it? Today, |
I agree. They should both be accepted. |
The exception for empty character literals was added in #1931 . I think we need a similar exception at |
agreed |
This reverts commit 93c157c.
Great, While I'm at it, we presently allow atoms with internal spaces. Should we? This works, and I'm not sure it should:
|
Just to see if it breaks Mathlib, I gave it a go |
It seems that |
leanprover-community/batteries#1050 makes |
While I think batteries#1050 is reasonable, I don't see a particular reason to ban tokens including whitespace? That is a thing you might want to do, it gives additional flexibility to DSL writers. |
This was a balance of footgun vs flexibility. A consequence of the way If someone really needs precisely that level of flexiblity for their DSL, it's still possible to drop down and write the corresponding |
I agree on this, it's not the first time this mistake has been made and I don't think there are any commands in batteries or mathlib that would want to do this. But that's justification for a warning at best. |
@david-christiansen, I'm seeing
erroring with "invalid atom" now. Can we add some further flexibility to allow this? |
If a real-world use case arises, then we can revisit this. Right now, it doesn't seem like a good use of development resources - "no internal whitespace" is easy to implement and solves the problem, while making it a warning would require more time and increase the complexity of the code overall. |
This PR liberalizes atom rules by allowing `''` to be a prefix of an atom, after #6012 only added an exception for `''` alone, and also adds some unit tests for atom validation.
I had a use case for this come up: axiom SProp : Type
axiom SProp.ip : UInt64 → SProp
prefix:80 "RIP ↦ " => SProp.ip from some separation logic project I'm working on. As I understand it this will not work in the next version of lean, and the The other unfortunate side effect of using two tokens here is that it makes |
I'm not totally convinced by this use case for spaces in the tokens. It's not that it doesn't seem like what's being asked for is useful, it's just that it seems to me that the usefulness really comes from new features rather than from undoing this new validation step. Keeping the old behavior would have resulted in a keyword with a single space in it. It doesn't seem bonkers to allow multi-token operators, though I'd like to see why a notation doesn't do what you want here. I think it's OK if operators make easy things easy, but don't cover a wide range of syntax, and from what I can see, you'd get all the benefits of a two-token prefix operator from a |
No disagreement from me on this! I just wanted to give you a reasonable use case to center your thinking on this one.
The idea here is that Context on the project isn't too relevant to this feature request, but to explain a bit more: |
This PR improves the validation of new syntactic tokens. Previously, the validation code had inconsistencies: some atoms would be accepted only if they had a leading space as a pretty printer hint. Additionally, atoms with internal whitespace are no longer allowed.
Closes #6011