Commit graph

31 commits

Author SHA1 Message Date
John Wiegley 3a29249e43 Normalize import statements, add option parsing 2018-03-27 21:59:27 -07: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
Joe Hermaszewski 295e26b208 Export Delta 2016-06-25 21:56:41 +01:00
Joe Hermaszewski c11aad7253 Implement Annotation support functions 2016-06-25 11:17:18 +01:00
Allen Nelson d3a1e7207f split into more modules, rename some things, add docs 2016-01-23 15:23:18 -06:00
Allen Nelson 892cad2b36 Correctly escape double quotes. Update nix files. Use quotes with reserved variable bindings 2015-10-15 18:38:06 -05:00
Allen Nelson 1448d3400a adding OverloadedStrings extension, hiding conflicting <$> operator 2015-06-23 11:22:51 -05: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
Benno Fünfstück c7a371d902 Use CommentStyle for comment parsing 2014-08-20 18:45:01 +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 ec5742a1a8 fix error parsing // (opLetter characters) 2014-08-16 00:35:36 +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 4f6402a840 tests and fixes for identifier name parsing 2014-08-05 16:52:28 +02: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 3922112bab add a few hunit tests for parser 2014-08-03 15:56:01 +02: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 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 03d8ccc5bb Add operator reserved names for the lexer 2014-07-04 02:06:43 -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 8158557bb9 Factor out the abstract of which parsing library to use 2014-06-30 23:29:06 -05:00