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.
* 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
* 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>
* 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
* 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
* 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>
* 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
* 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>
* 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>
* 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
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
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.
* 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>
* 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
* 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`
* 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`.
* 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
* 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>
* 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`
* 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>
* 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>
* 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>
* 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
* 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
* 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
* 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
* 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
* 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
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`.
* 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