Awk to Awk Templates; allows you to insert awk control code into plain text and generate awk script to print out the text. This project started as simple cheetah-like command and expression inclusion in text file and I'm working my way to more featured and extensible approach inspired by jinja2 so the amount of raw code that needs to be inserted is kept at minimum. Currently implemented syntax: any text not matching syntax below is printed out (a print statement will be generated in the resulting script) | lines starting with | are considered awk code and are expressed verbatim in resulting script || escape for above syntax, prints text out with one bar prepended @ special command to affect how the code is generated. user-defined macros should be possible @@ escape for above syntax, prints text out with one at prepended ... {% %} ... similar to | but works as a block, doesn't have to happen at column 0 ... {{}} ... inserts awk expression into the print command. Eg. a variable or result of computation Unimplemented: ... {} ... ... {} ... handling similar to jinja2. pass string to user-defined function, possibly define more functions to process it afterwards ... {@macro@} ... maybe? or perhaps just {% @macro %} to avoid yet another syntax ... {##} ... Implemented macros: @include Macro to recursively parse another template @awk Macro to insert another file as verbatim code @text Macro to insert another file as text Implemented macros via external postprocesor: @for in @for var @endfor helper for data.awk loops Unimplemented macros: @function set function to process {<...>} with @out @out > @out make the output be printed to stdout, specific file, or appended to a variable respectively @filter @macro @call @autoescape like in jinja2 --------------------------------------------------------------------------- data.awk; simple library for structured data, suitable for input for template scripts. Syntax for data specification: = simple string value. If following line starts with tab, it's considered as continuation of the value, similarly to MIME headers (but the newline is preserved) =[ ... ... ... ] field list. Simple table with named columns delimited by tab characters currently allowed variable name regex is: /[a-zA-Z_][a-zA-Z0-9_]*/ Functions for accessing data: loop_start(, ) -> loop_iter(depth) loop_end() iterate through field list of given name, make value for each filed accessible with given prefix. Loops can be nested, loop_end() ends the innermost one. Special field names are also exposed: _index the current iteration number, counted from 1 _index0 the current iteration number, counted from 0 _revindex number of iterations till the end of the loop, ending at 1 _revindex0 number of iterations till the end of the loop, ending at 0 _first 1 if on first item, 0 otherwise _last 1 if on last item, 0 otherwise _length number of items in the field list that is being iterated through get() -> returns the value of given variable, taking into account current loop state query() -> value (unimplemeted) query syntax suitable for {<...>} usage. EBNF for query syntax: query = part+ ("'" expression)? part = name | "'" expression "'" | "<" query ">" where: name is any permissible variable name expression is awk expression nested expressions allow indirection, eg.: the_shop would resolve to get("the_" get("cheese") "shop") while awk expression allow more flexible queries at expense of slightly more verbose syntax --------------------------------------------------------------------------- old readme Awk to Awk Templates; compiles interleaved awk and text into pure posix awk code. This is my first attempt to create jinja2-like templates in awk. (but it really works more like cheetah) Since proper solution for custom extensible tags would be quite complex, I went for generating awk code from the template and then postprocessing it with sed in place of proper macro support. This should be enough for generating system configuration files. The syntax feels quite ugly since the inner workings don't match jinja2 at all, so I might end up changing it. To test it out run: ./bin/aat hello.aat