module Main where
import Language.Haskell.Parser
import Language.Haskell.Pretty
import System.IO
import System.Environment
import Data.List
import Data.Char
splitString :: String -> [String]
splitString s = filter (" "/=) $ groupBy fGroup s
fGroup :: Char -> Char -> Bool
fGroup c1 c2 | c1 /= '{' && c1 /= '}' && c1 /= '[' && c1 /= ']' && c1 /= '(' && c1 /= ')' && c1 /= ',' && c1 /= ' ' && c2 /= '{' && c2 /= '}'&& c2 /= '[' && c2 /= ']' && c2 /= '(' && c2 /= ')' && c2 /= ',' && c2 /= ' ' = True
| otherwise = False
--showTree :: (Show a, Print a) => Int -> a -> String -> IO ()
--showTree v tree f
-- = do
-- putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree-
-- writeFile (f++".ast") $ show $ splitString (show tree)
-- putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
main :: IO ()
main = do fileNames <- getArgs
file <- readFile (head fileNames)
case parseModule file of
-- ParseOk m -> putStrLn (prettyPrint m)
-- ParseOk m -> putStrLn (show m)
ParseOk m -> do {writeFile ((head fileNames)++".ast") $ show $ splitString (show m);
writeFile ((head fileNames)++".ast.txt") $ show $ show m
}
ParseFailed loc e -> print e
|