Skip to content

Commit

Permalink
v0.1.2 - More of yaml spec supported and some code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
fvumbaca committed Dec 11, 2018
1 parent dd00546 commit 399ff33
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ YSH_LIB=1;source /usr/local/bin/ysh

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

## Flags
Expand Down
2 changes: 1 addition & 1 deletion _static/_get/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
curl -s -L https://raw.githubusercontent.com/azohra/yaml.sh/master/ysh --output /usr/local/bin/ysh
curl -s -L https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.2/ysh --output /usr/local/bin/ysh
chmod u+x /usr/local/bin/ysh
6 changes: 1 addition & 5 deletions src/ysh.awk
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function check_started() {
next
}


/^[[:space:]]*[^[:space:]]+:/ {
started=1
depth=level()
Expand Down Expand Up @@ -95,7 +94,6 @@ function check_started() {

/^[[:space:]]*-[[:space:]]+\{.*\}[[:space:]]*$/ {
check_started()
depth=level()
line=$0
sub(/^[[:space:]]*-[[:space:]]+\{/, "", line)
sub(/\}[[:space:]]*$/, "", line)
Expand All @@ -120,7 +118,7 @@ function check_started() {

/^[[:space:]]*-[[:space:]][^[:space:]]+:/ {
check_started()
depth=level() + 1
depth++
key=$0
sub(/^[[:space:]]*-[[:space:]]/, "", key)
sub(/:.*$/, "", key)
Expand All @@ -129,7 +127,6 @@ function check_started() {

/^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+[^[:space:]]+/ {
check_started()
depth=level() + 1
val=$0
sub(/^[[:space:]]*-[[:space:]][^[:space:]]+:[[:space:]]+/, "", val)
val = remove_sur_quotes(val)
Expand All @@ -139,7 +136,6 @@ function check_started() {

/^[[:space:]]*-[[:space:]]+[^[:space:]]+/ {
check_started()
depth=level()
val=$0
sub(/^[[:space:]]*-[[:space:]]+/, "", val)
sub(/[[:space:]]*$/, "", val)
Expand Down
1 change: 0 additions & 1 deletion src/ysh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ YSH_usage() {
echo " -l, --list <query> query for a list"
echo " -c, --count <query> count length of list element"
echo " -i, --index <i> array access by index"
echo " -I, --index <i> array access by index. Guarentees a value."
echo " -I, --index-val <i> safe array access by index. Guarentees a value."
echo " -t, --tops top level children keys of structure"
echo " -n, --next move to next block"
Expand Down
4 changes: 4 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ testNextBlock() {
file=$(ysh -T "$file" -n)
result=$(ysh -T "$file" -Q key)
assertEquals "block_2_value" "${result}"

file=$(ysh -T "$file" -n)
result=$(ysh -T "$file" -Q key)
assertEquals "block_3_value" "${result}"
}

. ./test/shunit2
2 changes: 1 addition & 1 deletion test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ key: value
---
key: block_2_value
---
key: block_3_value
key: block_3_value
11 changes: 5 additions & 6 deletions ysh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash
YSH_version='0.1.1'
YSH_version='0.1.2'
YAML_AWK_PARSER='
function raise(msg) { print msg > "/dev/stderr"; if (force_complete) { exit_status = 1; } else { exit 1; };};
function level() { match($0, /^[[:space:]]*/); if (RLENGTH % 2 != 0) { raise("Bad indentation on line "NR". Number of spaces uneven."); }; return RLENGTH / 2;};
Expand All @@ -11,10 +11,10 @@ function check_started() { if (started == 0) { raise("Keys must be added before
/^[[:space:]]*[^[:space:]]+:/ { started=1; depth=level(); key=$1; sub(/:.*$/, "", key); stack[depth] = key;};
/^[[: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;};
/^[[:space:]]*\-/ { check_started(); depth=level(); stack_key=join_stack(depth-1); indx=list_counter[stack_key]++; stack[depth]="[" indx "]";};
/^[[: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;};
/^[[:space:]]*-[[:space:]][^[:space:]]+:/ { check_started(); depth=level() + 1; key=$0; sub(/^[[:space:]]*-[[:space:]]/, "", key); sub(/:.*$/, "", key); stack[depth]=key;};
/^[[: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;};
/^[[: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;};
/^[[: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;};
/^[[:space:]]*-[[:space:]][^[:space:]]+:/ { check_started(); depth++; key=$0; sub(/^[[:space:]]*-[[:space:]]/, "", key); sub(/:.*$/, "", key); stack[depth]=key;};
/^[[: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;};
/^[[: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;};
/^[[:space:]]*[^[:space:]]+:[[:space:]]*$/ {next};
/^[[:space:]]*-[[:space:]]+[^[:space:]]+:[[:space:]]*$/ {next};
/^[[:space:]]*$/ { next };
Expand Down Expand Up @@ -66,7 +66,6 @@ YSH_usage() {
echo " -l, --list <query> query for a list"
echo " -c, --count <query> count length of list element"
echo " -i, --index <i> array access by index"
echo " -I, --index <i> array access by index. Guarentees a value."
echo " -I, --index-val <i> safe array access by index. Guarentees a value."
echo " -t, --tops top level children keys of structure"
echo " -n, --next move to next block"
Expand Down

0 comments on commit 399ff33

Please sign in to comment.