Skip to content

Commit 28d1f68

Browse files
authored
Fix: adapt case studies to also work on the website (#1022)
- Sometimes there were function definitions spanning across multiple code blocks, which is no longer supported by the new "unified" literate Effekt behaviour (#1009). I merged these blocks and added the explanation beneath. - I solved an ambiguous usage of `Success` and `Failure` by renaming it to `ParseSuccess` and `ParseFailure` as `module21::Success` for example would be rather awkward (and would not work locally). - Also fixed a bug which discarded empty lines in code blocks in literate Effekt files.
1 parent 7fa3dc6 commit 28d1f68

File tree

10 files changed

+199
-247
lines changed

10 files changed

+199
-247
lines changed

effekt/shared/src/main/scala/effekt/util/Source.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ case class MarkdownSource(source: Source) extends Source {
6868
lines += "}"
6969
// closing fence of ```effekt or ```
7070
case Code =>
71-
lines ++= code
71+
if (!code.isEmpty) lines ++= code
7272
lines += ""
7373
// closing fence of ```effekt:ignore
7474
case Ignore =>
@@ -83,7 +83,7 @@ case class MarkdownSource(source: Source) extends Source {
8383
}
8484
}
8585
// collect code if in code fence
86-
case line if fenceType.isDefined && line != "" =>
86+
case line if fenceType.isDefined =>
8787
code += line
8888
// add empty lines to preserve positional information outside of code fences
8989
case line =>

examples/casestudies/anf.effekt.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,15 @@ def traverse(e: Tree): Stmt / { Bind, Fresh } = e match {
7777
// should be inserted.
7878
CLet(x, bindHere { traverse(b) }, bindHere { traverse(body) })
7979
}
80-
```
81-
The handler `bindHere` handles `Bind` by generating a fresh name and
82-
inserting a let binding:
83-
```
80+
8481
def bindHere { prog: => Stmt / Bind } : Stmt / Fresh =
8582
try { prog() }
8683
with Bind { (e) =>
8784
val id = do Fresh()
8885
CLet(id, e, resume(CVar(id)))
8986
}
9087
```
88+
The handler `bindHere` handles `Bind` by generating a fresh name and inserting a let binding.
9189
Note, that the let binding will _enclose_ the overall result of `prog`. It is inserted on the outside.
9290

9391
The overall ANF transformation is simply a matter of composing the two handlers and calling `traverse`:
@@ -158,8 +156,8 @@ our input:
158156
```
159157
def pipeline(input: String): String =
160158
parse(input) { parseExpr() } match {
161-
case parser::Success(tree) => pretty(translate(tree))
162-
case parser::Failure(msg) => msg
159+
case ParseSuccess(tree) => pretty(translate(tree))
160+
case ParseFailure(msg) => msg
163161
}
164162
```
165163

examples/casestudies/frontend.check

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ Tuple3(Token(Ident(), foo, Position(1, 1, 0)), Token(Punct(), (, Position(1, 4,
44
()
55
Tuple3(Token(Ident(), foo, Position(1, 1, 0)), Token(Punct(), (, Position(1, 5, 4)), Token(Punct(), ), Position(2, 2, 11)))
66
()
7-
Success(1)
8-
Success(2)
9-
Success(3)
10-
Success(5)
11-
Success(6)
12-
Success(6)
13-
Failure(Expected ( but got })
14-
Success(Lit(42))
15-
Success(Let(x, Lit(4), Lit(42)))
16-
Success(Let(x, Let(y, Lit(2), Lit(1)), Lit(42)))
17-
Success(Let(x, Let(y, Lit(2), Lit(1)), Lit(42)))
18-
Success(Let(x, Let(y, App(f, Lit(42)), Lit(1)), Lit(42)))
19-
Success(Let(x, Let(y, App(f, Let(z, Lit(1), Var(z))), Lit(1)), Lit(42)))
7+
ParseSuccess(1)
8+
ParseSuccess(2)
9+
ParseSuccess(3)
10+
ParseSuccess(5)
11+
ParseSuccess(6)
12+
ParseSuccess(6)
13+
ParseFailure(Expected ( but got })
14+
ParseSuccess(Lit(42))
15+
ParseSuccess(Let(x, Lit(4), Lit(42)))
16+
ParseSuccess(Let(x, Let(y, Lit(2), Lit(1)), Lit(42)))
17+
ParseSuccess(Let(x, Let(y, Lit(2), Lit(1)), Lit(42)))
18+
ParseSuccess(Let(x, Let(y, App(f, Lit(42)), Lit(1)), Lit(42)))
19+
ParseSuccess(Let(x, Let(y, App(f, Let(z, Lit(1), Var(z))), Lit(1)), Lit(42)))
2020
()
2121
-----
2222
[1,

0 commit comments

Comments
 (0)