diff options
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 |
