aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-15 02:53:12 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-15 02:53:12 +0000
commita39c0ae45bf3485fbcb080576f8089ead05a94af (patch)
tree671f7209e8cb2e2c84fe38283316799cff4ae639 /spec
parent98ad4fe1c478aa7135a3085b8c0937ce08638843 (diff)
downloadthermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar
thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar.gz
thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar.bz2
thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar.xz
thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.zip
More framework for DomTree -> Printout
Diffstat (limited to 'spec')
-rw-r--r--spec/src/Thermoprint/Printout/BBCode.hs26
-rw-r--r--spec/thermoprint-spec.cabal1
-rw-r--r--spec/thermoprint-spec.nix9
3 files changed, 30 insertions, 6 deletions
diff --git a/spec/src/Thermoprint/Printout/BBCode.hs b/spec/src/Thermoprint/Printout/BBCode.hs
index ca69efc..f80f780 100644
--- a/spec/src/Thermoprint/Printout/BBCode.hs
+++ b/spec/src/Thermoprint/Printout/BBCode.hs
@@ -9,7 +9,13 @@ module Thermoprint.Printout.BBCode
9 ) where 9 ) where
10 10
11import Data.Text (Text) 11import Data.Text (Text)
12import qualified Data.Text as T () 12import qualified Data.Text as T (unpack)
13
14import Data.Map (Map)
15import qualified Data.Map as Map (lookup)
16
17import Data.CaseInsensitive (CI)
18import qualified Data.CaseInsensitive as CI
13 19
14import GHC.Generics (Generic) 20import GHC.Generics (Generic)
15import Control.Exception (Exception) 21import Control.Exception (Exception)
@@ -18,6 +24,10 @@ import Data.Typeable (Typeable)
18import Data.Bifunctor (bimap, first) 24import Data.Bifunctor (bimap, first)
19import Control.Monad (join) 25import Control.Monad (join)
20 26
27import Text.Read (readMaybe)
28
29import Data.Maybe (fromMaybe)
30
21import Text.BBCode (DomTree(..), TreeError(..)) 31import Text.BBCode (DomTree(..), TreeError(..))
22import qualified Text.BBCode as Raw (bbcode, BBCodeError(..)) 32import qualified Text.BBCode as Raw (bbcode, BBCodeError(..))
23 33
@@ -31,7 +41,8 @@ data BBCodeError = LexerError String -- ^ Error while parsing input to stream of
31 41
32instance Exception BBCodeError 42instance Exception BBCodeError
33 43
34data SemanticError = Placeholder 44data SemanticError = BlockTagInLineContext Text
45 | UnmappedTag Text
35 deriving (Show, Eq, Generic, Typeable) 46 deriving (Show, Eq, Generic, Typeable)
36 47
37instance Exception SemanticError 48instance Exception SemanticError
@@ -45,3 +56,14 @@ morph' (Raw.TreeError x) = TreeError x
45 56
46morph :: [DomTree] -> Either SemanticError Printout 57morph :: [DomTree] -> Either SemanticError Printout
47morph = undefined 58morph = undefined
59
60asBlock :: CI Text -> Map (CI Text) Text -> Either SemanticError Block
61asBlock "VSpace" = Right . VSpace . lookupAttr "size" 1
62asBlock t = Left . const (UnmappedTag . CI.original $ t)
63
64asLine :: CI Text -> Map (CI Text) Text -> Either SemanticError Line
65asLine "HSpace" = Right . HSpace . lookupAttr "size" 1
66asLine t = Left . const (UnmappedTag . CI.original $ t)
67
68lookupAttr :: Read a => CI Text -> a -> Map (CI Text) Text -> a
69lookupAttr t def attrs = fromMaybe def $ Map.lookup t attrs >>= (readMaybe . T.unpack)
diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal
index 40978c3..eb9d6d3 100644
--- a/spec/thermoprint-spec.cabal
+++ b/spec/thermoprint-spec.cabal
@@ -41,6 +41,7 @@ library
41 , aeson >=0.9.0 && <1 41 , aeson >=0.9.0 && <1
42 , base64-bytestring >=1.0.0 && <2 42 , base64-bytestring >=1.0.0 && <2
43 , encoding >=0.8 && <1 43 , encoding >=0.8 && <1
44 , case-insensitive >=1.2 && <2
44 -- hs-source-dirs: 45 -- hs-source-dirs:
45 default-language: Haskell2010 46 default-language: Haskell2010
46 47
diff --git a/spec/thermoprint-spec.nix b/spec/thermoprint-spec.nix
index 368f3a9..d20a8e6 100644
--- a/spec/thermoprint-spec.nix
+++ b/spec/thermoprint-spec.nix
@@ -1,6 +1,7 @@
1{ mkDerivation, aeson, base, base64-bytestring, bbcode, bytestring 1{ mkDerivation, aeson, base, base64-bytestring, bbcode, bytestring
2, Cabal, cabal-test-quickcheck, containers, deepseq, encoding 2, Cabal, cabal-test-quickcheck, case-insensitive, containers
3, hspec, QuickCheck, quickcheck-instances, servant, stdenv, text 3, deepseq, encoding, hspec, QuickCheck, quickcheck-instances
4, servant, stdenv, text
4}: 5}:
5mkDerivation { 6mkDerivation {
6 pname = "thermoprint-spec"; 7 pname = "thermoprint-spec";
@@ -8,8 +9,8 @@ mkDerivation {
8 src = ./.; 9 src = ./.;
9 libraryHaskellDepends = [ 10 libraryHaskellDepends = [
10 aeson base base64-bytestring bbcode bytestring Cabal 11 aeson base base64-bytestring bbcode bytestring Cabal
11 cabal-test-quickcheck containers deepseq encoding QuickCheck 12 cabal-test-quickcheck case-insensitive containers deepseq encoding
12 quickcheck-instances servant text 13 QuickCheck quickcheck-instances servant text
13 ]; 14 ];
14 testHaskellDepends = [ 15 testHaskellDepends = [
15 aeson base hspec QuickCheck quickcheck-instances 16 aeson base hspec QuickCheck quickcheck-instances