haskell-src-exts 1.4.0 → 1.5.0
raw patch · 5 files changed
+46/−7 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Language.Haskell.Exts.Parser: ignoreLinePragmas :: ParseMode -> Bool
- Language.Haskell.Exts.Parser: ParseMode :: String -> [Extension] -> Bool -> [Fixity] -> ParseMode
+ Language.Haskell.Exts.Parser: ParseMode :: String -> [Extension] -> Bool -> Bool -> [Fixity] -> ParseMode
Files
- haskell-src-exts.cabal +1/−1
- src/Language/Haskell/Exts.hs +1/−1
- src/Language/Haskell/Exts/Annotated.hs +2/−2
- src/Language/Haskell/Exts/Lexer.hs +25/−1
- src/Language/Haskell/Exts/ParseMonad.hs +17/−2
haskell-src-exts.cabal view
@@ -1,5 +1,5 @@ Name: haskell-src-exts-Version: 1.4.0+Version: 1.5.0 License: BSD3 License-File: LICENSE Author: Niklas Broberg
src/Language/Haskell/Exts.hs view
@@ -67,7 +67,7 @@ -- | Parse a source file from a string using a custom parse mode. parseFileContentsWithMode :: ParseMode -> String -> ParseResult Module-parseFileContentsWithMode p@(ParseMode fn exts ign _) rawStr =+parseFileContentsWithMode p@(ParseMode fn exts ign _ _) rawStr = let md = delit fn $ ppContents rawStr allExts = impliesExts $ case (ign, readExtensions md) of (False,Just es) -> exts ++ es
src/Language/Haskell/Exts/Annotated.hs view
@@ -86,7 +86,7 @@ -- | Parse a source file from a string using a custom parse mode. parseFileContentsWithMode :: ParseMode -> String -> ParseResult (Module SrcSpanInfo)-parseFileContentsWithMode p@(ParseMode fn exts ign _) rawStr =+parseFileContentsWithMode p@(ParseMode fn exts ign _ _) rawStr = let md = delit fn $ ppContents rawStr allExts = impliesExts $ case (ign, readExtensions md) of (False,Just es) -> exts ++ es@@ -94,7 +94,7 @@ in parseModuleWithMode (p { extensions = allExts }) md parseFileContentsWithComments :: ParseMode -> String -> ParseResult (Module SrcSpanInfo, [Comment])-parseFileContentsWithComments p@(ParseMode fn exts ign _) rawStr =+parseFileContentsWithComments p@(ParseMode fn exts ign _ _) rawStr = let md = delit fn $ ppContents rawStr allExts = impliesExts $ case (ign, readExtensions md) of (False,Just es) -> exts ++ es
src/Language/Haskell/Exts/Lexer.hs view
@@ -340,9 +340,14 @@ lexWhiteSpace :: Bool -> Lex a (Bool, Bool) lexWhiteSpace bol = do s <- getInput+ ignL <- ignoreLinePragmasL case s of -- If we find a recognised pragma, we don't want to treat it as a comment. '{':'-':'#':rest | isRecognisedPragma rest -> return (bol, False)+ | isLinePragma rest && not ignL -> do + l <- lexLinePragma+ setSrcLineL l+ lexWhiteSpace True '{':'-':_ -> do loc <- getSrcLocL discard 2@@ -380,11 +385,30 @@ return (bol, True) _ -> return (bol, False) -isRecognisedPragma :: String -> Bool+isRecognisedPragma, isLinePragma :: String -> Bool isRecognisedPragma str = let pragma = map toLower . takeWhile isAlphaNum . dropWhile isSpace $ str in case lookup pragma pragmas of Nothing -> False _ -> True++isLinePragma str = let pragma = map toLower . takeWhile isAlphaNum . dropWhile isSpace $ str+ in case pragma of+ "line" -> True+ _ -> False++lexLinePragma :: Lex a Int+lexLinePragma = do+ discard 3 -- {-#+ lexWhile isSpace+ discard 4 -- LINE+ lexWhile isSpace+ i <- lexWhile isDigit+ lexWhile isSpace+ _ <- lexString+ lexWhile isSpace+ mapM (flip matchChar "Improperly formatted LINE pragma") "#-}"+ lexNewline+ return (read i) lexNestedComment :: Bool -> String -> Lex a (Bool, String) lexNestedComment bol str = do
src/Language/Haskell/Exts/ParseMonad.hs view
@@ -24,7 +24,8 @@ -- * Lexing Lex(runL), getInput, discard, lexNewline, lexTab, lexWhile, alternative, checkBOL, setBOL, startToken, getOffside,- pushContextL, popContextL, getExtensionsL, pushComment, getSrcLocL,+ pushContextL, popContextL, getExtensionsL, pushComment, + getSrcLocL, setSrcLineL, ignoreLinePragmasL, -- * Harp/Hsx ExtContext(..), pushExtContextL, popExtContextL, getExtContext,@@ -114,6 +115,9 @@ -- | if 'True', the parser won't care about further extensions -- in LANGUAGE pragmas in source files ignoreLanguagePragmas :: Bool,+ -- | if 'True', the parser won't read line position information+ -- from LINE pragmas in source files+ ignoreLinePragmas :: Bool, -- | list of fixities to be aware of fixities :: [Fixity] }@@ -121,13 +125,14 @@ -- | Default parameters for a parse. -- The default is an unknown filename, -- no extensions (i.e. Haskell 98),--- don't ignore LANGUAGE pragmas,+-- don't ignore LANGUAGE pragmas, do ignore LINE pragmas, -- and be aware of fixities from the 'Prelude'. defaultParseMode :: ParseMode defaultParseMode = ParseMode { parseFilename = "<unknown>.hs", extensions = [], ignoreLanguagePragmas = False,+ ignoreLinePragmas = True, fixities = preludeFixities } @@ -354,6 +359,10 @@ getSrcLocL = Lex $ \cont -> P $ \i x y l -> runP (cont (l { srcLine = y, srcColumn = x })) i x y l +setSrcLineL :: Int -> Lex a ()+setSrcLineL y = Lex $ \cont -> P $ \i x _ ->+ runP (cont ()) i x y+ pushContextL :: LexContext -> Lex a () pushContextL ctxt = Lex $ \cont -> P $ \r x y loc (stk, e, pst, cs) -> runP (cont ()) r x y loc (ctxt:stk, e, pst, cs)@@ -397,6 +406,12 @@ getExtensionsL :: Lex a [Extension] getExtensionsL = Lex $ \cont -> P $ \r x y loc s m -> runP (cont $ extensions m) r x y loc s m++-- LINE-aware lexing++ignoreLinePragmasL :: Lex a Bool+ignoreLinePragmasL = Lex $ \cont -> P $ \r x y loc s m ->+ runP (cont $ ignoreLinePragmas m) r x y loc s m -- Comments