diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-11-23 10:46:32 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-11-23 10:46:32 -0800 |
commit | c1202a71a068c13a17b69348a6d7736b8855be0c (patch) | |
tree | eb2121adb2e75b6d2a0838d152a8c5b6c161ac1f /parser.y | |
parent | e1174f5ea6ff0a51738830e10a92819135a22b32 (diff) | |
download | txr-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 'parser.y')
-rw-r--r-- | parser.y | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -79,7 +79,7 @@ static val parsed_spec; %type <val> clause_parts additional_parts %type <val> output_clause define_clause try_clause catch_clauses_opt %type <val> line elems_opt elems clause_parts_h additional_parts_h -%type <val> elem var var_op meta_expr +%type <val> text texts elem var var_op meta_expr %type <val> list exprs exprs_opt expr out_clauses out_clauses_opt out_clause %type <val> repeat_clause repeat_parts_opt o_line %type <val> o_elems_opt o_elems_opt2 o_elems o_elem o_var rep_elem rep_parts_opt @@ -267,7 +267,8 @@ elems : elem { $$ = cons($1, nil); yyerror("rep outside of output"); } ; -elem : TEXT { $$ = rl(string_own($1), num(lineno)); } + +text : TEXT { $$ = rl(string_own($1), num(lineno)); } | SPACE { if ($1[0] == ' ' && $1[1] == 0) { val spaces = list(oneplus_s, chr(' '), nao); @@ -276,11 +277,18 @@ elem : TEXT { $$ = rl(string_own($1), num(lineno)); } free($1); } else { $$ = rl(string_own($1), num(lineno)); }} - | var { $$ = rl($1, num(lineno)); } - | list { $$ = $1; } | regex { $$ = cons(regex_compile(rest($1)), rest($1)); rl($$, num(lineno)); } + ; + +texts : text %prec LOW { $$ = rl(cons($1, nil), $1); } + | text texts { $$ = rl(cons($1, $2), $2); } + ; + +elem : texts { $$ = rl(cons(text_s, $1), $1); } + | var { $$ = rl($1, num(lineno)); } + | list { $$ = $1; } | COLL exprs_opt ')' elems END { $$ = list(coll_s, $4, nil, $2, nao); rl($$, num($1)); } | COLL exprs_opt ')' elems |