diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-09-22 06:45:36 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-09-22 06:45:36 -0700 |
commit | 5275930bb59eaaf60143ef83e4c2f17bc19b25ed (patch) | |
tree | d5e5cdc9398762a6c62cb08b2e09f4f967eb3780 /lib.c | |
parent | 75c8ed7c7ea232e98b1e6d0ba85ce269f5ea3fe7 (diff) | |
download | txr-5275930bb59eaaf60143ef83e4c2f17bc19b25ed.tar.gz txr-5275930bb59eaaf60143ef83e4c2f17bc19b25ed.tar.bz2 txr-5275930bb59eaaf60143ef83e4c2f17bc19b25ed.zip |
Regexes now callable as functions.
* lib.c (generic_funcall): Add case for regexes.
Handle arguments in such a way that the string is always
rightmost, with a view to convenient partial application.
* txr.1: Documented in multiple places.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -5357,6 +5357,22 @@ val generic_funcall(val fun, struct args *args_in) default: callerror(fun, lit("too many arguments")); } + } else if (fun->co.cls == regex_s) { + bug_unless (args->argc >= ARGS_MIN); + args_normalize(args, 3); + + switch (args->fill) { + case 0: + callerror(fun, lit("missing required arguments")); + case 1: + return search_regst(z(args->arg[0]), fun, nil, nil); + case 2: + return search_regst(z(args->arg[1]), fun, z(args->arg[0]), nil); + case 3: + return search_regst(z(args->arg[2]), fun, z(args->arg[0]), z(args->arg[1])); + default: + callerror(fun, lit("too many arguments")); + } } else if (structp(fun)) { fun = method(fun, lambda_s); break; |