Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions poorjson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __JNUM='(-?([1-9][0-9]*|0)(\.[0-9]+)?([eE][-+]?[0-9]+)?)'
__JSTR='("([^[:cntrl:]\\"]|\\(["\\\/bfnrt]|u[0-9a-fA-F]{4}))*")'
_TOK="" _TMP="" __JTOK="$__JSTR|$__JNUM|true|false|null|[][}{,:]"

_is_match() { case $1 in "$2"|'*'|.);; *)! :;; esac }
_is_match() { case "$1" in "$2"|'*'|.);; *)! :;; esac || case "$2" in "\"$1\"");; *)! :;; esac }
_err() { echo "Unexpected $1token: \"$_TOK\""; exit 1; }
_jread() {
read -r _TOK || _err "EOF after "
Expand All @@ -22,8 +22,8 @@ _jarr() {
while :; do
_jread "$1"
case $_TOK in "]") return;;
",") [ "$1" -ge 0 ] 2>/dev/null && _TMP=$(($1 - 1)) && shift && set -- "$_TMP" "$@";;
*) _err;;
",") [ "$1" -ge 0 ] 2>/dev/null && _TMP=$(($1 - 1)) && shift && set -- "$_TMP" "$@";;
*) _err;;
esac
if _is_match "$1" 0; then _jval "$@"; else _jval; fi || _err
done
Expand All @@ -49,9 +49,9 @@ _jval() {
[ "$#" -eq 0 ] || [ "$*" = . ] || shift
_jread "$1"
case $_TOK in '{') _jobj "$@";;
"[") _jarr "$@";;
true|false|null|-*|[0-9]*|'"'*'"') [ "$1" = \* ] && echo "$_TOK"; :;;
*) ! :;;
"[") _jarr "$@";;
true|false|null|-*|[0-9]*|'"'*'"') [ "$1" = \* ] && echo "$_TOK"; :;;
*) ! :;;
esac
}

Expand Down