Skip to content

Commit

Permalink
Convert Doc v1 transcripts to v2
Browse files Browse the repository at this point in the history
This does a very superficial conversion – it doesn’t correct all of the
verbiage that describes how to do things in v1, just changes the actual
syntax.
  • Loading branch information
sellout committed Jul 24, 2024
1 parent fac6924 commit 3b34107
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 252 deletions.
54 changes: 27 additions & 27 deletions unison-src/transcripts/doc-formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ This transcript explains a few minor details about doc parsing and pretty-printi
Docs can be used as inline code comments.

```ucm:hide
scratch/main> builtins.merge
scratch/main> builtins.mergeio
```

```unison
foo : Nat -> Nat
foo n =
_ = [: do the thing :]
_ = {{ do the thing }}
n + 1
```

Expand All @@ -20,10 +20,10 @@ scratch/main> add
scratch/main> view foo
```

Note that `@` and `:]` must be escaped within docs.
Note that `{{`, `@`, and `}}` must be escaped within docs.

```unison
escaping = [: Docs look [: like \@this \:] :]
escaping = {{ Docs look --doc open-- like --amphora--this --doc close-- }}
```

```ucm:hide
Expand All @@ -33,16 +33,16 @@ scratch/main> add
scratch/main> view escaping
```

(Alas you can't have `\@` or `\:]` in your doc, as there's currently no way to 'unescape' them.)
(Alas you can't have `\@` or `\}}` in your doc, as there's currently no way to 'unescape' them.)

```unison
-- Note that -- comments are preserved within doc literals.
commented = [:
commented = {{
example:
-- a comment
f x = x + 1
:]
}}
```

```ucm:hide
Expand All @@ -60,7 +60,7 @@ Handling of indenting in docs between the parser and pretty-printer is a bit fid
-- The leading and trailing spaces are stripped from the stored Doc by the
-- lexer, and one leading and trailing space is inserted again on view/edit
-- by the pretty-printer.
doc1 = [: hi :]
doc1 = {{ hi }}
```

```ucm:hide
Expand All @@ -71,15 +71,15 @@ scratch/main> view doc1
```

```unison
-- Lines (apart from the first line, i.e. the bit between the [: and the
-- Lines (apart from the first line, i.e. the bit between the {{ and the
-- first newline) are unindented until at least one of
-- them hits the left margin (by a post-processing step in the parser).
-- You may not notice this because the pretty-printer indents them again on
-- view/edit.
doc2 = [: hello
doc2 = {{ hello
- foo
- bar
and the rest. :]
and the rest. }}
```

```ucm:hide
Expand All @@ -90,7 +90,7 @@ scratch/main> view doc2
```

```unison
doc3 = [: When Unison identifies a paragraph, it removes any newlines from it before storing it, and then reflows the paragraph text to fit the display window on display/view/edit.
doc3 = {{ When Unison identifies a paragraph, it removes any newlines from it before storing it, and then reflows the paragraph text to fit the display window on display/view/edit.
For these purposes, a paragraph is any sequence of non-empty lines that have zero indent (after the unindenting mentioned above.)
Expand All @@ -101,7 +101,7 @@ For these purposes, a paragraph is any sequence of non-empty lines that have zer
is not treated | either.
Note that because of the special treatment of the first line mentioned above, where its leading space is removed, it is always treated as a paragraph.
:]
}}
```

```ucm:hide
Expand All @@ -112,11 +112,11 @@ scratch/main> view doc3
```

```unison
doc4 = [: Here's another example of some paragraphs.
doc4 = {{ Here's another example of some paragraphs.
All these lines have zero indent.
- Apart from this one. :]
- Apart from this one. }}
```

```ucm:hide
Expand All @@ -130,10 +130,10 @@ scratch/main> view doc4
-- The special treatment of the first line does mean that the following
-- is pretty-printed not so prettily. To fix that we'd need to get the
-- lexer to help out with interpreting doc literal indentation (because
-- it knows what columns the `[:` was in.)
doc5 = [: - foo
-- it knows what columns the `{{` was in.)
doc5 = {{ - foo
- bar
and the rest. :]
and the rest. }}
```

```ucm:hide
Expand All @@ -145,11 +145,11 @@ scratch/main> view doc5

```unison
-- You can do the following to avoid that problem.
doc6 = [:
doc6 = {{
- foo
- bar
and the rest.
:]
}}
```

```ucm:hide
Expand All @@ -163,7 +163,7 @@ scratch/main> view doc6

```unison
-- Check empty doc works.
empty = [::]
empty = {{}}
expr = foo 1
```
Expand All @@ -175,7 +175,7 @@ scratch/main> view empty
```

```unison
test1 = [:
test1 = {{
The internal logic starts to get hairy when you use the \@ features, for example referencing a name like @List.take. Internally, the text between each such usage is its own blob (blob ends here --> @List.take), so paragraph reflow has to be aware of multiple blobs to do paragraph reflow (or, more accurately, to do the normalization step where newlines with a paragraph are removed.)
Para to reflow: lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor ending in ref @List.take
Expand Down Expand Up @@ -211,7 +211,7 @@ para line lorem ipsum dolor lorem ipsum dolor lorem ipsum dolor lorem ipsum dolo
-- note the leading space below
@[signature] List.take
:]
}}
```
```ucm:hide
scratch/main> add
Expand All @@ -222,8 +222,8 @@ scratch/main> view test1

```unison
-- Regression test for #1363 - preservation of spaces after @ directives in first line when unindenting
reg1363 = [: `@List.take foo` bar
baz :]
reg1363 = {{ `@List.take foo` bar
baz }}
```
```ucm:hide
scratch/main> add
Expand All @@ -236,10 +236,10 @@ scratch/main> view reg1363
-- Demonstrate doc display when whitespace follows a @[source] or @[evaluate]
-- whose output spans multiple lines.
test2 = [:
test2 = {{
Take a look at this:
@[source] foo ▶ bar
:]
}}
```
```ucm:hide
scratch/main> add
Expand Down
Loading

0 comments on commit 3b34107

Please sign in to comment.