From ca7cd4ee2470115939523bb985aa576f9d87f18f Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 12 Jan 2016 10:26:45 +0100 Subject: cleanup & docs --- bbcode/src/Text/BBCode.hs | 17 ++++++++++++----- bbcode/src/Text/BBCode/Lexer.hs | 6 +++--- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'bbcode/src') 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 @@ -- | An implementation of BBcode parsing 'Text' to a syntax tree module Text.BBCode - ( TreeError(..) + ( bbcode + , BBCodeError(..) + , TreeError(..) , DomTree(..) - , dom - , BBLabel - , rose - , matches + -- , dom + -- , BBLabel + -- , rose + -- , matches ) where import Data.Text (Text) @@ -36,11 +38,15 @@ import qualified Data.CaseInsensitive as CI import Data.Bifunctor (Bifunctor(first)) +-- | Our target structure -- a rose tree with an explicit terminal constructor data DomTree = Element Text (Map Text Text) [DomTree] | Content Text deriving (Show, Eq) dom :: Forest BBLabel -> [DomTree] +-- ^ Parse semantically constrained rose tree to syntactically constrained version +-- +-- Silently drops children of semantically terminal nodes ('BBPlain') dom = map dom' where dom' (Node (BBPlain t) _) = Content t @@ -54,6 +60,7 @@ data BBCodeError = LexerError String -- ^ Error while parsing input to stream of instance Exception BBCodeError bbcode :: Text -> Either BBCodeError [DomTree] +-- ^ Parse BBCode bbcode t = fmap dom $ first LexerError (parseOnly (many token <* endOfInput) t) >>= first TreeError . rose -- | 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 @@ module Text.BBCode.Lexer ( BBToken(..) , token - , escapedText - , escapedText' + -- , escapedText + -- , escapedText' ) where import Data.Attoparsec.Text @@ -22,7 +22,7 @@ import Prelude hiding (takeWhile) -- | Our lexicographical unit data BBToken = BBOpen Text [(Text, Text)] -- ^ Tag open with attributes - | BBContained Text [(Text, Text)] + | BBContained Text [(Text, Text)] -- ^ Tag open & immediate close with attributes | BBClose Text -- ^ Tag close | BBStr Text -- ^ Content of a tag deriving (Eq, Show) -- cgit v1.2.3