Fixes#714
This adds a `--json` flag that `dhall decode` and `dhall encode` can use to
read/write the equivalent JSON representation of the CBOR. This comes in
handy for the parsing compliance tests which use this CBOR-as-JSON as the
standard representation of the abstract syntax tree.
Now that `constructors x` is the same as `x` we can have `dhall lint`
safely strip all uses of `constructors` in preparation for removing the
keyword entirely.
Fixes#509
The `Dhall.Import.HTTP` module had logic for pretty-printing HTTP error
message, but this logic wasn't being used anywhere! This change fixes
that and also polishes the error messages a little bit.
* Add dotgen as a dependency
Signed-off-by: Basile Henry <bjm.henry@gmail.com>
* Build up dot graph while resolving imports
Signed-off-by: Basile Henry <bjm.henry@gmail.com>
* Add --dot option to resolve in CLI
Signed-off-by: Basile Henry <bjm.henry@gmail.com>
* Handle diamond dependencies in dot graph
* Refactor dot graph generation
This fixes an apparently very old bug in import caching caught by @basile-henry
Before this change the import resolution algorithm was:
1. Retrieving the cache
2. Transitively resolving all imports
3. Setting the new cache to be current import insert into the cache retrieved in
step 1
The bug is that all of the transitive imports resolved in step 2 added
entries of their own to the cache and those new cache entries were being
clobbered by step 3.
The fix is simple: don't use the cache retrieved in step 1 to compute
the updated cache in step 3. Rather, use `modify` instead of `put` to
create the new cache so that we preserve newly-added cache entries.
`dhall lint` was incorrectly deleting `let` bindings that are being used
due to not checking other `let` bindings within the same multi-`let`
expression for free variable occurrences.
This change fixes that and adds the first regression test for `dhall
lint`
Fixes#692
The standard permits a user to access a constructor from a type stored inside
a record, but the Haskell implementation had a mistake which prevented this.
Specifically, the Haskell implementation was not normalizing the union type
as the standard specified before attempting to access the constructor, leading
to an unexpected type error.
This begins updates the filesystem layout for the tests to match
the new layout from the standard test suite (See:
https://github.com/dhall-lang/dhall-lang/pull/265)
This is still missing a part of the standard requirement, which is checking
parsing and import test results against an expected output (instead of
just checking that they succeed). I plan to add that in a subsequent
pull request. This is mainly to unblock other features that require using
the new standard layout.
Fixes https://github.com/dhall-lang/dhall-lang/issues/267
According to the standard, Unicode characters up to `0x10FFFF` do not
require escaping. See:
33cab24f8e/standard/dhall.abnf (L192)
... so we can preserve them when pretty-printing Dhall expressions.
Note that the current code still does not comply with the standard for Unicode
characters beyond `0x10FFFF`, but I'll defer fixing that to a subsequent
change.
The issue was that the parser was attempting to parse // first, which
will succeed on the prefix of //\\, then the parser will get an error
because it expects a sub expression but the input is \\.
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
https://github.com/dhall-lang/dhall-nix/issues/17 to be fixed since
`dhall-nix` is incompatible with later versions of `megaparsec` due to
`hnix`.
This moves the `dhall` executable's logic to a `Dhall.Main` module, for
two main reasons:
* To expose the executable's functionality as a library
* To support migrating more commands to be sub-commands for the executable
* Benchmark Prelude files
* Add issue 108 example
* Some cleaning up
* Remove printing of files
* Add bounds
* Clean cabal formatting
* Using strict Text instead of lazy Text
* Fixing compilation errors
* Update tests
* Cleanup
* Revert benchmark merge
* Update comments to replace the mention of Builder to Text
This updates the data types to match the terminology used in the
standard. Specifically, "path" specifically refers to a directory or
file, whereas "import" is a broader term encapsulating URLs and
environment variables.
This is a breaking change but an easy one to adapt to. Most downstream
consumers of the API just use the `Path` type, and this change includes
a `Path` type synonym for backwards compatibility.
This adds new `dhall version`, `dhall resolve`, `dhall type`, and
`dhall normalize` subcommands. The latter three subcommands can be used
to run just one phase of the interpreter.
If you omit the subcommand then the executable behaves the same as
before.
The long-term motivation for this change is so that we can eventually use a
separate `attoparsec`-based lexing step to greatly increase parsing speed since
the `trifecta`/`parsers` API doesn't allow tokens other than `Char`.
The secondary motivation for this is that `megaparsec` is a smaller dependency
that is more actively maintained.
The main reason for this change is stylistic (`dhall` doesn't need to
preserve the header because it's not filling the same purpose as
`dhall-format`)
The other reason for this is that `renderIO` was displaying the header
for both the type and the normalized expression. Rather than complicate
the code to fix this I felt it was easier to just remove the
header-printing logic.
This takes advantage of two features to simplify accessing options
fields:
* This uses `optparse-generic`'s support for generating option records
without `Helpful` newtype wrappers
* This also uses `RecordWildCards` to unpack the option record
This change fixes two issues with output rendering
The first was the following panic in the prettyprinter library when
calling `Data.Text.Prettyprinter.Doc.Render.Terminal.renderIO` on an
expression without any annotations:
```
$ dhall <<< '1' > stdout.dhall
Integer
Peeked an empty style stack! Please report this as a bug.
CallStack (from HasCallStack):
error, called at src/Data/Text/Prettyprint/Doc/Render/Util/Panic.hs:38:15 in prettyprinter-1.1.1-1CDqnG9d6HQ5GZzz2F5LpU:Data.Text.Prettyprint.Doc.Render.Util.Panic
```
The fix is to use `Data.Text.Prettyprinter.Doc.Render.Text.renderIO`
instead when the expression has no annotations.
The second issue is that the color detection was not correctly
working for `stderr`, meaning that this:
```
$ dhall <<< '1' 2> stderr.dhall
```
... would write escape codes to `stderr.dhall`. The fix is to
separately check if `stderr` supports color or not when writing
to `stderr`.
The `layoutSmart` option appears to not behave correctly when specifying an
`Unbounded` number of columns:
https://github.com/quchen/prettyprinter/issues/49
... and the symptom of this problem is that the `dhall` executable by
default (i.e. without `--pretty`) renders all expressions in the long
format (i.e. multiline with indentation), regardless of the number of available
columns.
However, the `layoutPretty` function behaves correctly with the
`Unbounded` directive, so this change switches to using that when
rendering output without `--pretty`.
The `dhall` executable was missing the empty line separating the type
from the normalized form when run without the `--pretty` flag. This
change fixes that.
On systems with the locale set to non-UTF8 (e.g. `LC_ALL=C`, the default POSIX
locale), handles are opened in that locale, so printing dhall’s error messages
fails on the first non-ASCII character:
```
Error: Not a function
Explanation: Expressions separated by whitespace denote function application,
like this:
dhall: <stderr>: hPutChar: invalid argument (invalid character)
```
We set the stderr handle accordingly.
From the dhall.abnf specification:
; The character encoding for Dhall is UTF-8
How Haskell decodes input depends on the locale otherwise.
Fixes https://github.com/dhall-lang/dhall-lang/issues/8
This takes a Dhall expression on standard input and outputs the same
expression to standard output except pretty-printed in a standard format