diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-12 10:26:45 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-12 10:26:45 +0100 |
commit | ca7cd4ee2470115939523bb985aa576f9d87f18f (patch) | |
tree | 986d5d941f718fd813bf3436ae823cf1d0df1774 /bbcode | |
parent | 9f58557a76b5ae5478a7b7fc9e83266cd215c448 (diff) | |
download | thermoprint-ca7cd4ee2470115939523bb985aa576f9d87f18f.tar thermoprint-ca7cd4ee2470115939523bb985aa576f9d87f18f.tar.gz thermoprint-ca7cd4ee2470115939523bb985aa576f9d87f18f.tar.bz2 thermoprint-ca7cd4ee2470115939523bb985aa576f9d87f18f.tar.xz thermoprint-ca7cd4ee2470115939523bb985aa576f9d87f18f.zip |
cleanup & docs
Diffstat (limited to 'bbcode')
-rw-r--r-- | bbcode/src/Text/BBCode.hs | 17 | ||||
-rw-r--r-- | bbcode/src/Text/BBCode/Lexer.hs | 6 |
2 files changed, 15 insertions, 8 deletions
diff --git a/bbcode/src/Text/BBCode.hs b/bbcode/src/Text/BBCode.hs index 32f74df..75fa219 100644 --- a/bbcode/src/Text/BBCode.hs +++ b/bbcode/src/Text/BBCode.hs | |||
@@ -3,12 +3,14 @@ | |||
3 | 3 | ||
4 | -- | An implementation of BBcode parsing 'Text' to a syntax tree | 4 | -- | An implementation of BBcode parsing 'Text' to a syntax tree |
5 | module Text.BBCode | 5 | module Text.BBCode |
6 | ( TreeError(..) | 6 | ( bbcode |
7 | , BBCodeError(..) | ||
8 | , TreeError(..) | ||
7 | , DomTree(..) | 9 | , DomTree(..) |
8 | , dom | 10 | -- , dom |
9 | , BBLabel | 11 | -- , BBLabel |
10 | , rose | 12 | -- , rose |
11 | , matches | 13 | -- , matches |
12 | ) where | 14 | ) where |
13 | 15 | ||
14 | import Data.Text (Text) | 16 | import Data.Text (Text) |
@@ -36,11 +38,15 @@ import qualified Data.CaseInsensitive as CI | |||
36 | 38 | ||
37 | import Data.Bifunctor (Bifunctor(first)) | 39 | import Data.Bifunctor (Bifunctor(first)) |
38 | 40 | ||
41 | -- | Our target structure -- a rose tree with an explicit terminal constructor | ||
39 | data DomTree = Element Text (Map Text Text) [DomTree] | 42 | data DomTree = Element Text (Map Text Text) [DomTree] |
40 | | Content Text | 43 | | Content Text |
41 | deriving (Show, Eq) | 44 | deriving (Show, Eq) |
42 | 45 | ||
43 | dom :: Forest BBLabel -> [DomTree] | 46 | dom :: Forest BBLabel -> [DomTree] |
47 | -- ^ Parse semantically constrained rose tree to syntactically constrained version | ||
48 | -- | ||
49 | -- Silently drops children of semantically terminal nodes ('BBPlain') | ||
44 | dom = map dom' | 50 | dom = map dom' |
45 | where | 51 | where |
46 | dom' (Node (BBPlain t) _) = Content t | 52 | dom' (Node (BBPlain t) _) = Content t |
@@ -54,6 +60,7 @@ data BBCodeError = LexerError String -- ^ Error while parsing input to stream of | |||
54 | instance Exception BBCodeError | 60 | instance Exception BBCodeError |
55 | 61 | ||
56 | bbcode :: Text -> Either BBCodeError [DomTree] | 62 | bbcode :: Text -> Either BBCodeError [DomTree] |
63 | -- ^ Parse BBCode | ||
57 | bbcode t = fmap dom $ first LexerError (parseOnly (many token <* endOfInput) t) >>= first TreeError . rose | 64 | bbcode t = fmap dom $ first LexerError (parseOnly (many token <* endOfInput) t) >>= first TreeError . rose |
58 | 65 | ||
59 | -- | Errors in input encountered during parsing of lexed token-stream | 66 | -- | Errors in input encountered during parsing of lexed token-stream |
diff --git a/bbcode/src/Text/BBCode/Lexer.hs b/bbcode/src/Text/BBCode/Lexer.hs index 4ad0792..218427d 100644 --- a/bbcode/src/Text/BBCode/Lexer.hs +++ b/bbcode/src/Text/BBCode/Lexer.hs | |||
@@ -5,8 +5,8 @@ | |||
5 | module Text.BBCode.Lexer | 5 | module Text.BBCode.Lexer |
6 | ( BBToken(..) | 6 | ( BBToken(..) |
7 | , token | 7 | , token |
8 | , escapedText | 8 | -- , escapedText |
9 | , escapedText' | 9 | -- , escapedText' |
10 | ) where | 10 | ) where |
11 | 11 | ||
12 | import Data.Attoparsec.Text | 12 | import Data.Attoparsec.Text |
@@ -22,7 +22,7 @@ import Prelude hiding (takeWhile) | |||
22 | 22 | ||
23 | -- | Our lexicographical unit | 23 | -- | Our lexicographical unit |
24 | data BBToken = BBOpen Text [(Text, Text)] -- ^ Tag open with attributes | 24 | data BBToken = BBOpen Text [(Text, Text)] -- ^ Tag open with attributes |
25 | | BBContained Text [(Text, Text)] | 25 | | BBContained Text [(Text, Text)] -- ^ Tag open & immediate close with attributes |
26 | | BBClose Text -- ^ Tag close | 26 | | BBClose Text -- ^ Tag close |
27 | | BBStr Text -- ^ Content of a tag | 27 | | BBStr Text -- ^ Content of a tag |
28 | deriving (Eq, Show) | 28 | deriving (Eq, Show) |