#!/bin/bash global BALLS_LIB := $[readlink -f $[dirname $0]/../lib] shopt -s extglob source $BALLS_LIB/balls.sh proc dash_trim_r { var str = $(!1) str := $(str%%*( )) export "$1"="$str" } proc compile { var code = '' var chunk = '' var trim_next = '0' while read_until '<%' chunk { if test $FOUND = 1 { read_until '%>' code trim code matchstr $(code:0:1) { = { code := $(code:1) trim code code := ""echo -n $code"" } - { code := $(code:1) dash_trim_r chunk trim code } } matchstr $(code:${#code}-1) { - { # read off the next line read code := $(code:0:${#code}-1) trim code } } } # if [ "$FOUND" = 1 ] # echo "echo -n $(bash_safe <<< "$chunk")" bash_safe chunk echo "echo -n $chunk" test $FOUND = 1 && echo $code } # while read_until '<%' chunk true } global fname := $1; shift export eof="$[echo -e '\004]" if test -n $fname { cat $fname || exit 1 } else { cat - } | compile (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BALLS_LIB) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(readlink)} {(-f)} { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {($ VSub_Number "$0")})] ) left_token: spids: [9 13] ) (/../lib) } ) ] ) left_token: spids: [4 15] ) } spids: [3] ) ] spids: [3] ) (C {(shopt)} {(-s)} {(extglob)}) (C {(.)} {($ VSub_Name "$BALLS_LIB") (/balls.sh)}) (FuncDef name: dash_trim_r body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:str) op: Equal rhs: {(DQ (BracedVarSub token: prefix_op:VSub_Bang spids:[4245]))} spids: [40] ) ] spids: [38] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:str) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DPercent arg_word:{("*( )")}) spids: [51 55] ) ) } spids: [49] ) ] spids: [49] ) (C {(export)} {(DQ ($ VSub_Number "$1")) (Lit_Other "=") (DQ ($ VSub_Name "$str"))}) ] spids: [35] ) spids: [31 34] ) (FuncDef name: compile body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [(assign_pair lhs:(LhsName name:code) op:Equal spids:[81])] spids: [79] ) (Assignment keyword: Assign_Local pairs: [(assign_pair lhs:(LhsName name:chunk) op:Equal spids:[86])] spids: [84] ) (Assignment keyword: Assign_Local pairs: [(assign_pair lhs:(LhsName name:trim_next) op:Equal rhs:{(0)} spids:[91])] spids: [89] ) (While cond: [ (Sentence child: (C {(read_until)} {(SQ <"<%">)} {(chunk)}) terminator: ) ] body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FOUND"))} {(Lit_Other "=")} {(1)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(read_until)} {(SQ <"%>">)} {(code)}) (C {(trim)} {(code)}) (Case to_match: { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithWord w:{(Lit_Digits 1)}) ) spids: [145 151] ) ) } arms: [ (case_arm pat_list: [{(Lit_Other "=")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:code) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 1)}) ) spids: [163 167] ) ) } spids: [161] ) ] spids: [161] ) (C {(trim)} {(code)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:code) op: Equal rhs: {(DQ ("echo -n ") ($ VSub_Name "$code"))} spids: [176] ) ] spids: [176] ) ] spids: [157 158 183 -1] ) (case_arm pat_list: [{(-)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:code) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 1)}) ) spids: [192 196] ) ) } spids: [190] ) ] spids: [190] ) (C {(dash_trim_r)} {(chunk)}) (C {(trim)} {(code)}) ] spids: [186 187 210 -1] ) ] spids: [142 154 213] ) (Case to_match: { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithBinary op_id: Arith_Minus left: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound spids: [223 226] ) } ) right: (ArithWord w:{(Lit_Digits 1)}) ) ) spids: [220 229] ) ) } arms: [ (case_arm pat_list: [{(-)}] action: [ (C {(read)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:code) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithBinary op_id: Arith_Minus left: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound spids: [253 256] ) } ) right: (ArithWord w:{(Lit_Digits 1)}) ) ) spids: [248 259] ) ) } spids: [246] ) ] spids: [246] ) (C {(trim)} {(code)}) ] spids: [235 236 268 -1] ) ] spids: [217 232 271] ) ] spids: [-1 124] ) ] spids: [-1 275] ) (C {(bash_safe)} {(chunk)}) (C {(echo)} {(DQ ("echo -n ") ($ VSub_Name "$chunk"))}) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$FOUND"))} {(Lit_Other "=")} {(1)} {(Lit_Other "]")} ) (C {(echo)} {(DQ ($ VSub_Name "$code"))}) ] op_id: Op_DAmp ) ] spids: [106 322] ) ) (C {(true)}) ] spids: [76] ) spids: [72 75] ) (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fname) op: Equal rhs: {($ VSub_Number "$1")} spids: [333] ) ] spids: [333] ) terminator: ) (C {(shift)}) (C {(export)} {(Lit_VarLike "eof=") (DQ (CommandSubPart command_list: (CommandList children:[(C {(echo)} {(-e)} {(SQ <"\\004">)})]) left_token: spids: [344 352] ) ) } ) (Pipeline children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$fname"))} {(Lit_Other "]")}) terminator: ) ] action: [ (AndOr children: [(C {(cat)} {($ VSub_Name "$fname")}) (C {(exit)} {(1)})] op_id: Op_DPipe ) ] spids: [-1 369] ) ] else_action: [(C {(cat)} {(-)})] spids: [382 389] ) (C {(compile)}) ] negated: False ) ] )