Skip to content

Commit 399ff33

Browse files
committed
v0.1.2 - More of yaml spec supported and some code cleanup.
1 parent dd00546 commit 399ff33

File tree

7 files changed

+13
-15
lines changed

7 files changed

+13
-15
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ YSH_LIB=1;source /usr/local/bin/ysh
2828

2929
If you want the internet as your only dependency:
3030
```bash
31-
$ YSH_LIB=1;source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/azohra/yaml.sh/master/y.sh)"
31+
$ YSH_LIB=1;source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.2/ysh)"
3232
```
3333

3434
## Flags

_static/_get/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
curl -s -L https://raw.githubusercontent.com/azohra/yaml.sh/master/ysh --output /usr/local/bin/ysh
1+
curl -s -L https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.2/ysh --output /usr/local/bin/ysh
22
chmod u+x /usr/local/bin/ysh

src/ysh.awk

+1-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ function check_started() {
6666
next
6767
}
6868

69-
7069
/^[[:space:]]*[^[:space:]]+:/ {
7170
started=1
7271
depth=level()
@@ -95,7 +94,6 @@ function check_started() {
9594

9695
/^[[:space:]]*-[[:space:]]+\{.*\}[[:space:]]*$/ {
9796
check_started()
98-
depth=level()
9997
line=$0
10098
sub(/^[[:space:]]*-[[:space:]]+\{/, "", line)
10199
sub(/\}[[:space:]]*$/, "", line)
@@ -120,7 +118,7 @@ function check_started() {
120118

121119
/^[[:space:]]*-[[:space:]][^[:space:]]+:/ {
122120
check_started()
123-
depth=level() + 1
121+
depth++
124122
key=$0
125123
sub(/^[[:space:]]*-[[:space:]]/, "", key)
126124
sub(/:.*$/, "", key)
@@ -129,7 +127,6 @@ function check_started() {
129127

130128
/^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+[^[:space:]]+/ {
131129
check_started()
132-
depth=level() + 1
133130
val=$0
134131
sub(/^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+/, "", val)
135132
val = remove_sur_quotes(val)
@@ -139,7 +136,6 @@ function check_started() {
139136

140137
/^[[:space:]]*-[[:space:]]+[^[:space:]]+/ {
141138
check_started()
142-
depth=level()
143139
val=$0
144140
sub(/^[[:space:]]*-[[:space:]]+/, "", val)
145141
sub(/[[:space:]]*$/, "", val)

src/ysh.sh

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ YSH_usage() {
6363
echo " -l, --list <query> query for a list"
6464
echo " -c, --count <query> count length of list element"
6565
echo " -i, --index <i> array access by index"
66-
echo " -I, --index <i> array access by index. Guarentees a value."
6766
echo " -I, --index-val <i> safe array access by index. Guarentees a value."
6867
echo " -t, --tops top level children keys of structure"
6968
echo " -n, --next move to next block"

test/test.sh

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ testNextBlock() {
129129
file=$(ysh -T "$file" -n)
130130
result=$(ysh -T "$file" -Q key)
131131
assertEquals "block_2_value" "${result}"
132+
133+
file=$(ysh -T "$file" -n)
134+
result=$(ysh -T "$file" -Q key)
135+
assertEquals "block_3_value" "${result}"
132136
}
133137

134138
. ./test/shunit2

test/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ key: value
5151
---
5252
key: block_2_value
5353
---
54-
key: block_3_value
54+
key: block_3_value

ysh

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/bash
2-
YSH_version='0.1.1'
2+
YSH_version='0.1.2'
33
YAML_AWK_PARSER='
44
function raise(msg) { print msg > "/dev/stderr"; if (force_complete) { exit_status = 1; } else { exit 1; };};
55
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
1111
/^[[:space:]]*[^[:space:]]+:/ { started=1; depth=level(); key=$1; sub(/:.*$/, "", key); stack[depth] = key;};
1212
/^[[: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;};
1313
/^[[: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;};
1818
/^[[:space:]]*[^[:space:]]+:[[:space:]]*$/ {next};
1919
/^[[:space:]]*-[[:space:]]+[^[:space:]]+:[[:space:]]*$/ {next};
2020
/^[[:space:]]*$/ { next };
@@ -66,7 +66,6 @@ YSH_usage() {
6666
echo " -l, --list <query> query for a list"
6767
echo " -c, --count <query> count length of list element"
6868
echo " -i, --index <i> array access by index"
69-
echo " -I, --index <i> array access by index. Guarentees a value."
7069
echo " -I, --index-val <i> safe array access by index. Guarentees a value."
7170
echo " -t, --tops top level children keys of structure"
7271
echo " -n, --next move to next block"

0 commit comments

Comments
 (0)