Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
343 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/dist/ | ||
/cabal-dev/ | ||
/.virtualenv/ | ||
/.hpc/ | ||
/.hsenv/ | ||
/.cabal-sandbox/ | ||
cabal.sandbox.config | ||
cabal.config | ||
*.o | ||
*.hi | ||
*.chi | ||
*.chs.h | ||
*.dyn_o | ||
*.dyn_hi | ||
*.prof | ||
*.aux | ||
*.hp | ||
*.tix | ||
default.nix | ||
shell.nix | ||
scratchpad.hs | ||
*~ | ||
[#]*[#] | ||
.\#* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
columns: 80 | ||
steps: | ||
- imports: | ||
align: global | ||
- language_pragmas: | ||
remove_redundant: true | ||
style: vertical | ||
- records: {} | ||
- tabs: | ||
spaces: 4 | ||
- trailing_whitespace: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
-- Usage: runhaskell Generate.hs New.Module | ||
module Generate (main) where | ||
|
||
import Data.List (groupBy, isInfixOf) | ||
import Data.Monoid ((<>)) | ||
import System.Directory (createDirectoryIfMissing) | ||
import System.Environment (getArgs) | ||
import System.FilePath (joinPath, takeDirectory, (<.>)) | ||
|
||
main :: IO () | ||
main = do | ||
ms <- getArgs | ||
mapM_ createDirectories ms | ||
mapM_ writeFiles ms | ||
mapM_ updateFiles ms | ||
where | ||
createDirectories m = do | ||
createLibraryDirectory m | ||
createTestSuiteDirectory m | ||
writeFiles m = do | ||
writeLibraryFile m | ||
writeTestSuiteFile m | ||
updateFiles m = do | ||
updateCabal m | ||
updateLibrary m | ||
|
||
-- | ||
|
||
createDirectory :: FilePath -> IO () | ||
createDirectory = createDirectoryIfMissing True . takeDirectory | ||
|
||
path :: FilePath -> String -> String -> FilePath | ||
path d s m = joinPath (d : parts (m <> s)) <.> "hs" | ||
|
||
parts :: String -> [String] | ||
parts = split '.' | ||
|
||
placeholder :: String | ||
placeholder = "New.Module" | ||
|
||
pragma :: String | ||
pragma = "-- GENERATE: " | ||
|
||
replace :: (Eq a) => [a] -> [a] -> [a] -> [a] | ||
replace [] _ _ = [] | ||
replace xs@(h : t) old new = | ||
if a == old | ||
then new <> replace b old new | ||
else h : replace t old new | ||
where | ||
(a, b) = splitAt (length old) xs | ||
|
||
split :: (Eq a) => a -> [a] -> [[a]] | ||
split x xs = fmap (dropWhile (== x)) (groupBy (const (x /=)) xs) | ||
|
||
updateFile :: FilePath -> String -> IO () | ||
updateFile p m = do | ||
contents <- readFile p | ||
seq (length contents) (return ()) | ||
writeFile p (unlines (go =<< lines contents)) | ||
where | ||
go line = if pragma `isInfixOf` line | ||
then [replace (replace line pragma "") placeholder m, line] | ||
else [line] | ||
|
||
-- Cabal | ||
|
||
cabalPath :: FilePath | ||
cabalPath = "..cabal" | ||
|
||
updateCabal :: String -> IO () | ||
updateCabal = updateFile cabalPath | ||
|
||
-- Library | ||
|
||
createLibraryDirectory :: String -> IO () | ||
createLibraryDirectory = createDirectory . libraryPath | ||
|
||
libraryDirectory :: String | ||
libraryDirectory = "library" | ||
|
||
libraryPath :: String -> FilePath | ||
libraryPath = path libraryDirectory librarySuffix | ||
|
||
libraryTemplate :: String -> String | ||
libraryTemplate m = unlines | ||
[ "-- | TODO" | ||
, "module " <> m <> " () where" | ||
] | ||
|
||
librarySuffix :: String | ||
librarySuffix = "" | ||
|
||
updateLibrary :: String -> IO () | ||
updateLibrary = updateFile (libraryPath "ICFP2015") | ||
|
||
writeLibraryFile :: String -> IO () | ||
writeLibraryFile m = writeFile (libraryPath m) (libraryTemplate m) | ||
|
||
-- Test Suite | ||
|
||
createTestSuiteDirectory :: String -> IO () | ||
createTestSuiteDirectory = createDirectory . testSuitePath | ||
|
||
testSuiteDirectory :: String | ||
testSuiteDirectory = "test-suite" | ||
|
||
testSuitePath :: String -> FilePath | ||
testSuitePath = path testSuiteDirectory testSuiteSuffix | ||
|
||
testSuiteTemplate :: String -> String | ||
testSuiteTemplate m = unlines | ||
[ "module " <> m <> "Spec (spec) where" | ||
, "" | ||
, "import " <> m <> " ()" | ||
, "" | ||
, "import Test.Hspec" | ||
, "" | ||
, "spec :: Spec" | ||
, "spec = it \"is\" pending" | ||
] | ||
|
||
testSuiteSuffix :: String | ||
testSuiteSuffix = "Spec" | ||
|
||
writeTestSuiteFile :: String -> IO () | ||
writeTestSuiteFile m = writeFile (testSuitePath m) (testSuiteTemplate m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
author: Sebastian Conybeare | ||
version: 0.0.1 | ||
build-type: Simple | ||
cabal-version: >= 1.10 | ||
category: AI | ||
copyright: 2015 Sebastian Conybeare <sebmathguy@gmail.com> | ||
description: The UIUC SIGPLAN entry into the ICFP 2015 competition. | ||
synopsis: The UIUC SIGPLAN entry into the ICFP 2015 competition. | ||
extra-source-files: README.md | ||
license-file: LICENSE.md | ||
license: MIT | ||
maintainer: sebmathguy@gmail.com | ||
name: ICFP2015 | ||
|
||
library | ||
build-depends: base >=4.6 && <5 | ||
, aeson >=0.9 && <1.0 | ||
default-language: Haskell2010 | ||
exposed-modules: ICFP2015 | ||
ghc-options: -Wall | ||
ghc-prof-options: -auto-all -prof | ||
hs-source-dirs: library | ||
default-extensions: OverloadedStrings | ||
|
||
executable ICFP2015 | ||
build-depends: base | ||
, ICFP2015 | ||
default-language: Haskell2010 | ||
ghc-options: -threaded | ||
ghc-prof-options: -auto-all -prof | ||
hs-source-dirs: executable | ||
main-is: Main.hs | ||
default-extensions: OverloadedStrings |
Oops, something went wrong.