Skip to content

Conversation

pchiusano
Copy link
Member

Fixes #4384

Previously, code like this would not parse:

fix_4384a = {{ {{ docExampleBlock 0 do 1  }} }}

fix_4384b = {{ {{ docExampleBlock 0 do
  x = 1
  y = 2
  x + y
  }} }}

Now it parses fine. The fix was to re-enable layout within a transclusion, and to have }} pop layout up to the enclosing {{. Prior to this change, layout was incorrectly being entirely disabled within a doc block, even within a nested transclusion which can contain arbitrary Unison code that uses layout.

The diff is actually very small, just one function (see self-review), but I had to move some helper functions out of a where clause to make them available for this change, so the actual diff looks bigger.

Interesting/controversial decisions

Nothing.

Test coverage

Added regression tests, including some weird examples I could think of, and existing transcripts cover the doc syntax. I feel pretty confident this can only improve parsing and round trip issues, but after merging to trunk, I'd recommend dogfooding it for a couple days just to make sure there aren't any regressions in weird corner cases I haven't thought of.

cc @stew @runarorama @ceedubs who I know have been affected by this.

Copy link
Member Author

@pchiusano pchiusano left a comment

Choose a reason for hiding this comment

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

Self review.

Comment on lines 538 to +553
P.label "transclusion (examples: {{ doc2 }}, {{ sepBy s [doc1, doc2] }})" $
wrap "syntax.docTransclude" $
docOpen *> lexemes' docClose
openAs "{{" "syntax.docTransclude"
<+> do {
env0 <- S.get;
-- we re-allow layout within a transclusion, then restore it to its
-- previous state after
S.put (env0 { inLayout = True });
-- Note: this P.lookAhead ensures the }} isn't consumed,
-- so it can be consumed below by the `close` which will
-- pop items off the layout stack up to the nearest enclosing
-- syntax.docTransclude.
ts <- lexemes' (P.lookAhead ([] <$ lit "}}"));
S.modify (\env -> env { inLayout = inLayout env0 });
pure ts
}
<+> close ["syntax.docTransclude"] (lit "}}")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the actual fix / change. The rest is just shuffling things around.

@pchiusano pchiusano requested a review from aryairani December 1, 2023 16:37
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.

Thanks!

@aryairani aryairani added the ready-to-merge Apply this to a PR and it will get merged automatically once CI passes and 1 reviewer has approved label Dec 1, 2023
@mergify mergify bot merged commit 95eabce into trunk Dec 1, 2023
@mergify mergify bot deleted the fix/4384 branch December 1, 2023 17:00
@mergify mergify bot removed the ready-to-merge Apply this to a PR and it will get merged automatically once CI passes and 1 reviewer has approved label Dec 1, 2023
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.

Parse error parsing blocks in doc quasiquote
2 participants