- f ("foreign" : "import" : ws) = f ws
- f ("import" : "{-#" : "SOURCE" : "#-}" : "qualified" : m : ws)
- = Left (mkMN m) : f ws
- f ("import" : "{-#" : "SOURCE" : "#-}" : m : ws)
- = Left (mkMN m) : f ws
- f ("import" : "qualified" : m : ws)
- = Right (mkMN m) : f ws
- f ("import" : m : ws)
- = Right (mkMN m) : f ws
- f (w:ws) = f ws
- f [] = []
-
- mkMN str = mkModuleName (takeWhile isModId str)
- isModId c = isAlphaNum c || c `elem` "'_"
-
--- remove literals and comments from a string
-clean :: String -> String
+ -- Only pick up the name following 'module' the first time.
+ -- Otherwise, we would be fooled by 'module Me ( module Wrong )'
+ -- and conclude that the module name is Wrong instead of Me.
+ f si ni old_me ("eludom" : me : ws)
+ = case old_me of
+ Nothing -> f si ni (Just (mkMN me)) ws
+ Just _ -> f si ni old_me ws
+
+ f si ni me ("ngierof" : "tropmi" : ws) = f si ni me ws
+ f si ni me ("tropmi" : "#-{" : "ECRUOS" : "}-#" : "deifilauq" : m : ws)
+ = f ((mkMN m):si) ni me ws
+ f si ni me ("tropmi" : "#-{" : "ECRUOS" : "}-#" : m : ws)
+ = f ((mkMN m):si) ni me ws
+
+ -- skip other contents of pragma comments
+ f si ni me ("#-{" : ws)
+ = f si ni me (drop 1 (dropWhile (/= "}-#") ws))
+
+ f si ni me ("tropmi" : "deifilauq" : m : ws)
+ = f si ((mkMN m):ni) me ws
+ f si ni me ("tropmi" : m : ws)
+ = f si ((mkMN m):ni) me ws
+ f si ni me (w:ws) = f si ni me ws
+ f si ni me [] = (nub si, nub ni, me)
+
+ mkMN str = mkModuleName (takeWhile isModId (reverse str))
+ isModId c = isAlphaNum c || c `elem` "'._"
+
+
+-- remove literals and comments from a string, producing a
+-- list of reversed words.
+clean :: String -> [String]