From c13617684eb10fc622cc502249591002e2f7d74c Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 25 Feb 2024 21:04:03 +0100 Subject: Separate out library --- app/Main.hs | 28 ++++++++++++++++++++++++++++ hie.yaml | 5 +++++ hs-visinter.cabal | 15 ++++++++++++--- src/Main.hs | 28 ---------------------------- 4 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 app/Main.hs delete mode 100644 src/Main.hs diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..b88d508 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE TupleSections #-} +module Main where + +import Data.List (intersperse) +import System.Environment (getArgs) +import System.Exit (die, exitFailure) + +import HSVIS.Parser + + +main :: IO () +main = do + (source, fname) <- getArgs >>= \case + [] -> (,"") <$> getContents + [fname] -> (,fname) <$> readFile fname + _ -> die "Usage: hs-visinter [filename.hs]" + + prog <- case parse fname source of + This errs -> do + sequence_ $ intersperse (putStrLn "") (map (putStrLn . printErrMsg) errs) + exitFailure + These errs res -> do + sequence_ $ intersperse (putStrLn "") (map (putStrLn . printErrMsg) errs) + return res + That res -> return res + + print prog diff --git a/hie.yaml b/hie.yaml index 9e856b5..ae8c4c0 100644 --- a/hie.yaml +++ b/hie.yaml @@ -1,6 +1,11 @@ cradle: multi: - path: "./src" + config: + cradle: + cabal: + component: "lib:hs-visinter" + - path: "./app" config: cradle: cabal: diff --git a/hs-visinter.cabal b/hs-visinter.cabal index 181d112..748355d 100644 --- a/hs-visinter.cabal +++ b/hs-visinter.cabal @@ -7,9 +7,8 @@ author: Tom Smeding maintainer: tom@tomsmeding.com build-type: Simple -executable hs-visinter - main-is: Main.hs - other-modules: +library + exposed-modules: Control.FAlternative HSVIS.AST HSVIS.Parser @@ -23,3 +22,13 @@ executable hs-visinter hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall -threaded + +executable hs-visinter + main-is: Main.hs + other-modules: + build-depends: + base, + hs-visinter + hs-source-dirs: app + default-language: Haskell2010 + ghc-options: -Wall -threaded diff --git a/src/Main.hs b/src/Main.hs deleted file mode 100644 index 750f749..0000000 --- a/src/Main.hs +++ /dev/null @@ -1,28 +0,0 @@ -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE TupleSections #-} -module Main where - -import Data.List (intersperse) -import System.Environment (getArgs) -import System.Exit (die, exitFailure) - -import Parser - - -main :: IO () -main = do - (source, fname) <- getArgs >>= \case - [] -> (,"") <$> getContents - [fname] -> (,fname) <$> readFile fname - _ -> die "Usage: hs-visinter [filename.hs]" - - prog <- case parse fname source of - This errs -> do - sequence_ $ intersperse (putStrLn "") (map (putStrLn . printErrMsg) errs) - exitFailure - These errs res -> do - sequence_ $ intersperse (putStrLn "") (map (putStrLn . printErrMsg) errs) - return res - That res -> return res - - print prog -- cgit v1.2.3-70-g09d2