summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-09-25 10:28:41 -0700
committerKaz Kylheku <kaz@kylheku.com>2011-09-25 10:28:41 -0700
commit4ce8dde9cafa8a77a0c623043fded0a751ad4b02 (patch)
tree2b18b7c7e838da2491327fdd8a9d291f31c2b46c /parser.y
parent658eb97af000aa0598e3544c2c7ea2cdd60b5b06 (diff)
downloadtxr-4ce8dde9cafa8a77a0c623043fded0a751ad4b02.tar.gz
txr-4ce8dde9cafa8a77a0c623043fded0a751ad4b02.tar.bz2
txr-4ce8dde9cafa8a77a0c623043fded0a751ad4b02.zip
Filtering feature for variable substitution in output.
* filter.c, filter.h: New files. * Makefile (OBJS): filter.o added. * gc.c (mark_obj): Mark new alloc field of string objets. * hash.c (struct hash): New member, userdata. (hash_mark): Mark new userdata member of hash. (make_hash): Initialize userdata. (get_hash_userdata, set_hash_userdata, hashp): New functions. * hash.h (get_hash_userdata, set_hash_userdata, hashp): New functions declared. * lib.c (getplist, string_extend, cobjp): New functions. (string_own, string, string_utf8): Initialize new alloc field to nil. (mkstring, mkustring): Initialize new alloc field to actual size. (length_str): When length is computed and cached, also compute and cache alloc. (init): Call filter_init. * lib.h (string string): New member, alloc. (num_fast): Macro converted to inline function. (getplist, string_extend, cobjp): New functions declared. * match.c (match_line): Follows change of modifier s-exp syntax. (format_field): New parameter, filter. New modifier syntax parsed. Filter retrieved, and applied. (subst_vars): New parameter, filter. Filter is either applied in this function or passed to format_field, as needed. (eval_form): Pass nil to new parameter of subst_vars. (do_output_line): New parameter, filter. Passed down to subst_vars. (do_output): New parameter, filter. Passed down to do_output_line. (match_files): Pass nil filter to subst_vars in cat directive. Output directive refactored to parse keywords, extract the filter and pass down to do_output. * parser.y (regex): Generate (sys:regex regex syntax ...) instead of (regex syntax ...). (elem, expr): Updated w.r.t. regex syntax change. (var): Cases '{' IDENT regex '}' and '{' IDENT NUMBER '}' are removed. new syntax '{' IDENT exprs '}' to handle these more generally and allow for keywords. * txr.1: Updated.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y15
1 files changed, 7 insertions, 8 deletions
diff --git a/parser.y b/parser.y
index d2bcf4ad..e6e66d1d 100644
--- a/parser.y
+++ b/parser.y
@@ -194,7 +194,8 @@ elems : elem { $$ = cons($1, nil); }
elem : TEXT { $$ = string_own($1); }
| var { $$ = $1; }
| list { $$ = $1; }
- | regex { $$ = cons(regex_compile($1), $1); }
+ | regex { $$ = cons(regex_compile(rest($1)),
+ rest($1)); }
| COLL elems END { $$ = list(coll_s, $2, nao); }
| COLL elems
UNTIL elems END { $$ = list(coll_s, $2, $4, nao); }
@@ -400,11 +401,8 @@ var : IDENT { $$ = list(var_s, intern(string_own($1), nil),
nao); }
| '{' IDENT '}' elem { $$ = list(var_s, intern(string_own($2), nil),
$4, nao); }
- | '{' IDENT regex '}' { $$ = list(var_s, intern(string_own($2), nil),
- nil, cons(regex_compile($3), $3),
- nao); }
- | '{' IDENT NUMBER '}' { $$ = list(var_s, intern(string_own($2), nil),
- nil, num($3), nao); }
+ | '{' IDENT exprs '}' { $$ = list(var_s, intern(string_own($2), nil),
+ nil, $3, nao); }
| var_op IDENT { $$ = list(var_s, intern(string_own($2), nil),
nil, $1, nao); }
| var_op IDENT elem { $$ = list(var_s, intern(string_own($2), nil),
@@ -445,13 +443,14 @@ expr : IDENT { $$ = intern(string_own($1), nil); }
keyword_package); }
| NUMBER { $$ = num($1); }
| list { $$ = $1; }
- | regex { $$ = cons(regex_compile($1), $1); }
+ | regex { $$ = cons(regex_compile(rest($1)),
+ rest($1)); }
| chrlit { $$ = $1; }
| strlit { $$ = $1; }
| quasilit { $$ = $1; }
;
-regex : '/' regexpr '/' { $$ = $2; end_of_regex(); }
+regex : '/' regexpr '/' { $$ = cons(regex_s, $2); end_of_regex(); }
| '/' error { $$ = nil;
yybadtoken(yychar, lit("regex"));
end_of_regex(); }