summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2015-11-12 20:33:39 +0100
committerBen Gamari <ben@smart-cactus.org>2015-11-12 20:33:39 +0100
commit5d6133bec0f682e86ee31bbdb6d82e6fb2ede8f7 (patch)
tree48af103f30112be15049e99c63e8d0f02289ab40 /compiler
parentac2e1e57ac0755af0d296c072584d27e4e29f9b1 (diff)
downloadhaskell-5d6133bec0f682e86ee31bbdb6d82e6fb2ede8f7.tar.gz
Ignore comments in getOptions
When Opt_KeepRawTokenStream is turned on then getOptions fails to find the language pragmas which can cause unexpected parse errors when using the GHC API. A simple solution is to make it skip over any comments in the token stream. Test Plan: ./validate Reviewers: austin, bgamari Subscribers: alanz, thomie Differential Revision: https://phabricator.haskell.org/D1444 GHC Trac Issues: #10942
Diffstat (limited to 'compiler')
-rw-r--r--compiler/main/HeaderInfo.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/main/HeaderInfo.hs b/compiler/main/HeaderInfo.hs
index 08c761994a..35107c8bc3 100644
--- a/compiler/main/HeaderInfo.hs
+++ b/compiler/main/HeaderInfo.hs
@@ -256,6 +256,9 @@ getOptions' dflags toks
parseToks (open:xs)
| ITlanguage_prag <- getToken open
= parseLanguage xs
+ parseToks (comment:xs) -- Skip over comments
+ | isComment (getToken comment)
+ = parseToks xs
parseToks _ = []
parseLanguage (L loc (ITconid fs):rest)
= checkExtension dflags (L loc fs) :
@@ -269,6 +272,17 @@ getOptions' dflags toks
parseLanguage []
= panic "getOptions'.parseLanguage(2) went past eof token"
+ isComment :: Token -> Bool
+ isComment c =
+ case c of
+ (ITlineComment {}) -> True
+ (ITblockComment {}) -> True
+ (ITdocCommentNext {}) -> True
+ (ITdocCommentPrev {}) -> True
+ (ITdocCommentNamed {}) -> True
+ (ITdocSection {}) -> True
+ _ -> False
+
-----------------------------------------------------------------------------
-- | Complain about non-dynamic flags in OPTIONS pragmas.