Commit graph

19 commits

Author SHA1 Message Date
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