-
Notifications
You must be signed in to change notification settings - Fork 23
Add SpaceSepBy and SpacePrefixSepBy constructs + nonempty attribute #312
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
Conversation
- Implemented SpaceSepBy, SpaceSepByNonEmpty, SpacePrefixedBy, SpacePrefixedByNonEmpty - Added support in AST, Parser, Format, Ion, Elab, and code generation - Updated SMT dialect to use new constructs, removing manual list categories - Simplified SMT dialect by eliminating IndexList, SMTSortList, TermList, etc. - All constructs parse elements with automatic whitespace handling - Formatting adds spaces between (SpaceSepBy) or before (SpacePrefixedBy) elements - Fixed unused variable warnings
d3ab789 to
fbadfef
Compare
aqjune-aws
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a great direction to me.
What do you think about the following changes?
- What do you think about marking non-emptiness using a new attribute, say
@[nonempty]? This way, we can also decorate existingcommaSepList. :) - I think the usefulness of
SpacePrefixedByandSpacePrefixedByNonEmptyis somewhat limited, sinceSpacePrefixedBycan always be replaced with" " SpaceSepBy(and similarly forSpacePrefixedByNonEmpty). What do you think about having this patch minimalistic and focusing on addingSpaceSepByandSpaceSepByNonEmptyonly? This will already be a very useful change.
I love this idea. Let me try that.
|
- Add @[nonempty] metadata attribute in StrataDDL - Remove SpaceSepByNonEmpty and SpacePrefixedByNonEmpty categories - Remove spaceSepListNonEmpty and spacePrefixedListNonEmpty AST constructors - Update parser to check @[nonempty] metadata and use many1Parser/sepBy1Parser - Update all supporting files (Format, Ion, ToExpr, OfAstM, Gen, Elab) - Replace all SpaceSepByNonEmpty usage with @[nonempty] SpaceSepBy in SMT dialect - Add comprehensive tests in StrataTest/DDM/NonemptyAttribute.lean - Clarify that SpaceSepBy/SpacePrefixedBy/Seq parse identically, differ only in formatting
aqjune-aws
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your updates..! I believe the two categories spaceSepBy and spacePrefixedBy are indeed useful ones.
Two more comments:
- Should we rename
spacePrefixedBytospaceSepPrefixedByto represent thatspacePrefixedByalso separates a list of items? - Let's add the two new categories as well as the nonempty attribute to
docs/verso/DDMDoc.leanas well. :)
…refixedBy - Unify commaSepList, spaceSepList, spacePrefixedList into single .seq constructor - Add SepFormat enum (.none, .comma, .space, .spacePrefix) to specify formatting - Rename SpacePrefixedBy to SpacePrefixSepBy throughout codebase - Remove unused spacePrefixedParser and spacePrefixed1Parser functions - Update all files to use new unified structure (AST, Format, Ion, ToExpr, OfAstM, Gen) - Update dialect translation files (Boogie, C_Simp, SMT) - Rename ofSpacePrefixedByM to ofSpacePrefixSepByM - Update documentation in docs/verso/DDMDoc.lean: - Document SpaceSepBy and SpacePrefixSepBy categories - Document @[nonempty] attribute for enforcing non-empty lists - Clarify parsing vs formatting differences for list categories
- Resolved conflict in StrataDDL.lean by keeping both nonempty and new constructor metadata - Fixed remaining commaSepList reference in Boogie Translate
- Update Java TestGen to use .seq with 3 arguments (ann, sep, array) - Update DDM Gen test expected output to show SepFormat.comma instead of commaSepList
- Update translateParameters to match .seq _ .comma - Update translateStmtExpr to match .seq _ .comma - Update translateSeqCommand to match .seq _ .none
- Add seq1 operation with @[nonempty] Seq - Add seq0 operation without @[nonempty] - Verify @[nonempty] enforcement works with Seq - Verify empty Seq is allowed without @[nonempty]
…nitions - Added SepFormat.fromIonName? with roundtrip theorem - Extracted toAstApplyArgSeq helper in Gen.lean to eliminate duplication - Added ofSeqSeqM wrapper in OfAstM.lean for plain Seq category - Refactored Ion.lean ArgF.fromIon to use SepFormat.fromIonName? instead of four separate cases - Simplified Parser.lean checkLeftRec with consolidated if statement - Extracted getOfIdentArgSeq helper in Gen.lean where clause
- Removed ofCommaSepByM, ofSpaceSepByM, ofSpacePrefixSepByM, ofSeqSeqM wrappers - Updated getOfIdentArgSeq to pass SepFormat directly to ofSeqM - Simplifies code by eliminating unnecessary one-line wrapper functions
- Replaced CommaSepInfo, SpaceSepInfo, SpacePrefixedInfo with single SeqInfo taking SepFormat parameter - Removed duplicate Info constructors (ofCommaSepInfo, ofSpaceSepInfo, ofSpacePrefixedInfo) - Updated asCommaSepInfo functions to check sep field - Extracted elabSeqWith helper in Core.lean to consolidate four similar elaboration cases - Reduces code duplication by ~50 lines across Tree.lean and Core.lean
aqjune-aws
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
Add space-separated list constructs and
@[nonempty]attribute to Strata DDM.New DDM Constructs
SpaceSepBy- Space-separated lists (renders asa b c)SpacePrefixSepBy- Space-prefix-separated lists (renders asa b c)Both parse identically to
Seq(whitespace-separated items) but differ in formatting.@[nonempty]AttributeMark list arguments to require at least one element:
Parser enforces non-emptiness with error: "expected at least one element"
Usage
Works with
CommaSepBy,SpaceSepBy,SpacePrefixSepBy, andSeq.Example from SMT dialect:
Tests in
StrataTest/DDM/NonemptyAttribute.leanverify enforcement.