lix/src/libexpr
Eelco Dolstra 976df480c9 Add a primop for regular expression pattern matching
The function ‘builtins.match’ takes a POSIX extended regular
expression and an arbitrary string. It returns ‘null’ if the string
does not match the regular expression. Otherwise, it returns a list
containing substring matches corresponding to parenthesis groups in
the regex. The regex must match the entire string (i.e. there is an
implied "^<pat>$" around the regex).  For example:

  match "foo" "foobar" => null
  match "foo" "foo" => []
  match "f(o+)(.*)" "foooobar" => ["oooo" "bar"]
  match "(.*/)?([^/]*)" "/dir/file.nix" => ["/dir/" "file.nix"]
  match "(.*/)?([^/]*)" "file.nix" => [null "file.nix"]

The following example finds all regular files with extension .nix or
.patch underneath the current directory:

  let

    findFiles = pat: dir: concatLists (mapAttrsToList (name: type:
      if type == "directory" then
        findFiles pat (dir + "/" + name)
      else if type == "regular" && match pat name != null then
        [(dir + "/" + name)]
      else []) (readDir dir));

  in findFiles ".*\\.(nix|patch)" (toString ./.)
2014-11-25 11:47:06 +01:00
..
attr-path.cc Use proper quotes everywhere 2014-08-20 18:03:48 +02:00
attr-path.hh Work on Values instead of Exprs 2013-09-03 13:17:51 +00:00
common-opts.cc Store Attrs inside Bindings 2014-09-19 16:49:41 +02:00
common-opts.hh Store Attrs inside Bindings 2014-09-19 16:49:41 +02:00
eval-inline.hh forceAttrs: Show position info 2014-04-04 19:11:40 +02:00
eval.cc forceString(): Accept pos argument 2014-11-25 10:23:36 +01:00
eval.hh forceString(): Accept pos argument 2014-11-25 10:23:36 +01:00
get-drvs.cc Store Attrs inside Bindings 2014-09-19 16:49:41 +02:00
get-drvs.hh Drop pointless #include 2014-03-29 22:20:33 +01:00
json-to-value.cc Store Attrs inside Bindings 2014-09-19 16:49:41 +02:00
json-to-value.hh Add builtin function ‘fromJSON’ 2014-07-04 13:34:15 +02:00
lexer.l Use proper quotes everywhere 2014-08-20 18:03:48 +02:00
local.mk Update spec file 2014-09-18 15:42:01 +02:00
names.cc Don't recompile the same regex over and over 2014-10-03 21:29:40 +02:00
names.hh Don't recompile the same regex over and over 2014-10-03 21:29:40 +02:00
nix-expr.pc.in Install some pkgconfig files 2014-09-18 12:00:40 +02:00
nixexpr.cc Improve printing of ASTs 2014-10-20 09:13:21 +02:00
nixexpr.hh Improve printing of ASTs 2014-10-20 09:13:21 +02:00
parser.y Get rid of some unnecessary ExprConcatStrings nodes in dynamic attrs 2014-10-05 01:04:58 +02:00
primops.cc Add a primop for regular expression pattern matching 2014-11-25 11:47:06 +01:00
symbol-table.hh Improve printing of ASTs 2014-10-20 09:13:21 +02:00
value-to-json.cc Support control characters in JSON output 2014-09-30 00:41:18 +02:00
value-to-json.hh Support control characters in JSON output 2014-09-30 00:41:18 +02:00
value-to-xml.cc Fix compilation on FreeBSD 2012-03-05 22:04:40 +01:00
value-to-xml.hh Use "#pragma once" to prevent repeated header file inclusion 2012-07-18 14:59:03 -04:00
value.hh mkList: Scrub better 2014-10-09 13:08:53 +02:00