summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2018-04-02 11:32:09 +0200
committerLars-Dominik Braun <lars@6xq.net>2018-04-02 11:33:43 +0200
commit39f9263fa38c32ce2e3a4f4bedb8349da47a3200 (patch)
tree0ecb02829315416dd4ddefed305c3c7e0f490057
parent6179ed50c00c3966dc95d1e25787f39e667d9197 (diff)
downloadpesto-master.tar.gz
pesto-master.tar.bz2
pesto-master.zip
Rename recipe terminator directiveHEADmaster
“Bon appétit” is French, but pesto is from Italy. This is a breaking change.
-rw-r--r--src/Codec/Pesto/Graph.lhs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/Codec/Pesto/Graph.lhs b/src/Codec/Pesto/Graph.lhs
index 316e593..511adca 100644
--- a/src/Codec/Pesto/Graph.lhs
+++ b/src/Codec/Pesto/Graph.lhs
@@ -29,40 +29,43 @@ Language semantics
> import Codec.Pesto.Parse hiding (test)
The parser’s output, a stream of instructions, may contain multiple recipes. A
-recipe must start with the directive “pesto” and may end with “bonappetit”.
+recipe must start with the directive “pesto” and may end with “buonappetito”.
This function extracts all recipes from the stream and removes both directives.
- easily embed recipes into other documents
+> startDirective = Directive "pesto"
+> endDirective = Directive "buonappetito"
+
> extract [] = []
-> extract (Directive "pesto":stream) = between:extract next
+> extract (s:stream) | s == startDirective = between:extract next
> where
-> isEnd (Directive x) | x `elem` ["bonappetit", "pesto"] = True
+> isEnd x | x `elem` [startDirective, endDirective] = True
> isEnd _ = False
> (between, next) = break isEnd stream
> extract (_:xs) = extract xs
Start and end directive are removed from the extracted instructions. The
-directive “bonappetit” is optional at the end of a stream.
+directive “buonappetito” is optional at the end of a stream.
> testExtract = [
-> extract [Directive "pesto", Directive "bonappetit"] ~?= [[]]
-> , extract [Directive "pesto", Action "foobar", Directive "bonappetit"] ~?= [[Action "foobar"]]
-> , extract [Directive "pesto"] ~?= [[]]
-> , extract [Directive "pesto", Directive "foobar"] ~?= [[Directive "foobar"]]
+> extract [startDirective, endDirective] ~?= [[]]
+> , extract [startDirective, Action "foobar", endDirective] ~?= [[Action "foobar"]]
+> , extract [startDirective] ~?= [[]]
+> , extract [startDirective, Directive "foobar"] ~?= [[Directive "foobar"]]
Instructions surrounding the start and end directive are removed.
-> , extract [Unknown "Something", Directive "pesto"] ~?= [[]]
-> , extract [Unknown "Something", Action "pour", Directive "pesto"] ~?= [[]]
-> , extract [Directive "pesto", Directive "bonappetit", Annotation "something"] ~?= [[]]
+> , extract [Unknown "Something", startDirective] ~?= [[]]
+> , extract [Unknown "Something", Action "pour", startDirective] ~?= [[]]
+> , extract [startDirective, endDirective, Annotation "something"] ~?= [[]]
The stream may contain multiple recipes. The start directive also ends the
previous recipe and starts a new one.
-> , extract [Directive "pesto", Action "pour", Directive "bonappetit", Action "foobar", Directive "pesto", Annotation "something"] ~?= [[Action "pour"], [Annotation "something"]]
-> , extract [Directive "pesto", Action "heat", Directive "pesto", Annotation "something"] ~?= [[Action "heat"], [Annotation "something"]]
-> , extract [Directive "pesto", Annotation "foobar", Directive "pesto", Directive "bonappetit"] ~?= [[Annotation "foobar"], []]
+> , extract [startDirective, Action "pour", endDirective, Action "foobar", startDirective, Annotation "something"] ~?= [[Action "pour"], [Annotation "something"]]
+> , extract [startDirective, Action "heat", startDirective, Annotation "something"] ~?= [[Action "heat"], [Annotation "something"]]
+> , extract [startDirective, Annotation "foobar", startDirective, endDirective] ~?= [[Annotation "foobar"], []]
> ]
Each recipe’s stream of instructions drives a stack-based machine that transforms