Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa McHale committed Jan 18, 2018
1 parent 058bbcd commit 4632244
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 92 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ script:
else
export BINPATH="$(find -name madlang -executable | tail -n4 | head -n1)"
fi
- echo $BINPATH
- mv $BINPATH madlang-$TARGET
- ls madlang-$TARGET

deploy:
api_key:
Expand Down
3 changes: 0 additions & 3 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ darcs:
darcs optimize pristine
darcs optimize cache

tokei:
tokei . .*.yml .*.yaml .yamllint -e Justfile

next:
@export VERSION=$(ac madlang.cabal | grep -P -o '\d+\.\d+\.\d+\.\d+' madlang.cabal | head -n1 | awk -F. '{$NF+=1; print $0}' | sed 's/ /\./g') && echo $VERSION && sed -i "2s/[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/$VERSION/" madlang.cabal
git commit -am "next"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ Download [cabal](https://www.haskell.org/cabal/download.html) and

```bash
$ cabal update
$ cabal install madlang
$ cabal new-install madlang --symlink-bindir ~/.local/bin
```

You may need to add `$HOME/.cabal/bin` to your `PATH`. To do so:
You may need to add `$HOME/.local/bin` to your `PATH`. To do so:

```
$ echo 'export PATH=$HOME/.cabal/bin:$PATH' >> $HOME/.bashrc
$ echo 'export PATH=$HOME/.local/bin:$PATH' >> $HOME/.bashrc
$ source $HOME/.bashrc
```

Expand Down
47 changes: 3 additions & 44 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,49 +1,8 @@
import Control.Monad (unless, void)
import Data.Maybe
import Distribution.CommandLine
import Distribution.Simple
import System.Directory (createDirectoryIfMissing)
import System.Environment (lookupEnv)
import System.Process (readCreateProcessWithExitCode, shell)

manpage :: IO String
manpage = readFile "man/madlang.1"

main :: IO ()
main = setManpath >>
writeManpages >>
writeBashCompletions >>
writeManpages "man/madlang.1" "madlang.1" >>
writeBashCompletions "madlang" >>
defaultMain

setManpath :: IO ()
setManpath = do
home <- lookupEnv "HOME"
case home of
Just x -> do
let bashRc = x ++ "/.bashrc"
config <- readFile bashRc
unless ("#manpath updated by madlang" `elem` lines config)
(appendFile bashRc "\n#manpath updated by madlang\nexport MANPATH=~/.local/share:$MANPATH\n" >>
void (readCreateProcessWithExitCode (shell $ "MANPATH=" ++ x ++ "/.local/share mandb") ""))
Nothing -> pure ()

writeManpages :: IO ()
writeManpages = do
home <- lookupEnv "HOME"
case home of
Just x -> do
let manPath = x ++ "/.local/share/man/man1"
createDirectoryIfMissing True manPath
writeFile (manPath ++ "/madlang.1") =<< manpage
Nothing -> pure ()

-- TODO only write if we can't find our own thing!
writeBashCompletions :: IO ()
writeBashCompletions = do
home <- lookupEnv "HOME"
case home of
Just x -> do
let bashRc = x ++ "/.bashrc"
config <- readFile bashRc
unless ("# Added by madlang" `elem` lines config)
(appendFile bashRc "\n# Added by madlang\neval \"$(madlang --bash-completion-script madlang)\"\n")
Nothing -> pure ()
8 changes: 4 additions & 4 deletions madlang.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: madlang
version: 3.2.0.2
version: 4.0.0.3
synopsis: Randomized templating language DSL
description: Madlang is a text templating language written in Haskell,
meant to explore computational creativity and generative
Expand All @@ -24,8 +24,7 @@ cabal-version: >=1.10
custom-setup
setup-depends: base
, Cabal
, directory
, process >= 1.4.0.0
, cli-setup >= 0.1.0.2

Flag profile {
Description: Build for profiling
Expand Down Expand Up @@ -65,7 +64,7 @@ library
, optparse-applicative
, template-haskell
, MonadRandom
, composition-prelude >= 0.1.1.0
, composition-prelude >= 1.1.0.0
, directory
, file-embed
, random-shuffle
Expand All @@ -81,6 +80,7 @@ library
, zlib
, zip-archive
, recursion-schemes
, binary
default-language: Haskell2010
if flag(development)
ghc-options: -Werror
Expand Down
10 changes: 0 additions & 10 deletions man/MANPAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ Currently supported modifiers are:
- reverse
- oulipo (removes all instances of the letter 'e')

# DISPLAYING TREES

You may wish to use the command

```
madlang tree file.mad | less
```

for larger trees.

# EXAMPLES

You can examine an example using the bundled libraries
Expand Down
13 changes: 1 addition & 12 deletions man/madlang.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 2.0.2
.\" Automatically generated by Pandoc 2.1.1
.\"
.TH "madlang (1)" "" "" "" ""
.hy
Expand Down Expand Up @@ -92,17 +92,6 @@ capitalize
reverse
.IP \[bu] 2
oulipo (removes all instances of the letter `e')
.SH DISPLAYING TREES
.PP
You may wish to use the command
.IP
.nf
\f[C]
madlang\ tree\ file.mad\ |\ less
\f[]
.fi
.PP
for larger trees.
.SH EXAMPLES
.PP
You can examine an example using the bundled libraries at
Expand Down
1 change: 0 additions & 1 deletion src/Text/Madlibs/Ana/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Text.Madlibs.Ana.Parse (
) where

import Control.Composition
import Control.Monad
import Control.Monad.State
import qualified Data.Map as M
import Data.Maybe
Expand Down
11 changes: 10 additions & 1 deletion src/Text/Madlibs/Ana/Resolve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Text.Madlibs.Ana.Resolve (
, runText
, runFileN
, pathSep
, cacheFile
) where

import Control.Arrow (first)
Expand Down Expand Up @@ -40,7 +41,7 @@ parseFile = fmap (fmap takeTemplate) .** getInclusionCtx False
-- | Generate text from file with inclusions
getInclusionCtx :: (MonadIO m) => Bool -> [T.Text] -> FilePath -> FilePath -> m (Either (ParseError Char (ErrorFancy Void)) [(Key, RandTok)])
getInclusionCtx isTree ins folder filepath = liftIO $ do
libDir <- do { home <- getEnv "HOME" ; if os /= "windows" then pure (home <> "/.madlang/") else pure (home <> "\\.madlang\\") }
libDir <- do { home <- getEnv "HOME" ; pure (home <> (pathSep : ".madlang" <> pure pathSep)) }
file <- catch (readFile' (folder ++ filepath)) (const (readLibFile (libDir <> folder <> filepath)) :: IOException -> IO T.Text)
let filenames = map T.unpack $ either (error . show) id $ parseInclusions filepath file -- TODO pass up errors correctly
let resolveKeys file' = fmap (first (((T.pack . (<> "-")) . dropExtension) file' <>))
Expand All @@ -54,6 +55,14 @@ pathSep :: Char
pathSep | os == "windows" = '\\'
| otherwise = '/'

filenameBytecode :: FilePath -> FilePath
filenameBytecode = id

-- | Cache the parsed strucutre (and libraries it depends on) as a binary file
-- `.filename.mbc`, reading instead from it when possible.
cacheFile :: FilePath -> IO T.Text
cacheFile = runFile [] . filenameBytecode

-- | Generate randomized text from a file containing a template
runFile :: [T.Text] -- ^ List of variables to substitute into the template
-> FilePath -- ^ Path to @.mad@ file.
Expand Down
10 changes: 3 additions & 7 deletions src/Text/Madlibs/Exec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import Text.Madlibs.Ana.Resolve
import Text.Madlibs.Cata.Display
import Text.Madlibs.Internal.Utils
import Text.Madlibs.Packaging.Fetch
import Text.Megaparsec
import Text.Megaparsec hiding (many)

-- | datatype for the program
newtype Program = Program { sub :: Subcommand }

-- | datatype for the subcommands
data Subcommand = Debug { input :: FilePath }
| Run { _rep :: Maybe Int , clInputs :: [String] , input :: FilePath }
| Run { _rep :: Maybe Int , input :: FilePath }
| Lint { clInputs :: [String] , input :: FilePath }
| Sample { clInputs :: [String], input :: FilePath }
| Get { _remote :: String }
Expand Down Expand Up @@ -50,10 +50,6 @@ temp = Run
<> short 'r'
<> metavar "REPETITIONS"
<> help "Number of times to repeat"))
<*> (many $ strOption
(short 'i'
<> metavar "VAR"
<> help "command-line inputs to the template."))
<*> (argument str
(metavar "FILEPATH"
<> completer (bashCompleter "file -X '!*.mad' -o plusdirs")
Expand Down Expand Up @@ -128,7 +124,7 @@ template rec =
let filepath = reverse . (takeWhile (/='/')) . reverse $ toFolder
let ins = map T.pack (clInputs . sub $ rec)
case sub rec of
(Run reps _ _) ->
(Run reps _) ->
(TL.init . TL.unlines . fmap TL.fromStrict <$> runFileN (fromMaybe 1 reps) ins filepath) >>= TLIO.putStrLn
(Sample _ _) ->
(TL.init . TL.unlines . fmap TL.fromStrict <$> runFileN 60 ins filepath) >>= TLIO.putStrLn
Expand Down
6 changes: 5 additions & 1 deletion src/Text/Madlibs/Internal/Types.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleInstances #-}
Expand All @@ -13,10 +15,12 @@ module Text.Madlibs.Internal.Types where

import Control.Arrow (second)
import Control.Monad.State
import Data.Binary (Binary)
import Data.Function
import Data.Functor.Foldable.TH (makeBaseFunctor)
import Data.Monoid
import qualified Data.Text as T
import GHC.Generics (Generic)
import Instances.TH.Lift ()
import Language.Haskell.TH.Syntax (Lift (..))

Expand All @@ -40,7 +44,7 @@ instance Eq PreTok where

-- | datatype for a token returning a random string
data RandTok = List [(Prob, RandTok)] | Value T.Text
deriving (Show, Eq, Lift)
deriving (Show, Eq, Lift, Generic, Binary)

apply :: (T.Text -> T.Text) -> RandTok -> RandTok -- TODO make a base functor so we can map f over stuff?
apply f (Value str) = Value (f str)
Expand Down
9 changes: 5 additions & 4 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
resolver: lts-9.11
resolver: lts-10.3
packages:
- .
extra-deps:
- composition-prelude-0.1.1.0
- recursion-schemes-ext-0.2.1.0
- megaparsec-6.2.0
- composition-prelude-1.1.0.0
- recursion-schemes-ext-1.0.0.0
- megaparsec-6.4.0
- hspec-megaparsec-1.0.0
- cli-setup-0.1.0.2
flags:
madlang:
development:
Expand Down

0 comments on commit 4632244

Please sign in to comment.