Skip to content
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

Require record fields to be simple identifiers #1086

Merged
merged 8 commits into from
Aug 2, 2023

Conversation

shonfeder
Copy link
Contributor

@shonfeder shonfeder commented Aug 1, 2023

When a :: appears in a quint identifiers, I am referring to that identifier as
"qualified". E.g., Foo::bar is qualified, but _ding is not.

This takes care of one problem identified in #1081 by introducing a syntax error
a record field is a qualified identifier.

Along the way, the PR also gives further illustration of how we can address #17
by using error grammar rules. (There was already precedent for this in the
errorEq rule checking for the misuse of = for equality). This shows how we
can move stronger syntactic checks into the grammar without sacrificing the
quality of our error messages.

E.g., errors for this new rule look like so:

>>> type r = {a: int, b::c::d: str}
syntax error: error: [QNT008] Identifiers in a record cannot be qualified with '::'. Found b::c::d.
type r = {a: int, b::c::d: str}
                         ^

To enable this improvement in the grammar, we had to refactor the lexical rule
for IDENTIFIER: without splitting this into a lexical rule for the
unqualified case and a grammar rule for the qualified, we end up with an
ambiguous lexical rule that makes parsing fail.

One incidental change is added to make the reference field in our error type
optional. This is implied by the fact that parser errors are errors that should
be represented with this structure, but we may not have a reference for them yet.

  • Tests added for any new code
  • [-] Documentation added for any new functionality
  • Entries added to the respective CHANGELOG.md for any new functionality
  • [-] Feature table on README.md updated for any listed functionality

Shon Feder added 5 commits August 1, 2023 17:08
I.e., prevent records like `{a::b::c : 1}`.

This includes refactoring the grammar so that qualified ids are now a
grammar rule rather than a lexical rule.
The previous commit made the `reference` field in quint errors optional,
this adapts the printer to handle that correctly.
@shonfeder
Copy link
Contributor Author

shonfeder commented Aug 1, 2023

The last three commits are generated/mechanical!

Shon Feder added 2 commits August 1, 2023 21:41
Add the generated but uncommitted test fixtures.
Move some notes to correct section, and add an entry for the stricter
rule for record labels.
Copy link
Contributor

@thpani thpani left a comment

Choose a reason for hiding this comment

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

Looks great!

I have an alternative suggestion to making the error type fields optional; not sure myself if I prefer one over the other.

quint/src/generated/QuintListener.ts Outdated Show resolved Hide resolved
quint/src/generated/Quint.g4 Show resolved Hide resolved
@shonfeder shonfeder merged commit 8feb3d8 into main Aug 2, 2023
15 checks passed
@shonfeder shonfeder deleted the 1081/simple-record-field-ids branch August 2, 2023 13:31
@shonfeder shonfeder self-assigned this Aug 2, 2023
@shonfeder shonfeder mentioned this pull request Aug 3, 2023
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.

2 participants