[project @ 2005-01-11 16:21:53 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverUtil.hs
index 2cee71d..8a85670 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------------
--- $Id: DriverUtil.hs,v 1.47 2005/01/11 15:22:04 simonmar Exp $
+-- $Id: DriverUtil.hs,v 1.49 2005/01/11 16:21:53 simonmar Exp $
 --
 -- Utils for the driver
 --
@@ -64,14 +64,27 @@ getOptionsFromSource file
                               return (words opts ++ rest)
                       | otherwise -> return []
 
+-- detect {-# OPTIONS_GHC ... #-}.  For the time being, we accept OPTIONS
+-- instead of OPTIONS_GHC, but that is deprecated.
 matchOptions s
-  | Just s1 <- maybePrefixMatch "{-#" s, -- -}
-    Just s2 <- maybePrefixMatch "OPTIONS" (remove_spaces s1),
-    not (is_ident (head s2)),
-    Just s3 <- maybePrefixMatch "}-#" (reverse s2)
-  = Just (reverse s3)
+  | Just s1 <- maybePrefixMatch "{-#" s -- -} 
+  = matchOptions1 (remove_spaces s1)
   | otherwise
   = Nothing
+ where
+  matchOptions1 s
+    | Just s2 <- maybePrefixMatch "OPTIONS" s
+    = case () of
+       _ | Just s3 <- maybePrefixMatch "_GHC" s2, not (is_ident (head s3))
+         -> matchOptions2 s3
+         | not (is_ident (head s2))
+         -> matchOptions2 s2
+         | otherwise
+         -> Just []  -- OPTIONS_anything is ignored, not treated as start of source
+    | otherwise = Nothing
+  matchOptions2 s
+    | Just s3 <- maybePrefixMatch "}-#" (reverse s) = Just (reverse s3)
+    | otherwise = Nothing
 
 -----------------------------------------------------------------------------
 -- A version of getDirectoryContents that is non-fatal if the