diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-09-25 10:39:11 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-09-25 10:39:11 -0700 |
commit | ea8a5447522adb776899e61594916fdcb4b210e6 (patch) | |
tree | ced81ca5a3699beab13c54b3d21d1c51fcbf770b | |
parent | e6763ab34d5cf2dbff5f97b431be128062608505 (diff) | |
download | txr-ea8a5447522adb776899e61594916fdcb4b210e6.tar.gz txr-ea8a5447522adb776899e61594916fdcb4b210e6.tar.bz2 txr-ea8a5447522adb776899e61594916fdcb4b210e6.zip |
New function: regex-source.
* regex.c (regex_source): New function.
(regex_init): regex-source intrinsic registered.
* regex.h (regex_source): Declared.
* txr.1: Documented.
-rw-r--r-- | regex.c | 7 | ||||
-rw-r--r-- | regex.h | 1 | ||||
-rw-r--r-- | txr.1 | 15 |
3 files changed, 23 insertions, 0 deletions
@@ -2082,6 +2082,12 @@ val regexp(val obj) return typeof(obj) == regex_s ? t : nil; } +val regex_source(val compiled_regex) +{ + regex_t *regex = coerce(regex_t *, cobj_handle(compiled_regex, regex_s)); + return regex->source; +} + static void puts_clear_flag(val str, val stream, int *semi_flag) { *semi_flag = 0; @@ -2933,6 +2939,7 @@ void regex_init(void) reg_fun(intern(lit("regex-compile"), user_package), func_n2o(regex_compile, 1)); reg_fun(intern(lit("regexp"), user_package), func_n1(regexp)); + reg_fun(intern(lit("regex-source"), user_package), func_n1(regex_source)); reg_fun(intern(lit("search-regex"), user_package), func_n4o(search_regex, 2)); reg_fun(intern(lit("range-regex"), user_package), func_n4o(range_regex, 2)); reg_fun(intern(lit("search-regst"), user_package), func_n4o(search_regst, 2)); @@ -31,6 +31,7 @@ extern wchar_t spaces[]; val regex_compile(val regex, val error_stream); val regexp(val); +val regex_source(val regex); val search_regex(val haystack, val needle_regex, val start_num, val from_end); val range_regex(val haystack, val needle_regex, val start_num, val from_end); val match_regex(val str, val regex, val pos); @@ -32173,6 +32173,21 @@ stream. (regex-compile "a|b|c") .cble +.coNP Function @ regex-source +.synb +.mets (regex-source << regex ) +.syne +.desc +The +.code regex-source +function returns the source code of compiled regular expression +.metn regex . + +The source code isn't the textual notation, but the Lisp +data structure representing the abstract syntax tree: the +same representation as what is returned by +.codn regex-parse . + .coNP Function @ regex-parse .synb .mets (regex-parse < string <> [ error-stream ]) |