Fix DDM precedence for single-argument wrapper ops#437
Open
joehendrix wants to merge 1 commit intomainfrom
Open
Fix DDM precedence for single-argument wrapper ops#437joehendrix wants to merge 1 commit intomainfrom
joehendrix wants to merge 1 commit intomainfrom
Conversation
8374f0c to
e2bf62b
Compare
3cac801 to
b1d7961
Compare
- Introduce SyntaxDef.passthrough so wrapper ops inherit the argument's precedence instead of forcing maxPrec parenthesization - Remove dead unwrap field from SyntaxDefAtom.ident (only used via metadata) - Replace sorry proofs with decideProp checks and panic fallbacks - Move passthrough decision after argument-usage validation so polymorphic ops with inferred type params are still checked - Replace unsafe array indexing with bounds-checked access in Format.lean - Fix missing whitespace in C_Simp invariant/decreases grammar tokens Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b1d7961 to
82a9df7
Compare
keyboardDrummer
approved these changes
Feb 18, 2026
| Without the `rightassoc` annotation, this is equivalent to the definition: | ||
|
|
||
| ``` | ||
| fn implies (p : Pred, q : Pred) : Pred => @[prec(20)] p:20 " ==> " q:19; |
Contributor
There was a problem hiding this comment.
Is there no way to infer the correct argument precedence values? I would think that the operator precedence already fully determines the parsing behavior, and from that we should be able to infer how a dual printer should behave.
| precedence in syntax definitions. | ||
| ### Precedence | ||
|
|
||
| Precedence controls when parentheses are inserted during pretty-printing. |
Contributor
There was a problem hiding this comment.
Cool!
Do you assume that every language will use ( ) to group expressions? Seems fine but I'm asking out of curiosity. What about other ways to manipulate precedence, like inserting $ in Lean, would there be ways to generate that during printing?
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.
Summary
Reduce unnecessary parentheses in DDM pretty printing by overhauling syntax elaboration — convert
SyntaxDefto an inductive type withstd/passthroughvariants, fix precedence for wrapper and string-literal ops, remove deadunwrapcode, and rewrite the precedence documentation.Details
maxPrec + 1(never parenthesized)NatandDecimalliteralsmaxPrec + 1so they are never spuriouslyparenthesized (e.g.,
i + (1)→i + 1)unwrapfield fromSyntaxDefAtomand related dead code(
unwrapSpecs,unwrapTree); unwrap is only used via metadata in Gen.leanmeasure/invariant/pre/postgrammarDocumentation
and section hierarchy
🤖 Generated with Claude Code
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.