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

Handle empty code blocks in Doc2 #5352

Merged
merged 2 commits into from
Sep 20, 2024
Merged

Conversation

sellout
Copy link
Contributor

@sellout sellout commented Sep 17, 2024

Overview

Empty code blocks still fail, but as a normal Unison error, not a Haskell exception. This matches their behavior in previous releases.

Fixes #5349.

Implementation notes

With the update to the Doc2 parser in #5187, there was the introduction of a dummy layout block used to delimit the boundary of the Unison parser state outside the current Doc2 block and inside it.

There were two bugs here – the first was using List.last, which is what crashed the lexer when there were no tokens lexed. That is avoided by always getting a fresh position rather than the position of the last token.

But that hid the real issue, which is that if there were no tokens lexed, the dummy block never moved to layout and rather than inserting the correct number of Close tokens to complete the block, it closed all of the blocks, including the ones outside of the Doc2 block. Since the ParsingEnv is local, we can just start with an empty layout, making it impossible to close extra blocks.

Test coverage

There is a new transcript that covers a few different code blocks in Doc cases, and a trivial empty lex case in unison-syntax tests.

Loose ends

There is still some overly complicated layout-based logic spread throughout the lexer, notably in token''.

Empty blocks still fail, which matches the previous behavior, but we should handle this more gracefully inside Doc, so that bad Docs don’t fail the parser.

There is no output, because this results in a Haskell exception, not a
Unison error.
These code blocks still fail, but as a normal Unison error, not a Haskell exception. This matches their
behavior in previous releases.

Fixes unisonweb#5349.
Copy link
Contributor

@aryairani aryairani left a comment

Choose a reason for hiding this comment

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

👍

@aryairani aryairani merged commit 7cdd9c1 into unisonweb:trunk Sep 20, 2024
17 checks passed
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.

Empty code block in doc causes UCM exception
2 participants