Commit graph

57 commits

Author SHA1 Message Date
Eelco Dolstra 9279174dde * Added an experimental feature suggested by Andres: ellipses ("...")
in attribute set pattern matches.  This allows defining a function
  that takes *at least* the listed attributes, while ignoring
  additional attributes.  For instance,

    {stdenv, fetchurl, fuse, ...}:
    
    stdenv.mkDerivation {
      ...
    };
    
  defines a function that requires an attribute set that contains the 
  specified attributes but ignores others.  The main advantage is that
  we can then write in all-packages.nix

    aefs = import ../bla/aefs pkgs;

  instead of

    aefs = import ../bla/aefs {
      inherit stdenv fetchurl fuse;
    };

  This saves a lot of typing (not to mention not having to update
  all-packages.nix with purely mechanical changes).  It saves as much
  typing as the "args: with args;" style, but has the advantage that
  the function arguments are properly declared (not implicit in what
  the body of the "with" uses).
2008-08-14 14:00:44 +00:00
Eelco Dolstra 1b962fc720 * @-patterns as in Haskell. For instance, in a function definition
f = args @ {x, y, z}: ...;

  `args' refers to the argument as a whole, which is further
  pattern-matched against the attribute set pattern {x, y, z}.
2008-08-14 12:53:29 +00:00
Eelco Dolstra efe4b690ae * Refactoring: combine functions that take an attribute set and
functions that take a single argument (plain lambdas) into one AST
  node (Function) that contains a Pattern node describing the
  arguments.  Current patterns are single lazy arguments (VarPat) and
  matching against an attribute set (AttrsPat).

  This refactoring allows other kinds of patterns to be added easily,
  such as Haskell-style @-patterns, or list pattern matching.
2008-08-14 10:04:22 +00:00
Eelco Dolstra 5664b6d7ba * Removed the "valid values" feature. Nobody uses it anyway. 2008-08-11 13:36:40 +00:00
Eelco Dolstra 7cd88b1dec * Generalised the dependencyClosure primop to builtins.genericClosure,
which is hopefully more useful.
* New primops: length, mul, div.
2008-07-11 13:29:04 +00:00
Eelco Dolstra d567baabbd * Export the nix-env derivation name parsing and version comparison
logic through the `parseDrvName' and `compareVersions' primops.
  This will allow expressions to easily check whether some dependency
  is a specific needed version or falls in some version range.  See
  tests/lang/eval-okay-versions.nix for examples.
2008-07-01 10:10:32 +00:00
Eelco Dolstra 4066f450c2 * Doh. 2008-02-05 13:35:49 +00:00
Eelco Dolstra e7bdde981f * Regression test. 2008-02-05 13:25:18 +00:00
Eelco Dolstra 7d0f6aed59 * New primop `unsafeDiscardStringContext' to get rid of string
contexts.  Needed to prevent unnecessary dependencies when building
  the NixOS manual.
2008-01-04 14:22:49 +00:00
Eelco Dolstra b42ef9c054 * Syntax to escape '', ${. 2007-12-06 10:20:58 +00:00
Eelco Dolstra 6d6c68c0d2 * Added a new kind of multi-line string literal delimited by two
single quotes.  Example (from NixOS):

    job = ''
      start on network-interfaces

      start script

        rm -f /var/run/opengl-driver
        ${if videoDriver == "nvidia"        
          then "ln -sf ${nvidiaDrivers} /var/run/opengl-driver"
          else if cfg.driSupport
          then "ln -sf ${mesa} /var/run/opengl-driver"
          else ""
        }

        rm -f /var/log/slim.log

      end script
    '';

  This style has two big advantages:

  - \, ' and " aren't special, only '' and ${.  So you get a lot less
    escaping in shell scripts / configuration files in Nixpkgs/NixOS.
    The delimiter '' is rare in scripts (and can usually be written as
    "").  ${ is also fairly rare.

    Other delimiters such as <<...>>, {{...}} and <|...|> were also
    considered but this one appears to have the fewest drawbacks
    (thanks Martin).

  - Indentation is intelligently stripped so that multi-line strings
    can follow the nesting structure of the containing Nix
    expression.  E.g. in the example above 6 spaces are stripped from
    the start of each line.  This prevents unnecessary indentation in
    generated files (which sometimes even breaks things).

  See tests/lang/eval-okay-ind-string.nix for some examples.
2007-11-30 16:48:45 +00:00
Eelco Dolstra 06f95dd07c * New primop `readFile' to get the contents of a file as a string. 2007-11-21 13:49:59 +00:00
Marc Weber 2629998e91 primop functions listToAttrs (+test), __isAttrs, __trace added
new configuration style proposal in lib/default-unstable.nix
2007-08-18 22:12:00 +00:00
Eelco Dolstra ca00aa1171 * Allow empty argument lists in function definitions (e.g., `{}:
bla').  Also allow trailing commas (`{x, y,}: ...') as a unintented
  consequence.  Hopefully the reduce/reduce conflict won't cause any
  problems.
2007-05-15 12:14:37 +00:00
Eelco Dolstra 7349bd0176 New primitives:
* `sub' to subtract two numbers.
* `stringLength' to get the length of a string.
* `substring' to get a substring of a string.  These should be enough
  to allow most string operations to be expressed.
2007-01-29 14:23:09 +00:00
Eelco Dolstra e418976107 * Option --argstr for passing string arguments easily. (NIX-75) 2007-01-14 12:32:44 +00:00
Eelco Dolstra f23dcdd603 * Canonicalise ASTs in `nix-instantiate --eval': remove position
info, sort attribute sets.
2007-01-13 16:17:07 +00:00
Eelco Dolstra 1a7e88bbd9 * New built-in function `builtins.attrNames' that returns the
names of the attributes in an attribute set.
2006-12-12 16:14:31 +00:00
Eelco Dolstra dfc042a0c1 * Another test. 2006-10-17 11:16:02 +00:00
Eelco Dolstra 9e30694f98 * Fix the tests wrt the AST changes, i.e., Str(s) -> Str(s, []), and
the semantic changes.
2006-10-17 11:08:59 +00:00
Eelco Dolstra 7d4567f2cc * Removed URIs from the evaluator (NIX-66). They are now just another
kind of notation for strings.
2006-10-11 21:59:33 +00:00
Eelco Dolstra ac19b333b3 * Finally, a real "let" syntax: `let x = ...; ... z = ...; in ...'. 2006-10-02 15:52:44 +00:00
Eelco Dolstra 0e705391db * Primop `toPath' to convert a string to a path.
* Primop `pathExists' to check for path existence.
2006-09-24 18:23:32 +00:00
Eelco Dolstra e47e0c2dbe * Builtin function `getEnv' for getting environment variables. 2006-09-24 17:48:41 +00:00
Eelco Dolstra df8873e14a * lessThan primitive for integer comparison. 2006-09-24 15:21:48 +00:00
Eelco Dolstra 2ab4bc44c7 * Builtin function `add' to add integers.
* Put common test functions in tests/lang/lib.nix.
2006-09-22 15:29:21 +00:00
Eelco Dolstra d315210612 * Added a builtin function `isList' to test whether a value is a list.
With this primitive, a list-flattening function can be implemented
  (NIX-55, example is in tests/lang/eval-okay-flatten.nix).
2006-09-22 14:55:19 +00:00
Eelco Dolstra c02a44183f * Builtin functions head' and tail' to return the head and tail of
list.  Useful for lots of things, such as implementing a fold
  function (see NIX-30, example is in tests/lang/eval-okay-list.nix).
2006-09-22 14:46:36 +00:00
Eelco Dolstra 8a1ab709a4 * New builtin functions builtins.{hasAttr, getAttr} to check for
attribute existence and to return an attribute from an attribute
  set, respectively.  Example: `hasAttr "foo" {foo = 1;}'.  They
  differ from the `?' and `.' operators in that the attribute name is
  an arbitrary expression.  (NIX-61)
2006-09-22 14:31:55 +00:00
Eelco Dolstra de90fdf908 * Allow "$" in strings as long as they are not followed by "{". (Too
bad flex doesn't have lexical restrictions, the current solution
  isn't quite right...)
2006-09-01 12:04:06 +00:00
Eelco Dolstra f93f7b75be * Okay, that's a bit harder than expected. 2006-08-30 13:10:04 +00:00
Eelco Dolstra dce1afdc67 * TDD: == should do a deep equality test, i.e., it should strictly
evaluate its arguments.
2006-08-30 12:25:27 +00:00
Eelco Dolstra 215ec2ddc6 * New primop __toXML (or builtins.toXML) to convert an expression to
an XML representation stored in a string.  This should be useful to
  pass structured information to builders.
2006-08-24 14:34:29 +00:00
Eelco Dolstra 38f18aa6d4 * New primop: abort "error message". 2006-08-23 15:46:00 +00:00
Eelco Dolstra 4a053bfdfd * A new primop `builtins', which returns an attribute set containing
all the primops.  This allows Nix expressions to test for new
  primops and take appropriate action if they're not available.  For
  instance, rather than calling a primop `foo' directly, they could
  say `if builtins ? foo then builtins.foo ... else ...'.
2006-08-23 14:39:11 +00:00
Eelco Dolstra 93d9797eda * Urgh (see NIX-56). 2006-08-22 09:34:38 +00:00
Eelco Dolstra 4874fd2d9a * Test for `nix-instantiate --eval-only --xml'. 2006-08-17 11:28:29 +00:00
Eelco Dolstra fe101fa785 * Meh. 2006-08-16 10:29:43 +00:00
Eelco Dolstra bfe19b3c37 * A test for NIX-53. 2006-08-16 10:23:02 +00:00
Eelco Dolstra f4c5531d92 * New language feature: domain checks, which check whether a function
argument has a valid value, i.e., is in a certain domain.  E.g.,

    { foo : [true false]
    , bar : ["a" "b" "c"]
    }: ...

  This previously could be done using assertions, but domain checks
  will allow the buildfarm to automatically extract the configuration
  space from functions.
2006-07-24 16:35:34 +00:00
Eelco Dolstra b545c669a0 * Tests for domain checks. 2006-07-24 15:50:29 +00:00
Eelco Dolstra 57751fdb55 * Refactoring to support domain checks. 2006-07-24 15:16:03 +00:00
Eelco Dolstra 2b4b0658fa * This expression has an undefined variable which isn't detected, so
evaluation fails:

    error: impossible: undefined variable `gcc'
2006-07-10 17:35:00 +00:00
Eelco Dolstra 5cabd47394 * Allow function argument default values to refer to other arguments
of the function.  Implements NIX-45.
2006-05-08 12:52:47 +00:00
Eelco Dolstra ae55e79541 * More tests. 2006-05-02 11:20:55 +00:00
Eelco Dolstra dca43ef795 * Tests for NIX-45. 2006-05-02 11:15:04 +00:00
Eelco Dolstra 0064599a27 * String interpolation. Expressions like
"--with-freetype2-library=" + freetype + "/lib"

  can now be written as

    "--with-freetype2-library=${freetype}/lib"

  An arbitrary expression can be enclosed within ${...}, not just
  identifiers.

* Escaping in string literals: \n, \r, \t interpreted as in C, any
  other character following \ is interpreted as-is.
  
* Newlines are now allowed in string literals.
2006-05-01 14:01:47 +00:00
Eelco Dolstra 6cecad2be0 * Allow string concatenations involving derivations, e.g.,
configureFlags = "--with-freetype2-library="
      + freetype + "/lib";
2006-05-01 09:56:56 +00:00
Eelco Dolstra fa95f4be3f * More test coverage. 2006-03-01 16:26:13 +00:00
Eelco Dolstra 44409f52c1 * "Fix" the test, since we cannot feasibly support the intended semantics. 2005-11-17 11:58:22 +00:00