diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-12 09:39:42 +0100 | 
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-12 09:39:42 +0100 | 
| commit | 478bc6572d3ba508bddf1fdcf697e5a9e56e4055 (patch) | |
| tree | 8470747547cdc304c7573b4c5545119ea3e3374b /bbcode/src/Text/BBCode | |
| parent | 07759433a7e075e99267e2ea04f232c99118c9fd (diff) | |
| download | thermoprint-478bc6572d3ba508bddf1fdcf697e5a9e56e4055.tar thermoprint-478bc6572d3ba508bddf1fdcf697e5a9e56e4055.tar.gz thermoprint-478bc6572d3ba508bddf1fdcf697e5a9e56e4055.tar.bz2 thermoprint-478bc6572d3ba508bddf1fdcf697e5a9e56e4055.tar.xz thermoprint-478bc6572d3ba508bddf1fdcf697e5a9e56e4055.zip | |
DomTree
Diffstat (limited to 'bbcode/src/Text/BBCode')
| -rw-r--r-- | bbcode/src/Text/BBCode/Lexer.hs | 12 | 
1 files changed, 6 insertions, 6 deletions
| diff --git a/bbcode/src/Text/BBCode/Lexer.hs b/bbcode/src/Text/BBCode/Lexer.hs index 03f57d2..560324b 100644 --- a/bbcode/src/Text/BBCode/Lexer.hs +++ b/bbcode/src/Text/BBCode/Lexer.hs | |||
| @@ -21,7 +21,7 @@ import Control.Applicative | |||
| 21 | import Prelude hiding (takeWhile) | 21 | import Prelude hiding (takeWhile) | 
| 22 | 22 | ||
| 23 | -- | Our lexicographical unit | 23 | -- | Our lexicographical unit | 
| 24 | data BBToken = BBOpen Text [(Text, Maybe Text)] -- ^ Tag open with attributes | 24 | data BBToken = BBOpen Text [(Text, Text)] -- ^ Tag open with attributes | 
| 25 | | BBClose Text -- ^ Tag close | 25 | | BBClose Text -- ^ Tag close | 
| 26 | | BBStr Text -- ^ Content of a tag | 26 | | BBStr Text -- ^ Content of a tag | 
| 27 | deriving (Eq, Show) | 27 | deriving (Eq, Show) | 
| @@ -32,18 +32,18 @@ token = BBClose <$> ("[/" *> escapedText' [']'] <* "]") | |||
| 32 | <|> uncurry BBOpen <$ "[" <*> openTag <* "]" | 32 | <|> uncurry BBOpen <$ "[" <*> openTag <* "]" | 
| 33 | <|> BBStr <$> escapedText ['['] | 33 | <|> BBStr <$> escapedText ['['] | 
| 34 | 34 | ||
| 35 | openTag :: Parser (Text, [(Text, Maybe Text)]) | 35 | openTag :: Parser (Text, [(Text, Text)]) | 
| 36 | openTag = (,) <$> escapedText' [']', ' ', '='] <*> attrs' | 36 | openTag = (,) <$> escapedText' [']', ' ', '='] <*> attrs' | 
| 37 | 37 | ||
| 38 | attrs :: Parser [(Text, Maybe Text)] | 38 | attrs :: Parser [(Text, Text)] | 
| 39 | attrs = (:) <$> (namedAttr <|> plainValue) <* takeWhile isSpace <*> attrs' | 39 | attrs = (:) <$> (namedAttr <|> plainValue) <* takeWhile isSpace <*> attrs' | 
| 40 | where | 40 | where | 
| 41 | namedAttr = (,) <$ takeWhile isSpace <*> escapedText ['=', ']', ' '] <*> optional ("=" *> attrArg) | 41 | namedAttr = (,) <$ takeWhile isSpace <*> escapedText ['=', ']', ' '] <*> option "" ("=" *> attrArg) | 
| 42 | plainValue = (,) <$> pure "" <* "=" <*> (Just <$> attrArg) | 42 | plainValue = (,) <$> pure "" <* "=" <*> attrArg | 
| 43 | attrArg = "\"" *> escapedText ['"'] <* "\"" | 43 | attrArg = "\"" *> escapedText ['"'] <* "\"" | 
| 44 | <|> escapedText [']', ' '] | 44 | <|> escapedText [']', ' '] | 
| 45 | 45 | ||
| 46 | attrs' :: Parser [(Text, Maybe Text)] | 46 | attrs' :: Parser [(Text, Text)] | 
| 47 | attrs' = option [] attrs | 47 | attrs' = option [] attrs | 
| 48 | 48 | ||
| 49 | escapedText :: [Char] -> Parser Text | 49 | escapedText :: [Char] -> Parser Text | 
