aboutsummaryrefslogtreecommitdiff
path: root/spec/src/Thermoprint/Printout/BBCode.hs
diff options
context:
space:
mode:
Diffstat (limited to 'spec/src/Thermoprint/Printout/BBCode.hs')
-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