summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--eval.c2
-rw-r--r--parser.y10
-rw-r--r--regex.c6
-rw-r--r--regex.h2
-rw-r--r--txr.113
6 files changed, 38 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 8c820750..4afa1f16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
2013-12-06 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (eval_init): Update registration of regex-compile
+ to reflect that it has two arguments now.
+
+ * parser.y (grammar): Update calls to regex_compile to
+ pass two arguments. Since we don't expect regex_compile to
+ parse, we specify the error stream as nil.
+ (spec): The "secret syntax" for a regex is simplified
+ not to include the slashes. This provides better diagnostics for
+ unterminated syntax and requires less string processing to generate.
+ Also, the form returned doesn't have the regex symbol
+ consed onto it, which parse_regex just throws away.
+
+ * regex.c (regex_compile): Now takes a stream argument.
+
+ * regex.h (regex_compile): Declaration updated.
+
+ * txr.1: Updated
+
+2013-12-06 Kaz Kylheku <kaz@kylheku.com>
+
Fixing some old-style coding that became obsolete
around November 2009.
diff --git a/eval.c b/eval.c
index ea3020d2..1a3c378f 100644
--- a/eval.c
+++ b/eval.c
@@ -2307,7 +2307,7 @@ void eval_init(void)
reg_fun(intern(lit("logtrunc"), user_package), func_n2(logtrunc));
reg_fun(intern(lit("ash"), user_package), func_n2(ash));
- reg_fun(intern(lit("regex-compile"), user_package), func_n1(regex_compile));
+ 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("search-regex"), user_package), func_n4o(search_regex, 2));
reg_fun(intern(lit("match-regex"), user_package), func_n3o(match_regex, 2));
diff --git a/parser.y b/parser.y
index 321b32e0..917f2208 100644
--- a/parser.y
+++ b/parser.y
@@ -114,7 +114,7 @@ static val parsed_spec;
spec : clauses { parsed_spec = $1; }
| /* empty */ { parsed_spec = nil; }
- | SECRET_ESCAPE_R regex { parsed_spec = $2; }
+ | SECRET_ESCAPE_R regexpr { parsed_spec = $2; end_of_regex(); }
| error '\n' { parsed_spec = nil;
if (errors >= 8)
YYABORT;
@@ -320,12 +320,12 @@ text : TEXT { $$ = rl(string_own($1), num(lineno)); }
| SPACE { if ($1[0] == ' ' && $1[1] == 0)
{ val spaces = list(oneplus_s,
chr(' '), nao);
- $$ = cons(regex_compile(spaces), spaces);
+ $$ = cons(regex_compile(spaces, nil), spaces);
rl($$, num(lineno));
free($1); }
else
{ $$ = rl(string_own($1), num(lineno)); }}
- | regex { $$ = cons(regex_compile(rest($1)),
+ | regex { $$ = cons(regex_compile(rest($1), nil),
rest($1));
rl($$, num(lineno)); }
;
@@ -652,7 +652,7 @@ var_op : '*' { $$ = list(t, nao); }
;
modifiers : NUMBER { $$ = cons($1, nil); }
- | regex { $$ = cons(cons(regex_compile(rest($1)),
+ | regex { $$ = cons(cons(regex_compile(rest($1), nil),
rest($1)), nil);
rlcp($$, $1); }
| list { $$ = cons($1, nil); }
@@ -742,7 +742,7 @@ expr : IDENT { $$ = rl(intern(string_own($1), nil),
| vector { $$ = $1; }
| hash { $$ = $1; }
| meta_expr { $$ = $1; }
- | lisp_regex { $$ = cons(regex_compile(rest($1)),
+ | lisp_regex { $$ = cons(regex_compile(rest($1), nil),
rest($1));
rlcp($$, $1); }
| chrlit { $$ = rl($1, num(lineno)); }
diff --git a/regex.c b/regex.c
index c589b0ca..fb22649f 100644
--- a/regex.c
+++ b/regex.c
@@ -1613,11 +1613,11 @@ static val regex_requires_dv(val exp)
}
}
-val regex_compile(val regex_sexp)
+val regex_compile(val regex_sexp, val error_stream)
{
if (stringp(regex_sexp)) {
- regex_sexp = regex_parse(regex_sexp, nil);
- return if2(regex_sexp, regex_compile(regex_sexp));
+ regex_sexp = regex_parse(regex_sexp, error_stream);
+ return if2(regex_sexp, regex_compile(regex_sexp, error_stream));
} else if (opt_derivative_regex || regex_requires_dv(regex_sexp)) {
return cons(compiled_regex_s, cons(dv_compile_regex(regex_sexp), nil));
} else {
diff --git a/regex.h b/regex.h
index c75b44f1..75758e8b 100644
--- a/regex.h
+++ b/regex.h
@@ -27,7 +27,7 @@
extern val space_k, digit_k, word_char_k;
extern val cspace_k, cdigit_k, cword_char_k;
-val regex_compile(val regex);
+val regex_compile(val regex, val error_stream);
val regexp(val);
val search_regex(val haystack, val needle_regex, val start_num, val from_end);
val match_regex(val str, val regex, val pos);
diff --git a/txr.1 b/txr.1
index ad83f669..980d2976 100644
--- a/txr.1
+++ b/txr.1
@@ -9348,7 +9348,7 @@ object. For any other object type, it returns nil.
.TP
Syntax:
- (regex-compile <form-or-string>)
+ (regex-compile <form-or-string> : <error-stream>)
.TP
Description:
@@ -9363,6 +9363,9 @@ abstract syntax tree first, if by a call to (regex-parse <form-or-string>).
If the parse is successful (the result is not nil) then
it is compiled by a recursive call to regex-compile.
+The optional <error-stream> argument is passed down to regex-compile,
+if that call takes place.
+
.TP
Examples:
@@ -9384,7 +9387,7 @@ Examples:
.TP
Syntax:
- (regex-parse <string> : <stream>)
+ (regex-parse <string> : <error-stream>)
.TP
Description:
@@ -9399,10 +9402,10 @@ function performs this parsing at run-time.
If there are parse errors, the function returns nil.
-The optional <stream> argument specifies a stream to which error messages
+The optional <error-stream> argument specifies a stream to which error messages
are sent from the parser. By default, diagnostic output goes to the *stdnull*
-stream, which discards it. If <stream> is specified as t, then the diagnostic
-output goes to the *stdout* stream.
+stream, which discards it. If <error-stream> is specified as t, then the
+diagnostic output goes to the *stdout* stream.
If regex-parse returns a non-nil value, that structure is then something
which is suitable as input to regex-compile.