aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bbcode/src/Text/BBCode/Lexer.hs6
-rw-r--r--bbcode/test/Text/BBCode/LexerSpec.hs2
2 files changed, 6 insertions, 2 deletions
diff --git a/bbcode/src/Text/BBCode/Lexer.hs b/bbcode/src/Text/BBCode/Lexer.hs
index 1c20928..7171a0e 100644
--- a/bbcode/src/Text/BBCode/Lexer.hs
+++ b/bbcode/src/Text/BBCode/Lexer.hs
@@ -33,11 +33,13 @@ token = BBClose <$> ("[/" *> escapedText' [']'] <* "]")
33 <|> BBStr <$> escapedText ['['] 33 <|> BBStr <$> escapedText ['[']
34 34
35openTag :: Parser (Text, [(Text, Maybe Text)]) 35openTag :: Parser (Text, [(Text, Maybe Text)])
36openTag = (,) <$ "[" <*> escapedText' [']', ' '] <* takeWhile isSpace <*> attrs' <* "]" 36openTag = (,) <$ "[" <*> escapedText' [']', ' ', '='] <*> attrs' <* "]"
37 37
38attrs :: Parser [(Text, Maybe Text)] 38attrs :: Parser [(Text, Maybe Text)]
39attrs = (:) <$> ((,) <$> escapedText ['=', ']', ' '] <*> optional ("=" *> attrArg)) <* takeWhile isSpace <*> attrs' 39attrs = (:) <$> (namedAttr <|> plainValue) <* takeWhile isSpace <*> attrs'
40 where 40 where
41 namedAttr = (,) <$ takeWhile isSpace <*> escapedText ['=', ']', ' '] <*> optional ("=" *> attrArg)
42 plainValue = (,) <$> pure "" <* "=" <*> (Just <$> attrArg)
41 attrArg = "\"" *> escapedText ['"'] <* "\"" 43 attrArg = "\"" *> escapedText ['"'] <* "\""
42 <|> escapedText [']', ' '] 44 <|> escapedText [']', ' ']
43 45
diff --git a/bbcode/test/Text/BBCode/LexerSpec.hs b/bbcode/test/Text/BBCode/LexerSpec.hs
index f4dcee6..fcc1c4f 100644
--- a/bbcode/test/Text/BBCode/LexerSpec.hs
+++ b/bbcode/test/Text/BBCode/LexerSpec.hs
@@ -83,6 +83,8 @@ examples = [ ("[t]test[/t]"
83 , [BBOpen "t" [], BBStr "test", BBClose "t]"]) 83 , [BBOpen "t" [], BBStr "test", BBClose "t]"])
84 , ("[t attr]test[/t]" 84 , ("[t attr]test[/t]"
85 , [BBOpen "t" [("attr", Nothing)], BBStr "test", BBClose "t"]) 85 , [BBOpen "t" [("attr", Nothing)], BBStr "test", BBClose "t"])
86 , ("[t=attr]test[/t]"
87 , [BBOpen "t" [("", Just "attr")], BBStr "test", BBClose "t"])
86 , ("[t attr=val]test[/t]" 88 , ("[t attr=val]test[/t]"
87 , [BBOpen "t" [("attr", Just "val")], BBStr "test", BBClose "t"]) 89 , [BBOpen "t" [("attr", Just "val")], BBStr "test", BBClose "t"])
88 , ("[t attr=\"val\"]test[/t]" 90 , ("[t attr=\"val\"]test[/t]"