Commit Graph

234 Commits

Author SHA1 Message Date
Gabriel Gonzalez
8bc595be7f
Add support for quoted path components (#690)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/293
2018-11-20 18:08:43 -08:00
David Virgilio
adf94a6503 Encode doubles as Double, do bounds checks, and add support for NaN and Infinity values (#667) 2018-11-20 15:07:08 -08:00
Gabriel Gonzalez
8a74105007
Update tests to match the filesystem layout from the standard (#688)
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.
2018-11-17 08:23:26 -08:00
Gabriel Gonzalez
96a360a5bc
Add lower bound to optparse-applicative (#685)
Fixes https://github.com/dhall-lang/dhall-lang/issues/282
2018-11-16 08:43:23 -08:00
Gabriel Gonzalez
3ed5f4d293
Prevent Hurkens' paradox (#680)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/272
2018-11-15 19:49:57 -08:00
Oliver Charles
9d3e493f69 Allow custom normalization to be entered top-down (#684) 2018-11-15 18:25:30 -08:00
Gabriel Gonzalez
8a5bfaa3b9
Add support for multi-let (#675)
... as standardized in: https://github.com/dhall-lang/dhall-lang/pull/266

This also adds `dhall lint` support for consolidating nested `let` expressions
2018-11-13 08:01:59 -08:00
Gabriel Gonzalez
b3968f681a
Preserve Unicode characters (#679)
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.
2018-11-12 09:46:33 -08:00
Javier Neira
5db1051311 Update stack/cabal config to sync with new structure (#671)
Also, add build instructions for cabal and stack in alphabetical order
2018-11-06 05:42:23 -08:00
Dan Burton
9d39286e35 Test that formatting preserves projection order (#672) 2018-11-05 21:37:10 -08:00
Alexander Biehl
096c03936e Introduce normalizeWithM for monadic normalization (#371) 2018-11-05 20:21:29 -08:00
Dan Burton
7aba79118c Use an Ordered Set for Project (#670) 2018-11-05 19:59:01 -08:00
Sofia Rose
9d0fd42d95 Fix parsing of //\\ (#666)
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 \\.
2018-10-29 20:28:50 -07:00
Gabriel Gonzalez
aecfbc9acc
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
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`.
2018-10-28 17:32:51 -07:00
Gabriel Gonzalez
5c84d39775
Relocate dhall/Main.hs to src/Dhall/Main.hs (#432)
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
2018-06-07 11:26:38 +01:00
Fintan Halpenny
8bd410f8f5
Use Strict Text for Parsing. (#422)
* 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
2018-06-01 11:54:07 -06:00
Gabriel Gonzalez
fa4569eaaf
Rename Path{,Mode,Hashed,Type} to Import{,Mode,Hashed,Type} (#376)
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.
2018-05-11 08:58:06 -07:00
Gabriel Gonzalez
50a10f69d1
Add sub-commands for each interpreter phase (#352)
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.
2018-04-07 07:10:30 -07:00
Gabriel Gonzalez
a07424a81b
Use optparse-applicative instead of optparse-generic (#351)
There are two motivations for this change:

* To slim down `dhall`'s dependency footprint
* To allow greater control over option customization
2018-04-05 07:28:35 -07:00
Oliver Charles
922e20e6ab Replace trifecta with megaparsec (#268)
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.
2018-03-27 09:09:20 -07:00
Gabriel Gonzalez
404c97d96c
Add --plain flag to disable syntax highlighting (#310)
... as requested by @PierreR
2018-03-01 13:45:51 -08:00
Gabriel Gonzalez
4b3f28374c
Always format output of the dhall executable (#303)
Fixes #284
2018-02-25 14:31:38 -08:00
Gabriel Gonzalez
c2329c52f4
Don't pretty-print header for dhall executable (#289)
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.
2018-02-21 09:08:53 -08:00
Gabriel Gonzalez
be7a5771ea
Use the latest prettyprinter library (#287)
This fixes the root cause of e24b3d90fa so
that we no longer need the workaround of using `Pretty.Text.renderIO`
2018-02-19 11:05:11 -08:00
Gabriel Gonzalez
8e1acafac4
Enforce -Werror in CI (#286)
This adds the `-Werror` flag to CI so that warnings don't sneak into the
build (and also fixes the current set of warnings)
2018-02-19 10:31:21 -08:00
Gabriel Gonzalez
48ca8d18df
Simplify option extraction (#285)
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
2018-02-19 08:08:20 -08:00
Gabriel Gonzalez
e24b3d90fa
Fix output rendering (#280)
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`.
2018-02-18 16:34:53 -08:00
Gabriel Gonzalez
4733ef8710
Fix layout when not using --pretty (#271)
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`.
2018-02-16 08:47:47 -08:00
Gabriel Gonzalez
20c4e5f460
Restore missing line in dhall output (#270)
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.
2018-02-16 08:29:26 -08:00
Oliver Charles
d329f1017b Have dhall use syntax highlighting if ANSI is supported (#267) 2018-02-16 06:58:12 -08:00
Profpatsch
1370c362f3 set hPrint encodings to use utf8, independent of locale (#188)
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.
2017-12-11 10:32:40 -08:00
Armando Ramirez
28db97ca91 Simpe custom typechecking for Embedded terms (#186) 2017-12-05 11:01:44 -08:00
Gabriel Gonzalez
c7dbb71ed4
Add --pretty option to dhall executable (#177)
This option causes the executable to format the output, for ease of
reading
2017-11-07 11:44:22 -08:00
Gabriel Gonzalez
5f7d46b179 Add dhall-format executable (#137)
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
2017-09-17 08:18:15 -07:00