aat

git mirror of https://ccx.te2000.cz/bzr/aat
git clone https://ccx.te2000.cz/git/aat
Log | Files | Refs | README

commit 3ce424494e0ed622fc2617efbd02cbf61695c3ec
parent 643d7ff61660609a7f0c9988428edef286dd8dbf
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Wed, 11 Sep 2013 23:26:09 +0000

WIP data reader
Diffstat:
Adata | 6++++++
Adata.awk | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ahello2.aat | 9+++++++++
3 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/data b/data @@ -0,0 +1,6 @@ +foo=bar +spam=[ +name value eggs +hello world 12 +fish thanks 42 +] diff --git a/data.awk b/data.awk @@ -0,0 +1,54 @@ +#!/bin/awk -f +BEGIN { + IFS="\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_]*/ +} + +$0 == "]" && state == 2 { + # end of field list + state = 0 + next +} + +state == 2 { + V[varname,list_n++] = $0 + next +} + +state == 1 { + V[varname,"fields"] = $0 + list_n = 1 + next +} + +/[a-zA-Z_][a-zA-Z0-9_]*=\[$/ { + # start of field list + state = 1 + m = match(ident_re) + varname = substr($0, m, RLENGTH) + next +} + +/[a-zA-Z_][a-zA-Z0-9_]*=/ { + m = match(ident_re) + varname = substr($0, m, RLENGTH) + V[varname] = substr($0, m+1+RLENGTH) + next +} + +/\t/ { + V[varname] = V[varname] "\n" substr($0, 1) +} + +# TODO error + +END { + for(key in V) { + printf("s\ts\n", key, V[key]) + } +} diff --git a/hello2.aat b/hello2.aat @@ -0,0 +1,9 @@ +|!/bin/awk -f +|BEGIN { +| split("Jack Joe Jonathan", names) +| FOR name IN names +Hello {{name}}{{is_last ? "!" : ","}} +| ENDFOR + +Welcome to the world of {{toupper("awk")}} templating! +|}