-
Notifications
You must be signed in to change notification settings - Fork 444
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
Allow trailing comma in tuples, lists, and tactics #2643
Conversation
I'm modifying the array syntax and for some reason this doesn't work -- src/Init/Data/Array/Basic.lean
syntax "#[" withoutPosition(sepBy(term, ", ", allowTrailingSep)) "]" : term which gives
This is puzzling since the 3rd argument is explicitly marked as optional: -- src/Lean/Parser/Syntax.lean
@[builtin_syntax_parser] def sepBy := leading_parser
"sepBy(" >> withoutPosition (many1 syntaxParser >> ", " >> strLit >>
optional (", " >> many1 syntaxParser) >> optional (", " >> nonReservedSymbol "allowTrailingSep")) >> ")" |
Because there isn't any disambiguator between the two optional fields, it just prefers the first parse in which |
I tried |
It should... one is literally just a macro for the other. What error do you get, and when? |
This is what I get when I write either of -- Array/Basic.lean
syntax "#[" withoutPosition(term,*,?) "]" : term
syntax "#[" withoutPosition(sepBy(term, ",", ", ", allowTrailingSep)) "]" : term The same schematic allowed me to implement trailing comma for lists though
|
That's a bootstrapping issue, you will get the same error making any change to a builtin parser. See https://leanprover.zulipchat.com/#narrow/stream/341532-lean4-dev/topic/Bootstrapping.20issue.3F for a recent similar discussion, and see if setting parseQuotWithCurrentStage in stage0/src/stdlib_flags.h works for you. |
Would the unit tests pass if I just change the file in |
You should make the stage0 change (and commit it), then run |
|
I think I'm doing this correctly but it is not working:
which gives Lean/SubExpr.lean:198:21: error: elaboration function for '«term#[_,]»' has not been implemented
[Error pretty printing syntax: unknown constant 'term#[_,]'. Falling back to raw printer.]
(«term#[_,]»
"#["
[(Term.app `toJson[email protected]._hyg.1526 [`a[email protected]._hyg.1870])
","
(Term.app `toJson[email protected]._hyg.1526 [`a[email protected]._hyg.1871])]
"]")
Lean/SubExpr.lean:198:21: error: elaboration function for '«term#[_,]»' has not been implemented
[Error pretty printing syntax: unknown constant 'term#[_,]'. Falling back to raw printer.]
(«term#[_,]»
"#["
[(Term.app `toJson[email protected]._hyg.1526 [`a[email protected]._hyg.1872])
","
(Term.app `toJson[email protected]._hyg.1526 [`a[email protected]._hyg.1873])]
"]")
[ ] Building ../build/debug/stage1/lib/temp/Lean/Elab/Config.c This fails even if I just write |
I believe the reason for the change is that the default name for the |
How come the same change for list was fine? |
Most likely because the derive handler in question (running stage0 code which is no longer correct) happens to be constructing arrays and not lists. |
so should I just leave the stage 0 code alone and add a separate syntax for arrays with a trailing comma? |
I dug into this a bit more and all of the errors occur in |
67fbcfb
to
5f8d488
Compare
@semorrison Could you take a look to see if this is ready to merge? |
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.
LGTM, but just to double-check: are we happy with (1,)
meaning the same as (1)
? It has a special meaning (1-tuple) in Python but I don't think that has to affect the design of a statically typed language like Lean.
Hmm this is a good point. I think tuples should not allow trailing commas. |
I lean toward allowing this, with |
Thanks! |
Put an X in this bracket to confirm you have read the
External Contribution Guidelines.
Please put the link to your
RFC
orbug
issue here.PRs missing this link will be marked as
missing RFC
.#2635
If that issue does not already have approval from a developer,
please be sure to open this PR in "Draft" mode.
Please make sure the PR has excellent documentation and tests.
If we label it
missing documentation
ormissing tests
then it needs fixing!You can manage the
awaiting-review
,awaiting-author
, andWIP
labelsyourself, by writing a comment containing one of these labels on its own line.