Skip to content

Commit

Permalink
Parsing: Small code improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Dec 8, 2020
1 parent 8031ac1 commit 5990cbb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Text/Pandoc/Parsing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ uri = try $ do
scheme <- uriScheme
char ':'
-- Avoid parsing e.g. "**Notes:**" as a raw URI:
notFollowedBy (oneOf "*_]")
notFollowedBy $ satisfy (\c -> c == '*' || c == '_' || c == ']')

This comment has been minimized.

Copy link
@josephcsible

josephcsible Dec 28, 2020

Contributor

I might be missing something obvious, but I don't see how this is better.

This comment has been minimized.

Copy link
@jgm

jgm Dec 28, 2020

Author Owner

I thought it might be more efficient to avoid constructing a list and using elem (which is what oneOf does). But it could be that the compiler turns them both into the same code, I don't know.

-- We allow sentence punctuation except at the end, since
-- we don't want the trailing '.' in 'http://google.com.' We want to allow
-- http://en.wikipedia.org/wiki/State_of_emergency_(disambiguation)
Expand Down Expand Up @@ -693,7 +693,7 @@ mathInlineWith op cl = try $ do
(("\\text" <>) <$> inBalancedBraces 0 ""))
<|> (\c -> T.pack ['\\',c]) <$> anyChar))
<|> do (blankline <* notFollowedBy' blankline) <|>
(oneOf " \t" <* skipMany (oneOf " \t"))
(spaceChar <* skipMany spaceChar)
notFollowedBy (char '$')
return " "
) (try $ textStr cl)
Expand Down Expand Up @@ -723,7 +723,8 @@ mathInlineWith op cl = try $ do
mathDisplayWith :: Stream s m Char => Text -> Text -> ParserT s st m Text
mathDisplayWith op cl = try $ fmap T.pack $ do
textStr op
many1Till (noneOf "\n" <|> (newline <* notFollowedBy' blankline)) (try $ textStr cl)
many1Till (satisfy (/= '\n') <|> (newline <* notFollowedBy' blankline))
(try $ textStr cl)

mathDisplay :: (HasReaderOptions st, Stream s m Char)
=> ParserT s st m Text
Expand Down

0 comments on commit 5990cbb

Please sign in to comment.