Skip to content

Commit aecfbc9

Browse files
authored
Migrate dhall-{bash,json,text} into this repository (#661)
The motivation for this change is: * To catch build failures in downstream packages whenever we make a breaking change to the `dhall` API * To reduce the amount of work I need in order to cut a release for all of these packages * To better share Nix/CI-related logic between the projects Note that I have not yet migrated `dhall-nix` in. I'm waiting for dhall-lang/dhall-nix#17 to be fixed since `dhall-nix` is incompatible with later versions of `megaparsec` due to `hnix`.
1 parent 6fd4c83 commit aecfbc9

File tree

539 files changed

+2601
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

539 files changed

+2601
-162
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017 Gabriel Gonzalez
1+
Copyright (c) 2018 Gabriel Gonzalez
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 12 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,25 @@
1-
# `dhall 1.18.0`
1+
# `dhall-haskell`
22

3-
Dhall is a programmable configuration language that is not Turing-complete
3+
This repository is a shared repository for all of the `dhall-*` Haskell
4+
packages, including:
45

5-
You can think of Dhall as: JSON + functions + types + imports
6+
* [`dhall`](./dhall)
7+
* [`dhall-bash`](./dhall-bash)
8+
* [`dhall-json`](./dhall-json)
9+
* [`dhall-text`](./dhall-text)
610

7-
You will probably want to read the language-agnostic README here:
11+
Navigate to each package's directory for their respective `README`s
812

9-
* [`dhall-lang` `README`](https://github.com/dhall-lang/dhall-lang/blob/master/README.md)
13+
# Quick start
1014

11-
This repository (and this `README`) focuses on the Haskell implementation of
12-
Dhall
15+
You can build all of the packages by running:
1316

14-
## Motivation
15-
16-
*"Why not configure my program using JSON or YAML?"*
17-
18-
JSON or YAML are suitable for small configuration files, but larger
19-
configuration files with complex schemas require programming language features
20-
to reduce repetition. Otherwise, the repetitive configuration files become
21-
error-prone and difficult to maintain/migrate.
22-
23-
This post explains in more detail the motivation behind programmable
24-
configuration files:
25-
26-
* [Programmable configuration files](https://github.com/dhall-lang/dhall-lang/wiki/Programmable-configuration-files)
27-
28-
*"Why not configure my program using Haskell code?"*
29-
30-
You probably don't want to rebuild your program every time you make a
31-
configuration change. Recompilation is slow and requires the GHC toolchain
32-
to be installed anywhere you want to make configuration changes.
33-
34-
## Quick start
35-
36-
Given this Haskell program saved to `example.hs`:
37-
38-
```haskell
39-
-- example.hs
40-
41-
{-# LANGUAGE DeriveGeneric #-}
42-
{-# LANGUAGE OverloadedStrings #-}
43-
44-
import Dhall
45-
46-
data Example = Example { foo :: Integer, bar :: Vector Double }
47-
deriving (Generic, Show)
48-
49-
instance Interpret Example
50-
51-
main :: IO ()
52-
main = do
53-
x <- input auto "./config"
54-
print (x :: Example)
55-
```
56-
57-
... which reads in this configuration file:
58-
59-
```bash
60-
$ cat ./config
61-
{ foo = 1
62-
, bar = ./bar
63-
}
64-
```
65-
66-
... which in turn references this other file:
67-
68-
```
69-
$ cat ./bar
70-
[3.0, 4.0, 5.0]
7117
```
72-
73-
... you can interpret the Haskell program like this:
74-
75-
```bash
76-
$ nix-shell nix/test-dhall.nix
77-
[nix-shell]$ runghc example.hs
78-
Example {foo = 1, bar = [3.0,4.0,5.0]}
79-
```
80-
81-
You can also interpret Dhall programs directly using the installed command-line
82-
compiler:
83-
84-
```bash
85-
$ dhall
86-
List/head Double ./bar
87-
<Ctrl-D>
88-
Optional Double
89-
90-
Some 3.0
91-
```
92-
93-
... and you can reference remote expressions or functions by their URL, too:
94-
95-
```bash
96-
$ dhall
97-
let null = https://github.com/raw/dhall-lang/Prelude/35deff0d41f2bf86c42089c6ca16665537f54d75/List/null
98-
in null Double ./bar
99-
<Ctrl-D>
100-
Bool
101-
102-
False
103-
```
104-
105-
Now go read the
106-
[Dhall tutorial](https://hackage.haskell.org/package/dhall/docs/Dhall-Tutorial.html)
107-
to learn more
108-
109-
## Building this project
110-
111-
Nix + Cabal is the recommended workflow for project development since continuous
112-
integration uses Nix to build and test the project. Other development tools and
113-
workflows are also supported on a best-effort basis.
114-
115-
You can build the project using only Nix by running this command from the root
116-
of the repository:
117-
118-
```bash
11918
$ nix-build
12019
```
12120

122-
More commonly, you will want to incrementally build the project using `cabal`.
123-
You can either do so inside of a `nix-shell`:
124-
125-
```bash
126-
$ nix-shell
127-
[nix-shell]$ cabal configure
128-
[nix-shell]$ cabal build
129-
[nix-shell]$ cabal test
130-
```
131-
132-
... or you can add `nix: True` to your `~/.cabal/config` file and then you can
133-
run the same `cabal` commands without an explicit `nix-shell`:
134-
135-
```bash
136-
$ cabal configure
137-
$ cabal build
138-
$ cabal test
139-
```
21+
... or you can run `nix-build` within each package's respective directory to
22+
build just that one package.
14023

14124
## Development status
14225

default.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
(import ./shared.nix {}).dhall
1+
let
2+
shared = import ./nix/shared.nix {};
3+
4+
in
5+
{ inherit (shared) dhall dhall-bash dhall-json dhall-text; }

dhall-bash/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2018 Gabriel Gonzalez
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
3. Neither the name of the author nor the names of its contributors may be
15+
used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

dhall-bash/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# `dhall-bash 1.0.16`
2+
3+
[![Hackage](https://img.shields.io/hackage/v/dhall-bash.svg)](https://hackage.haskell.org/package/dhall-bash)
4+
5+
This `dhall-bash` package provides a Dhall to Bash compiler so that you can
6+
easily marshall Dhall values into your Bash scripts
7+
8+
This does not compile all available Dhall language constructs into Bash and
9+
only supports extracting primitive values, lists, optional values and records
10+
from normalized expressions.
11+
12+
## Quick start
13+
14+
If you have Nix installed, then you can build and install this package using:
15+
16+
```bash
17+
$ nix-env --install --file default.nix
18+
$ dhall-to-bash <<< '1'
19+
1
20+
$ dhall-to-bash <<< '"ABC" ++ "DEF"'
21+
ABCDEF
22+
$ dhall-to-bash --declare FOO <<< '"ABC" ++ "DEF"'
23+
declare -r FOO=ABCDEF
24+
$ eval $(dhall-to-bash --declare FOO <<< '"ABC" ++ "DEF"')
25+
$ echo "${FOO}"
26+
ABCDEF
27+
$ dhall-to-bash --declare BAR
28+
let replicate = https://ipfs.io/ipfs/QmcTbCdS21pCxXysTzEiucDuwwLWbLUWNSKwkJVfwpy2zK/Prelude/List/replicate
29+
in replicate +10 Integer 1
30+
<Ctrl-D>
31+
declare -r -a BAR=(1 1 1 1 1 1 1 1 1 1)
32+
$ dhall-to-bash --declare BAZ <<< '{ qux = 1, xyzzy = True }'
33+
declare -r -A BAZ=([qux]=1 [xyzzy]=true)
34+
```
File renamed without changes.

dhall-bash/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(import ../nix/shared.nix {}).dhall-bash

dhall-bash/dhall-bash.cabal

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Name: dhall-bash
2+
Version: 1.0.16
3+
Cabal-Version: >=1.8.0.2
4+
Build-Type: Simple
5+
Tested-With: GHC == 7.10.2, GHC == 8.0.1
6+
License: BSD3
7+
License-File: LICENSE
8+
Copyright: 2017 Gabriel Gonzalez
9+
Author: Gabriel Gonzalez
10+
Maintainer: [email protected]
11+
Bug-Reports: https://github.com/dhall-lang/dhall-haskell/issues
12+
Synopsis: Compile Dhall to Bash
13+
Description:
14+
Use this package if you want to compile Dhall expressions to Bash.
15+
You can use this package as a library or an executable:
16+
.
17+
* See the "Dhall.Bash" module if you want to use this package as a library
18+
.
19+
* Use the @dhall-to-bash@ if you want an executable
20+
.
21+
The "Dhall.Bash" module also contains instructions for how to use this
22+
package
23+
Category: Compiler
24+
Source-Repository head
25+
Type: git
26+
Location: https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-bash
27+
28+
Library
29+
Hs-Source-Dirs: src
30+
Build-Depends:
31+
base >= 4.8.0.0 && < 5 ,
32+
bytestring < 0.11,
33+
containers < 0.6 ,
34+
dhall >= 1.18.0 && < 1.19,
35+
neat-interpolation < 0.4 ,
36+
shell-escape < 0.3 ,
37+
text >= 0.2 && < 1.3
38+
Exposed-Modules: Dhall.Bash
39+
GHC-Options: -Wall
40+
41+
Executable dhall-to-bash
42+
Hs-Source-Dirs: exec
43+
Main-Is: Main.hs
44+
Build-Depends:
45+
base ,
46+
bytestring ,
47+
dhall ,
48+
dhall-bash ,
49+
optparse-generic >= 1.1.1 && < 1.4 ,
50+
text
51+
GHC-Options: -Wall

dhall-bash/exec/Main.hs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DeriveAnyClass #-}
3+
{-# LANGUAGE DeriveGeneric #-}
4+
{-# LANGUAGE OverloadedStrings #-}
5+
{-# LANGUAGE RecordWildCards #-}
6+
{-# LANGUAGE TypeOperators #-}
7+
8+
module Main where
9+
10+
import Control.Exception (SomeException)
11+
import Data.ByteString (ByteString)
12+
import Options.Generic (Generic, ParseRecord, type (<?>)(..))
13+
import System.Exit (ExitCode(..))
14+
15+
import qualified Control.Exception
16+
import qualified Data.ByteString
17+
import qualified Data.Text.IO
18+
import qualified Dhall
19+
import qualified Dhall.Bash
20+
import qualified Dhall.Import
21+
import qualified Dhall.Parser
22+
import qualified Dhall.TypeCheck
23+
import qualified GHC.IO.Encoding
24+
import qualified Options.Generic
25+
import qualified System.Exit
26+
import qualified System.IO
27+
28+
data Options = Options
29+
{ explain :: Bool
30+
<?> "Explain error messages in detail"
31+
, declare :: Maybe ByteString
32+
<?> "Declare the given variable as a statement instead of an expression"
33+
} deriving (Generic, ParseRecord)
34+
35+
main :: IO ()
36+
main = do
37+
GHC.IO.Encoding.setLocaleEncoding GHC.IO.Encoding.utf8
38+
Options {..} <- Options.Generic.getRecord "Compile Dhall to Bash"
39+
40+
(if unHelpful explain then Dhall.detailed else id) (handle (do
41+
inText <- Data.Text.IO.getContents
42+
43+
expr <- case Dhall.Parser.exprFromText "(stdin)" inText of
44+
Left err -> Control.Exception.throwIO err
45+
Right expr -> return expr
46+
47+
expr' <- Dhall.Import.load expr
48+
case Dhall.TypeCheck.typeOf expr' of
49+
Left err -> Control.Exception.throwIO err
50+
Right _ -> return ()
51+
52+
bytes <- case unHelpful declare of
53+
Nothing -> do
54+
case Dhall.Bash.dhallToExpression expr' of
55+
Left err -> Control.Exception.throwIO err
56+
Right bytes -> return bytes
57+
Just var -> do
58+
case Dhall.Bash.dhallToStatement expr' var of
59+
Left err -> Control.Exception.throwIO err
60+
Right bytes -> return bytes
61+
Data.ByteString.putStr bytes ))
62+
63+
handle :: IO a -> IO a
64+
handle = Control.Exception.handle handler
65+
where
66+
handler :: SomeException -> IO a
67+
handler e = case Control.Exception.fromException e of
68+
Just ExitSuccess -> do
69+
Control.Exception.throwIO e
70+
_ -> do
71+
System.IO.hPutStrLn System.IO.stderr ""
72+
System.IO.hPrint System.IO.stderr e
73+
System.Exit.exitFailure

dhall-bash/shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(import ../nix/shared.nix {}).shell-dhall-bash

0 commit comments

Comments
 (0)