record-dot-preprocessor 0.2.3 → 0.2.4
raw patch · 3 files changed
+19/−6 lines, 3 files
Files
- CHANGES.txt +2/−0
- preprocessor/Lexer.hs +16/−5
- record-dot-preprocessor.cabal +1/−1
CHANGES.txt view
@@ -1,5 +1,7 @@ Changelog for record-dot-preprocessor +0.2.4, released 2020-05-04+ #3, emit more LINE declarations 0.2.3, released 2020-04-01 Support GHC 8.10 0.2.2, released 2019-12-08
preprocessor/Lexer.hs view
@@ -99,13 +99,24 @@ unlexerFile :: FilePath -> [Lexeme] -> String unlexerFile src xs = dropping 1 ++- go 1 True [(line, lexeme ++ whitespace) | Lexeme{..} <- xs]+ -- we split the whitespace up to increase the chances of startLine being true below+ -- pretty ugly code...+ go 1 True (concat+ [ [(line, lexeme ++ w1 ++ take 1 w2)+ ,(if line == 0 then 0 else line + length (filter (== '\n') (lexeme ++ w1 ++ take 1 w2)), drop 1 w2)]+ | Lexeme{..} <- xs, let (w1,w2) = break (== '\n') whitespace]) where- go :: Int -> Bool -> [(Int, String)] -> String- go doc drp ((i, x):xs) =- (if doc /= i && i /= 0 && drp then dropping i else "") +++ go+ :: Int -- ^ What line does GHC think we are on+ -> Bool -- ^ Are we at the start of a line+ -> [(Int, String)] -- ^ (original line, lexemes followed by their whitespace)+ -> String+ go ghcLine startLine ((i, x):xs) =+ (if emitDropping then dropping i else "") ++ x ++- go ((if i == 0 then doc else i) + length (filter (== '\n') x)) ("\n" `isSuffixOf` x) xs+ go ((if emitDropping then i else ghcLine) + length (filter (== '\n') x)) ("\n" `isSuffixOf` x) xs+ where emitDropping = ghcLine /= i && i /= 0 && startLine go _ _ [] = "" + -- write out a line marker with a trailing newline dropping n = "{-# LINE " ++ show n ++ " " ++ show src ++ " #-}\n"
record-dot-preprocessor.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.18 build-type: Simple name: record-dot-preprocessor-version: 0.2.3+version: 0.2.4 license: BSD3 x-license: BSD-3-Clause OR Apache-2.0 license-file: LICENSE