Skip to content

Commit fba734f

Browse files
committed
bypass parsing boz for cpp pragmas
1 parent 6b04276 commit fba734f

File tree

1 file changed

+22
-14
lines changed
  • src/Language/Fortran/Parser/Free

1 file changed

+22
-14
lines changed

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)