[Git][ghc/ghc][wip/az/ghc-cpp] Return other pragmas as cpp ignored when GHC_CPP active

Alan Zimmerman pushed to branch wip/az/ghc-cpp at Glasgow Haskell Compiler / GHC Commits: 57c097da by Alan Zimmerman at 2025-05-22T20:03:11+01:00 Return other pragmas as cpp ignored when GHC_CPP active - - - - - 2 changed files: - compiler/GHC/Parser/Lexer.x - utils/check-cpp/Main.hs Changes: ===================================== compiler/GHC/Parser/Lexer.x ===================================== @@ -273,7 +273,7 @@ $tab { warnTab } -- set. "{-" / { isNormalComment } { nested_comment } -"/*" / { ifExtension GhcCppBit } { cpp_comment } +-- "/*" / { ifExtension GhcCppBit } { cpp_comment } -- Single-line comments are a bit tricky. Haskell 98 says that two or -- more dashes followed by a symbol should be parsed as a varsym, so we @@ -333,11 +333,16 @@ $unigraphic / { isSmartQuote } { smart_quote_error } ^\# line { begin line_prag1 } ^\# / { followedByDigit } { begin line_prag1 } - ^\#.*\n / { ifExtensionGhcCppNotComment } { cppSkip } + ^\ *\# \ * $idchar+ .*\n / { ifExtensionGhcCppNotComment } { cppSkip } + + ^\# pragma .* \n / { ifExtensionGhcCppNotComment } { cppSkip } -- GCC 3.3 CPP generated, apparently + ^\# \! .* \n / { ifExtensionGhcCppNotComment } { cppSkip } -- #!, for scripts -- gcc + ^\ \# \! .* \n / { ifExtensionGhcCppNotComment } { cppSkip } -- #!, for scripts -- clang; See #6132 ^\# pragma .* \n ; -- GCC 3.3 CPP generated, apparently ^\# \! .* \n ; -- #!, for scripts -- gcc ^\ \# \! .* \n ; -- #!, for scripts -- clang; See #6132 + () { do_bol } } @@ -1771,8 +1776,9 @@ linePrag span buf len buf2 = do usePosPrags <- getBit UsePosPragsBit if usePosPrags then begin line_prag2 span buf len buf2 - else let !src = lexemeToFastString buf len - in return (L span (ITline_prag (SourceText src))) + -- else let !src = lexemeToFastString buf len + -- in return (L span (ITline_prag (SourceText src))) + else nested_comment span buf len buf2 -- When 'UsePosPragsBit' is not set, it is expected that we emit a token instead -- of updating the position in 'PState' @@ -3736,6 +3742,7 @@ lexToken = do let span = mkPsSpan loc1 end let bytes = byteDiff buf buf2 span `seq` setLastToken buf span bytes + -- function t is `Action p` lt <- t span buf bytes buf2 let lt' = unLoc lt if (isComment lt') then setLastComment lt else setLastTk lt ===================================== utils/check-cpp/Main.hs ===================================== @@ -891,3 +891,29 @@ t40 = do , "x='a'" , "" ] + +t41 :: IO () +t41 = do + dump + [ "{-# LANGUAGE GHC_CPP #-}" + , "module CFG where" + , "" + , "{-# LINE 6 \"src/CFG.ag\" #-}" + , "" + , "import Data.Word" + , "import ByteCode" + ] + +t42 :: IO () +t42 = do + dump + [ "{-# LANGUAGE GHC_CPP #-}" + , "module T23465 where" + , "" + , "{-# WARNInG" + , " in \"x-f\" f \"fw\" ;" + , " in \"x-f\" g \"gw\"" + , "#-}" + , "f = f" + , "g = g" + ] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/57c097dad0ebf79e229ccf7f04d2a9a9... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/57c097dad0ebf79e229ccf7f04d2a9a9... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Alan Zimmerman (@alanz)