Commit graph

218 commits

Author SHA1 Message Date
Allen Nelson 4b514c0d1e added a bunch of wrapper functions, simpler representation of empty lists and sets 2015-06-23 13:32:14 -05:00
John Wiegley 8aab289653 Merge pull request #19 from adnelson/feature/overloaded_strings
adding OverloadedStrings extension, hiding conflicting <$> operator
2015-06-23 12:48:38 -05:00
Allen Nelson 1448d3400a adding OverloadedStrings extension, hiding conflicting <$> operator 2015-06-23 11:22:51 -05:00
John Wiegley d68ba45367 Update default.nix 2015-06-22 20:47:07 -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
John Wiegley 7e9b2e534f Merge pull request #17 from shlevy/null-not-reserved
null is a constant added to the base environment, not a reserved word
2014-09-12 01:56:25 +01:00
Shea Levy 547c76a288 null is a constant added to the base environment, not a reserved word 2014-09-11 15:07:04 -04:00
Shea Levy 9eada9e32d Add shell.nix for easy local development 2014-09-11 14:39:14 -04:00
Benno Fünfstück c89db27dd9 Add some more tests for edge cases 2014-08-31 18:06:55 +02:00
John Wiegley 108800bb76 Update default.nix file 2014-08-28 14:46:21 -05:00
Benno Fünfstück 323f51f97b Rename benchmarks to hnix-benchmarks, like tests 2014-08-28 00:02:56 +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 c7a371d902 Use CommentStyle for comment parsing 2014-08-20 18:45:01 +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 82c19b650c Add Pretty to cabal file and remove Internal 2014-08-19 18:51:13 +02:00
Benno Fünfstück 3413a817e6 subdirectory for main to avoid redundant compile
Cabal builds the library files twice if the main executable and the
library share the same hs-source-dirs. Moving the main executable source
code to a subdirectory avoids this issue.
2014-08-19 18:48:55 +02:00
Benno Fünfstück 2c7a43c929 PrettyPrinter: support let and 2 small fixes 2014-08-18 23:38:38 +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 76efcb6c7d Fix pretty printing precedence of special operator 2014-08-18 22:13:40 +02:00
Benno Fünfstück c67dcf7c67 Move NSym out of NAtom
An NSym doesn't evaluate to itself and never appears in an NValue, so it
should not be an atom.
2014-08-18 19:08:49 +02:00
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