diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-04-02 11:32:09 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2018-04-02 11:33:43 +0200 |
commit | 39f9263fa38c32ce2e3a4f4bedb8349da47a3200 (patch) | |
tree | 0ecb02829315416dd4ddefed305c3c7e0f490057 /src/Codec | |
parent | 6179ed50c00c3966dc95d1e25787f39e667d9197 (diff) | |
download | pesto-39f9263fa38c32ce2e3a4f4bedb8349da47a3200.tar.gz pesto-39f9263fa38c32ce2e3a4f4bedb8349da47a3200.tar.bz2 pesto-39f9263fa38c32ce2e3a4f4bedb8349da47a3200.zip |
Rename recipe terminator directive
“Bon appétit” is French, but pesto is from Italy. This is a breaking
change.
Diffstat (limited to 'src/Codec')
-rw-r--r-- | src/Codec/Pesto/Graph.lhs | 31 |
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 |