summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-11-23 10:46:32 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-11-23 10:46:32 -0800
commitc1202a71a068c13a17b69348a6d7736b8855be0c (patch)
treeeb2121adb2e75b6d2a0838d152a8c5b6c161ac1f /match.c
parente1174f5ea6ff0a51738830e10a92819135a22b32 (diff)
downloadtxr-c1202a71a068c13a17b69348a6d7736b8855be0c.tar.gz
txr-c1202a71a068c13a17b69348a6d7736b8855be0c.tar.bz2
txr-c1202a71a068c13a17b69348a6d7736b8855be0c.zip
Semantics change. If a variable is followed by a mixture
of text and regular expressions, that whole mixture is considered to follow the variable and used for matching. The earlier semantics change whereby a single unescaped space denotes the regular expression / +/ broke the simple case @a word. It caused the @a to be followed not by the text " word" but by just the regular expression element. With this change @a word means that a is followed by the regex / +/ and "word". * match.c (text_s): New symbol variable. (h_text): New function. (syms_init): Initialize new symbol variable. (dir_tables_init): Hook h_text into horizontal directives table. * match.h (text_s): Declared. * parser.y (text, texts): New nonterminals. (elem): TEXT, SPACE and regex are now handled under texts grammar production. All texts are run together and produce an item which looks like (text items ...). * txr.1, RELNOTES: Updated. * txr.c (remove_hash_bang_line): Updated to find #! buried in (text ...) syntax.
Diffstat (limited to 'match.c')
-rw-r--r--match.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/match.c b/match.c
index 52f79624..9f49657d 100644
--- a/match.c
+++ b/match.c
@@ -54,7 +54,7 @@ int opt_arraydims = 1;
val decline_k, next_spec_k, repeat_spec_k;
val mingap_k, maxgap_k, gap_k, mintimes_k, maxtimes_k, times_k;
val lines_k, chars_k;
-val choose_s, gather_s;
+val text_s, choose_s, gather_s;
val longest_k, shortest_k, greedy_k;
val vars_k, resolve_k;
val append_k, into_k, var_k, list_k, string_k, env_k;
@@ -400,6 +400,21 @@ typedef val (*h_match_func)(match_line_ctx c, match_line_ctx *cout);
val elem_var = first(specline); \
val directive_var = first(elem_var)
+static val h_text(match_line_ctx c, match_line_ctx *cout)
+{
+ val elem = first(c.specline);
+ val texts = rest(elem);
+ val new_pos = cdr(match_line(ml_specline(c, texts)));
+
+ if (new_pos) {
+ c.pos = new_pos;
+ *cout = c;
+ return next_spec_k;
+ }
+
+ return nil;
+}
+
static val search_form(match_line_ctx *c, val needle_form, val from_end)
{
if (regexp(first(needle_form))) {
@@ -3250,6 +3265,7 @@ static void syms_init(void)
times_k = intern(lit("times"), keyword_package);
lines_k = intern(lit("lines"), keyword_package);
chars_k = intern(lit("chars"), keyword_package);
+ text_s = intern(lit("text"), user_package);
choose_s = intern(lit("choose"), user_package);
gather_s = intern(lit("gather"), user_package);
longest_k = intern(lit("longest"), keyword_package);
@@ -3306,6 +3322,7 @@ static void dir_tables_init(void)
sethash(v_directive_table, filter_s, cptr((mem_t *) v_filter));
sethash(v_directive_table, eof_s, cptr((mem_t *) v_eof));
+ sethash(h_directive_table, text_s, cptr((mem_t *) h_text));
sethash(h_directive_table, var_s, cptr((mem_t *) h_var));
sethash(h_directive_table, skip_s, cptr((mem_t *) h_skip));
sethash(h_directive_table, coll_s, cptr((mem_t *) h_coll));