Commit Graph

2145 Commits

Author SHA1 Message Date
Benno Fünfstück 52a97733d2 Fix pretty printing of escape codes in strings
A line break in a string should not be outputed as a literal linebreak,
but instead must be outputed as an escape code.
2014-08-17 00:02:59 +02:00
Benno Fünfstück ba744bf166 Remove unnecessary whiteSpace & more error info 2014-08-16 23:16:04 +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
John Wiegley 147624425d Merge pull request #14 from bennofs/assert-and-with
Add assert and with to parser
2014-08-16 12:18:31 -05:00
John Wiegley 732171c22c Merge pull request #15 from bennofs/lambda-less-try
Limit scope of 'try' for lambda
2014-08-16 12:17:57 -05:00
Benno Fünfstück ba83f13342 Limit scope of 'try' for lambda
This improves error messages, because we don't backtrack anymore after
we succeeded parsing a lambda arglist.
2014-08-16 10:28:22 +02:00
John Wiegley 77f8d98713 Merge pull request #13 from bennofs/restructure
antiquotes + improve pretty printer + restructure
2014-08-15 23:39:37 -05:00
Benno Fünfstück cb00c57306 Add assert and with to parser 2014-08-16 01:35:40 +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 ec5742a1a8 fix error parsing `//` (opLetter characters) 2014-08-16 00:35:36 +02:00
Benno Fünfstück 4a271d0103 fix error parsing paths 2014-08-16 00:18:16 +02:00
Benno Fünfstück 568c153c77 fix pretty printing of argument sets 2014-08-16 00:17:54 +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
John Wiegley e85c166608 Merge pull request #12 from bennofs/parsec-parsers
parsec: Also use parsers (like trifecta)
2014-08-15 12:36:45 -05:00
Benno Fünfstück 4550c1a05a trifecta: reserved(Op) shouldn't return a value
this fixes another difference between the trifecta / parsec interface.
2014-08-15 16:15:11 +02:00
Benno Fünfstück 4657427357 true/false are not reserved words
if you don't believe me, try this in nix-repl:

`let false = true; in false`
2014-08-15 16:13:08 +02:00
Benno Fünfstück 1b85b76a4e parsec: Also use parsers (like trifecta)
This saves a lot of duplication and also makes it easier
to keep the parsec and trifecta versions of the parser in sync.
2014-08-15 16:11:05 +02:00
John Wiegley 018ad98827 Merge pull request #11 from bennofs/tests-and-fixes
Tests and fixes for the parser
2014-08-14 03:59:38 -05: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 457d55e81a fix / simplify parsing of lambda arguments
lambda arguments can be parsed without using try at all:

First, we decide if we have a set or an identifier. If we have a set,
there are two cases:

  * the lambda argument is a plain set (not followed by an `@` character)
  * or the set is optionally followed by `@<identifier>`, in which
    case the argument is a <right at> pattern.

If we got an identifier, we can do a similar thing, there are also two
cases:

  * plain identifier: not followed by `@`.
  * the idenfitifier is followed by `@<set>`. In this case, the argument
    is a <left at> pattern.

Avoiding excess use of try should improve performance and lead to better
error messages.
2014-08-13 23:25:30 +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 e8e129a759 factor out "inherit" keyword in binding parser
When parsing '{ inherit a; }' without this fix, the `scopedInherit`
parser would be tried first. Because this parser already consumes the
`inherit` keyword, it won't backtrack anymore and the non-scoped
`inherit` parser will never be tried, so we get a parse failure which is
of course not correct.

The solution is to first parse `inherit` (in both cases) and then decide
whether it is a scoped import or not by looking for a following '('.
2014-08-13 22:35:51 +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 0f29cd6951 fix parsing of "$cdef" on parsec
'string' doesn't imply 'try' on parsec (on trifecta, 'string' does use 'try')
2014-08-13 19:47:50 +02:00
Benno Fünfstück a0e5650f42 fix compile errors 2014-08-13 19:33:19 +02:00
Benno Fünfstück 0aa8fc2602 Merge branch 'master' into tests-and-fixes 2014-08-13 19:23:11 +02:00
Benno Fünfstück ac9675baae More tests (one currently failing) and fixes 2014-08-05 21:23:28 +02:00
John Wiegley a3f1a41ef8 Merge pull request #10 from jwiegley/formals
Formal parameters
2014-08-05 13:15:02 -04:00
Benno Fünfstück 4f6402a840 tests and fixes for identifier name parsing 2014-08-05 16:52:28 +02:00
Daniel Bergey 9f07afd101 Handle full formal parameters syntax 2014-08-03 16:01:09 +00:00
Benno Fünfstück e5a0f645d2 trifecta: allow _ at identifier start 2014-08-03 16:20:09 +02:00
Benno Fünfstück 19c77ae2d1 trifecta: don't allow reserved in identifier
trifecta should not parse reserved words as identifiers. Before
this commit, `in` would parse as an identifier name and thus
`let a = b; in c` fails to parse.
2014-08-03 16:16:52 +02:00
Benno Fünfstück 2b186aed67 Remove unused symbol parser
'symbol' had a different type for parsec/trifecta and
wasn't used anywhere.
2014-08-03 16:16:04 +02:00
Benno Fünfstück bc71229ab0 parser nixList: consume whitespace between items 2014-08-03 15:57:16 +02:00
Benno Fünfstück 3922112bab add a few hunit tests for parser 2014-08-03 15:56:01 +02:00
Daniel Bergey 4242b91e8a add some language pragmas 2014-08-02 22:28:15 +00:00
Daniel Bergey 71a0876120 simplify set and lambda parsing
use try and parser failure
2014-08-02 22:28:14 +00:00
Daniel Bergey 149ae51d60 make function application left-associative 2014-08-02 18:36:26 +00:00
Daniel Bergey 05596093c4 Add semicolons to inherit pretty-printer 2014-08-02 16:00:41 +00:00
John Wiegley 748bebf965 Improvements to default.nix file 2014-08-02 11:08:46 -04:00
John Wiegley 5cd581ce0d Merge pull request #9 from jwiegley/inherit
implement inherit in name bindings
2014-08-02 10:57:58 -04:00
Daniel Bergey 8e795d2f4e implement inherit in name bindings
Two points which are not clear from the manual, where this patch follows
the grammar.y bison implementation:
- The presence of parens in the first argument distinguishes the scoped
inherit
- inherit has the same syntax in sets as in let
2014-07-22 03:14:26 +00:00
John Wiegley 755f39d3c6 Merge pull request #8 from bergey/bool
accept false in nixBool
2014-07-20 02:13:51 -05:00
Daniel Bergey 8111b111cd accept false in nixBool 2014-07-19 22:49:28 +00:00
John Wiegley a2a9dc32bf Merge pull request #6 from bergey/attr-list
Accept NAttr attribute paths in lists
2014-07-19 15:43:49 -05:00
Daniel Bergey 7b9ad451f8 Accept NAttr attribute paths in lists
This is a common pattern, e.g., maintainers or fonts.fonts
2014-07-19 16:49:38 +00:00
John Wiegley 92cf6eecf9 Switch from pretty to ansi-wl-pprint 2014-07-18 04:42:06 -05:00
Luca Bruno 74e85e44f8 Evaluate non-recursive let expression 2014-07-08 14:46:56 +02:00