diff options
author | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-08-16 02:02:51 +0200 |
---|---|---|
committer | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-08-16 02:05:06 +0200 |
commit | fb34e977d60bf9edfec822132c1da4bd0823c10d (patch) | |
tree | 847bb34a23a92428d41c87e6a4b1d9225cf7fade | |
parent | 2fc83c8f4321b35c1fceb9d8434bf9828a9757de (diff) |
fix(emoji-generic/DataFiles.hs): fix comment line parsing
previously despite my efforts "# subgroup: …" and "# group: …" where parsed as a comment line. also includes minor clean up.
-rw-r--r-- | src/Text/Emoji/DataFiles.hs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/Text/Emoji/DataFiles.hs b/src/Text/Emoji/DataFiles.hs index 0e2755c..a0af8bf 100644 --- a/src/Text/Emoji/DataFiles.hs +++ b/src/Text/Emoji/DataFiles.hs @@ -16,6 +16,7 @@ import Data.Attoparsec.Text (Parser (..), takeWhile1, takeWhile, string , notInClass, skipWhile, skipMany, isHorizontalSpace , decimal, hexadecimal, char, many1, endOfLine) import Data.Text (Text) +import qualified Data.Text as T import Data.Word (Word32) type EmojiTest = [EmojiTestEntry] @@ -66,11 +67,13 @@ emojiTestGroup maxLevel = do name <- takeWhile1 notEol skipMany endOfLine - let addMiddleParser = if maxLevel == EmojiTestGroup - then (<|> emojiTestGroup EmojiTestSubgroup) - else id + let groupParser = + if maxLevel == EmojiTestGroup + then emojiTestGroup EmojiTestSubgroup + else fail "fails always" + groupEntries <- many1 - (addMiddleParser emojiTestEntryLine <|> emojiTestCommentLine) + (groupParser <|> emojiTestEntryLine <|> emojiTestCommentLine) pure $ Group EmojiTestGroup name groupEntries @@ -109,9 +112,13 @@ emojiTestEntryLine = do pure $ Entry codePoints status version shortName emojiTestCommentLine :: Parser EmojiTestEntry -emojiTestCommentLine = char '#' >> skipSpace >> - (((string "group:" <|> string "subgroup:") >> fail "group, not comment") <|> - (takeWhile notEol <* skipMany endOfLine) >>= pure . Comment) +emojiTestCommentLine = do + char '#' + skipSpace + text <- takeWhile notEol <* skipMany endOfLine + if "group:" `T.isPrefixOf` text || "subgroup:" `T.isPrefixOf` text + then fail "group, not comment" + else pure $ Comment text emojiTestFile :: Parser EmojiTest emojiTestFile = many1 $ |