Commit graph

148 commits

Author SHA1 Message Date
John Wiegley 3a29249e43 Normalize import statements, add option parsing 2018-03-27 21:59:27 -07:00
John Wiegley 1e0e47d064 Remove monadic context from evalExpr: we weren't using it! 2018-03-27 19:07:08 -07:00
John Wiegley 278916a9ab Further work on argument evaluation 2018-03-27 18:42:31 -07:00
John Wiegley ecd18e3da3 Merge branch 'master' into fix-recursive-argument-set 2018-03-27 14:34:28 -07:00
Georges Dubus 2e26bd75a5 Fix a bug where defaultargs are absent from the atpattern argument 2018-03-11 12:15:33 +01:00
Georges Dubus 0f7332636e Add support for variadic parameters
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.
2018-03-09 14:09:43 +01:00
Kosyrev Serge 0693768550
Fix #93: true/false being mis-parsed when part of an attribute name. 2018-03-06 04:14:16 +03:00
Georges Dubus 6a8ae208b4 Use environment in evaluation of function definitions 2018-03-01 20:04:54 +01:00
Allen Nelson 46bb504ccc whack that mole 2018-02-28 11:45:34 -06:00
Allen Nelson cbee241685 remove mkDots test, no longer necessary 2018-02-28 10:59:53 -06:00
John Wiegley f2ceb7513d
Merge pull request #82 from layus/nix-test
Run nix language tests from upstream
2018-02-20 16:07:41 -08:00
Guillaume Maudoux 25f1da3408 Run lang tests from upstream 2018-02-15 12:06:09 +01:00
Georges Dubus e73fc5d196 More WIP 2018-02-13 15:49:46 +01:00
Guillaume Maudoux 0914047115 Handle let { body = ... } expressions 2018-02-10 13:30:33 +01:00
Georges Dubus 7b651303e2 WIP fix recursive default args 2018-01-29 19:56:58 +01:00
Georges Dubus b61b5791bb Change the environment in evaluation to be a Map Text (NValue m)
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.
2018-01-28 23:27:33 +01:00
Rhys 0d456691b5 Escape ${ but not plain $ in indented strings
Includes some very basic regression tests, but no change for
non-indented strings.
2017-05-31 21:24:43 +10:00
Profpatsch 8b4c137a3b Shorthands.hs, mkDot/mkDots: automatically quote non-symbols
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.
2017-04-21 03:54:06 +02:00
Rhys c15de4532a Correctly parse identifiers with reserved word prefixes 2017-04-17 19:33:57 +10:00
Allen Nelson 99b52fe48e separate expr into types and shorthands 2016-01-25 01:00:27 -06:00
Allen Nelson f04ccf9476 use KeyName list instead of AttrPath list 2016-01-24 18:01:45 -06:00
Allen Nelson 80a7dcb684 bump version, separate back out different kinds of params 2016-01-23 18:11:26 -06:00
Allen Nelson 29acdfe988 remove types for rec/nonrec, make unit tests pass 2016-01-23 17:32:45 -06:00
Allen Nelson 50a3d0d0db make tests pass 2016-01-23 15:51:34 -06:00
Allen Nelson d3a1e7207f split into more modules, rename some things, add docs 2016-01-23 15:23:18 -06:00
Anders Papitto 00d7f06dd0 add some evaluation tests and fix bug 2015-12-20 22:17:34 -08:00
Allen Nelson 9765256ab4 parsing variadic functions, avoiding empty list error 2015-06-23 19:19:46 -05:00
Benno Fünfstück 1b82727a17 Use data-fix for Fix and fix path parsing bug 2014-09-27 20:12:30 +02:00
Benno Fünfstück c89db27dd9 Add some more tests for edge cases 2014-08-31 18:06:55 +02:00
Benno Fünfstück 94b7e4b1d7 tests for comment parsing and parser benchmarks 2014-08-27 23:54:31 +02:00
Benno Fünfstück 3a08227c0c Parse double unary - correctly and improve perf
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.
2014-08-27 22:12:12 +02:00
Benno Fünfstück f3ec70192c parse // in paths correctly as update operator 2014-08-20 15:47:41 +02:00
Benno Fünfstück fe596a3e3a 1 + if true then 1 else 1 should also not parse
Operators are also not allowed to have an `if`, `let`, `with` or `assert`
expression as their argument (just like functions).
2014-08-19 19:20:17 +02:00
Benno Fünfstück 303fb9a3d7 Fix function application vs operator precedence
We now parse all of all-packages.nix! There are probably still
some parse bugs to catch, though.
2014-08-18 23:06:57 +02:00
Benno Fünfstück 8f0648f5bb Implement indented strings + uri + SPATH
We now parse till line 10005 of all-packages.nix
2014-08-18 22:54:20 +02:00
Benno Fünfstück bf77dde7fc f if true then null else null should not parse 2014-08-16 23:16:04 +02:00
Benno Fünfstück 87a83407a2 More tests for select expressions 2014-08-16 01:31:41 +02:00
Benno Fünfstück 24a4ffdce4 now really fix parsing paths 2014-08-16 01:17:01 +02:00
Benno Fünfstück 4a271d0103 fix error parsing paths 2014-08-16 00:18:16 +02:00
Benno Fünfstück bce48c438c parser: add tests and fix bugs 2014-08-15 23:30:24 +02:00
Benno Fünfstück a6bacc3150 antiquotes + improve pretty printer + restructure
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.
2014-08-15 22:11:54 +02:00
Benno Fünfstück e81145094d tests for parsing of lambda args (patterns, ...) 2014-08-13 23:30:24 +02:00
Benno Fünfstück a620e4c387 Extend tests for set / let (inherit, rec, ...) 2014-08-13 22:40:35 +02:00
Benno Fünfstück 5d6de23d8c tests: use new lambda arg AST representation 2014-08-13 19:48:38 +02:00
Benno Fünfstück a0e5650f42 fix compile errors 2014-08-13 19:33:19 +02:00
Benno Fünfstück ac9675baae More tests (one currently failing) and fixes 2014-08-05 21:23:28 +02:00
Benno Fünfstück 4f6402a840 tests and fixes for identifier name parsing 2014-08-05 16:52:28 +02:00
Benno Fünfstück 3922112bab add a few hunit tests for parser 2014-08-03 15:56:01 +02:00