aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/nixexpr.hh
AgeCommit message (Collapse)Author
2020-12-18Replace Value type setters with mk* functionsSilvan Mosberger
Move clearValue inside Value mkInt instead of setInt mkBool instead of setBool mkString instead of setString mkPath instead of setPath mkNull instead of setNull mkAttrs instead of setAttrs mkList instead of setList* mkThunk instead of setThunk mkApp instead of setApp mkLambda instead of setLambda mkBlackhole instead of setBlackhole mkPrimOp instead of setPrimOp mkPrimOpApp instead of setPrimOpApp mkExternal instead of setExternal mkFloat instead of setFloat Add note that the static mk* function should be removed eventually
2020-06-23use plain errPos instead of nixCode; fix testsBen Burdette
2020-06-18Merge branch 'master' into caveman-LOCsBen Burdette
2020-06-15Get rid of explicit ErrorInfo constructorsEelco Dolstra
2020-05-20print LOC for stdin, string argsBen Burdette
2020-05-12new pos format for more errorsBen Burdette
2020-05-11fixes to merged codeBen Burdette
2020-05-11Merge branch 'master' into errors-phase-2Ben Burdette
2020-04-29uncrustify formattingBen Burdette
2020-04-21remove 'format' from Error constructor callsBen Burdette
2020-04-09Attach pos to if expression errorsDomen Kožar
2020-04-02Make function arguments retain position infoSilvan Mosberger
This allows querying the location of function arguments. E.g. builtins.unsafeGetAttrPos "x" (builtins.functionArgs ({ x }: null)) => { column = 57; file = "/home/infinisil/src/nix/inst/test.nix"; line = 1; }
2019-11-10Fix extra ; warnings involving MakeErrorJohn Ericson
2018-05-11Revert "Throw a specific error for incomplete parse errors."Eelco Dolstra
This reverts commit 6498adb002bcf7e715afe46c23b8635d4592c156. We don't actually use IncompleteParseError in 'nix repl'.
2018-05-02Fix some random -Wconversion warningsEelco Dolstra
2018-03-14Fix compatibility with latest boost::formatEelco Dolstra
2018-03-09Modified MakeBinOp to no longer produce its name using concatenation and "##".Tim Engler
Doing so prevents emacs tags from working, as well as makes the code extremely confusing for a newbie. In the prior state, if someone wants to find the definition of "ExprApp" for example, a grep through the code reveals nothing. Since the definition could be hiding in numerous ".h" files, it's really difficult to find. This personally took me several hours to figure out.
2017-07-30Replace Unicode quotes in user-facing strings by ASCIIJörg Thalheim
Relevant RFC: NixOS/rfcs#4 $ ag -l | xargs sed -i -e "/\"/s/’/'/g;/\"/s/‘/'/g"
2016-11-26Revert "Get rid of unicode quotes (#1140)"Eelco Dolstra
This reverts commit f78126bfd6b6c8477fcdbc09b2f98772dbe9a1e7. There really is no need for such a massive change...
2016-11-25Get rid of unicode quotes (#1140)Guillaume Maudoux
2016-02-24Throw a specific error for incomplete parse errors.Scott Olson
`nix-repl` will use this for deciding whether to keep waiting for input or error out right away.
2016-01-05First hit at providing support for floats in the language.Christian Theune
2015-02-23Add restricted evaluation modeEelco Dolstra
If ‘--option restrict-eval true’ is given, the evaluator will throw an exception if an attempt is made to access any file outside of the Nix search path. This is primarily intended for Hydra, where we don't want people doing ‘builtins.readFile ~/.ssh/id_dsa’ or stuff like that.
2014-10-20Improve printing of ASTsEelco Dolstra
2014-10-05Get rid of some unnecessary ExprConcatStrings nodes in dynamic attrsEelco Dolstra
This gives a ~18% speedup in NixOS evaluation (after converting most calls to hasAttr/getAttr to dynamic attrs).
2014-08-20Use proper quotes everywhereEelco Dolstra
2014-06-12Drop ImportError and FindErrorEelco Dolstra
We're not catching these anywhere.
2014-06-12findFile: Realise the context of the path attributesShea Levy
2014-05-26Remove ExprBuiltinEelco Dolstra
It's slower than ExprVar since it doesn't compute a static displacement. Since we're not using the throw primop in the implementation of <...> anymore, it's also not really needed.
2014-05-26Make the Nix search path declarativeEelco Dolstra
Nix search path lookups like <nixpkgs> are now desugared to ‘findFile nixPath <nixpkgs>’, where ‘findFile’ is a new primop. Thus you can override the search path simply by saying let nixPath = [ { prefix = "nixpkgs"; path = "/my-nixpkgs"; } ]; in ... <nixpkgs> ... In conjunction with ‘scopedImport’ (commit c273c15cb13bb86420dda1e5341a4e19517532b5), the Nix search path can be propagated across imports, e.g. let overrides = { nixPath = [ ... ] ++ builtins.nixPath; import = fn: scopedImport overrides fn; scopedImport = attrs: fn: scopedImport (overrides // attrs) fn; builtins = builtins // overrides; }; in scopedImport overrides ./nixos
2014-05-26Add primop ‘scopedImport’Eelco Dolstra
‘scopedImport’ works like ‘import’, except that it takes a set of attributes to be added to the lexical scope of the expression, essentially extending or overriding the builtin variables. For instance, the expression scopedImport { x = 1; } ./foo.nix where foo.nix contains ‘x’, will evaluate to 1. This has a few applications: * It allows getting rid of function argument specifications in package expressions. For instance, a package expression like: { stdenv, fetchurl, libfoo }: stdenv.mkDerivation { ... buildInputs = [ libfoo ]; } can now we written as just stdenv.mkDerivation { ... buildInputs = [ libfoo ]; } and imported in all-packages.nix as: bar = scopedImport pkgs ./bar.nix; So whereas we once had dependencies listed in three places (buildInputs, the function, and the call site), they now only need to appear in one place. * It allows overriding builtin functions. For instance, to trace all calls to ‘map’: let overrides = { map = f: xs: builtins.trace "map called!" (map f xs); # Ensure that our override gets propagated by calls to # import/scopedImport. import = fn: scopedImport overrides fn; scopedImport = attrs: fn: scopedImport (overrides // attrs) fn; # Also update ‘builtins’. builtins = builtins // overrides; }; in scopedImport overrides ./bla.nix * Similarly, it allows extending the set of builtin functions. For instance, during Nixpkgs/NixOS evaluation, the Nixpkgs library functions could be added to the default scope. There is a downside: calls to scopedImport are not memoized, unlike import. So importing a file multiple times leads to multiple parsings / evaluations. It would be possible to construct the AST only once, but that would require careful handling of variables/environments.
2014-04-04Show position info in attribute selection errorsEelco Dolstra
2014-04-04Show position info in Boolean operationsEelco Dolstra
2014-04-04Show position info in string concatenation / addition errorsEelco Dolstra
2014-04-04forceString: Show position infoEelco Dolstra
2014-04-04Include position info in function applicationEelco Dolstra
This allows error messages like: error: the anonymous function at `/etc/nixos/configuration.nix:1:1' called without required argument `foo', at `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:77:59'
2014-03-10The expr of AttrNames/DynamicAttrDefs is always an ExprConcatStringsShea Levy
2014-01-21Fix some clang warningsEelco Dolstra
2013-12-31Don't use any syntactic sugar for dynamic attrsShea Levy
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-31Dynamic attrsShea Levy
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-31Add the ExprBuiltin Expr type to the ASTShea Levy
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-18Add a symbol __curPos that expands to the current source locationEelco Dolstra
I.e. an attribute set { file = <string>; line = <int>; column = <int>; }.
2013-11-12Make function calls tail-recursiveEelco Dolstra
2013-10-24Rename "attribute sets" to "sets"Eelco Dolstra
We don't have any other kind of sets so calling them attribute sets is unnecessarily verbose.
2013-10-08Deduplicate filenames in PosEelco Dolstra
This saves ~4 MiB of RAM for NixOS system instantiation, and ~18 MiB for "nix-env -qa".
2013-10-08Treat undefined variable errors consistentlyEelco Dolstra
Previously, a undefined variable inside a "with" caused an EvalError (which can be caught), while outside, it caused a ParseError (which cannot be caught). Now both cause an UndefinedVarError (which cannot be caught).
2013-10-08Show the exact position of undefined variablesEelco Dolstra
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-10-08Merge VarRef into ExprVarEelco Dolstra
2013-09-02Fix whitespaceEelco Dolstra
2013-08-26Simplify inherited attribute handlingShea Levy
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>