From 35eb4dbc80f857007f99278c48e22f8557e13b68 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 13 Oct 2011 08:41:56 -0700 Subject: * Makefile (%.ok: %.txr): Use unified diff for showing differences between expected and actual test output. * parser.l (yybadtoken): Handle new terminal symbol, SPACE. New rule for producing SPACE token out of an extent of tabs and spaces. * parser.y (SPACE): New terminal symbol. (o_var): New nonterminal. I noticed that the var rule was being used for output elements, and the var rule refers to elem rather than o_elem. A new o_var rule is a simplified duplicate of var. (elem): Handle SPACE token. Transform to regex if it is a single space, otherwise to literal text. (o_elem): Handle SPACE token in output. * tests/001/query-2.txr: This query depends on matching single spaces and so needs to use escapes. * tests/001/query-4.txr, test/001/query-4.expected: New test case, based on query-2.txr. It produces the same output, but is simpler thanks to the new semantics of space. * txr.1: Documented. --- ChangeLog | 27 ++ Makefile | 2 +- parser.l | 8 +- parser.y | 40 ++- tests/001/query-2.txr | 2 +- tests/001/query-4.expected | 696 +++++++++++++++++++++++++++++++++++++++++++++ tests/001/query-4.txr | 7 + txr.1 | 27 +- 8 files changed, 800 insertions(+), 9 deletions(-) create mode 100644 tests/001/query-4.expected create mode 100644 tests/001/query-4.txr diff --git a/ChangeLog b/ChangeLog index 4f7746d3..173f64e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2011-10-13 Kaz Kylheku + + * Makefile (%.ok: %.txr): Use unified diff for showing + differences between expected and actual test output. + + * parser.l (yybadtoken): Handle new terminal symbol, SPACE. + New rule for producing SPACE token out of an extent of + tabs and spaces. + + * parser.y (SPACE): New terminal symbol. + (o_var): New nonterminal. I noticed that the var rule was + being used for output elements, and the var rule refers to + elem rather than o_elem. A new o_var rule is a simplified + duplicate of var. + (elem): Handle SPACE token. Transform to regex if it is + a single space, otherwise to literal text. + (o_elem): Handle SPACE token in output. + + * tests/001/query-2.txr: This query depends on matching + single spaces and so needs to use escapes. + + * tests/001/query-4.txr, test/001/query-4.expected: New test + case, based on query-2.txr. It produces the same output, + but is simpler thanks to the new semantics of space. + + * txr.1: Documented. + 2011-10-12 Kaz Kylheku Bug #34538 diff --git a/Makefile b/Makefile index c18fc9ec..fa62e9fb 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,7 @@ tests/002/%: TXR_SCRIPT_ON_CMDLINE := y $(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) -c "$$(cat $^)" \ $(TXR_ARGS) > $(@:.ok=.out),\ $(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) $^ $(TXR_ARGS) > $(@:.ok=.out)) - diff $(^:.txr=.expected) $(@:.ok=.out) + diff -u $(^:.txr=.expected) $(@:.ok=.out) %.expected: %.txr $(PROG) $(TXR_OPTS) $^ $(TXR_ARGS) > $@ diff --git a/parser.l b/parser.l index c9c39764..af450f95 100644 --- a/parser.l +++ b/parser.l @@ -92,6 +92,7 @@ void yybadtoken(int tok, val context) val problem = nil; switch (tok) { + case SPACE: problem = lit("space"); break; case TEXT: problem = lit("text"); break; case IDENT: problem = lit("identifier"); break; case KEYWORD: problem = lit("keyword"); break; @@ -511,7 +512,12 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} num((unsigned char) yytext[0]), nao); } -({UONLY}|[^@\n])+ { +[ ]+ { + yylval.lexeme = utf8_dup_from(yytext); + return SPACE; + } + +({UONLY}|[^@\n ])+ { yylval.lexeme = utf8_dup_from(yytext); return TEXT; } diff --git a/parser.y b/parser.y index 96fec8f6..b814c1d6 100644 --- a/parser.y +++ b/parser.y @@ -58,11 +58,14 @@ static val parsed_spec; cnum num; } -%token TEXT IDENT KEYWORD METAVAR ALL SOME NONE MAYBE CASES CHOOSE +%token SPACE TEXT IDENT KEYWORD METAVAR +%token ALL SOME NONE MAYBE CASES CHOOSE %token AND OR END COLLECT %token UNTIL COLL OUTPUT REPEAT REP SINGLE FIRST LAST EMPTY DEFINE %token TRY CATCH FINALLY + %token NUMBER + %token REGCHAR LITCHAR %token METAPAR @@ -75,16 +78,17 @@ static val parsed_spec; %type elem var var_op meta_expr %type list exprs exprs_opt expr out_clauses out_clauses_opt out_clause %type repeat_clause repeat_parts_opt o_line -%type o_elems_opt o_elems_opt2 o_elems o_elem rep_elem rep_parts_opt +%type o_elems_opt o_elems_opt2 o_elems o_elem o_var rep_elem rep_parts_opt %type regex regexpr regbranch %type regterm regclass regclassterm regrange %type strlit chrlit quasilit quasi_items quasi_item litchars %type regchar + %nonassoc LOW /* used for precedence assertion */ %nonassoc ALL SOME NONE MAYBE CASES CHOOSE AND OR END COLLECT UNTIL COLL %nonassoc OUTPUT REPEAT REP FIRST LAST EMPTY DEFINE %nonassoc '[' ']' '(' ')' -%right IDENT TEXT NUMBER '{' '}' +%right IDENT SPACE TEXT NUMBER '{' '}' %left '-' %left '|' '/' %left '&' @@ -220,6 +224,15 @@ elems : elem { $$ = cons($1, nil); } ; elem : TEXT { $$ = string_own($1); } + | SPACE { if ($1[0] == ' ' && $1[1] == 0) + { val spaces = list(oneplus_s, + list(set_s, chr(' '), + chr('\t'), nao), + nao); + $$ = cons(regex_compile(spaces), spaces); + free($1); } + else + { $$ = string_own($1); }} | var { $$ = $1; } | list { $$ = $1; } | regex { $$ = cons(regex_compile(rest($1)), @@ -423,7 +436,8 @@ o_elems : o_elem { $$ = cons($1, nil); } ; o_elem : TEXT { $$ = string_own($1); } - | var { $$ = $1; } + | SPACE { $$ = string_own($1); } + | o_var { $$ = $1; } | rep_elem { $$ = $1; } ; @@ -483,6 +497,23 @@ var : IDENT { $$ = list(var_s, intern(string_own($1), nil), yybadtoken(yychar, lit("variable spec")); } ; +o_var : IDENT { $$ = list(var_s, intern(string_own($1), nil), + nao); } + | IDENT o_elem { $$ = list(var_s, intern(string_own($1), nil), + $2, nao); } + | '{' IDENT '}' { $$ = list(var_s, intern(string_own($2), nil), + nao); } + | '{' IDENT '}' o_elem { $$ = list(var_s, intern(string_own($2), nil), + $4, nao); } + | '{' IDENT exprs '}' { $$ = list(var_s, intern(string_own($2), nil), + nil, $3, nao); } + | '{' IDENT exprs '}' o_elem { $$ = list(var_s, + intern(string_own($2), nil), + $5, $3, nao); } + | IDENT error { $$ = nil; + yybadtoken(yychar, lit("variable spec")); } + ; + var_op : '*' { $$ = list(t, nao); } ; @@ -632,7 +663,6 @@ litchars : LITCHAR { $$ = cons(chr($1), nil); } | LITCHAR litchars { $$ = cons(chr($1), $2); } ; - %% val repeat_rep_helper(val sym, val main, val parts) diff --git a/tests/001/query-2.txr b/tests/001/query-2.txr index c040ca9f..3682284d 100644 --- a/tests/001/query-2.txr +++ b/tests/001/query-2.txr @@ -3,5 +3,5 @@ @# It was authored by Kaz Kylheku in 2009 @# @(collect) -@{UID 8} @{PID 5} @{PPID 5} @{C 1} @{STIME 5} @{TTY 8} @{TIME 8} @CMD +@{UID 8}@\ @{PID 5}@\ @{PPID 5}@\ @\ @{C 1}@\ @{STIME 5}@\ @{TTY 8}@\ @{TIME 8}@\ @CMD @(end) diff --git a/tests/001/query-4.expected b/tests/001/query-4.expected new file mode 100644 index 00000000..90f363ce --- /dev/null +++ b/tests/001/query-4.expected @@ -0,0 +1,696 @@ +UID[0]="UID" +UID[1]="root" +UID[2]="root" +UID[3]="root" +UID[4]="root" +UID[5]="root" +UID[6]="root" +UID[7]="root" +UID[8]="root" +UID[9]="root" +UID[10]="root" +UID[11]="root" +UID[12]="root" +UID[13]="root" +UID[14]="root" +UID[15]="root" +UID[16]="root" +UID[17]="root" +UID[18]="root" +UID[19]="rpc" +UID[20]="rpcuser" +UID[21]="root" +UID[22]="root" +UID[23]="root" +UID[24]="root" +UID[25]="root" +UID[26]="root" +UID[27]="root" +UID[28]="root" +UID[29]="root" +UID[30]="root" +UID[31]="root" +UID[32]="root" +UID[33]="root" +UID[34]="root" +UID[35]="root" +UID[36]="root" +UID[37]="root" +UID[38]="root" +UID[39]="root" +UID[40]="root" +UID[41]="xfs" +UID[42]="daemon" +UID[43]="dbus" +UID[44]="root" +UID[45]="root" +UID[46]="root" +UID[47]="root" +UID[48]="root" +UID[49]="root" +UID[50]="kaz" +UID[51]="kaz" +UID[52]="kaz" +UID[53]="kaz" +UID[54]="kaz" +UID[55]="kaz" +UID[56]="kaz" +UID[57]="kaz" +UID[58]="kaz" +UID[59]="kaz" +UID[60]="kaz" +UID[61]="kaz" +UID[62]="kaz" +UID[63]="kaz" +UID[64]="kaz" +UID[65]="kaz" +UID[66]="kaz" +UID[67]="kaz" +UID[68]="root" +UID[69]="kaz" +UID[70]="kaz" +UID[71]="kaz" +UID[72]="kaz" +UID[73]="kaz" +UID[74]="root" +UID[75]="root" +UID[76]="kaz" +UID[77]="kaz" +UID[78]="root" +UID[79]="kaz" +UID[80]="kaz" +UID[81]="root" +UID[82]="root" +UID[83]="root" +UID[84]="kaz" +UID[85]="kaz" +UID[86]="kaz" +PID[0]="PID" +PID[1]="1" +PID[2]="2" +PID[3]="3" +PID[4]="4" +PID[5]="5" +PID[6]="16" +PID[7]="29" +PID[8]="17" +PID[9]="28" +PID[10]="103" +PID[11]="175" +PID[12]="186" +PID[13]="870" +PID[14]="1068" +PID[15]="1235" +PID[16]="1236" +PID[17]="1620" +PID[18]="1624" +PID[19]="1645" +PID[20]="1665" +PID[21]="1698" +PID[22]="1766" +PID[23]="1790" +PID[24]="1791" +PID[25]="1821" +PID[26]="1839" +PID[27]="1851" +PID[28]="1887" +PID[29]="1902" +PID[30]="1921" +PID[31]="1925" +PID[32]="1926" +PID[33]="1927" +PID[34]="1928" +PID[35]="1929" +PID[36]="1930" +PID[37]="1931" +PID[38]="1932" +PID[39]="1936" +PID[40]="1963" +PID[41]="1989" +PID[42]="2008" +PID[43]="2027" +PID[44]="2041" +PID[45]="2052" +PID[46]="2062" +PID[47]="2124" +PID[48]="2184" +PID[49]="2354" +PID[50]="2551" +PID[51]="2579" +PID[52]="2625" +PID[53]="2626" +PID[54]="2631" +PID[55]="2634" +PID[56]="2636" +PID[57]="2638" +PID[58]="2644" +PID[59]="2661" +PID[60]="2685" +PID[61]="2689" +PID[62]="2691" +PID[63]="2693" +PID[64]="2695" +PID[65]="2698" +PID[66]="2701" +PID[67]="2707" +PID[68]="2717" +PID[69]="2718" +PID[70]="2720" +PID[71]="2722" +PID[72]="2726" +PID[73]="2728" +PID[74]="30737" +PID[75]="31905" +PID[76]="31907" +PID[77]="31908" +PID[78]="32672" +PID[79]="32674" +PID[80]="32675" +PID[81]="27121" +PID[82]="27243" +PID[83]="27682" +PID[84]="27684" +PID[85]="27685" +PID[86]="6481" +PPID[0]="PPID" +PPID[1]="0" +PPID[2]="1" +PPID[3]="1" +PPID[4]="3" +PPID[5]="3" +PPID[6]="3" +PPID[7]="3" +PPID[8]="1" +PPID[9]="1" +PPID[10]="1" +PPID[11]="1" +PPID[12]="1" +PPID[13]="1" +PPID[14]="1" +PPID[15]="1" +PPID[16]="1" +PPID[17]="1" +PPID[18]="1" +PPID[19]="1" +PPID[20]="1" +PPID[21]="1" +PPID[22]="1" +PPID[23]="1" +PPID[24]="1" +PPID[25]="1" +PPID[26]="1" +PPID[27]="1" +PPID[28]="1" +PPID[29]="1" +PPID[30]="1" +PPID[31]="1" +PPID[32]="1" +PPID[33]="1" +PPID[34]="1" +PPID[35]="1" +PPID[36]="1" +PPID[37]="1" +PPID[38]="1" +PPID[39]="1" +PPID[40]="1" +PPID[41]="1" +PPID[42]="1" +PPID[43]="1" +PPID[44]="1" +PPID[45]="1" +PPID[46]="1" +PPID[47]="1" +PPID[48]="2124" +PPID[49]="2184" +PPID[50]="2184" +PPID[51]="1" +PPID[52]="1" +PPID[53]="1" +PPID[54]="1" +PPID[55]="1" +PPID[56]="1" +PPID[57]="1" +PPID[58]="1" +PPID[59]="1" +PPID[60]="1" +PPID[61]="1" +PPID[62]="1" +PPID[63]="1" +PPID[64]="1" +PPID[65]="1" +PPID[66]="1" +PPID[67]="1" +PPID[68]="2701" +PPID[69]="1" +PPID[70]="1" +PPID[71]="1" +PPID[72]="1" +PPID[73]="1" +PPID[74]="1" +PPID[75]="1887" +PPID[76]="31905" +PPID[77]="31907" +PPID[78]="1887" +PPID[79]="32672" +PPID[80]="32674" +PPID[81]="3" +PPID[82]="3" +PPID[83]="1887" +PPID[84]="27682" +PPID[85]="27684" +PPID[86]="27685" +C[0]="C" +C[1]="0" +C[2]="0" +C[3]="0" +C[4]="0" +C[5]="0" +C[6]="0" +C[7]="0" +C[8]="0" +C[9]="0" +C[10]="0" +C[11]="0" +C[12]="0" +C[13]="0" +C[14]="0" +C[15]="0" +C[16]="0" +C[17]="0" +C[18]="0" +C[19]="0" +C[20]="0" +C[21]="0" +C[22]="0" +C[23]="0" +C[24]="0" +C[25]="0" +C[26]="0" +C[27]="0" +C[28]="0" +C[29]="0" +C[30]="0" +C[31]="0" +C[32]="0" +C[33]="0" +C[34]="0" +C[35]="0" +C[36]="0" +C[37]="0" +C[38]="0" +C[39]="0" +C[40]="0" +C[41]="0" +C[42]="0" +C[43]="0" +C[44]="0" +C[45]="0" +C[46]="0" +C[47]="0" +C[48]="0" +C[49]="1" +C[50]="0" +C[51]="0" +C[52]="0" +C[53]="0" +C[54]="0" +C[55]="0" +C[56]="0" +C[57]="0" +C[58]="0" +C[59]="0" +C[60]="0" +C[61]="0" +C[62]="0" +C[63]="0" +C[64]="0" +C[65]="0" +C[66]="0" +C[67]="1" +C[68]="0" +C[69]="0" +C[70]="0" +C[71]="0" +C[72]="0" +C[73]="0" +C[74]="0" +C[75]="0" +C[76]="0" +C[77]="0" +C[78]="0" +C[79]="0" +C[80]="0" +C[81]="0" +C[82]="0" +C[83]="0" +C[84]="0" +C[85]="0" +C[86]="0" +STIME[0]="STIME" +STIME[1]="Aug21" +STIME[2]="Aug21" +STIME[3]="Aug21" +STIME[4]="Aug21" +STIME[5]="Aug21" +STIME[6]="Aug21" +STIME[7]="Aug21" +STIME[8]="Aug21" +STIME[9]="Aug21" +STIME[10]="Aug21" +STIME[11]="Aug21" +STIME[12]="Aug21" +STIME[13]="Aug21" +STIME[14]="Aug21" +STIME[15]="Aug21" +STIME[16]="Aug21" +STIME[17]="Aug21" +STIME[18]="Aug21" +STIME[19]="Aug21" +STIME[20]="Aug21" +STIME[21]="Aug21" +STIME[22]="Aug21" +STIME[23]="Aug21" +STIME[24]="Aug21" +STIME[25]="Aug21" +STIME[26]="Aug21" +STIME[27]="Aug21" +STIME[28]="Aug21" +STIME[29]="Aug21" +STIME[30]="Aug21" +STIME[31]="Aug21" +STIME[32]="Aug21" +STIME[33]="Aug21" +STIME[34]="Aug21" +STIME[35]="Aug21" +STIME[36]="Aug21" +STIME[37]="Aug21" +STIME[38]="Aug21" +STIME[39]="Aug21" +STIME[40]="Aug21" +STIME[41]="Aug21" +STIME[42]="Aug21" +STIME[43]="Aug21" +STIME[44]="Aug21" +STIME[45]="Aug21" +STIME[46]="Aug21" +STIME[47]="Aug21" +STIME[48]="Aug21" +STIME[49]="Aug21" +STIME[50]="Aug21" +STIME[51]="Aug21" +STIME[52]="Aug21" +STIME[53]="Aug21" +STIME[54]="Aug21" +STIME[55]="Aug21" +STIME[56]="Aug21" +STIME[57]="Aug21" +STIME[58]="Aug21" +STIME[59]="Aug21" +STIME[60]="Aug21" +STIME[61]="Aug21" +STIME[62]="Aug21" +STIME[63]="Aug21" +STIME[64]="Aug21" +STIME[65]="Aug21" +STIME[66]="Aug21" +STIME[67]="Aug21" +STIME[68]="Aug21" +STIME[69]="Aug21" +STIME[70]="Aug21" +STIME[71]="Aug21" +STIME[72]="Aug21" +STIME[73]="Aug21" +STIME[74]="Aug26" +STIME[75]="Aug27" +STIME[76]="Aug27" +STIME[77]="Aug27" +STIME[78]="Aug27" +STIME[79]="Aug27" +STIME[80]="Aug27" +STIME[81]="Sep12" +STIME[82]="Sep12" +STIME[83]="Sep12" +STIME[84]="Sep12" +STIME[85]="Sep12" +STIME[86]="17:47" +TTY[0]="TTY" +TTY[1]="?" +TTY[2]="?" +TTY[3]="?" +TTY[4]="?" +TTY[5]="?" +TTY[6]="?" +TTY[7]="?" +TTY[8]="?" +TTY[9]="?" +TTY[10]="?" +TTY[11]="?" +TTY[12]="?" +TTY[13]="?" +TTY[14]="?" +TTY[15]="?" +TTY[16]="?" +TTY[17]="?" +TTY[18]="?" +TTY[19]="?" +TTY[20]="?" +TTY[21]="?" +TTY[22]="?" +TTY[23]="?" +TTY[24]="?" +TTY[25]="?" +TTY[26]="?" +TTY[27]="?" +TTY[28]="?" +TTY[29]="?" +TTY[30]="?" +TTY[31]="?" +TTY[32]="?" +TTY[33]="?" +TTY[34]="?" +TTY[35]="?" +TTY[36]="?" +TTY[37]="?" +TTY[38]="?" +TTY[39]="?" +TTY[40]="?" +TTY[41]="?" +TTY[42]="?" +TTY[43]="?" +TTY[44]="?" +TTY[45]="?" +TTY[46]="tty1" +TTY[47]="?" +TTY[48]="?" +TTY[49]="?" +TTY[50]="?" +TTY[51]="?" +TTY[52]="?" +TTY[53]="?" +TTY[54]="?" +TTY[55]="?" +TTY[56]="?" +TTY[57]="?" +TTY[58]="?" +TTY[59]="?" +TTY[60]="?" +TTY[61]="?" +TTY[62]="?" +TTY[63]="?" +TTY[64]="?" +TTY[65]="?" +TTY[66]="?" +TTY[67]="?" +TTY[68]="?" +TTY[69]="?" +TTY[70]="?" +TTY[71]="?" +TTY[72]="?" +TTY[73]="?" +TTY[74]="?" +TTY[75]="?" +TTY[76]="?" +TTY[77]="pts/2" +TTY[78]="?" +TTY[79]="?" +TTY[80]="pts/4" +TTY[81]="?" +TTY[82]="?" +TTY[83]="?" +TTY[84]="?" +TTY[85]="pts/1" +TTY[86]="pts/1" +TIME[0]="TIME" +TIME[1]="00:01:11" +TIME[2]="00:00:00" +TIME[3]="00:01:23" +TIME[4]="00:00:00" +TIME[5]="00:00:00" +TIME[6]="00:00:00" +TIME[7]="00:00:00" +TIME[8]="00:00:00" +TIME[9]="00:00:06" +TIME[10]="00:00:00" +TIME[11]="00:00:00" +TIME[12]="00:04:49" +TIME[13]="00:00:00" +TIME[14]="00:00:00" +TIME[15]="00:00:00" +TIME[16]="00:00:09" +TIME[17]="00:00:16" +TIME[18]="00:00:00" +TIME[19]="00:00:08" +TIME[20]="00:00:00" +TIME[21]="00:00:07" +TIME[22]="00:05:17" +TIME[23]="00:00:23" +TIME[24]="00:00:00" +TIME[25]="00:00:00" +TIME[26]="00:00:00" +TIME[27]="00:01:33" +TIME[28]="00:00:00" +TIME[29]="00:00:00" +TIME[30]="00:00:00" +TIME[31]="00:00:00" +TIME[32]="00:00:00" +TIME[33]="00:00:00" +TIME[34]="00:00:00" +TIME[35]="00:00:00" +TIME[36]="00:00:00" +TIME[37]="00:00:00" +TIME[38]="00:00:00" +TIME[39]="00:00:00" +TIME[40]="00:00:29" +TIME[41]="00:00:01" +TIME[42]="00:00:03" +TIME[43]="00:00:00" +TIME[44]="00:00:00" +TIME[45]="00:05:00" +TIME[46]="00:00:00" +TIME[47]="00:00:00" +TIME[48]="00:00:00" +TIME[49]="12:18:15" +TIME[50]="00:00:01" +TIME[51]="00:00:00" +TIME[52]="00:00:00" +TIME[53]="00:00:00" +TIME[54]="00:00:47" +TIME[55]="00:00:00" +TIME[56]="00:00:00" +TIME[57]="00:00:00" +TIME[58]="00:13:10" +TIME[59]="00:01:18" +TIME[60]="00:00:00" +TIME[61]="00:00:02" +TIME[62]="00:27:25" +TIME[63]="00:00:00" +TIME[64]="00:00:37" +TIME[65]="00:00:00" +TIME[66]="00:01:31" +TIME[67]="11:09:59" +TIME[68]="00:02:30" +TIME[69]="00:00:05" +TIME[70]="00:00:00" +TIME[71]="00:14:36" +TIME[72]="00:43:09" +TIME[73]="00:00:00" +TIME[74]="00:00:00" +TIME[75]="00:00:06" +TIME[76]="00:00:55" +TIME[77]="00:00:01" +TIME[78]="00:00:06" +TIME[79]="00:02:11" +TIME[80]="00:00:06" +TIME[81]="00:00:00" +TIME[82]="00:00:31" +TIME[83]="00:00:03" +TIME[84]="00:09:06" +TIME[85]="00:00:26" +TIME[86]="00:00:00" +CMD[0]="CMD" +CMD[1]="init [5] " +CMD[2]="[ksoftirqd/0]" +CMD[3]="[events/0]" +CMD[4]="[khelper]" +CMD[5]="[kacpid]" +CMD[6]="[kblockd/0]" +CMD[7]="[aio/0]" +CMD[8]="[khubd]" +CMD[9]="[kswapd0]" +CMD[10]="[kseriod]" +CMD[11]="[scsi_eh_0]" +CMD[12]="[kjournald]" +CMD[13]="udevd" +CMD[14]="/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-eth0.leases -pf /var/run/dhclient-eth0.pid eth0" +CMD[15]="[kjournald]" +CMD[16]="[kjournald]" +CMD[17]="syslogd -m 0" +CMD[18]="klogd -x" +CMD[19]="portmap" +CMD[20]="rpc.statd" +CMD[21]="rpc.idmapd" +CMD[22]="/usr/sbin/vmware-guestd --background /var/run/vmware-guestd.pid" +CMD[23]="[rpciod]" +CMD[24]="[lockd]" +CMD[25]="ypbind" +CMD[26]="/usr/sbin/acpid" +CMD[27]="cupsd" +CMD[28]="/usr/sbin/sshd" +CMD[29]="xinetd -stayalive -pidfile /var/run/xinetd.pid" +CMD[30]="rpc.rquotad" +CMD[31]="[nfsd]" +CMD[32]="[nfsd]" +CMD[33]="[nfsd]" +CMD[34]="[nfsd]" +CMD[35]="[nfsd]" +CMD[36]="[nfsd]" +CMD[37]="[nfsd]" +CMD[38]="[nfsd]" +CMD[39]="rpc.mountd" +CMD[40]="crond" +CMD[41]="xfs -droppriv -daemon" +CMD[42]="/usr/sbin/atd" +CMD[43]="dbus-daemon-1 --system" +CMD[44]="cups-config-daemon" +CMD[45]="hald" +CMD[46]="/sbin/mingetty tty1" +CMD[47]="/usr/bin/gdm-binary -nodaemon" +CMD[48]="/usr/bin/gdm-binary -nodaemon" +CMD[49]="/usr/X11R6/bin/X :0 -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7" +CMD[50]="/usr/bin/gnome-session" +CMD[51]="/usr/bin/ssh-agent -s" +CMD[52]="/usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients" +CMD[53]="dbus-daemon-1 --fork --print-pid 8 --print-address 6 --session" +CMD[54]="/usr/libexec/gconfd-2 11" +CMD[55]="/usr/bin/gnome-keyring-daemon" +CMD[56]="/usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=18" +CMD[57]="/usr/libexec/gnome-settings-daemon --oaf-activate-iid=OAFIID:GNOME_SettingsDaemon --oaf-ior-fd=22" +CMD[58]="/usr/libexec/gam_server" +CMD[59]="xscreensaver -nosplash" +CMD[60]="/usr/bin/metacity --sm-client-id=default1" +CMD[61]="gnome-panel --sm-client-id default2" +CMD[62]="nautilus --no-default-window --sm-client-id default3" +CMD[63]="gnome-volume-manager --sm-client-id default6" +CMD[64]="eggcups --sm-client-id default5" +CMD[65]="/usr/libexec/gnome-vfs-daemon --oaf-activate-iid=OAFIID:GNOME_VFS_Daemon_Factory --oaf-ior-fd=28" +CMD[66]="pam-panel-icon --sm-client-id default0" +CMD[67]="/usr/bin/python /usr/bin/rhn-applet-gui --sm-client-id default4" +CMD[68]="/sbin/pam_timestamp_check -d root" +CMD[69]="/usr/libexec/mapping-daemon" +CMD[70]="/usr/libexec/wnck-applet --oaf-activate-iid=OAFIID:GNOME_Wncklet_Factory --oaf-ior-fd=30" +CMD[71]="/usr/libexec/mixer_applet2 --oaf-activate-iid=OAFIID:GNOME_MixerApplet_Factory --oaf-ior-fd=32" +CMD[72]="/usr/libexec/clock-applet --oaf-activate-iid=OAFIID:GNOME_ClockApplet_Factory --oaf-ior-fd=34" +CMD[73]="/usr/libexec/notification-area-applet --oaf-activate-iid=OAFIID:GNOME_NotificationAreaApplet_Factory --oaf-ior-fd=36" +CMD[74]="/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-eth0.leases -pf /var/run/dhclient-eth0.pid eth0" +CMD[75]="sshd: kaz [priv] " +CMD[76]="sshd: kaz@pts/2 " +CMD[77]="-bash" +CMD[78]="sshd: kaz [priv] " +CMD[79]="sshd: kaz@pts/4 " +CMD[80]="-bash" +CMD[81]="[pdflush]" +CMD[82]="[pdflush]" +CMD[83]="sshd: kaz [priv] " +CMD[84]="sshd: kaz@pts/1 " +CMD[85]="-bash" +CMD[86]="ps -ef" diff --git a/tests/001/query-4.txr b/tests/001/query-4.txr new file mode 100644 index 00000000..04a04cd7 --- /dev/null +++ b/tests/001/query-4.txr @@ -0,0 +1,7 @@ +@# +@# This file is in the public domain. +@# It was authored by Kaz Kylheku in 2011 +@# +@(collect) +@UID @PID @PPID @C @STIME @TTY @TIME @CMD +@(end) diff --git a/txr.1 b/txr.1 index b9dbe78b..e88dd7bf 100644 --- a/txr.1 +++ b/txr.1 @@ -32,7 +32,7 @@ txr \- text extractor (version 039) is a query tool for extracting pieces of text buried in one or more text file based on pattern matching. A .B txr -query specifies a pattern which matches (a prefix of) entire file, or +query specifies a pattern which matches (a prefix of) an entire file, or multiple files. The pattern is matched against the material in the files, and free variables occurring in the pattern are bound to the pieces of text occurring in the corresponding positions. If the overall match is @@ -312,6 +312,31 @@ However, if the hash bang line can use the -f option: Now, the name of the script is passed as an argument to the -f option, and txr will look for more options after that. +.SS Whitespace + +Outside of directives, whitespace is significant in TXR queries, and represents +a pattern match for whitespace in the input. An extent of text consisting of +an undivided mixture of tabs and spaces is a whitespace token. + +Whitespace tokens match a precisely identical piece of whitespace in the input, +with one exception: a whitespace token consisting of precisely one space has a +special meaning. It is equivalent to the regular expression @/[ \t]+/: match +one or more tabs or spaces. + +Thus, the query line "a b" (one space) matches texts like "a b", "a b", et +cetera (arbitrary number of tabs and spaces between a and b). However "a b" +(two spaces) matches only "a b" (two spaces). + +For matching a single space, the syntax @\ can be used (backslash-escaped +space). + +It is more often necessary to match multiple spaces, than to exactly +match one space, so this rule simplifies many queries and adds inconvenience +to only few. + +In output clauses, string and character literals and quasiliterals, a space +token denotes a space. + .SS Text Query material which is not escaped by the special character @ is -- cgit v1.2.3