aboutsummaryrefslogtreecommitdiff
path: root/bbcode/src/Text/BBCode
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-12 09:39:42 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-12 09:39:42 +0100
commit478bc6572d3ba508bddf1fdcf697e5a9e56e4055 (patch)
tree8470747547cdc304c7573b4c5545119ea3e3374b /bbcode/src/Text/BBCode
parent07759433a7e075e99267e2ea04f232c99118c9fd (diff)
downloadthermoprint-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.hs12
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
21import Prelude hiding (takeWhile) 21import Prelude hiding (takeWhile)
22 22
23-- | Our lexicographical unit 23-- | Our lexicographical unit
24data BBToken = BBOpen Text [(Text, Maybe Text)] -- ^ Tag open with attributes 24data 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
35openTag :: Parser (Text, [(Text, Maybe Text)]) 35openTag :: Parser (Text, [(Text, Text)])
36openTag = (,) <$> escapedText' [']', ' ', '='] <*> attrs' 36openTag = (,) <$> escapedText' [']', ' ', '='] <*> attrs'
37 37
38attrs :: Parser [(Text, Maybe Text)] 38attrs :: Parser [(Text, Text)]
39attrs = (:) <$> (namedAttr <|> plainValue) <* takeWhile isSpace <*> attrs' 39attrs = (:) <$> (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
46attrs' :: Parser [(Text, Maybe Text)] 46attrs' :: Parser [(Text, Text)]
47attrs' = option [] attrs 47attrs' = option [] attrs
48 48
49escapedText :: [Char] -> Parser Text 49escapedText :: [Char] -> Parser Text