From 6b04276193b6c1277c3c9e3c7b13e55be4647579 Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Wed, 11 Dec 2024 16:36:23 +0000 Subject: [PATCH 1/2] report bad boz --- src/Language/Fortran/AST/Literal/Boz.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Language/Fortran/AST/Literal/Boz.hs b/src/Language/Fortran/AST/Literal/Boz.hs index 34113786..fa68d794 100644 --- a/src/Language/Fortran/AST/Literal/Boz.hs +++ b/src/Language/Fortran/AST/Literal/Boz.hs @@ -95,7 +95,7 @@ parseBoz s = | p' == 'x' = Just $ BozPrefixZ Nonconforming | otherwise = Nothing where p' = Char.toLower p - errInvalid = error "Language.Fortran.AST.BOZ.parseBoz: invalid BOZ string" + errInvalid = error ("Language.Fortran.AST.BOZ.parseBoz: invalid BOZ string: " <> show s) -- | Remove the first and last elements in a list. shave = tail . init From fba734fa7d3e31c6a54d97531e3a1bf2405b6032 Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Wed, 11 Dec 2024 17:24:15 +0000 Subject: [PATCH 2/2] bypass parsing boz for cpp pragmas --- src/Language/Fortran/Parser/Free/Lexer.x | 36 +++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Language/Fortran/Parser/Free/Lexer.x b/src/Language/Fortran/Parser/Free/Lexer.x index 51f6cbb5..a8f263ed 100644 --- a/src/Language/Fortran/Parser/Free/Lexer.x +++ b/src/Language/Fortran/Parser/Free/Lexer.x @@ -1105,20 +1105,28 @@ advance move position = processLinePragma :: String -> AlexInput -> AlexInput processLinePragma m ai = - case dropWhile ((`elem` ["#", "line", "#line"]) . map toLower) (words m) of - -- 'line' pragma - rewrite the current line and filename - lineStr:otherWords - | line <- readIntOrBoz lineStr -> do - let revdropWNQ = reverse . drop 1 . dropWhile (flip notElem "'\"") - let file = revdropWNQ . revdropWNQ $ unwords otherWords - -- if a newline is present, then the aiPosition is already on the next line - let maybe1 | elem '\n' m = 0 | otherwise = 1 - -- lineOffs is the difference between the given line and the current next line - let lineOffs = fromIntegral line - (posLine (aiPosition ai) + maybe1) - let newP = (aiPosition ai) { posPragmaOffset = Just (lineOffs, file) - , posColumn = 1 } - ai { aiPosition = newP } - _ -> ai + let wordsm = words m + isLinePragma x = x `elem` ["#", "line", "#line"] + in -- If this is a line pragma then process this + if length wordsm > 0 && isLinePragma (head wordsm) + || (length wordsm > 1 && isLinePragma (head (tail wordsm))) + then + case dropWhile ((`elem` ["#", "line", "#line"]) . map toLower) wordsm of + -- 'line' pragma - rewrite the current line and filename + lineStr:otherWords + | line <- readIntOrBoz lineStr -> do + let revdropWNQ = reverse . drop 1 . dropWhile (flip notElem "'\"") + let file = revdropWNQ . revdropWNQ $ unwords otherWords + -- if a newline is present, then the aiPosition is already on the next line + let maybe1 | elem '\n' m = 0 | otherwise = 1 + -- lineOffs is the difference between the given line and the current next line + let lineOffs = fromIntegral line - (posLine (aiPosition ai) + maybe1) + let newP = (aiPosition ai) { posPragmaOffset = Just (lineOffs, file) + , posColumn = 1 } + ai { aiPosition = newP } + _ -> ai + -- Otherwise this is probably a CPP directive or some other pragma so ignore + else ai -- Handle pragmas that begin with # lexHash :: LexAction (Maybe Token)