Muse reader: rewrite code parser in applicative style

This commit is contained in:
Alexander Krotov 2018-10-10 03:11:34 +03:00
parent d3b2161bd1
commit 36c763a647

View file

@ -873,14 +873,11 @@ nbsp = try $ pure (B.str "\160") <$ string "~~"
-- | Parse code markup, indicated by @\'=\'@ characters.
code :: PandocMonad m => MuseParser m (F Inlines)
code = try $ do
atStart $ char '='
contents <- many1Till (noneOf "\n\r" <|> (newline <* notFollowedBy newline)) $ char '='
guard $ not $ null contents
guard $ head contents `notElem` " \t\n"
guard $ last contents `notElem` " \t\n"
notFollowedBy $ satisfy isAlphaNum
return $ return $ B.code contents
code = try $ fmap pure $ B.code . uncurry (++)
<$ atStart (char '=')
<* notFollowedBy (spaceChar <|> newline)
<*> manyUntil (noneOf "\n\r" <|> (newline <* notFollowedBy newline)) (try $ fmap pure $ noneOf " \t\n\r=" <* char '=')
<* notFollowedBy (satisfy isAlphaNum)
-- | Parse @\<code>@ tag.
codeTag :: PandocMonad m => MuseParser m (F Inlines)