Accept 4-5 quotes at end of triple-quoted string#2388
Merged
Conversation
added 4 commits
July 21, 2025 22:54
The FailFastErrors are really all from the parser, so now calling these CustomParserException, which is a thin wrapper around CustomParserErrors - this way we can treat errors the same regardless how they propagate to us, via megaparsec errors or jumping direct using Control.Exception (wrapped in CustomParserException). This means that we now use nice custom error types for exceptions we raise as Control.Exception from within the parser rather than just a single text message as we had in the FailFastError. Much nicer and we can now include hints in the parser exceptions!
The test suite and compiler now use the same error formatting logic for custom parse errors, ensuring that hints (like for type variable name errors) are preserved and displayed consistently. Our `handle` function dumbs down errors to our internal acton error type which just consists of (loc, msg) so hints etc get lost... but no more! - Add customParseExceptionToDiagnostic to convert exceptions with hints - Add customParseErrorDiagnostic for consistent formatting - Update ActonSpec.hs to use common diagnostic functions - Use handleDiagnostic for custom parse exceptions to preserve hints
In triple-quoted strings we accept unescaped quotes inside the string,
for example:
a = """"foo""" # note the 4 " at the start
a = """my dog "foo" ate the cat"""
But it hasn't been supported at the end
a = """foo""""
Because the first three " of the end run of 4 quote chars would be
recognized as the end of the string, leaving a single trailing " that
would result in a syntax error. That has now changed, so we accept 4 or
5 runs of quotes at the end, like so:
a = """foo"""" # string payload: foo"
^------ payload
^^^--- end of quote
a = """foo""""" # string payload: foo""
^^----- payload
^^^-- end of quote
Separate the note and hint - simple and clean!
e82dc2e to
2a455f3
Compare
Rather than printing little text messages we now emit proper structured
errors for a number of errors we have in the parser, in particular for
string formatting. This allows us to add Notes and Hints, for example:
ERROR: [error Syntax error]: Expected digits after '.' in format specifier
╭──▶ test@1:38-1:38
│
1 │ f"Missing precision digits {value:10.}"
•
• ╰╸ Expected digits after '.' in format specifier
•
│ Hint: Add precision digits, e.g. .2f for 2 decimal places
─────╯
27bade4 to
a9b91ef
Compare
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.
In triple-quoted strings we accept unescaped quotes inside the string,
for example:
But it hasn't been supported at the end
Because the first three " of the end run of 4 quote chars would be
recognized as the end of the string, leaving a single trailing " that
would result in a syntax error. That has now changed, so we accept 4 or
5 runs of quotes at the end, like so:
There are some preparatory commits first that restructure error handling and improves the flow so that we can propagate hints/notes in structured errors. Many errors from the parser have been converted to such structured errors and now come with Notes / Hints, for example:
Fixes #2387