1
1
#! /bin/bash
2
- YSH_version=' 0.1.1 '
2
+ YSH_version=' 0.1.2 '
3
3
YAML_AWK_PARSER='
4
4
function raise(msg) { print msg > "/dev/stderr"; if (force_complete) { exit_status = 1; } else { exit 1; };};
5
5
function level() { match($0, /^[[:space:]]*/); if (RLENGTH % 2 != 0) { raise("Bad indentation on line "NR". Number of spaces uneven."); }; return RLENGTH / 2;};
@@ -11,10 +11,10 @@ function check_started() { if (started == 0) { raise("Keys must be added before
11
11
/^[[:space:]]*[^[:space:]]+:/ { started=1; depth=level(); key=$1; sub(/:.*$/, "", key); stack[depth] = key;};
12
12
/^[[:space:]]*[^[:space:]]+:[[:space:]]+[^[:space:]]+/ { started=1; depth=level(); val=$0; sub(/^[[:space:]]*[^[:space:]]+:[[:space:]]+/, "", val); val = remove_sur_quotes(val); print join_stack(depth) "=\"" val "\""; next;};
13
13
/^[[:space:]]*\-/ { check_started(); depth=level(); stack_key=join_stack(depth-1); indx=list_counter[stack_key]++; stack[depth]="[" indx "]";};
14
- /^[[:space:]]*-[[:space:]]+\{.*\}[[:space:]]*$/ { check_started(); depth=level(); line=$0; sub(/^[[:space:]]*-[[:space:]]+\{/, "", line); sub(/\}[[:space:]]*$/, "", line); safe_split(line, entries); for (i in entries) { key=entries[i]; val=entries[i]; sub(/^[[:space:]]*/, "", key); sub(/:.*$/, "", key); sub(/^[[:space:]]*[^[:space:]]+:[[:space:]]+\"?/, "", val) ; sub(/\"?[[:space:]]*$/, "", val) ; val = remove_sur_quotes(val); print join_stack(depth) "." key "=\"" val "\""; }; delete entries; next;};
15
- /^[[:space:]]*-[[:space:]][^[:space:]]+:/ { check_started(); depth=level() + 1 ; key=$0; sub(/^[[:space:]]*-[[:space:]]/, "", key); sub(/:.*$/, "", key); stack[depth]=key;};
16
- /^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+[^[:space:]]+/ { check_started(); depth=level() + 1; val=$0; sub(/^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+/, "", val); val = remove_sur_quotes(val); print join_stack(depth) "=\"" val "\""; next;};
17
- /^[[:space:]]*-[[:space:]]+[^[:space:]]+/ { check_started(); depth=level(); val=$0; sub(/^[[:space:]]*-[[:space:]]+/, "", val); sub(/[[:space:]]*$/, "", val); val = remove_sur_quotes(val); print join_stack(depth) "=\"" val "\""; next;};
14
+ /^[[:space:]]*-[[:space:]]+\{.*\}[[:space:]]*$/ { check_started(); line=$0; sub(/^[[:space:]]*-[[:space:]]+\{/, "", line); sub(/\}[[:space:]]*$/, "", line); safe_split(line, entries); for (i in entries) { key=entries[i]; val=entries[i]; sub(/^[[:space:]]*/, "", key); sub(/:.*$/, "", key); sub(/^[[:space:]]*[^[:space:]]+:[[:space:]]+\"?/, "", val) ; sub(/\"?[[:space:]]*$/, "", val) ; val = remove_sur_quotes(val); print join_stack(depth) "." key "=\"" val "\""; }; delete entries; next;};
15
+ /^[[:space:]]*-[[:space:]][^[:space:]]+:/ { check_started(); depth++ ; key=$0; sub(/^[[:space:]]*-[[:space:]]/, "", key); sub(/:.*$/, "", key); stack[depth]=key;};
16
+ /^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+[^[:space:]]+/ { check_started(); val=$0; sub(/^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+/, "", val); val = remove_sur_quotes(val); print join_stack(depth) "=\"" val "\""; next;};
17
+ /^[[:space:]]*-[[:space:]]+[^[:space:]]+/ { check_started(); val=$0; sub(/^[[:space:]]*-[[:space:]]+/, "", val); sub(/[[:space:]]*$/, "", val); val = remove_sur_quotes(val); print join_stack(depth) "=\"" val "\""; next;};
18
18
/^[[:space:]]*[^[:space:]]+:[[:space:]]*$/ {next};
19
19
/^[[:space:]]*-[[:space:]]+[^[:space:]]+:[[:space:]]*$/ {next};
20
20
/^[[:space:]]*$/ { next };
@@ -66,7 +66,6 @@ YSH_usage() {
66
66
echo " -l, --list <query> query for a list"
67
67
echo " -c, --count <query> count length of list element"
68
68
echo " -i, --index <i> array access by index"
69
- echo " -I, --index <i> array access by index. Guarentees a value."
70
69
echo " -I, --index-val <i> safe array access by index. Guarentees a value."
71
70
echo " -t, --tops top level children keys of structure"
72
71
echo " -n, --next move to next block"
0 commit comments