-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
base: main
Are you sure you want to change the base?
Tolerant Block Parsing #7112
Conversation
@@ -317,6 +317,7 @@ pub fn desugar_expr<'a>( | |||
| AccessorFunction(_) | |||
| Var { .. } | |||
| Underscore { .. } | |||
| EmptyBlock(_) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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?
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. |
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:
The PR is only partially done, but I figured I'd release a draft to get eyes on the overall plan.