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

Tolerant Block Parsing #7112

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smores56
Copy link
Collaborator

This PR plans to convert empty blocks into malformed blocks and add malformed expressions to the end of blocks not already ending in expressions. In doing so, we can make the user experience better for Roc devs by more consistently continuing to parse and analyze incorrect code.

An example error:

── MISSING BODY in /home/smores/dev/test.roc ───────────────────────────────────

This definition has no body:

26│  { x, y } =
     ^^^^^^^^^^

I would need to crash if I used it!

The PR is only partially done, but I figured I'd release a draft to get eyes on the overall plan.

@smores56 smores56 marked this pull request as draft September 22, 2024 12:26
@@ -317,6 +317,7 @@ pub fn desugar_expr<'a>(
| AccessorFunction(_)
| Var { .. }
| Underscore { .. }
| EmptyBlock(_)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Slight preference to calling this MalformedEmptyBlock, to make it extra clear

@@ -539,6 +541,15 @@ pub enum Expr<'a> {
OptionalFieldInRecordBuilder(&'a Loc<&'a str>, &'a Loc<Expr<'a>>),
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EmptyBlockParent {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this information be derivable from where the empty block exists in the syntax tree?

),
map_with_arena(
space0_after_e(
optional(space0_after_e(
block(options, false, EIf::IndentThenBranch, EIf::ThenBranch),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if we just made the block function return in malformed empty block?

@smores56
Copy link
Collaborator Author

Just to update anyone wondering on the status of this PR, I'm trying to consider some advice given to me by Joshua Warner on Zulip. Specifically, he thinks that we can potentially track where in an invalid AST node we find a failure with the existing context node code and, I presume, recover parsing based on indentation afterwards. For now, I will leave this PR up while I investigate that option, but expect I may come back to this parsing and canonicalization-aware solution if that doesn't pan out. It might take some time, this is a low priority change.

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