#!/bin/sed -f s/^[[:space:]]*FOR[[:space:]]\+\([[:alnum:]]\+\)[[:space:]]\+IN[[:space:]]\+\(.\+\)$/for(last in \2){};for(key in \2){\n\1 = \2[key]; is_last = key == last/ s/^[[:space:]]*ENDFOR[[:space:]]*$/}/ s/^[[:space:]]*IF[[:space:]]\+\(.\+\)$/if(\1) {\n/ s/^[[:space:]]*ELIF[[:space:]]\+\(.\+\)$/} else if(\1) {\n/ s/^[[:space:]]*ELSE[[:space:]]*$/} else {/ s/^[[:space:]]*ENDIF[[:space:]]*$/}/ s/^[[:space:]]*@for[[:space:]]\+\([[:alnum:]]\+\)[[:space:]]\+in[[:space:]]\+\(.\+\)$/for(_loop_\1=loop_start("\2", "\1."); loop_iter(_loop_\1);) {/ s/^[[:space:]]*@for[[:space:]]\+\([[:alnum:]]\+\)[[:space:]]\+var[[:space:]]\+\(.\+\)$/for(_loop_\1=loop_start(\2, "\1."); loop_iter(_loop_\1);) {/ s/^[[:space:]]*@endfor[[:space:]]*$/} loop_end()/ s/^[[:space:]]*@if[[:space:]]\+\(.\+\)$/if(get("\1")) {\n/ s/^[[:space:]]*@elif[[:space:]]\+\(.\+\)$/} else if(get("\1")) {\n/ s/^[[:space:]]*@else[[:space:]]*$/} else {/ s/^[[:space:]]*@endif[[:space:]]*$/}/ #s/^[[:space:]]*@let[[:space:]]\+\([a-zA-Z_][a-zA-Z0-9_]*\)[[:space:]]*=[[:space:]]*\(.*\)$/V["\1"] = \2\n/