Everything was already in place, but not used for variadic parameters.
On the other hand fixed parameters sets are currently bugged, as they don't
reject extra arguments (they act like variadic parameters set). This commit adds
a TODO mentionning that.
Currently, the environment is passed as a `NValue m`, but is assumed to be
a set every single time it is used. This commit changes it `Map Text (NValue
m)`. Since this is used a lot, it defines a new type alias:
```
type ValueSet m = Map.Map Text (NValue m)
```
This has multiples benefits:
- Simplify some code by removing all the checks that the env is indeed a set
- Simplify the usage of the module by making clear that we need a set as the
environment. (I especially like this, since it took me a while to figure out
what that argument was supposed to be the first time).
- Make it simple to inject functions in the environment (for example to have
builtins) since now the function definition doesn't need to unwrap the set.
Nix can accept (nearly?) arbitrary values as attributes, if they are quoted in
strings. So generating “dots” should always result in valid nix attributes.
This uses the same regex as the nix lexer (as of 1.11).
Also add a few tests whether it correctly generates symbol/non-symbol
attributes.
We now don't use `buildExpressionParser` from parsers because it cannot
deal with double unary `-`, as in `--a`. Because nix doesn't have
operators which have the same precendence but different associativities,
we can greatly simplify the operator parser. This also has the effect of
improving performance and the error messages a bit.
This commit improves the pretty printing and adds support for
antiquotes. It also fixes an issue with the parser that caused `[if true
then false else true]` to parse successfully, even though that is not a
valid nix expression.
The pretty printer now produces a lot more readable output and also
supports operator precedences.
The changes to the AST are:
* strings are no longer atomic, because they may contain other
expressions in the form of antiquotes. For strings, the new type
NString is introduced and the constructor NStr is added to NExprF
* the unused NVar constructor of NExprF is removed
* operators are now represented uniformly so that the pretty printer
can lookup information about operators (in particular, associativity
and precedence)
* the NArgs constructor is removed. The first argument of the NAbs
constructor now directly represents the lambda arguments.
* the select and the hasattr operator are moved into NExpr because
they are special (they only accept a selector as second argument, and
select also supports 'or')
The list of operators is now in Types.hs and Parser.hs re-uses that list
to build the parser. This is required because the pretty printer and
parser both need access to operator precedences.
Parser and evaluator also support dynamic attributes and attributes with
dots now. As an example, `let b.a = 3; b.c = { e = {}; }; b.c.e.${"f"} =
4; in b` is parsed and evaluated correctly. As a side effect, NSym
values now don't evaluate to themselves anymore, but instead to the
value retrieved by looking up the variable in the current environment.
Support for evaluating `inherit` bindings was removed because it was
broken before (`{ inherit a; }` would evaluate to a set where the
attribute `a` had the value `NSym a`, not the value of `a`).
The manual Show instances for the AST were replaced by derived
ones, because the manual instances often resulted in output were it was
difficult to determine the missing parentheses.