Commit graph

126 commits

Author SHA1 Message Date
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
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
Benno Fünfstück cb00c57306 Add assert and with to parser 2014-08-16 01:35:40 +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
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
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 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 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
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
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
Daniel Bergey 8111b111cd accept false in nixBool 2014-07-19 22:49:28 +00: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
Luca Bruno 5ecd9e1a1a Evaluate assert 2014-07-08 14:34:56 +02:00
Luca Bruno b254b0347c Evaluate with expression 2014-07-08 13:47:31 +02:00
Luca Bruno cf34b6edee Evaluate if condition 2014-07-08 13:38:48 +02:00
Luca Bruno 2e8e2be67a Evaluate NArgSet to NVArgSet 2014-07-08 11:27:31 +02:00
Luca Bruno ea6cdf330d pretty: wrap app argument around parens 2014-07-07 18:23:16 +02:00
Luca Bruno 5849e17529 pretty: Fix displaying double quotes for strings 2014-07-07 17:39:49 +02:00
Luca Bruno 610fc3c780 Use pretty util functions for filling paragraphs 2014-07-07 17:29:55 +02:00
Luca Bruno a12c576bcc Pretty print operators 2014-07-07 17:25:28 +02:00
Luca Bruno 8103ed8cc8 Fix compilation. Better indentation for the pretty printer 2014-07-07 16:55:03 +02:00
John Wiegley be5c81d190 Merge pull request #5 from lethalman/pretty
Pretty print nix expressions
2014-07-07 09:31:28 -05:00
John Wiegley 806e497ce8 Merge pull request #4 from lethalman/fixdot
Fix dot operator associativity. a.b.c would not be parsed otherwise
2014-07-07 09:31:20 -05:00
Luca Bruno b12dc4f187 Pretty print nix expressions 2014-07-07 16:26:14 +02:00
Luca Bruno 1e8ee3af67 Fix dot operator associativity. a.b.c would not be parsed otherwise 2014-07-07 15:01:03 +02:00
Luca Bruno 8ea220ea4f Use a type to express rec sets instead of a bool 2014-07-07 11:29:25 +02:00
John Wiegley bad6a0a6d5 Add the NInherit type 2014-07-04 16:26:13 -05:00
John Wiegley 5b8ef9997d if/then/else is working, next to do is "inherit" 2014-07-04 16:24:47 -05:00
John Wiegley bb378af269 Several more minor fixes 2014-07-04 16:23:21 -05:00
John Wiegley 0f0f865e4f Add a reserved words as "stop words" for nixApp 2014-07-04 16:15:58 -05:00
John Wiegley 072b2e8d51 Add support for more operators 2014-07-04 16:07:32 -05:00
John Wiegley 2468bf6826 Normalize recent changes to fit the overall design 2014-07-04 15:56:53 -05:00
John Wiegley 74e1812f74 Merge pull request #1 from lethalman/master
Fix parsing of rec sets with reserved keyword
2014-07-04 15:43:30 -05:00
Luca Bruno 051e8fffc2 Parse if then else 2014-07-04 14:39:41 +02:00
Luca Bruno f8d0496bba Fix parsing of rec sets with reserved keyword 2014-07-04 13:43:22 +02:00
John Wiegley f5ab0e5be4 Building with Trifecta works again, but there are issues 2014-07-04 04:08:38 -05:00
John Wiegley bb3648cf73 Let is working, next is "if" syntax 2014-07-04 02:15:20 -05:00
John Wiegley 3c7025f9f3 Preliminary support for "let" syntax 2014-07-04 02:06:56 -05:00
John Wiegley 03d8ccc5bb Add operator reserved names for the lexer 2014-07-04 02:06:43 -05:00
John Wiegley 2a931e52e1 Add a stub in the evaluator for operators 2014-07-04 02:06:27 -05:00
John Wiegley b01890048c Remove a comment which is already out of date 2014-07-04 01:55:04 -05:00
John Wiegley 710b421b46 Remove some dead code in Types.hs 2014-07-04 01:54:44 -05:00
John Wiegley 569ebf3f9a Clean up parser, implement operators
We now parse down to line 45 in all-packages.nix: let.
2014-07-04 01:52:50 -05:00
John Wiegley d2df092907 Simple code refactoring 2014-07-03 17:16:25 -05:00
John Wiegley 831e96fc85 Simplify includes in Eval.hs 2014-07-03 17:09:17 -05:00
John Wiegley d62b7747b2 default.nix is parsing again, but not all-packages.nix 2014-07-01 03:27:13 -05:00
John Wiegley 682f039023 Switch to a Parsec expression table 2014-07-01 03:11:26 -05:00
John Wiegley be1434726a Add initial support for parsing operators 2014-07-01 01:12:28 -05:00
John Wiegley 52bfdd126b Cleaned up the parsing code 2014-07-01 00:15:49 -05:00
John Wiegley 8158557bb9 Factor out the abstract of which parsing library to use 2014-06-30 23:29:06 -05:00
John Wiegley 9b12ebf081 Break up Parser.hs, make use of Parsec optional 2014-06-30 23:12:18 -05:00
John Wiegley 29909a2598 Setup cabal file, fix all warnings
The next step is splitting up and prettifying Parser.hs
2014-06-30 22:37:20 -05:00