diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-12 05:59:38 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-12 05:59:38 +0000 |
commit | 9bc6cd27e1c4b52f46e1b210b3d560c5340d1fe4 (patch) | |
tree | c7edccdab108fb4557e41c79502ab71cb84e9f07 /bbcode | |
parent | 6c526fc1f57b666f978244db9c760841318e2251 (diff) | |
download | thermoprint-9bc6cd27e1c4b52f46e1b210b3d560c5340d1fe4.tar thermoprint-9bc6cd27e1c4b52f46e1b210b3d560c5340d1fe4.tar.gz thermoprint-9bc6cd27e1c4b52f46e1b210b3d560c5340d1fe4.tar.bz2 thermoprint-9bc6cd27e1c4b52f46e1b210b3d560c5340d1fe4.tar.xz thermoprint-9bc6cd27e1c4b52f46e1b210b3d560c5340d1fe4.zip |
Unnamed attributes
Diffstat (limited to 'bbcode')
-rw-r--r-- | bbcode/src/Text/BBCode/Lexer.hs | 6 | ||||
-rw-r--r-- | bbcode/test/Text/BBCode/LexerSpec.hs | 2 |
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 | ||
35 | openTag :: Parser (Text, [(Text, Maybe Text)]) | 35 | openTag :: Parser (Text, [(Text, Maybe Text)]) |
36 | openTag = (,) <$ "[" <*> escapedText' [']', ' '] <* takeWhile isSpace <*> attrs' <* "]" | 36 | openTag = (,) <$ "[" <*> escapedText' [']', ' ', '='] <*> attrs' <* "]" |
37 | 37 | ||
38 | attrs :: Parser [(Text, Maybe Text)] | 38 | attrs :: Parser [(Text, Maybe Text)] |
39 | attrs = (:) <$> ((,) <$> escapedText ['=', ']', ' '] <*> optional ("=" *> attrArg)) <* takeWhile isSpace <*> attrs' | 39 | attrs = (:) <$> (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]" |