added file suffix and check

This commit is contained in:
sebastian 2023-03-26 00:09:47 +01:00
parent ac43af8110
commit d49e2401bf
2 changed files with 42 additions and 25 deletions

View file

@ -2,38 +2,53 @@
module Main where module Main where
import Codegen.Codegen (generateCode) import Codegen.Codegen (generateCode)
import Data.Bool (bool) import Data.Bool (bool)
import GHC.IO.Handle.Text (hPutStrLn) import GHC.IO.Handle.Text (hPutStrLn)
import Grammar.ErrM (Err) import Grammar.ErrM (Err)
import Grammar.Par (myLexer, pProgram) import Grammar.Par (myLexer, pProgram)
import Grammar.Print (printTree) import Grammar.Print (printTree)
import Monomorphizer.Monomorphizer (monomorphize) import Monomorphizer.Monomorphizer (monomorphize)
import Control.Monad (when) import Control.Monad (when)
import Data.List.Extra (isSuffixOf) import Data.List.Extra (isSuffixOf)
import Compiler (compile) import Compiler (compile)
import Renamer.Renamer (rename) import Renamer.Renamer (rename)
import System.Directory (createDirectory, doesPathExist, import System.Directory (
getDirectoryContents, createDirectory,
removeDirectoryRecursive, doesPathExist,
setCurrentDirectory) getDirectoryContents,
import System.Environment (getArgs) removeDirectoryRecursive,
import System.Exit (ExitCode, exitFailure, setCurrentDirectory,
exitSuccess) )
import System.IO (stderr) import System.Environment (getArgs)
import System.Process.Extra (readCreateProcess, shell, import System.Exit (
spawnCommand, waitForProcess) ExitCode,
import TypeChecker.TypeChecker (typecheck) exitFailure,
exitSuccess,
)
import System.IO (stderr)
import System.Process.Extra (
readCreateProcess,
shell,
spawnCommand,
waitForProcess,
)
import TypeChecker.TypeChecker (typecheck)
main :: IO () main :: IO ()
main = main =
getArgs >>= \case getArgs >>= \case
[] -> print "Required file path missing" [] -> putStrLn "Required file path missing"
("-d" : s : _) -> main' True s ["-d", s] -> do
(s : _) -> main' False s when (".crf" `isSuffixOf` s) (main' True s)
putStrLn $ "File '" ++ s ++ "' is not a churf file"
[s] -> do
when (".crf" `isSuffixOf` s) (main' False s)
putStrLn $ "File '" ++ s ++ "' is not a churf file"
xs -> putStrLn $ "Can't process: " ++ unwords xs
main' :: Bool -> String -> IO () main' :: Bool -> String -> IO ()
main' debug s = do main' debug s = do

View file

@ -26,3 +26,5 @@ bind ma f = case ma of {
Nothing => Nothing ; Nothing => Nothing ;
Just a => f a ; Just a => f a ;
}; };