diff options
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | parser.y | 10 | ||||
-rw-r--r-- | regex.c | 6 | ||||
-rw-r--r-- | regex.h | 2 | ||||
-rw-r--r-- | txr.1 | 13 |
6 files changed, 38 insertions, 15 deletions
@@ -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. @@ -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)); @@ -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)); } @@ -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 { @@ -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); @@ -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. |