=== modified file 'aat_data.test' --- aat_data.test 2015-09-09 16:23:54 +0000 +++ aat_data.test 2015-09-03 22:01:00 +0000 @@ -1,58 +1,12 @@ ./aattest tests/data1 <<< -|BEGIN { -|print "Hello!" -|} ->>> -Hello! ->>>2 ->>>= 0 - -./aattest tests/data2 -<<< -@awk ../../data.awk -|END{ -Hello {}! -|} ---- -name=world ->>> -Hello world! ->>>2 ->>>= 0 - -./aattest tests/data3 -<<< -@awk ../../data.awk -|END{ -Hello {}! -|} ---- -name=world ->>> -Hello world! ->>>2 ->>>= 0 - -./aattest tests/data4 -<<< -@awk ../../data.awk -|END{ -Hello {}! -|} ---- ->>> -Hello everyone! ->>>2 ->>>= 0 - -./aattest tests/data5 -<<< -@awk ../../data.awk -|END{ -Hello {}! -|} ---- ->>> /Makefile:.*failed/ ->>>2 /error: undefined variable 'name'/ ->>>= 2 +@awk ../../data.awk +|END{ +Hello {}! +|} +--- +name=world +>>> +Hello world! +>>>2 +>>>= 0 === modified file 'aattest' --- aattest 2015-09-09 16:23:54 +0000 +++ aattest 2015-09-03 22:01:00 +0000 @@ -19,10 +19,7 @@ awk -f test.qawk DEBUG=\$(DEBUG) test.data >test.out test.qawk: test.awk - swipl -q -g main -s $bin:h/query.pl test.awk >test.qawk - -# test.qawk: test.awk -# awk -f $bin/query.awk test.qawk + awk -f $bin/query.awk test.qawk test.awk: test.mac sed -f $bin/aat_macros.sed test.awk === modified file 'data.awk' --- data.awk 2015-09-09 16:23:54 +0000 +++ data.awk 2015-09-03 22:01:00 +0000 @@ -136,7 +136,7 @@ function get(varname) { if(!find(varname)) { - print "error: undefined variable '"varname"'" >"/dev/stderr" + print "error: undefined variable '"$varname"'" >"/dev/stderr" exit 1 } if(DEBUG) { === modified file 'query.pl' --- query.pl 2015-09-09 16:23:54 +0000 +++ query.pl 2015-09-03 13:53:24 +0000 @@ -74,7 +74,7 @@ [H], {assertion(H \= 0'\n)}, !, awk_comment(T,R). -% awk_comment(L) --> awk_comment(L,[]). +awk_comment(L) --> awk_comment(L,[]). awk_code([0'"|T0],R,_,F) --> `"`, !, awk_string_content(T0,T1), `"`, { T1=[0'"|T2] }, awk_code(T2,R,expr,F). === modified file 'query.test' --- query.test 2015-09-09 16:23:54 +0000 +++ query.test 2015-09-03 19:57:24 +0000 @@ -1,4 +1,4 @@ -./querytest tests/query1 +./q <<< BEGIN { } @@ -8,7 +8,7 @@ >>>2 >>>= 0 -./querytest tests/query2 +./q <<< foo() >>> @@ -16,7 +16,7 @@ >>>2 >>>= 0 -./querytest tests/query3 +./q <<< x[>] = >>> @@ -24,7 +24,7 @@ >>>2 >>>= 0 -./querytest tests/query4 +./q <<< y = "" >>> @@ -32,7 +32,7 @@ >>>2 >>>= 0 -./querytest tests/query5 +./q <<< y = (y) () >>> @@ -40,7 +40,7 @@ >>>2 >>>= 0 -./querytest tests/query6 +./q <<< y = (y) () >>> @@ -48,7 +48,7 @@ >>>2 >>>= 0 -./querytest tests/query7 +./q <<< y = (y) (>) >>> @@ -56,7 +56,7 @@ >>>2 >>>= 0 -./querytest tests/query8 +./q <<< y = (y) (>>) >>> @@ -64,7 +64,7 @@ >>>2 >>>= 0 -./querytest tests/query9 +./q <<< y = (y) ( - ()'>>>) >>> @@ -72,7 +72,7 @@ >>>2 >>>= 0 -./querytest tests/query10 +./q <<< y = (y) () - ()'>>>) >>> @@ -80,7 +80,7 @@ >>>2 >>>= 0 -./querytest tests/query11 +./q <<< y = (y) () >>> @@ -88,7 +88,7 @@ >>>2 >>>= 0 -./querytest tests/query12 +./q <<< y = (y) () >>> @@ -96,370 +96,10 @@ >>>2 >>>= 0 -./querytest tests/query13 +./q <<< y = (y) () >>> y = (y) (C(get("a"))) >>>2 >>>= 0 - -./querytest tests/query14 -<<< -#!/bin/awk -f ->>> -#!/bin/awk -f ->>>2 ->>>= 0 - -./querytest tests/query15 -<<< -#!/bin/awk -f -BEGIN { - print "Hello!" -} ->>> -#!/bin/awk -f -BEGIN { - print "Hello!" -} ->>>2 ->>>= 0 - -./querytest tests/query16 -<<< -#!/bin/awk -f -BEGIN { - FS="\t" - SUBSEP="." - state = 0 - # 0 read normal variables - # 1 seen start of field list, read titles - # 2 reading list values - # ident_re = /[a-zA-Z_][a-zA-Z0-9_]*/ - ident_re = "[a-zA-Z_][a-zA-Z0-9_]*" -} ->>> -#!/bin/awk -f -BEGIN { - FS="\t" - SUBSEP="." - state = 0 - # 0 read normal variables - # 1 seen start of field list, read titles - # 2 reading list values - # ident_re = /[a-zA-Z_][a-zA-Z0-9_]*/ - ident_re = "[a-zA-Z_][a-zA-Z0-9_]*" -} ->>>2 ->>>= 0 - -./querytest tests/query17 -<<< -$0 == "]" && state == 2 { - # end of field list - state = 0 - next -} - -state == 2 { - V[varname,++V[varname,"rows"]] = $0 - next -} - -state == 1 { - if((varname, "fields") in V) { - if(V[varname,"fields"] != $0) { - print "data.awk: differing field definition for '"varname"'" >"/dev/stderr" - print "previous: '"V[varname,"fields"]"'" >"/dev/stderr" - print "current: '"$0"'" >"/dev/stderr" - exit 1 - } - } - V[varname,"fields"] = $0 - state = 2 - next -} ->>> -$0 == "]" && state == 2 { - # end of field list - state = 0 - next -} - -state == 2 { - V[varname,++V[varname,"rows"]] = $0 - next -} - -state == 1 { - if((varname, "fields") in V) { - if(V[varname,"fields"] != $0) { - print "data.awk: differing field definition for '"varname"'" >"/dev/stderr" - print "previous: '"V[varname,"fields"]"'" >"/dev/stderr" - print "current: '"$0"'" >"/dev/stderr" - exit 1 - } - } - V[varname,"fields"] = $0 - state = 2 - next -} ->>>2 ->>>=0 - -./querytest tests/query18 -<<< -/^del[ \t].*[a-zA-Z_][a-zA-Z0-9_.]$/ { - del_pattern = substr($0, 5) - for(varname in V) { - if (match(varname, del_pattern)) { - delete V[varname] - } - } -} - -/^[a-zA-Z_][a-zA-Z0-9_.]*=\[$/ { - # start of field list - state = 1 - m = match($0, ident_re) - varname = substr($0, m, RLENGTH) - next -} - -/^[a-zA-Z_][a-zA-Z0-9_.]*=/ { - m = match($0, ident_re) - varname = substr($0, m, RLENGTH) - V[varname] = substr($0, m+1+RLENGTH) - if(DEBUG) printf "got scalar: %s ⇒ %s (%d)\n", varname, V[varname], m >"/dev/stderr" - next -} - -/^\t/ { - V[varname] = V[varname] "\n" substr($0, 1) - next -} - -/^#/ { next } -/^$/ { next } ->>> -/^del[ \t].*[a-zA-Z_][a-zA-Z0-9_.]$/ { - del_pattern = substr($0, 5) - for(varname in V) { - if (match(varname, del_pattern)) { - delete V[varname] - } - } -} - -/^[a-zA-Z_][a-zA-Z0-9_.]*=\[$/ { - # start of field list - state = 1 - m = match($0, ident_re) - varname = substr($0, m, RLENGTH) - next -} - -/^[a-zA-Z_][a-zA-Z0-9_.]*=/ { - m = match($0, ident_re) - varname = substr($0, m, RLENGTH) - V[varname] = substr($0, m+1+RLENGTH) - if(DEBUG) printf "got scalar: %s ⇒ %s (%d)\n", varname, V[varname], m >"/dev/stderr" - next -} - -/^\t/ { - V[varname] = V[varname] "\n" substr($0, 1) - next -} - -/^#/ { next } -/^$/ { next } ->>>2 ->>>=0 - -./querytest tests/query19 -<<< -{ - # TODO posix compliance - print "data.awk: unparseable line: '"$0"'" >"/dev/stderr" - exit 1 -} - -function loop_start(varname, prefix, depth) { - depth = ++loop_stack["depth"] - loop_stack[depth,"row"] = 0 - loop_stack[depth,"var"] = varname - loop_stack[depth,"pre"] = prefix - return depth -} - -function loop_iter(depth) { - loop_stack[depth,"row"]++ - return (loop_stack[depth,"var"], loop_stack[depth,"row"]) in V -} - -function loop_end() { - delete loop_stack[loop_stack["depth"], "row"] - delete loop_stack[loop_stack["depth"], "var"] - delete loop_stack[loop_stack["depth"], "pre"] - loop_stack["depth"]-- -} - -function find(varname, i, n, names, values, loopvar, looprow, prefix) { - for(i=loop_stack["depth"]; i>0; i--) { - prefix = loop_stack[i, "pre"] - if(prefix) - if(substr(varname, 1, length(prefix)) != prefix) - continue - loopvar = loop_stack[i, "var"] - looprow = loop_stack[i, "row"] - if(varname == prefix"_index") - return looprow - if(varname == prefix"_index0") - return looprow - 1 - if(varname == prefix"_revindex") - return V[loopvar, "rows"] - looprow + 1 - if(varname == prefix"_revindex0") - return V[loopvar, "rows"] - looprow - if(varname == prefix"_first") - return looprow == 1 - if(varname == prefix"_last") - return looprow == V[loopvar, "rows"] - if(varname == prefix"_length") - return V[loopvar, "rows"] - split(V[loopvar, "fields"], names) - for(n in names) { - if(varname == (prefix names[n])) { - split(V[loopvar, looprow], values) - return values[n] - } - } - } - if(!(varname in V)) { - if(DEBUG) { - print "variable not found: " varname >"/dev/stderr" - } - return 0 - } - found = V[varname] - return 1 -} - -function get(varname) { - if(!find(varname)) { - print "error: undefined variable '"varname"'" >"/dev/stderr" - exit 1 - } - if(DEBUG) { - print "get →" varname "← ⇒ →"found"←" >"/dev/stderr" - } - return found -} - -function or_(a, b) { - return a ? a : b -} - -END { - if(DEBUG) { - print "--- loaded keys ---" >"/dev/stderr" - for(key in V) - printf("%s\t→%s←\t", key, V[key]) >"/dev/stderr" - printf(">> %d →%s←\n", find(key), found) >"/dev/stderr" - print "-------------------" >"/dev/stderr" - } -} ->>> -{ - # TODO posix compliance - print "data.awk: unparseable line: '"$0"'" >"/dev/stderr" - exit 1 -} - -function loop_start(varname, prefix, depth) { - depth = ++loop_stack["depth"] - loop_stack[depth,"row"] = 0 - loop_stack[depth,"var"] = varname - loop_stack[depth,"pre"] = prefix - return depth -} - -function loop_iter(depth) { - loop_stack[depth,"row"]++ - return (loop_stack[depth,"var"], loop_stack[depth,"row"]) in V -} - -function loop_end() { - delete loop_stack[loop_stack["depth"], "row"] - delete loop_stack[loop_stack["depth"], "var"] - delete loop_stack[loop_stack["depth"], "pre"] - loop_stack["depth"]-- -} - -function find(varname, i, n, names, values, loopvar, looprow, prefix) { - for(i=loop_stack["depth"]; i>0; i--) { - prefix = loop_stack[i, "pre"] - if(prefix) - if(substr(varname, 1, length(prefix)) != prefix) - continue - loopvar = loop_stack[i, "var"] - looprow = loop_stack[i, "row"] - if(varname == prefix"_index") - return looprow - if(varname == prefix"_index0") - return looprow - 1 - if(varname == prefix"_revindex") - return V[loopvar, "rows"] - looprow + 1 - if(varname == prefix"_revindex0") - return V[loopvar, "rows"] - looprow - if(varname == prefix"_first") - return looprow == 1 - if(varname == prefix"_last") - return looprow == V[loopvar, "rows"] - if(varname == prefix"_length") - return V[loopvar, "rows"] - split(V[loopvar, "fields"], names) - for(n in names) { - if(varname == (prefix names[n])) { - split(V[loopvar, looprow], values) - return values[n] - } - } - } - if(!(varname in V)) { - if(DEBUG) { - print "variable not found: " varname >"/dev/stderr" - } - return 0 - } - found = V[varname] - return 1 -} - -function get(varname) { - if(!find(varname)) { - print "error: undefined variable '"varname"'" >"/dev/stderr" - exit 1 - } - if(DEBUG) { - print "get →" varname "← ⇒ →"found"←" >"/dev/stderr" - } - return found -} - -function or_(a, b) { - return a ? a : b -} - -END { - if(DEBUG) { - print "--- loaded keys ---" >"/dev/stderr" - for(key in V) - printf("%s\t→%s←\t", key, V[key]) >"/dev/stderr" - printf(">> %d →%s←\n", find(key), found) >"/dev/stderr" - print "-------------------" >"/dev/stderr" - } -} ->>>2 ->>>= 0 === removed file 'querytest' --- querytest 2015-09-09 16:23:54 +0000 +++ querytest 1970-01-01 00:00:00 +0000 @@ -1,9 +0,0 @@ -#!/bin/zsh -dst=$1 -query=$0:h:a/query.pl -[[ -d $dst ]] && rm -r $dst -mkdir -p $dst || exit $? - -cat >$dst/test.qawk || exit $? - -exec swipl -q -g main -s $query $dst/test.qawk