Skip to content

Commit

Permalink
(2) Fixes #10: Variables with hyphens in them do not work.
Browse files Browse the repository at this point in the history
Fixes #8: Needs example with curl
  • Loading branch information
kristopolous committed Dec 12, 2011
1 parent 464e43d commit a0e08cb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
File renamed without changes.
19 changes: 19 additions & 0 deletions tests/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"query": {},
"pathname": "/echo/request.json",
"href": "http://foobar3000.com/echo/request.json",
"httpVersion": "1.1",
"method": "GET",
"headers": {
"user-agent": "curl/7.21.6 (i686-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3",
"host": "foobar3000.com",
"accept": "*/*"
},
"trailers": {},
"remoteAddress": "99.59.97.101",
"remotePort": 39099,
"protocol": "http:",
"host": "foobar3000.com",
"hostname": "foobar3000.com",
"session": "NjMzMjgxODMxNjAw"
}
9 changes: 9 additions & 0 deletions tests/runtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
. ../ticktick.sh

DATA=`cat data.json`

tickParse "$DATA"

echo ``pathname``
echo ``headers["user-agent"]``
17 changes: 14 additions & 3 deletions ticktick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ __tick_json_parse_value() {
local prej=${jpath//\"/}

[ "$prej" ] && prej="_$prej"
[ "$prej" ] && prej=${prej/-/__hyphen__}

case "$Token" in
'{') __tick_json_parse_object "$jpath" ;;
'[') __tick_json_parse_array "$jpath" ;;

*)
Value=$Token
echo __tick_data_$Prefix$prej=$Value
Path="$Prefix$prej"
Path=${Path/#_/}
echo __tick_data_$Path=$Value
;;
esac
}
Expand Down Expand Up @@ -146,6 +149,7 @@ __tick_fun_parse_expression() {
if [ "$suffix" ]; then
echo "$suffix" | __tick_json_tokenize | __tick_json_parse
else
Prefix=${Prefix/-/__hyphen__}
echo '${__tick_data_'$Prefix'}'
fi
}
Expand Down Expand Up @@ -196,6 +200,7 @@ __tick_fun_tokenize() {
exit
}

## Runtime {
__tick_runtime_length() { echo $#; }
__tick_runtime_first() { echo ${!1}; }
__tick_runtime_last() { eval 'echo $'${!#}; }
Expand All @@ -215,14 +220,20 @@ __tick_runtime_shift() {
eval unset $left
}
__tick_runtime_push() {
local value="${1/\"/\\\"}"
local value="${1/\'/\\\'}"
local base=$2
local lastarg=${!#}

let nextval=${lastarg/$base/}+1
nextval=`printf "%012d" $nextval`

eval $base$nextval=\"$value\"
eval $base$nextval=\'$value\'
}

tickParse() {
eval `echo "$1" | __tick_json_tokenize | __tick_json_parse | tr '\n' ';'`
}
## } End of Runtime


[ $__tick_var_tokenized ] || __tick_fun_tokenize

0 comments on commit a0e08cb

Please sign in to comment.