Skip to content

Commit 35c50b6

Browse files
authored
Merge pull request #295 from camfort/fixboz
Avoid interpreting CPP as Boz
2 parents efb539f + fba734f commit 35c50b6

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/Language/Fortran/AST/Literal/Boz.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ parseBoz s =
9595
| p' == 'x' = Just $ BozPrefixZ Nonconforming
9696
| otherwise = Nothing
9797
where p' = Char.toLower p
98-
errInvalid = error "Language.Fortran.AST.BOZ.parseBoz: invalid BOZ string"
98+
errInvalid = error ("Language.Fortran.AST.BOZ.parseBoz: invalid BOZ string: " <> show s)
9999
-- | Remove the first and last elements in a list.
100100
shave = tail . init
101101

src/Language/Fortran/Parser/Free/Lexer.x

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,20 +1105,28 @@ advance move position =
11051105

11061106
processLinePragma :: String -> AlexInput -> AlexInput
11071107
processLinePragma m ai =
1108-
case dropWhile ((`elem` ["#", "line", "#line"]) . map toLower) (words m) of
1109-
-- 'line' pragma - rewrite the current line and filename
1110-
lineStr:otherWords
1111-
| line <- readIntOrBoz lineStr -> do
1112-
let revdropWNQ = reverse . drop 1 . dropWhile (flip notElem "'\"")
1113-
let file = revdropWNQ . revdropWNQ $ unwords otherWords
1114-
-- if a newline is present, then the aiPosition is already on the next line
1115-
let maybe1 | elem '\n' m = 0 | otherwise = 1
1116-
-- lineOffs is the difference between the given line and the current next line
1117-
let lineOffs = fromIntegral line - (posLine (aiPosition ai) + maybe1)
1118-
let newP = (aiPosition ai) { posPragmaOffset = Just (lineOffs, file)
1119-
, posColumn = 1 }
1120-
ai { aiPosition = newP }
1121-
_ -> ai
1108+
let wordsm = words m
1109+
isLinePragma x = x `elem` ["#", "line", "#line"]
1110+
in -- If this is a line pragma then process this
1111+
if length wordsm > 0 && isLinePragma (head wordsm)
1112+
|| (length wordsm > 1 && isLinePragma (head (tail wordsm)))
1113+
then
1114+
case dropWhile ((`elem` ["#", "line", "#line"]) . map toLower) wordsm of
1115+
-- 'line' pragma - rewrite the current line and filename
1116+
lineStr:otherWords
1117+
| line <- readIntOrBoz lineStr -> do
1118+
let revdropWNQ = reverse . drop 1 . dropWhile (flip notElem "'\"")
1119+
let file = revdropWNQ . revdropWNQ $ unwords otherWords
1120+
-- if a newline is present, then the aiPosition is already on the next line
1121+
let maybe1 | elem '\n' m = 0 | otherwise = 1
1122+
-- lineOffs is the difference between the given line and the current next line
1123+
let lineOffs = fromIntegral line - (posLine (aiPosition ai) + maybe1)
1124+
let newP = (aiPosition ai) { posPragmaOffset = Just (lineOffs, file)
1125+
, posColumn = 1 }
1126+
ai { aiPosition = newP }
1127+
_ -> ai
1128+
-- Otherwise this is probably a CPP directive or some other pragma so ignore
1129+
else ai
11221130

11231131
-- Handle pragmas that begin with #
11241132
lexHash :: LexAction (Maybe Token)

0 commit comments

Comments
 (0)