Skip to content

Fix parsing of indented modules #63

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

Merged
merged 2 commits into from
May 26, 2025
Merged

Fix parsing of indented modules #63

merged 2 commits into from
May 26, 2025

Conversation

natefaubion
Copy link
Owner

No description provided.

Indented modules weren't parsing due to an error in how the recovery
routine derived the current indent column.

Recovery derived the indent from the layout stack in the token stream.
This layout stack, however, represents the stack after the current
token. This is usually OK, but has an edge case when the current token
is TokLayoutEnd. For the purposes of recovery, we want TokLayoutEnd's
column to represent the current indent.

In the specific case of top-level module/declaration parsing, we invoke
recovery for all declarations, which are also wrapped in a `many`.
Indentation recovery eats any token indented more than the current
indentation. Once we get to a TokLayoutEnd for the module, which closes
the top-level `where` block, the current layout stack is only LytRoot,
so the indent defaults to 0. Because the module is also indented to 0,
this will fail the recovery predicate as we expect, resulting in a
correct module parse. When the indent is more than 0, it will satisfy
the recovery predicate (since TokLayoutEnd col is greater than 0),
eating the TokLayoutEnd token. Module parsing would then fail due to an
unexpected EOF (where TokLayoutEnd was expected).

When take the TokLayoutEnd column into account when deriving the
current indent, then the recovery predicate will fail as expected,
resulting in a correct parse.

Fixes #56
While there are no currently known bugs due to this, the consumed
semantics are implemented incorrectly. Consumed should act as a
Semigroup across binds (Writer).
@natefaubion natefaubion merged commit 4913300 into main May 26, 2025
1 check passed
@natefaubion natefaubion deleted the fix-root-indent branch May 26, 2025 17:26
natefaubion added a commit that referenced this pull request May 26, 2025
With the fixes to indentation recovery in #63, the workaround for empty
ado parsing is no longer necessary. This effectively reverts #46.
@natefaubion natefaubion mentioned this pull request May 26, 2025
natefaubion added a commit that referenced this pull request May 26, 2025
With the fixes to indentation recovery in #63, the workaround for empty
ado parsing is no longer necessary. This effectively reverts #46.
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.

1 participant