git.iko.soy/typeable/pandoc
on master help sign in
Small improvements to BibTeX parser.
commitdd3c4000ff4941d3ce943b4d18b8965d94496de1 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 8 Oct 2020, 20:48 (6 years ago) parent0cfba4e
1 file changed+11−10
src/Text/Pandoc/Citeproc/BibTeX.hs+11−10
src/Text/Pandoc/Citeproc/BibTeX.hs+11−10
@@ -38,7 +38,7 @@ import Data.Text (Text)
3838import qualified Data.Text as T
3939import qualified Data.Map as Map
4040import Data.Maybe
41−import Text.Parsec hiding (State, many, (<|>))
41+import Text.Pandoc.Parsing hiding ((<|>), many)
4242import Control.Applicative
4343import Data.List.Split (splitOn, splitWhen, wordsBy)
4444import Control.Monad.RWS hiding ((<>))
@@ -73,7 +73,7 @@ defaultLang = Lang "en" (Just "US")
7373-- a map of bibtex "string" macros
7474type StringMap = Map.Map Text Text
7575
76−type BibParser = Parsec Text (Lang, StringMap)
76+type BibParser = Parser Text (Lang, StringMap)
7777
7878data Item = Item{ identifier :: Text
7979 , sourcePos :: SourcePos
@@ -571,7 +571,7 @@ bibEntries = do
571571 (bibComment <|> bibPreamble <|> bibString))
572572
573573bibSkip :: BibParser ()
574−bibSkip = skipMany1 (satisfy (/='@'))
574+bibSkip = () <$ take1WhileP (/='@')
575575
576576bibComment :: BibParser ()
577577bibComment = do
@@ -597,7 +597,7 @@ bibString = do
597597 return ()
598598
599599inBraces :: BibParser Text
600−inBraces = try $ do
600+inBraces = do
601601 char '{'
602602 res <- manyTill
603603 ( (T.pack <$> many1 (noneOf "{}\\"))
@@ -621,8 +621,9 @@ inQuotes = do
621621 ) (char '"')
622622
623623fieldName :: BibParser Text
624−fieldName = resolveAlias . T.toLower . T.pack
625− <$> many1 (letter <|> digit <|> oneOf "-_:+")
624+fieldName = resolveAlias . T.toLower
625+ <$> take1WhileP (\c ->
626+ isAlphaNum c || c == '-' || c == '_' || c == ':' || c == '+')
626627
627628isBibtexKeyChar :: Char -> Bool
628629isBibtexKeyChar c =
@@ -632,18 +633,18 @@ bibItem :: BibParser Item
632633bibItem = do
633634 char '@'
634635 pos <- getPosition
635− enttype <- map toLower <$> many1 letter
636+ enttype <- T.toLower <$> take1WhileP isLetter
636637 spaces
637638 char '{'
638639 spaces
639− entid <- many1 (satisfy isBibtexKeyChar)
640+ entid <- take1WhileP isBibtexKeyChar
640641 spaces
641642 char ','
642643 spaces
643644 entfields <- entField `sepEndBy` (char ',' >> spaces)
644645 spaces
645646 char '}'
646− return $ Item (T.pack entid) pos (T.pack enttype) (Map.fromList entfields)
647+ return $ Item entid pos enttype (Map.fromList entfields)
647648
648649entField :: BibParser (Text, Text)
649650entField = do
@@ -662,7 +663,7 @@ resolveAlias "primaryclass" = "eprintclass"
662663resolveAlias s = s
663664
664665rawWord :: BibParser Text
665−rawWord = T.pack <$> many1 alphaNum
666+rawWord = take1WhileP isAlphaNum
666667
667668expandString :: BibParser Text
668669expandString = do