From 14dc5206697539cd8f9afc2b5c640ed2df319a1a Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Wed, 29 Aug 2007 21:03:26 +0000 Subject: Cleaned up LaTeX reader. Rearranged order of parsers in inline for slight speed improvement. Added ` to special characters and 'unescapedChar'. git-svn-id: https://pandoc.googlecode.com/svn/trunk@960 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/LaTeX.hs | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 729f597fa..58e0fa21a 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -47,7 +47,7 @@ readLaTeX :: ParserState -- ^ Parser state, including options for parser readLaTeX = readWith parseLaTeX -- characters with special meaning -specialChars = "\\$%^&_~#{}\n \t|<>'\"-" +specialChars = "\\`$%^&_~#{}\n \t|<>'\"-" -- -- utility functions @@ -69,7 +69,7 @@ isArg other = False commandArgs = many optOrArg -- | Parses LaTeX command, returns (name, star, list of options or arguments). -command = try $ do +command = do char '\\' name <- many1 alphaNum star <- option "" (string "*") -- some commands have starred versions @@ -152,16 +152,15 @@ block = choice [ hrule -- header blocks -- -header = choice (map headerLevel (enumFromTo 1 5)) "header" - -headerLevel n = try $ do - let subs = concat $ replicate (n - 1) "sub" - string ("\\" ++ subs ++ "section") +header = try $ do + char '\\' + subs <- many (try (string "sub")) + string "section" optional (char '*') char '{' title <- manyTill inline (char '}') spaces - return $ Header n (normalizeSpaces title) + return $ Header (length subs + 1) (normalizeSpaces title) -- -- hrule block @@ -386,7 +385,18 @@ comment = try $ char '%' >> manyTill anyChar newline >> spaces >> return Null -- inline -- -inline = choice [ strong +inline = choice [ str + , endline + , whitespace + , quoted + , apostrophe + , spacer + , strong + , math + , ellipses + , emDash + , enDash + , hyphen , emph , strikeout , superscript @@ -394,27 +404,17 @@ inline = choice [ strong , ref , lab , code - , linebreak - , spacer - , math - , ellipses - , emDash - , enDash - , hyphen - , quoted - , apostrophe - , accentedChar - , specialChar , url , link , image , footnote + , linebreak + , accentedChar + , specialChar , rawLaTeXInline , escapedChar , unescapedChar - , str - , endline - , whitespace ] "inline" + ] "inline" accentedChar = normalAccentedChar <|> specialAccentedChar @@ -492,7 +492,7 @@ escapedChar = do return $ if result == Str "\n" then Str " " else result -- ignore standalone, nonescaped special characters -unescapedChar = oneOf "$^&_#{}|<>" >> return (Str "") +unescapedChar = oneOf "`$^&_#{}|<>" >> return (Str "") specialChar = choice [ backslash, tilde, caret, bar, lt, gt ] -- cgit v1.2.3