1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-11 11:47:03 +03:00
Commit Graph

48 Commits

Author SHA1 Message Date
Yann Hamdaoui
25cba8c21e
Fix clippy 1.75 warnings (#1750) 2024-01-07 17:32:34 +00:00
Yann Hamdaoui
957305c678
Add unstability warning for --error-format (#1744) 2023-12-20 16:21:53 +00:00
Yann Hamdaoui
d35baaee1c
Add --error-format flag to serialize err diagnostics (#1740)
* Add --error-format flag to serialize err diagnostics

* Make other CLI errors follow --error-format as well
2023-12-19 15:36:57 +00:00
Yann Hamdaoui
5c4298f685
Print something when nickel doc succeeds (#1729)
The doc subcommand has been reported to be a bit confusing, because it
generates file in a default location but just returns without further
details upon success. This commits add a print statement that says where
the document has been generated instead.
2023-12-01 10:05:15 +00:00
jneem
a6dca6ad8f
Add a cli param to specify the search path (#1721)
* Add a cli param to specify the search path

* Change the names around
2023-11-28 15:09:57 +00:00
jneem
f7ffe31697
Search for imports in NICKEL_PATH (#1716)
* Search for imports in NICKEL_PATH

* Move the env variable part to the cli

* Add a test

* Add a failing test
2023-11-22 16:56:58 +00:00
Yann Hamdaoui
eda326f92b
Add a --field argument to subcommands whenever it makes sense (#1712)
* Factor out extract_field() from query()

* Add selectable field to Program

* Add --field to supported commands

This commit finishes the series on adding `--field` argument to the CLI.
This argument is factorized as a new Customize implementer which
regroups commands that don't support general customization (overriding)
but still support selecting a specific field from the configuration.
It's added to the full customization as well.

In consequence, commands that didn't support selecting particular field
before now generically support the `--field` argument. The `--path`
argument for `--query` is removed and is just a `--field` argument for
`nickel query`.

* Fix not taking the --field into account when not customizing

* Formatting

* Fix tests for new --field argument

* Fix clippy warning

* Fix compilation errors, tests, and improve error messages

* Avoid duplicating 'field' declaration in clap
2023-11-16 11:37:54 +00:00
Yann Hamdaoui
f186e0e169
New syntax for customize mode (#1709)
* Customize mode new assignment syntax, part 1

* Add StaticPathField parsing rule

* Add cli assignment parsing rule

* Use new assignment parsing rule, refactor common code

* Fix compilation warnings

* Improve the output of `-- list` including type and contracts

* Remove unused datatype

* Formatting

* Fix old tests and add new for customize mode

* Reword documentation of FieldInterface::is_input

* Pass on code documentation

* Remove obsolete comment

* Update cli/tests/snapshot/inputs/customize-mode/unknown_override.ncl

Co-authored-by: jneem <joeneeman@gmail.com>

* Update cli/tests/snapshot/inputs/customize-mode/unkonwn_field_path.ncl

Co-authored-by: jneem <joeneeman@gmail.com>

* Update cli/src/customize/interface.rs

Co-authored-by: jneem <joeneeman@gmail.com>

* Fix typos in snapshot tests

* Add suggestion for customize mode unknown field errors

* Update snapshot tests with new output

* Get rid of '-- show', hint at using query instead

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2023-11-16 10:26:39 +00:00
Yann Hamdaoui
c0729415e4
Add suggestions when misspelling a record field (#1710)
* Add strsim dependency

* Move error module into its own directory

* Add error::suggest module and fn to find best suggestion

* Add field_names() method to RecordData

* Make find_match more generic

* Add conversion identifier/nickel string

* Add suggestion to missing field errors

* Fix tests and rename item

* Add snapshot test for field suggestion

* Remove debug println and fix code comment

* Review suggestion: improve missing field error message

* Formatting
2023-11-13 17:17:35 +00:00
Yann Hamdaoui
11c8fab020
Fix unsound contract equality fast check (#1703)
* Fix unsound ptr eq check in contract equality

For performance reason, the contract equality checker performs a quick
pointer check to see if the two terms to compare are physically equal.
In this case, it used to return `true` directly, eschewing more costly
recursive checks.

However, this is unsound, because the same term (physically) might be in two
different environments, and have two different values. This is typically
the case with function application: when evaluating `f 1` and `f 2`,
both terms will physically point to the body of `f`, but in a different
environment. Thus, we also need to ensure that environment are equals as
well in this quick check.

This commit adds a fast `ptr_eq` check to the environment as well, and
now checks that both terms and their respective environments are
pairwise physically equals.

Passing by, this commits also fix unrelated clippy warning, after the
udpate to clippy 1.73.

* Add regression test for #1700

* Implement env equality during typechecking

* Cosmetic renaming and slight rework of comments

* Fix contract test by deeply evaluating it

* Remove confusing comments
2023-10-29 12:21:14 +00:00
Yann Hamdaoui
2a727baaea
Get rid of most generated variables (#1679)
* add Closure node to AST

* Implement non-looping partial eq for Term

* Fix contracts app

* Use closure within records as well everywhere

* Fix double closurization

* Fix subst to update closurized attrs

* Fix type eq for closures

* More typecheck eq

* More work + formatting

* Get rid of share normal form + move Closurize to dedicated mod

* Accept new snapshots (error msg less noisy)

* Fix compilation warnings

* Fix various small TODOs left

* Cleaning comments and debug println

* Update documentation for new closurize approach

* Apply suggestions from code review

Co-authored-by: jneem <joeneeman@gmail.com>

* Update core/src/closurize.rs

Co-authored-by: jneem <joeneeman@gmail.com>

* Fix various code comments

* Post-rebase fixup

* Formatting + post-rebase fixup

* Restore array contract dedup fix messed up by rebases

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2023-10-16 11:57:30 +00:00
Yann Hamdaoui
3edcb52ebb
Get rid of shallow_repr and print full terms (#1676) 2023-10-12 16:58:23 +00:00
Viktor Kleen
19bed669f9
Track more metrics (#1635)
* Track thunk allocation

* Track `Program::new_from_files` as `Program::new`

* Track environment inserts and gets

* Implement tracking histograms

* Track environment layer size on `get`

* Track number of environment layers traversed on `get`

* Update core/src/environment.rs

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

* Formatting

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-09-28 16:31:16 +00:00
Viktor Kleen
98824c5480
Honor nostdlib in customize mode as well (#1634) 2023-09-27 14:27:43 +00:00
Viktor Kleen
c4b7e0dd5c
Implement a first solution for collecting metrics during a Nickel evaluation (#1633)
* Implement prototype metrics collection and reporting

* Add a few sample metrics

* Document some of the rationale

* Remove unused `metrics-utils`

* Don't enable metrics by default

* Report metrics to stderr
2023-09-27 10:55:03 +00:00
Viktor Kleen
0433886d11
Make eval an explicit subcommand and restructure the CLI somewhat (#1632)
* Make `eval` CLI explicit and remove `-f`

* Implement multiple file inputs as merging

* Use `add_string` instead of `add_term`

* `format` cannot create files anymore

* Update snapshot tests

* Separate customize mode from the `export` subcommand

* Decouple customize mode from export and make it available for every evaluation

* Disable an `unused_mut` warning

* Apply suggestions from code review

Co-authored-by: jneem <joeneeman@gmail.com>

* Add a short option for `export --format`

* Update cli/src/eval.rs

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

---------

Co-authored-by: jneem <joeneeman@gmail.com>
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-09-26 20:31:30 +00:00
gtsiam
365e14da36
Cleanup the code a bit (a lot) (#1595)
* Removed explicit state from Traverse trait

* Make clippy happy

* Consistent whitespace between documented items

I kept running into this while going through the codebase,
so I thought I'd fix it once and for all.

And no, I did not do this by hand. So I might have missed some cases.

* More formatting.

Mainly includes wrapping of comments to the 100 column mark,
as well as some more formatting on macros and strings.

* restore try_map_state in Traverse impl

* Removed IdentKind

It was technically only used in the PartialEq implmentation of Thunk.
Still, I don't think that had any effect.

* Fix doc comment

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>

---------

Co-authored-by: Taeer Bar-Yam <taeer.bar-yam@tweag.io>
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-09-18 11:38:33 +00:00
Yann Hamdaoui
fcde9ba0ad
[REVIEW & CI] 1.2.1 release (#1606)
* Tentative fix for 1.2.0 not installing

* Update to 1.2.1 (fix cargo install)

* Update Cargo.lock
2023-09-14 19:53:55 +00:00
Taeer Bar-Yam
f0bf0beba9
Cache more (#1580)
* cache most of the work even if rev changes

* longer string for more reliable search.

* more recognizable dummyRev

* nickel-lang-static needs env

* appease nixpkgs-fmt

* copy meta to new derivation

* add comment
2023-09-11 08:53:20 +00:00
Viktor Kleen
c557118f8a
Exit with nonzero exit code on failure (#1576)
We previously just reported the error and then pretended to exit
successfully. With this change the process returns `ExitCode::FAILURE`
whenever it needed to report an error, and `ExitCode::SUCCESS`
otherwise.

Fixes #1575
2023-09-05 15:09:24 +00:00
Yann Hamdaoui
80e9abe2a0
Handle override and help inputs in customize mode (#1563)
* customize mode conflicts: improve help messages

* Enablze overriding input fields with --override

* Fix unescaped [ in rustdoc
2023-09-04 15:10:23 +00:00
Yann Hamdaoui
b687ea3322
Get rid of uninformative generic notes (#1564)
Upon the failure of a higher-order contracts, we used to include quite
generic notes showing a plain illustration of the kind of higher-order
violation that happened. However, this text was totally generic (the
example didn't relate to the source code at all), quite verbose (around
4-5 lines of notes), and to be honest, not very helpful.

We now have good mechanisms to underline the right part of the function
contract that failed, together with customized label (e.g. "broken by the
caller"), which makes look like the original generic note aren't very
valuable.

This patch ditches those notes altogether.
2023-09-01 17:24:14 +00:00
Taeer Bar-Yam
b8e292d44b
set record arguments with -- (#1475)
* set arguments with --

Create term that merges command line arguments with program

* Move building the override term into `Program`
* instead of immediately evaluating argument values, use
`ImportResolver::add_string` to make them separate imports.
* Move CLI export into its own file
* Integrate record builder interface
* Make record field paths work correctly
* Evaluate annotations, too, for record normal form
* Make term interfaces a first class concept
* Stop printing terms on export

* Rename eval_for_doc to be less doc-specific

And expand the documentation at the same time.

* Augment FieldInterface with more data

Augment the field interface type - for freeform argument passing in the
CLI - with additional metadata, such as being optional or defined, taken
directly from the original field's metadata. Add a somehow heuristic
(but simple) `is_input` method, which decides if a field is an input and
should have a dedicated argument.

Minor reworking/renaming of other part of the CLI export code around
freeform arguments.

* Restore the path argument, add more documentation

* Use Field/FieldMetadata instead of custom types

In the CLI export function, instead of using a structure that mostly
mirror record fields, we directly use record fields to avoid code
duplication, although fields do carry a bit more information that what
we exactly need.

* Use query printer to render freeform args help

* Continue proper handling of overrides/inputs in CLI

* Fix eval_record_spine, add sources for CLI arguments

* Remove debug println, improve CLI freeform output

* Move around reporting code to error module

* Actually implement --override, add custom error messages

* Make overrides have a `force` priority

* Add some untested tests

* Small rewording of Ident documentation

* Post-rebase fixups + get rid of Merge trait

* Fix snapshot test runner for freeform args

* Fix CLI freeform snapshot tests

* Fix unused import warning

* Formatting

* Review pass, smallfixes and clippy fix

* Fix cargo doc warnings

* Fix 1.72 new clippy warnings

* Update snapshots after extra-args -> customize mode

* Move the Combine trait in its own mod

* Apply suggestions from code review

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>

* Update core/src/term/make/builder.rs

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>

* Remove questionable Option<> layer

* Update cli/src/export.rs

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>

* Update cli/src/export.rs

Co-authored-by: jneem <joeneeman@gmail.com>

* Apply suggestions from code review

Co-authored-by: jneem <joeneeman@gmail.com>

* Add warning about usage of Label::default

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
Co-authored-by: jneem <joeneeman@gmail.com>
2023-09-01 09:57:30 +00:00
Yann Hamdaoui
182568a8da
flake.lock: Update (#1545)
* flake.lock: Update

Flake lock file updates:

• Updated input 'crane':
    'github:ipetkov/crane/7809d369710abb17767b624f9e72b500373580bc' (2023-08-12)
  → 'github:ipetkov/crane/ef5d11e3c2e5b3924eb0309dba2e1fea2d9062ae' (2023-08-23)
• Updated input 'flake-utils':
    'github:numtide/flake-utils/919d646de7be200f3bf08cb76ae1f09402b6f9b4' (2023-07-11)
  → 'github:numtide/flake-utils/f9e7cf818399d17d347f847525c5a5a8032e4e44' (2023-08-23)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/d680ded26da5cf104dd2735a51e88d2d8f487b4d' (2023-08-19)
  → 'github:NixOS/nixpkgs/5690c4271f2998c304a45c91a0aeb8fb69feaea7' (2023-08-25)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/598b2f04ed252eb5808b108d7a10084c0c548753' (2023-08-19)
  → 'github:oxalica/rust-overlay/e90223633068a44f0fb62374e0fa360ccc987292' (2023-08-26)
• Updated input 'topiary':
    'github:tweag/topiary/e30432a29b6d3bb606cbb09b022a5ad0598810dc' (2023-07-31)
  → 'github:tweag/topiary/577fe940aa0b9dae478b463bddd1238e20f86e3a' (2023-08-24)

* Run `cargo fmt`

* Fix new clippy lints

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
2023-08-28 11:01:43 +00:00
Viktor Kleen
a153a9b618
Fix contract application order in let bindings and annotations (#1544)
* Fix contract application order in let bindings and annotations

In a let binding `let foo | A | B = ...` and in an infix contract
annotation `foo | A | B` the contracts `A` and `B` were actually being
applied in reverse order. That is, first `B`, then `A`. The contract
application order for record fields was still correct, however.

The root cause was the fact that there were two places with code that
merged separate annotations into a single annotation containing multiple
contracts. With this change, both spots call into the same code and I've
added regression tests to ensure the correct behaviour.

* `Annot` -> `Combine` in comments

* Add a snapshot test for let-binding contract order
2023-08-25 15:03:38 +00:00
Viktor Kleen
6b44916454
Overhaul and improve testing of the pretty printer (#1532)
* Move `Type` pretty printer test into `core/src/pretty.rs`

* Revamp pretty printer for `TypeF::Array`

* Start overhauling and testing the Type pretty printer

* Simplify pretty printer integration test

* Expand pretty printer integration tests to include stdlib

* continue overhauling the pretty printer

* Add tests for "let" pretty printing

* Ignore empty annotations in TypeAnnotation::attach_term

* Get almost all pretty printer tests to pass, missing `pass/strings/symbolic_strings.ncl`

* Use `Term::StrChunks` when desugaring symbolic strings

* Fix missing newlines in multiline strings

* Handle record patterns in let bindings

* `fun` pretty printing

* Update snapshot tests

* Fix pretty-printer dependent test cases

* Remove TODO comment

* Improve formatting for record fields with metadata

* Remove a redundant clone and some redundant calls to `pretty`

* Consistently use `%<stuff>` for internal values

* Address comments from code review

* Derive `Eq` for `OpPos`

* format other binary operators the same way as `&&` and `||`

* Add a comment about special unary operators

* Adjust grouping for field metadata annotations

* Simplify `Array` pretty printing code

* Document the lack of `indoc!` in `pretty_multiline_strings`
2023-08-25 08:50:32 +00:00
Viktor Kleen
db12730802
Refactor destructuring bindings (#1537)
* Simplify parsing of record destructuring

* Capture pattern destructuring errors as snapshot tests

* Record the destructuring contract in a label

This makes error reporting point at the destructuring instead of at a
fictitious `Dyn`.
2023-08-21 08:46:02 +00:00
Viktor Kleen
3df013169b
Use the original unevaluated type and contract annotation in nickel doc (#1529)
* Use the original unevaluated type and contract annotation in `nickel doc`

With this change we no longer print evaluated types or contracts in
field annotations for `nickel doc`. Ever since `nickel doc` started
evaluating terms to address #1462 contract and type annotations would be
evaluated before reaching the documentation extraction stage. This means
they would be affected by program transformations and the result would
most likely be meaningless to the user.

Incidentally, `nickel query` already correctly used the original
unevaluated type for contract annotations but not for type annotations.
If a type annotation contains a `Term` as a `TypeF::Flat` variant, it
was possible to trigger the same undesirable behaviour:

```
❯ cargo run --bin nickel -- query foo <<<'{ foo : { x | Dyn, y } = {x = 1, y = 2} | { x | Dyn, y } }'
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/nickel query foo`
• type: let %182 = $dyn in { x | Dyn, y, }

Available fields
• x
• y
```

Fixes #1519

* Add a snapshot test against regressions
2023-08-14 13:34:14 +00:00
Viktor Kleen
bb410b8aa3
LSP formatting without calling the topiary binary (#1526)
* Introduce nickel_lang_core::format and use it in the CLI

* Use nickel_lang_core::format for formatting in the LSP

* Update lsp/nls/README.md

* Update lsp/nls/README.md

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

* Remove an unused import

* Remove the format feature flag for NLS

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-08-11 18:02:21 +00:00
Viktor Kleen
07be729e76
Use the pretty printer in the Display implementation for Type (#1518)
* Use the pretty printer in the  `Display` implementation for `Type`

We previously used a bespoke formatting algorithm for `Type`. I replaced
the analogous code for `Term`s by the pretty printer in #1262 but we
were worried about some questionable code for contract error reporting
before doing the same for types. Namely, at some point it relied on hard
coded string offsets for pointing at parts of types that were inferred
by Nickel and consequently had no `TermPos`. In #1229 we ripped out
that code and replaced it by reparsing the pretty printer output when
necessary.

Incidentally, this change also fixes some terms being truncated when
formatted. For example, previously

```
SomeUserDefinedContract "that" "takes" "many" "arguments"
```

would be printed as `SomeUserDefinedContract "that" …`. This is somewhat
useful to prevent huge screenfuls of error messages sometimes, but it
makes the `Display` implementation useless for other natural purposes.

* Revert a useless change to snapshot test inputs

* Factor out calling the pretty printer for `Display`
2023-08-10 12:56:40 +00:00
Yann Hamdaoui
98e84fc977
Add warning for empty query path on the CLI (#1517)
* Add warning for empty query path on the CLI

* Update cli/src/error.rs

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>

* Fix formatting after committing reviewer's suggestion

---------

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
2023-08-09 17:00:12 +00:00
Théophane Hufschmitt
56c66c6291
Add a linebreak between contract and the documentation in the doc output (#1520)
* Add a linebreak between contract and the documentation in the doc output

The markdown output of `nickel doc` for record fields with both a
contract and a documentation currently looks like

```markdown
- `foo | Dyn`
documentation
```

which in strict markdown is equivalent to

```markdown
- `foo | Dyn` documentation
```

and isn't really nice once converted to Html.

Change that to

```markdown
- `foo | Dyn`
\
documentation
```

which renders `documentation` on a newline (still whithin the same
bullet point though)

* Accept new snapshots

---------

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
2023-08-09 15:24:15 +00:00
Viktor Kleen
84da9e78af
Refactor the Nickel CLI (#1502)
* Refactor the Nickel CLI structure

* Add an `Error` enum for the CLI

* Restore the previous user-facing interface

* Make clippy happy

* Restore `nickel format` CLI behaviour

* Change command options naming

* Properly respect feature flags

* WithProgram -> ReportWithProgram

* Remove the unecessary `Files` struct for now

* ReportWithProgram -> ResultErrorExt

* Suggestions from code review
2023-08-08 11:55:03 +00:00
Théophane Hufschmitt
5572b444b0
Disable the colors when stdout isn't a tty (#1508)
Fix https://github.com/tweag/nickel/issues/1500
2023-08-08 08:55:46 +00:00
Yann Hamdaoui
e934796dc6
Restore --version for CLI, include git revision (#1486)
* Restore --version for CLI, include git revision

* Use git revision from nix during the build

* Update flake.nix

---------

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
2023-08-07 11:55:13 +00:00
jneem
39caa5dc23
Cleanup: use normalize_path instead of canonicalize (#1496) 2023-08-03 19:12:38 +00:00
Viktor Kleen
edc7394f0b
Actually persist output files for formatting (#1483)
* Actually persist output files for formatting

All the code for properly formatting files in-place was there, but
in the original PR I forgot to persist the output file. As a result,
formatting works for as a pipeline from stdin to stdout but when
an output file is specified, the formatted Nickel code is silently
discarded.

With this change we actually persist the formatted result.

* Add a rudimentary CLI integration test to make sure output files are created
2023-07-28 10:47:13 +00:00
Yann Hamdaoui
498e91d06b
[Refactor] Types -> Type, types -> typ (#1472)
* Types -> Type, types -> typ

`type` is a reserved keyword in Rust, which is why we've been adding an
`s` to uppercase `Type` and lowercase as in `crate::types::Types`.
However:
1. uppercase `Type` is actually valid, only lowercase `type` clashes
   with the Rust keyword.
2. Adding an `s` has caused confusion, because there's no easy way to
   tell if a struct field `types` means there are several types, or if
   it's just a work-around to avoid the keyword.

In consequence, this commits rename lowercase `types` to `typ` (and in
particular the module `types` is now `typ`), and the uppercase `Types`
to `Type` (so, previously `types::Types` is now `type::Type`).

* Formatting
2023-07-25 12:47:28 +00:00
Viktor Kleen
835f15cbfb
Evaluate terms before extracting documentation (#1463)
* Extract documentation before touching the filesystem

* Draft evaluation mechanism for documentation extraction

* Properly collect evaluation errors

* eval_for_docs -> eval_for_doc

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-07-25 11:43:02 +00:00
Viktor Kleen
aff367df7e
Error on serializing very large numbers (#1470)
* Error on serializing very large numbers

Instead of blindly using the nearest `f64` for all Nickel `Number`s when
serializing, with this change we only use nearest rounding when a number
is in the range `[f64::MIN, f64::MAX]`. Otherwise we trigger a newly
introduced serialization error.

This stops the previous, arguably surprising, result that for example
`e400` gets serialized as `1.7976931348623157e308`. While techincally
this is the nearest `f64` to `1e400`, one wouldn't expect serialization
to incur an absolute error of about `1e92`.

Fixes #1457

* Add tests
2023-07-21 12:36:11 +00:00
Viktor Kleen
3d47bac01e
Static linking with nickel format (#1455)
* Enable `format` feature in the nix build and fix static linking

* Document static building

* Update flake.nix

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

* Enable `format` by default

* Remove `nickel-static` output on darwin

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-07-17 14:06:29 +00:00
Viktor Kleen
997e344f4f
Topiary integration as nickel format (#1371)
* Implement `nickel format` PoC as a topiary wrapper

Improve error reporting for `nickel format`

nix build with topiary

Use upstream topiary query export

* Pin wasm-bindgen version

* Disable `format` feature in nickelStatic for now

* Remove thiserror dependency and make tempfile optional

* Update Cargo.lock

* Disable `nickel format` by default
2023-07-13 10:43:51 +00:00
Yann Hamdaoui
7a01d60270
Backport 1.1.1 (#1439)
* Version bump: 1.0.0 -> 1.1.0

* Add release notes for 1.1

* Bump version - part 2, reset to 0.1 for new crates

* Add missing README to nickel-lang-cli

* Update Cargo.lock, make nickel-wasm-repl's version consistent

* Update releasing instructions for new crate layout

* Fix typo in RELEASES.md

* Update Cargo.lock
2023-07-10 15:31:28 +00:00
Yann Hamdaoui
664c397aad
[Fix] Fix bad lexing of mutline string closing delimiter (#1435)
* StringEndMismatch -> StringDelimiterMismatch

* Remove unneeded lexer hack

We introduced a hack in the lexer because of some Logo's issue about
backtracking. Pre 1.0, the problem was related to sequences like:

```nickel
let x = "string" in m%%"some "%%{x}"%%m
```

Here, `"%%{x}` had to be interpreted as a double quote `"` followed by
an interpolation sequence `%%{`. The problem has been that backtracking
is required, because up to `{`, we don't know yet if we are lexing an
end delimiter `"%%m` or `"` followed by interpolation sequence. So we
added another token for this "ambiguous" (not literally) sequence, the
`CandidateQuoteInterpolation`. However, now that that the final `m` is
not required, a sequence of the form `"%%{` is either an end delimiter
followed by `{` (if there's as many `%` as in the opening delimiter), or
otherwise a verbatim `"%%{` (if there's less `%` than in the opening
delimiter). This can never be a double quote followed by an interpolated
sequence.

Thus, we can get rid of the ad-hoc `CandidateQuoteInterpolation` and
related special treatments, which makes the lexer simpler. This also get
rid of regression tests, because this subtelty had caused several issues
up to know, but they're now moot since the 1.0 syntax.

* Fix dangling reference in documentation
2023-07-07 15:38:56 +00:00
Viktor Kleen
5a1d17644d
Merge RecordOperand into Atom in the grammar (#1418)
Having separate `RecordOperand` and `Atom` productions turns out to be
unnecessary. As a positive side effect, this change fixes a parse error
discovered by @yannham:

```nickel
let foo = {bar = fun x => x} in %assume% foo.bar foo.bar
```

This error stemmed from an oversight in parsing prefix primops
where the second argument was required to be an `Atom` instead of
a `RecordOperand`.

It also improves the pretty printing of record access by reducing
unnecessary parentheses. For example, `std.string.length` was previously
printed as `(std.string).length`.
2023-06-29 15:10:37 +00:00
Viktor Kleen
44f5eb610e
Make the pretty printer correctly escape field names (#1410)
* Make the pretty printer correctly escape field names

Previously, the pretty printer relied on `Ident::label_quoted` for
printing record field names. This function blindly placed an identifier
between quotes if it was deemed necessary. This produces incorrect
results if the identifier label itself contains quotes, for example.

* Move `Ident::label_quoted` into `pretty` as a freestanding function
2023-06-29 08:36:53 +00:00
Viktor Kleen
ccf88b4099
Make the pretty printer understand let rec (#1411)
Fixes #1409
2023-06-28 14:30:10 +00:00
Viktor Kleen
78e7a8814b
Rename and move workspace crates (#1399)
* Rename and move workspace crates

nickel-lang -> nickel-lang-cli in cli/
nickel-lang-lib -> nickel-lang-core in core/
nickel-lang-utilities -> nickel-lang-utils in utils/
nickel-repl -> nickel-repl in wasm-repl/

* Finish renaming in rust sources

* Update RELEASING.md

* Move to workspace dependencies

* Rename nickel-repl -> nickel-wasm-repl

* Update RELEASING.md

Co-authored-by: Taeer Bar-Yam <Radvendii@users.noreply.github.com>

* Address suggestions from code review

* Update HACKING.md

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

* Elaborate on the versioning scheme in RELEASING.md

---------

Co-authored-by: Taeer Bar-Yam <Radvendii@users.noreply.github.com>
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-06-26 16:58:40 +00:00