aihc-cpp 2.0.0.0 → 2.0.0.1
raw patch · 4 files changed
+47/−3 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +11/−0
- aihc-cpp.cabal +1/−1
- src/Aihc/Cpp.hs +24/−2
- test/Spec.hs +11/−0
CHANGELOG.md view
@@ -4,6 +4,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [2.0.0.1] - 2026-11-15++### Fixed++- A string literal whose line ends in a single unpaired backslash, continued+ on the next line without a closing string-gap backslash, is now spliced the+ way GCC does: the backslash and newline are removed and the two lines join.+ Previously the backslash was left in place, which broke modules such as+ `streamly-core`. A line whose continuation starts with a backslash is still+ kept as a Haskell string gap.+ ## [2.0.0.0] - 2026-09-10 ### Performance
aihc-cpp.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.8 name: aihc-cpp-version: 2.0.0.0+version: 2.0.0.1 build-type: Simple license: Unlicense license-file: LICENSE
src/Aihc/Cpp.hs view
@@ -257,7 +257,7 @@ joinContinuationLines cur lineStart lineEnd rest else let lineText = sliceBytes lineStart lineEnd cur- in if hasGccStringContinuation emptyQuoteState lineText+ in if hasStringContinuation emptyQuoteState lineText rest then joinStringContinuationLines cur lineStart lineEnd rest else (lineText, 1, rest) @@ -332,6 +332,28 @@ hasGccStringContinuation st lineText = "\\\\" `C.isSuffixOf` lineText && qsInString (scanQuoteState st lineText) +-- | Tell if a line continues on the next physical line inside a string.+--+-- The double-backslash spelling is 'hasGccStringContinuation'. A line can+-- also end in one unpaired backslash inside a string. If the next line+-- starts with a backslash after blanks, the pair is a Haskell string gap and+-- stays. Otherwise the backslash is only the CPP continuation marker, so GCC+-- removes it with the newline. For example, streamly-core writes+-- @\"an \\@ and continues the string on the next line with no gap close.+hasStringContinuation :: QuoteState -> ByteString -> Cursor -> Bool+hasStringContinuation st lineText next =+ "\\" `C.isSuffixOf` lineText+ && ( hasGccStringContinuation st lineText+ || ( let end = scanQuoteState st lineText+ in qsInString end+ && qsEscaped end+ && not (atEnd next)+ && peekByte (skipWhile isSpaceOrTab next) /= Just 0x5C -- '\'+ )+ )+ where+ isSpaceOrTab b = b == 0x20 || b == 0x09+ joinStringContinuationLines :: Cursor -> Int -> Int -> Cursor -> (ByteString, Int, Cursor) joinStringContinuationLines origCur lineStart firstLineEnd firstRest = let buf = curBuf origCur@@ -349,7 +371,7 @@ segEnd = curPos eol rest' = fromMaybe eol (skipNewline eol) segmentText = sliceBytes segStart segEnd origCur- in if hasGccStringContinuation quoteState segmentText+ in if hasStringContinuation quoteState segmentText rest' then let segmentBytes = BSB.byteString (sliceBS segStart (segEnd - 1) (curBuf origCur)) scannedText = sliceBytes segStart (segEnd - 1) origCur
test/Spec.hs view
@@ -285,6 +285,10 @@ assertPreprocessOutput ghcStringGapInput (C.unlines ["#line 1 \"<input>\"", "x = \"a\\", " \\b\""]),+ testCase "ordinary string splices single backslash with no gap close" $+ assertPreprocessOutput+ singleBackslashSpliceInput+ (C.unlines ["#line 1 \"<input>\"", "x = \"a b\""]), testCase "function macro argument accepts GCC double-backslash continuation" $ assertPreprocessOutput gccStringContinuationMacroInput@@ -523,6 +527,13 @@ C.unlines [ "x = \"a\\", " \\b\""+ ]++singleBackslashSpliceInput :: BS.ByteString+singleBackslashSpliceInput =+ C.unlines+ [ "x = \"a\\",+ " b\"" ] gccStringContinuationMacroInput :: BS.ByteString