tools/unitCycles.hs
changeset 4353 671d66ba3af6
child 4355 4554c4df9f1a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/unitCycles.hs	Wed Nov 17 16:19:28 2010 +0300
@@ -0,0 +1,19 @@
+module Main where
+
+import PascalParser
+import System
+import Control.Monad
+import Data.Either
+import Data.List
+
+unident :: Identificator -> String
+unident (Identificator s) = s
+
+extractUnits :: PascalUnit -> (String, [String])
+extractUnits (Program (Identificator name) (Implementation (Uses idents) _ _) _) = ("program " ++ name, map unident idents)
+extractUnits (Unit (Identificator name) (Interface (Uses idents1) _) (Implementation (Uses idents2) _ _) _ _) = (name, map unident $ idents1 ++ idents2)
+
+main = do
+    fileNames <- getArgs
+    files <- mapM readFile fileNames
+    mapM_ (putStrLn . show . extractUnits) . rights . map parsePascalUnit $ files