-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`.
- Loading branch information
1 parent
6fd4c83
commit aecfbc9
Showing
539 changed files
with
2,601 additions
and
162 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
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
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
(import ./shared.nix {}).dhall | ||
let | ||
shared = import ./nix/shared.nix {}; | ||
|
||
in | ||
{ inherit (shared) dhall dhall-bash dhall-json dhall-text; } |
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,27 @@ | ||
Copyright (c) 2018 Gabriel Gonzalez | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the author nor the names of its contributors may be | ||
used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,34 @@ | ||
# `dhall-bash 1.0.16` | ||
|
||
[![Hackage](https://img.shields.io/hackage/v/dhall-bash.svg)](https://hackage.haskell.org/package/dhall-bash) | ||
|
||
This `dhall-bash` package provides a Dhall to Bash compiler so that you can | ||
easily marshall Dhall values into your Bash scripts | ||
|
||
This does not compile all available Dhall language constructs into Bash and | ||
only supports extracting primitive values, lists, optional values and records | ||
from normalized expressions. | ||
|
||
## Quick start | ||
|
||
If you have Nix installed, then you can build and install this package using: | ||
|
||
```bash | ||
$ nix-env --install --file default.nix | ||
$ dhall-to-bash <<< '1' | ||
1 | ||
$ dhall-to-bash <<< '"ABC" ++ "DEF"' | ||
ABCDEF | ||
$ dhall-to-bash --declare FOO <<< '"ABC" ++ "DEF"' | ||
declare -r FOO=ABCDEF | ||
$ eval $(dhall-to-bash --declare FOO <<< '"ABC" ++ "DEF"') | ||
$ echo "${FOO}" | ||
ABCDEF | ||
$ dhall-to-bash --declare BAR | ||
let replicate = https://ipfs.io/ipfs/QmcTbCdS21pCxXysTzEiucDuwwLWbLUWNSKwkJVfwpy2zK/Prelude/List/replicate | ||
in replicate +10 Integer 1 | ||
<Ctrl-D> | ||
declare -r -a BAR=(1 1 1 1 1 1 1 1 1 1) | ||
$ dhall-to-bash --declare BAZ <<< '{ qux = 1, xyzzy = True }' | ||
declare -r -A BAZ=([qux]=1 [xyzzy]=true) | ||
``` |
File renamed without changes.
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 @@ | ||
(import ../nix/shared.nix {}).dhall-bash |
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,51 @@ | ||
Name: dhall-bash | ||
Version: 1.0.16 | ||
Cabal-Version: >=1.8.0.2 | ||
Build-Type: Simple | ||
Tested-With: GHC == 7.10.2, GHC == 8.0.1 | ||
License: BSD3 | ||
License-File: LICENSE | ||
Copyright: 2017 Gabriel Gonzalez | ||
Author: Gabriel Gonzalez | ||
Maintainer: Gabriel439@gmail.com | ||
Bug-Reports: https://github.com/dhall-lang/dhall-haskell/issues | ||
Synopsis: Compile Dhall to Bash | ||
Description: | ||
Use this package if you want to compile Dhall expressions to Bash. | ||
You can use this package as a library or an executable: | ||
. | ||
* See the "Dhall.Bash" module if you want to use this package as a library | ||
. | ||
* Use the @dhall-to-bash@ if you want an executable | ||
. | ||
The "Dhall.Bash" module also contains instructions for how to use this | ||
package | ||
Category: Compiler | ||
Source-Repository head | ||
Type: git | ||
Location: https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-bash | ||
|
||
Library | ||
Hs-Source-Dirs: src | ||
Build-Depends: | ||
base >= 4.8.0.0 && < 5 , | ||
bytestring < 0.11, | ||
containers < 0.6 , | ||
dhall >= 1.18.0 && < 1.19, | ||
neat-interpolation < 0.4 , | ||
shell-escape < 0.3 , | ||
text >= 0.2 && < 1.3 | ||
Exposed-Modules: Dhall.Bash | ||
GHC-Options: -Wall | ||
|
||
Executable dhall-to-bash | ||
Hs-Source-Dirs: exec | ||
Main-Is: Main.hs | ||
Build-Depends: | ||
base , | ||
bytestring , | ||
dhall , | ||
dhall-bash , | ||
optparse-generic >= 1.1.1 && < 1.4 , | ||
text | ||
GHC-Options: -Wall |
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,73 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module Main where | ||
|
||
import Control.Exception (SomeException) | ||
import Data.ByteString (ByteString) | ||
import Options.Generic (Generic, ParseRecord, type (<?>)(..)) | ||
import System.Exit (ExitCode(..)) | ||
|
||
import qualified Control.Exception | ||
import qualified Data.ByteString | ||
import qualified Data.Text.IO | ||
import qualified Dhall | ||
import qualified Dhall.Bash | ||
import qualified Dhall.Import | ||
import qualified Dhall.Parser | ||
import qualified Dhall.TypeCheck | ||
import qualified GHC.IO.Encoding | ||
import qualified Options.Generic | ||
import qualified System.Exit | ||
import qualified System.IO | ||
|
||
data Options = Options | ||
{ explain :: Bool | ||
<?> "Explain error messages in detail" | ||
, declare :: Maybe ByteString | ||
<?> "Declare the given variable as a statement instead of an expression" | ||
} deriving (Generic, ParseRecord) | ||
|
||
main :: IO () | ||
main = do | ||
GHC.IO.Encoding.setLocaleEncoding GHC.IO.Encoding.utf8 | ||
Options {..} <- Options.Generic.getRecord "Compile Dhall to Bash" | ||
|
||
(if unHelpful explain then Dhall.detailed else id) (handle (do | ||
inText <- Data.Text.IO.getContents | ||
|
||
expr <- case Dhall.Parser.exprFromText "(stdin)" inText of | ||
Left err -> Control.Exception.throwIO err | ||
Right expr -> return expr | ||
|
||
expr' <- Dhall.Import.load expr | ||
case Dhall.TypeCheck.typeOf expr' of | ||
Left err -> Control.Exception.throwIO err | ||
Right _ -> return () | ||
|
||
bytes <- case unHelpful declare of | ||
Nothing -> do | ||
case Dhall.Bash.dhallToExpression expr' of | ||
Left err -> Control.Exception.throwIO err | ||
Right bytes -> return bytes | ||
Just var -> do | ||
case Dhall.Bash.dhallToStatement expr' var of | ||
Left err -> Control.Exception.throwIO err | ||
Right bytes -> return bytes | ||
Data.ByteString.putStr bytes )) | ||
|
||
handle :: IO a -> IO a | ||
handle = Control.Exception.handle handler | ||
where | ||
handler :: SomeException -> IO a | ||
handler e = case Control.Exception.fromException e of | ||
Just ExitSuccess -> do | ||
Control.Exception.throwIO e | ||
_ -> do | ||
System.IO.hPutStrLn System.IO.stderr "" | ||
System.IO.hPrint System.IO.stderr e | ||
System.Exit.exitFailure |
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 @@ | ||
(import ../nix/shared.nix {}).shell-dhall-bash |
Oops, something went wrong.