Skip to content

Tidy the SAWCore parser #2331

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

Merged
merged 6 commits into from
May 15, 2025
Merged

Tidy the SAWCore parser #2331

merged 6 commits into from
May 15, 2025

Conversation

sauclovian-g
Copy link
Contributor

Make it more legible, fix a couple minor problems found while doing so.

No functional change intended.

Part 1; part 2 with purely whitespace will follow separately to make
it easier to audit the overall changes.
(part 2 of legibility cleanup)
Previously, if you wrote "module where" at the top of a SAWCore file
(instead of "module Foo where"), it was accepted by the grammar and
then called Haskell "error" to bail out.

Fix the grammar so this is a parse error, and change the error call
involved to a panic.

This degrades the message printed a bit, maybe, since there's no
longer an explicit "empty module name" message; but it now includes
the offending source position, which is quite a bit more important.

Add a test.

Note that the source position prints as rubbish; that's a different
problem (#2140)
It's important for readability to keep the grammar and the actions
visually separate, but also good to not become super-wide when doing
so.
Comment on lines +194 to +197
| IdentRec { Recursor Nothing $1 }
| 'Prop' { Sort (pos $1) propSort noFlags }
| Sort nat { Sort (pos $1) (mkSort (tokNat (val $2))) (val $1) }
| AtomTerm '.' Ident { RecordProj $1 (val $3) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The { Sort (pos $1) (mkSort (tokNat (val $2))) (val $1) } part is indented differently from the others—intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's so it fits the advertised edit width. Which isn't obvious from here.

Comment on lines +110 to +112
'data' Ident VarCtx ':' LTerm 'where' '{' list(CtorDecl) '}' { DataDecl $2 $3 $5 $8 }
| 'primitive' Ident ':' LTerm ';' { mkPrimitive $2 $4 }
| 'axiom' Ident ':' LTerm ';' { mkAxiom $2 $4 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment here about { DataDecl $2 $3 $5 $8 }.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that's to avoid indenting all the others by one more just because the LHS doesn't quite fit. I guess currently indenting all the others by one more would still fit the edit width (I think that wasn't true up front) so I could change it if you object strongly.

@sauclovian-g sauclovian-g merged commit 90ce9e7 into master May 15, 2025
37 checks passed
@sauclovian-g sauclovian-g deleted the tidy-sawcore-parser branch May 15, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants