aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-14 22:23:10 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-14 22:23:10 +0000
commit5b43a6abdca2366f507eefcebe77dc714598b149 (patch)
treea55aa04793f29e8039e5ddcf4250363a97e10c02
parent48390f18b6b5690f015291af83fafefd10c70f57 (diff)
downloadthermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar
thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar.gz
thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar.bz2
thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.tar.xz
thermoprint-5b43a6abdca2366f507eefcebe77dc714598b149.zip
Framework for BBCode Syntax tree -> Printout morph
-rw-r--r--spec/src/Thermoprint/Printout/BBCode.hs45
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
4module Thermoprint.Printout.BBCode
5 ( bbcode
6 , TreeError(..)
7 ) where
8
9import Data.Text (Text)
10import qualified Data.Text as T ()
11
12import GHC.Generics (Generic)
13import Control.Exception (Exception)
14import Data.Typeable (Typeable)
15
16import Data.Bifunctor (bimap, first)
17import Control.Monad (join)
18
19import Text.BBCode (DomTree(..), TreeError(..))
20import qualified Text.BBCode as Raw (bbcode, BBCodeError(..))
21
22import 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
25data 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
30instance Exception BBCodeError
31
32data SemanticError = Placeholder
33 deriving (Show, Eq, Generic, Typeable)
34
35instance Exception SemanticError
36
37bbcode :: Text -> Either BBCodeError Printout
38bbcode = join . fmap (first SemanticError) . bimap morph' morph . Raw.bbcode
39
40morph' :: Raw.BBCodeError -> BBCodeError
41morph' (Raw.LexerError x) = LexerError x
42morph' (Raw.TreeError x) = TreeError x
43
44morph :: [DomTree] -> Either SemanticError Printout
45morph = undefined