texmath 0.7.0.1 → 0.7.0.2
raw patch · 3 files changed
+42/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- changelog +8/−1
- src/Text/TeXMath/Readers/TeX.hs +33/−6
- texmath.cabal +1/−1
changelog view
@@ -1,3 +1,11 @@+texmath (0.7.0.2)++ * TeX reader: further improvements in error reporting.+ Instead of reporting line and column, a snippet is printed+ with a caret indicating the position of the error. Also+ fixed bad position information when control sequences are+ followed by a letter.+ texmath (0.7.0.1) * TeX reader:@@ -5,7 +13,6 @@ + Improved error reporting. + Optimized parser. + Treat `\ ` as ESpaced rather than ESymbol.- + Fixed parsing of `\phantom`. + Internal improvements, including using the parsec3 interface instead of the older parsec2 compatibility interface.
src/Text/TeXMath/Readers/TeX.hs view
@@ -28,6 +28,7 @@ import Data.Char (isDigit, isAscii, isLetter) import qualified Data.Map as M import Text.Parsec hiding (label)+import Text.Parsec.Error import Text.Parsec.String import Text.TeXMath.Types import Control.Applicative ((<*), (*>), (<*>), (<$>), (<$), pure)@@ -63,14 +64,36 @@ readTeX :: String -> Either String [Exp] readTeX inp = let (ms, rest) = parseMacroDefinitions inp in- either (Left . show) (Right . id) $ parse formula "formula" (applyMacros ms rest)+ either (Left . showParseError inp) (Right . id)+ $ parse formula "formula" (applyMacros ms rest) +showParseError :: String -> ParseError -> String+showParseError inp pe =+ snippet ++ "\n" ++ caretline +++ showErrorMessages "or" "unknown" "expecting" "unexpected" "eof"+ (errorMessages pe)+ where errln = sourceLine (errorPos pe)+ errcol = sourceColumn (errorPos pe)+ snipoffset = max 0 (errcol - 20)+ inplns = lines inp+ ln = if length inplns >= errln+ then inplns !! (errln - 1)+ else "" -- should not happen+ snippet = take 40 $ drop snipoffset ln+ caretline = replicate (errcol - snipoffset - 1) ' ' ++ "^"++ ctrlseq :: String -> TP String-ctrlseq s = lexeme $+ctrlseq s = lexeme $ try $ do+ result <- string ('\\':s) case s of- [c] | not (isLetter c) -> try (string ['\\',c])- _ -> try (string ('\\':s) <* (notFollowedBy letter- <?> ("non-letter after \\" ++ s)))+ [c] | not (isLetter c) -> return ()+ _ -> (do pos <- getPosition+ letter+ setPosition pos+ mzero <?> ("non-letter after \\" ++ s))+ <|> return ()+ return result ignorable :: TP () ignorable = skipMany (comment <|> label <|> (skipMany1 space <?> "whitespace"))@@ -508,7 +531,11 @@ cmd <- oneOfStrings cmds case cmd of ['\\',c] | not (isLetter c) -> return ()- _ -> notFollowedBy letter <?> ("non-letter after " ++ cmd)+ _ -> (do pos <- getPosition+ letter+ setPosition pos+ mzero <?> ("non-letter after " ++ cmd))+ <|> return () spaces return cmd
texmath.cabal view
@@ -1,5 +1,5 @@ Name: texmath-Version: 0.7.0.1+Version: 0.7.0.2 Cabal-Version: >= 1.10 Build-type: Simple Synopsis: Conversion between formats used to represent mathematics.