about summary refs log tree commit diff
path: root/src/libexpr/parser.y (follow)
AgeCommit message (Collapse)AuthorFilesLines
2013-12-31 Don't use any syntactic sugar for dynamic attrsShea Levy1-119/+23
This doesn't change any functionality but moves some behavior out of the parser and into the evaluator in order to simplify the code. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31 Fold dynamic binds handling into addAttrShea Levy1-55/+35
Since addAttr has to iterate through the AttrPath we pass it, it makes more sense to just iterate through the AttrNames in addAttr instead. As an added bonus, this allows attrsets where two dynamic attribute paths have the same static leading part (see added test case for an example that failed previously). Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31 Dynamic attrsShea Levy1-21/+197
This adds new syntax for attribute names: * attrs."${name}" => getAttr name attrs * attrs ? "${name}" => isAttrs attrs && hasAttr attrs name * attrs."${name}" or def => if attrs ? "${name}" then attrs."${name}" else def * { "${name}" = value; } => listToAttrs [{ inherit name value; }] Of course, it's a bit more complicated than that. The attribute chains can be arbitrarily long and contain combinations of static and dynamic parts (e.g. attrs."${foo}".bar."${baz}" or qux), which is relatively straightforward for the getAttrs/hasAttrs cases but is more complex for the listToAttrs case due to rules about duplicate attribute definitions. For attribute sets with dynamic attribute names, duplicate static attributes are detected at parse time while duplicate dynamic attributes are detected when the attribute set is forced. So, for example, { a = null; a.b = null; "${"c"}" = true; } will be a parse-time error, while { a = {}; "${"a"}".b = null; c = true; } will be an eval-time error (technically that case could theoretically be detected at parse time, but the general case would require full evaluation). Moreover, duplicate dynamic attributes are not allowed even in cases where they would be with static attributes ({ a.b.d = true; a.b.c = false; } is legal, but { a."${"b"}".d = true; a."${"b"}".c = false; } is not). This restriction might be relaxed in the future in cases where the static variant would not be an error, but it is not obvious that that is desirable. Finally, recursive attribute sets with dynamic attributes have the static attributes in scope but not the dynamic ones. So rec { a = true; "${"b"}" = a; } is equivalent to { a = true; b = true; } but rec { "${"a"}" = true; b = a; } would be an error or use a from the surrounding scope if it exists. Note that the getAttr, getAttr or default, and hasAttr are all implemented purely in the parser as syntactic sugar, while attribute sets with dynamic attribute names required changes to the AST to be implemented cleanly. This is an alternative solution to and closes #167 Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31 Add the ExprBuiltin Expr type to the ASTShea Levy1-9/+9
Certain desugaring schemes may require the parser to use some builtin function to do some of the work (e.g. currently `throw` is used to lazily cause an error if a `<>`-style path is not in the search path) Unfortunately, these names are not reserved keywords, so an expression that uses such a syntactic sugar will not see the expected behavior (see tests/lang/eval-okay-redefine-builtin.nix for an example). This adds the ExprBuiltin AST type, which when evaluated uses the value from the rootmost variable scope (which of course is initialized internally and can't shadow any of the builtins). Signed-off-by: Shea Levy <shea@shealevy.com>
2013-11-18 Add a symbol __curPos that expands to the current source locationEelco Dolstra1-1/+6
I.e. an attribute set { file = <string>; line = <int>; column = <int>; }.
2013-10-17 Ensure proper type checking/coercion of "${expr}"Eelco Dolstra1-2/+3
Now we only rewrite "${expr}" to expr if expr is a string literal.
2013-10-08 Deduplicate filenames in PosEelco Dolstra1-2/+2
This saves ~4 MiB of RAM for NixOS system instantiation, and ~18 MiB for "nix-env -qa".
2013-10-08 Show the exact position of undefined variablesEelco Dolstra1-18/+14
In particular, undefined variable errors in a "with" previously didn't show *any* position information, so this should help a lot in those cases.
2013-09-03 Get rid of the parse tree cacheEelco Dolstra1-9/+7
Since we already cache files in normal form (fileEvalCache), caching parse trees is redundant. Note that getting rid of this cache doesn't actually save much memory at the moment, because parse trees are currently not freed / GC'ed.
2013-09-02 Add some support code for nix-replEelco Dolstra1-4/+10
2013-09-02 Fix whitespaceEelco Dolstra1-17/+17
2013-08-26 Simplify inherited attribute handlingShea Levy1-1/+1
This reduces the difference between inherited and non-inherited attribute handling to the choice of which env to use (in recs and lets) by setting the AttrDef::e to a new ExprVar in the parser rather than carrying a separate AttrDef::v VarRef member. As an added bonus, this allows inherited attributes that inherit from a with to delay forcing evaluation of the with's attributes. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-08-19 Store Nix integers as longsEelco Dolstra1-1/+1
So on 64-bit systems, integers are now 64-bit. Fixes #158.
2013-08-02 Add comparison operators ‘<’, ‘<=’, ‘>’ and ‘>=’Eelco Dolstra1-0/+5
2013-08-02 Add integer ‘-’, ‘*’ and ‘/’ operatorsEelco Dolstra1-1/+5
2013-08-02 Add a unary integer negation operatorEelco Dolstra1-2/+4
This allows saying "-1" instead of "builtins.sub 0 1".
2013-05-16 Show function names in error messagesEelco Dolstra1-0/+1
Functions in Nix are anonymous, but if they're assigned to a variable/attribute, we can use the variable/attribute name in error messages, e.g. while evaluating `concatMapStrings' at `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/pkgs/lib/strings.nix:18:25': ...
2013-03-14 Fix building against Bison 2.6Eelco Dolstra1-5/+4
2013-03-08 Revert "Prevent config.h from being clobbered"Eelco Dolstra1-3/+3
This reverts commit 28bba8c44f484eae38e8a15dcec73cfa999156f6.
2013-03-07 Prevent config.h from being clobberedEelco Dolstra1-3/+3
2013-02-08 Make "${./path} ..." evaluate to a string, not a pathEelco Dolstra1-3/+3
Wacky string coercion semantics caused expressions like exec = "${./my-script} params..."; to evaluate to a path (‘/path/my-script params’), because anti-quotations are desuged to string concatenation: exec = ./my-script + " params..."; By constrast, adding a space at the start would yield a string as expected: exec = " ${./my-script} params..."; Now the first example also evaluates to a string.
2012-08-13 Avoid concatenating lists of one stringEelco Dolstra1-1/+1
2012-04-13 Use Bison 2.5Eelco Dolstra1-0/+2
2011-08-06 * Handle the case where the search path element is a regular file.Eelco Dolstra1-1/+2
2011-08-06 * Allow redirections in search path entries. E.g. if you have aEelco Dolstra1-4/+22
directory /home/eelco/src/stdenv-updates that you want to use as the directory for import such as with (import <nixpkgs> { }); then you can say $ nix-build -I nixpkgs=/home/eelco/src/stdenv-updates
2011-08-06 * Add a Nix expression search path feature. Paths between angleEelco Dolstra1-5/+42
brackets, e.g. import <nixpkgs/pkgs/lib> are resolved by looking them up relative to the elements listed in the search path. This allows us to get rid of hacks like import "${builtins.getEnv "NIXPKGS_ALL"}/pkgs/lib" The search path can be specified through the ‘-I’ command-line flag and through the colon-separated ‘NIX_PATH’ environment variable, e.g., $ nix-build -I /etc/nixos ... If a file is not found in the search path, an error message is lazily thrown.
2011-08-06 * Refactoring: move parseExprFromFile() and parseExprFromString() intoEelco Dolstra1-9/+15
the EvalState class.
2011-07-13 * Allow attribute names to be strings. Based on theEelco Dolstra1-0/+2
allow-arbitrary-strinsg-in-names patch by Marc Weber.
2011-07-13 * Allow a default value in attribute selection by writingEelco Dolstra1-12/+24
x.y.z or default (as originally proposed in https://mail.cs.uu.nl/pipermail/nix-dev/2009-September/002989.html). For instance, an expression like stdenv.lib.attrByPath ["features" "ckSched"] false args can now be written as args.features.ckSched or false
2011-07-06 * Change the right-hand side of the ‘.’ operator from an attribute toEelco Dolstra1-3/+3
an attribute path. This is a refactoring to support default values.
2011-07-06 * In the ‘?’ operator, allow attribute paths. For instance, you canEelco Dolstra1-18/+8
write ‘attrs ? a.b’ to test whether ‘attrs’ has an attribute ‘a’ containing an attribute ‘b’. This is more convenient than ‘attrs ? a && attrs.a ? b’. Slight change in the semantics: it's no longer an error if the left-hand side of ‘?’ is not an attribute set. In that case it just returns false. So, ‘null ? foo’ no longer throws an error.
2010-10-24 * Keep attribute sets in sorted order to speed up attribute lookups.Eelco Dolstra1-17/+15
* Simplify the representation of attributes in the AST. * Change the behaviour of listToAttrs() in case of duplicate names.
2010-10-23 * Optimise string constants by putting them in the symbol table.Eelco Dolstra1-32/+40
2010-10-04 * Make sure that config.h is included before the system headers,Eelco Dolstra1-6/+4
because it defines _FILE_OFFSET_BITS. Without this, on OpenSolaris the system headers define it to be 32, and then the 32-bit stat() ends up being called with a 64-bit "struct stat", or vice versa. This also ensures that we get 64-bit file sizes everywhere. * Remove the redundant call to stat() in parseExprFromFile(). The file cannot be a symlink because that's the exit condition of the loop before.
2010-05-07 * Store position info for inherited attributes.Eelco Dolstra1-2/+3
2010-05-06 * Store attribute positions in the AST and report duplicate attributeEelco Dolstra1-29/+26
errors with position info. * For all positions, use the position of the first character of the first token, rather than the last character of the first token plus one.
2010-04-22 * Check for duplicate attribute names / function arguments. `makeEelco Dolstra1-43/+40
check' now succeeds :-) * An attribute set such as `{ foo = { enable = true; }; foo.port = 23; }' now parses. It was previously rejected, but I'm too lazy to implement the check. (The only reason to reject it is that the reverse, `{ foo.port = 23; foo = { enable = true; }; }', is rejected, which is kind of ugly.)
2010-04-14 * Fix builtins.Eelco Dolstra1-2/+1
2010-04-14 * After parsing, compute level/displacement pairs for each variableEelco Dolstra1-1/+2
use site, allowing environments to be stores as vectors of values rather than maps. This should speed up evaluation and reduce the number of allocations.
2010-04-13 * Evaluate lets directly (i.e. without desugaring to `rec { attrs...;Eelco Dolstra1-1/+1
<let-body> = e; }.<let-body>). This prevents the unnecessary allocation of an attribute set.
2010-04-13 * Use a symbol table to represent identifiers and attribute namesEelco Dolstra1-29/+40
efficiently. The symbol table ensures that there is only one copy of each symbol, thus allowing symbols to be compared efficiently using a pointer equality test.
2010-04-12 * Finished the ATerm-less parser.Eelco Dolstra1-92/+31
2010-04-12 * Indented strings.Eelco Dolstra1-37/+33
2010-04-12 * More missing constructs.Eelco Dolstra1-49/+31
2010-04-12 * Don't use ATerms for the abstract syntax trees anymore. NotEelco Dolstra1-86/+105
finished yet.
2010-04-12 * Don't use ATerms to represent integers in the lexer.Eelco Dolstra1-2/+4
2010-04-01 * Removed the `~' operator.Eelco Dolstra1-1/+0
2010-03-31 * Cache parse trees to prevent repeated parsing of imported NixEelco Dolstra1-6/+0
expressions.
2010-03-29 * Started integrating the new evaluator.Eelco Dolstra1-2/+2
2010-03-25 * Simplify @-patterns: only `{attrs}@name' or `name@{attrs}' are nowEelco Dolstra1-25/+20
allowed. So `name1@name2', `{attrs1}@{attrs2}' and so on are now no longer legal. This is no big loss because they were not useful anyway. This also changes the output of builtins.toXML for @-patterns slightly.