diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-14 22:23:10 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-14 22:23:10 +0000 |
commit | 5b43a6abdca2366f507eefcebe77dc714598b149 (patch) | |
tree | a55aa04793f29e8039e5ddcf4250363a97e10c02 /spec/src | |
parent | 48390f18b6b5690f015291af83fafefd10c70f57 (diff) | |
download | thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar.gz thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar.bz2 thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar.xz thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.zip |
Framework for BBCode Syntax tree -> Printout morph
Diffstat (limited to 'spec/src')
-rw-r--r-- | spec/src/Thermoprint/Printout/BBCode.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/src/Thermoprint/Printout/BBCode.hs b/spec/src/Thermoprint/Printout/BBCode.hs new file mode 100644 index 0000000..8d98da1 --- /dev/null +++ b/spec/src/Thermoprint/Printout/BBCode.hs | |||
@@ -0,0 +1,45 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | {-# LANGUAGE DeriveGeneric #-} | ||
3 | |||
4 | module Thermoprint.Printout.BBCode | ||
5 | ( bbcode | ||
6 | , TreeError(..) | ||
7 | ) where | ||
8 | |||
9 | import Data.Text (Text) | ||
10 | import qualified Data.Text as T () | ||
11 | |||
12 | import GHC.Generics (Generic) | ||
13 | import Control.Exception (Exception) | ||
14 | import Data.Typeable (Typeable) | ||
15 | |||
16 | import Data.Bifunctor (bimap, first) | ||
17 | import Control.Monad (join) | ||
18 | |||
19 | import Text.BBCode (DomTree(..), TreeError(..)) | ||
20 | import qualified Text.BBCode as Raw (bbcode, BBCodeError(..)) | ||
21 | |||
22 | import Thermoprint.Printout | ||
23 | |||
24 | -- ^ We replicate 'Raw.BBCodeError' but add a new failure mode documenting incompatibly of the parsed syntax tree with our document format | ||
25 | data BBCodeError = LexerError String -- ^ Error while parsing input to stream of tokens | ||
26 | | TreeError TreeError -- ^ Error while parsing stream of tokens to syntax tree | ||
27 | | SemanticError SemanticError -- ^ Error while mapping syntax tree to document format | ||
28 | deriving (Show, Eq, Generic, Typeable) | ||
29 | |||
30 | instance Exception BBCodeError | ||
31 | |||
32 | data SemanticError = Placeholder | ||
33 | deriving (Show, Eq, Generic, Typeable) | ||
34 | |||
35 | instance Exception SemanticError | ||
36 | |||
37 | bbcode :: Text -> Either BBCodeError Printout | ||
38 | bbcode = join . fmap (first SemanticError) . bimap morph' morph . Raw.bbcode | ||
39 | |||
40 | morph' :: Raw.BBCodeError -> BBCodeError | ||
41 | morph' (Raw.LexerError x) = LexerError x | ||
42 | morph' (Raw.TreeError x) = TreeError x | ||
43 | |||
44 | morph :: [DomTree] -> Either SemanticError Printout | ||
45 | morph = undefined | ||