Skip to content

Commit

Permalink
Moved to taktoa's template
Browse files Browse the repository at this point in the history
  • Loading branch information
taktoa committed Aug 8, 2015
1 parent a66e176 commit ce12be2
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 675 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
25 changes: 25 additions & 0 deletions .gitignore
@@ -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
*~
[#]*[#]
.\#*

11 changes: 11 additions & 0 deletions .stylish-haskell.yaml
@@ -0,0 +1,11 @@
columns: 80
steps:
- imports:
align: global
- language_pragmas:
remove_redundant: true
style: vertical
- records: {}
- tabs:
spaces: 4
- trailing_whitespace: {}
127 changes: 127 additions & 0 deletions Generate.hs
@@ -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)
33 changes: 33 additions & 0 deletions ICFP2015.cabal
@@ -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

0 comments on commit ce12be2

Please sign in to comment.