Skip to content

Commit

Permalink
Preserve comments in legacy77 that don't precede a continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
burz authored and mrd committed May 10, 2019
1 parent 800afd3 commit 75c0cba
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Language/Fortran/Lexer/FixedForm.x
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,7 @@ lexComment :: LexAction (Maybe Token)
lexComment =
lexLineWithWhitespace $ \ m -> do
s <- getLexemeSpan
version <- getVersion
case version of
Fortran77Legacy -> return Nothing
_ -> return . Just . TComment s $ tail m
return . Just . TComment s $ tail m

-- Get a line without losing the whitespace, then call continuation with it.
lexLineWithWhitespace :: (String -> LexAction (Maybe Token)) -> LexAction (Maybe Token)
Expand Down Expand Up @@ -925,8 +922,8 @@ alexGetByte ai
-- Skip the continuation line altogether
| isContinuation ai && _isWhiteInsensitive = skip Continuation ai
-- Skip the newline before a comment
| aiFortranVersion ai == Fortran77Legacy &&
_isWhiteInsensitive && isNewlineComment ai = skip NewlineComment ai
| aiFortranVersion ai == Fortran77Legacy && _isWhiteInsensitive
&& isNewlineCommentsFollowedByContinuation ai = skip NewlineComment ai
-- If we are not parsing a Hollerith skip whitespace
| _curChar `elem` [ ' ', '\t' ] && _isWhiteInsensitive = skip Char ai
-- Ignore inline comments
Expand Down Expand Up @@ -983,6 +980,13 @@ isNewlineComment ai =
_next1 = takeNChars 1 ai
p = (aiPosition ai) { posAbsoluteOffset = posAbsoluteOffset (aiPosition ai) + 1 }

isNewlineCommentsFollowedByContinuation :: AlexInput -> Bool
isNewlineCommentsFollowedByContinuation ai
| isNewlineComment ai
= isNewlineCommentsFollowedByContinuation (ai { aiPosition = advance NewlineComment ai })
| isContinuation ai = True
| otherwise = False

skip :: Move -> AlexInput -> Maybe (Word8, AlexInput)
skip move ai =
let _newPosition = advance move ai in
Expand Down

0 comments on commit 75c0cba

Please sign in to comment.