Skip to content

Commit

Permalink
Merge pull request #4312 from unisonweb/fix/doc-eval-pp
Browse files Browse the repository at this point in the history
Prefer triple backtick syntax during doc source printing, even for old docs
  • Loading branch information
runarorama authored Sep 8, 2023
2 parents 3565bfa + d494cf7 commit 0a9ed4d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion parser-typechecker/src/Unison/Syntax/TermPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ toDocVerbatim ppe (App' (Ref' r) (toDocWord ppe -> Just txt))
toDocVerbatim _ _ = Nothing

toDocEval :: (Var v) => PrettyPrintEnv -> Term3 v PrintAnnotation -> Maybe (Term3 v PrintAnnotation)
toDocEval ppe (App' (Ref' r) (Delay' tm))
toDocEval ppe (App' (Ref' r) (DDelay' tm))
| nameEndsWith ppe ".docEval" r = Just tm
| r == _oldDocEval = Just tm
toDocEval _ _ = Nothing
Expand Down
6 changes: 2 additions & 4 deletions unison-src/transcripts-round-trip/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ x = ()
.a3_old> delete.namespace.force lib.builtin
```

These are currently all expected to have different hashes on round trip, though we'd prefer if they round tripped with the same hash.
These are currently all expected to have different hashes on round trip.

NOTE, since we don't currently have anything that round trips with a different hash, this fails. If you find an example that reparses with a different hash, add it to `reparses.u` and change this stanza to `ucm` rather than `ucm:error`.

```ucm:error
```ucm
.> diff.namespace a3 a3_old
```

Expand Down
23 changes: 19 additions & 4 deletions unison-src/transcripts-round-trip/main.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,19 +641,34 @@ x = ()
Put definitions in here that are expected to
parse with a different hash after pretty-printing.
"""
sloppyDocEval : Doc2
sloppyDocEval =
use Nat +
{{
Here's an example of an eval block that's technically a
lambda but should print as a backticked block (since old
docs in the wild still use this format).
```
1 + 1
```
}}

You can edit them there, then do `update` to replace the
definitions currently in this namespace.

```
These are currently all expected to have different hashes on round trip, though we'd prefer if they round tripped with the same hash.

NOTE, since we don't currently have anything that round trips with a different hash, this fails. If you find an example that reparses with a different hash, add it to `reparses.u` and change this stanza to `ucm` rather than `ucm:error`.
These are currently all expected to have different hashes on round trip.
```ucm
.> diff.namespace a3 a3_old
The namespaces are identical.
Updates:
1. sloppyDocEval : Doc2
2. sloppyDocEval : Doc2
```
## Other regression tests not covered by above
Expand Down
14 changes: 14 additions & 0 deletions unison-src/transcripts-round-trip/reparses.u
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ explanationOfThisFile = """
Put definitions in here that are expected to
parse with a different hash after pretty-printing.
"""

-- This is expected to round trip with the ``` syntax,
-- even though the original didn't use that syntax and
-- defined the eval block with a lambda rather than a delay.
sloppyDocEval =
docUntitledSection [
docParagraph [
docWord "Here's an example of an eval block that's",
docWord "technically a lambda but should print as a",
docWord "backticked block (since old docs in the wild",
docWord "still use this format)."
],
docEval (_ -> 1 Nat.+ 1)
]

0 comments on commit 0a9ed4d

Please sign in to comment.