./querytest tests/query1 <<< BEGIN { } >>> BEGIN { } >>>2 >>>= 0 ./querytest tests/query2 <<< foo() >>> foo(get("bar")) >>>2 >>>= 0 ./querytest tests/query3 <<< x[>] = >>> x[get("y"get("z"))] = get("a"(b())) >>>2 >>>= 0 ./querytest tests/query4 <<< y = "" >>> y = "" >>>2 >>>= 0 ./querytest tests/query5 <<< y = (y) () >>> y = (y) ((find("c")?found:"")) >>>2 >>>= 0 ./querytest tests/query6 <<< y = (y) () >>> y = (y) ((find("d")?found:(0))) >>>2 >>>= 0 ./querytest tests/query7 <<< y = (y) (>) >>> y = (y) ((find("e")?found:get("f"))) >>>2 >>>= 0 ./querytest tests/query8 <<< y = (y) (>>) >>> y = (y) ((find("g")?found:(find("h")?found:get("i")))) >>>2 >>>= 0 ./querytest tests/query9 <<< y = (y) ( - ()'>>>) >>> y = (y) ((find("g")?found:(find("h")?found:(find("i")?found:(get("j") - ((find("k")?found:(0)))))))) >>>2 >>>= 0 ./querytest tests/query10 <<< y = (y) () - ()'>>>) >>> y = (y) ((find("g")?found:(find("h")?found:(find("i")?found:((get("j")) - ((find("k")?found:(0)))))))) >>>2 >>>= 0 ./querytest tests/query11 <<< y = (y) () >>> y = (y) ((find("a")?C(found):("r\n"))) >>>2 >>>= 0 ./querytest tests/query12 <<< y = (y) () >>> y = (y) ((find("a")?C(found):"r\n")) >>>2 >>>= 0 ./querytest tests/query13 <<< 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 ./querytest tests/query20 <<< # start @awk /home/ccx/.local/bzr/aat/data.awk {{{ #!/bin/awk -f BEGIN { } # }}} end @awk /home/ccx/.local/bzr/aat/data.awk # START: bar/inherit/example/data.aat END{ printf "%s", "hostname=" () "\n" } # END: bar/inherit/example/data.aat >>> # start @awk /home/ccx/.local/bzr/aat/data.awk {{{ #!/bin/awk -f BEGIN { } # }}} end @awk /home/ccx/.local/bzr/aat/data.awk # START: bar/inherit/example/data.aat END{ printf "%s", "hostname=" ((find("hostname")?found:"localhost")) "\n" } # END: bar/inherit/example/data.aat >>>2 >>>= 0 ./querytest tests/query21 <<< if(DEBUG) printf "got scalar: %s ⇒ %s (%d)\n", varname, V[varname], m >"/dev/stderr" >>> if(DEBUG) printf "got scalar: %s ⇒ %s (%d)\n", varname, V[varname], m >"/dev/stderr" >>>2 >>>= 0 ./querytest tests/query22 <<< printf "%s", (ifdir) "/" (int_args[n]) " " () "\n" >>> printf "%s", (ifdir) "/" (int_args[n]) " " ((find("int."(int_args[n]))?C(found):"r")) "\n" >>>2 >>>= 0 ./querytest tests/query23 <<< printf "%s", (vsdir) "/shellͺ " () "\n" >>> printf "%s", (vsdir) "/shellͺ " ((find("vs.shell")?C(found):"r")) "\n" >>>2 >>>= 0