Skip to content

Commit 6bfabfb

Browse files
committed
refactor: REPLIES => REPLY_QUERYTREE. Closes #13
The name is much more descriptive and since the function setting `REPLY_QUERYTREE` is internal, its OK
1 parent 0027e5d commit 6bfabfb

File tree

7 files changed

+128
-74
lines changed

7 files changed

+128
-74
lines changed

bake

+76-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/src/parse.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# @exitcode 1 Miscellaneous error
66
# @exitcode 2 Parsing error
77
bash_object.parse_querytree() {
8-
declare -ga REPLIES=()
8+
declare -ga REPLY_QUERYTREE=()
99

1010
local flag_parser_type=
1111

@@ -33,7 +33,7 @@ bash_object.parse_querytree() {
3333
continue
3434
fi
3535

36-
REPLIES+=("$key")
36+
REPLY_QUERYTREE+=("$key")
3737
done
3838
IFS="$old_ifs"
3939
elif [ "$flag_parser_type" = 'advanced' ]; then
@@ -112,7 +112,7 @@ bash_object.parse_querytree() {
112112
return
113113
fi
114114

115-
REPLIES+=("$reply")
115+
REPLY_QUERYTREE+=("$reply")
116116
mode='MODE_EXPECTING_CLOSING_BRACKET'
117117
elif [ "$char" = $'\n' ]; then
118118
bash_object.util.die 'ERROR_QUERYTREE_INVALID' 'Querytree is not complete'
@@ -135,7 +135,7 @@ bash_object.parse_querytree() {
135135
;;
136136
MODE_EXPECTING_READ_NUMBER)
137137
if [ "$char" = ']' ]; then
138-
REPLIES+=("$reply")
138+
REPLY_QUERYTREE+=("$reply")
139139
mode='MODE_BEFORE_DOT'
140140
else
141141
case "$char" in

pkg/src/traverse-get.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ bash_object.traverse-get() {
7878
*) bash_object.parse_querytree --simple "$querytree" ;;
7979
esac
8080
local i=
81-
for ((i=0; i<${#REPLIES[@]}; i++)); do
82-
local key="${REPLIES[$i]}"
81+
for ((i=0; i<${#REPLY_QUERYTREE[@]}; i++)); do
82+
local key="${REPLY_QUERYTREE[$i]}"
8383

8484
local is_index_of_array='no'
8585
if [ "${key::1}" = $'\x1C' ]; then
@@ -163,11 +163,11 @@ bash_object.traverse-get() {
163163
return
164164
fi
165165

166-
if ((i+1 < ${#REPLIES[@]})); then
166+
if ((i+1 < ${#REPLY_QUERYTREE[@]})); then
167167
# Do nothing, and continue to next element in query. We already check for the
168168
# validity of the virtual object above, so no need to do anything here
169169
:
170-
elif ((i+1 == ${#REPLIES[@]})); then
170+
elif ((i+1 == ${#REPLY_QUERYTREE[@]})); then
171171
# We are last element of query, return the object
172172
if [ "$final_value_type" = object ]; then
173173
case "$vmd_dtype" in
@@ -245,10 +245,10 @@ bash_object.traverse-get() {
245245
bash_object.trace_print 2 "BLOCK: STRING"
246246
fi
247247

248-
if ((i+1 < ${#REPLIES[@]})); then
248+
if ((i+1 < ${#REPLY_QUERYTREE[@]})); then
249249
bash_object.util.die 'ERROR_NOT_FOUND' "The passed querytree implies that '$key' accesses an object or array, but a string with a value of '$key_value' was found instead"
250250
return
251-
elif ((i+1 == ${#REPLIES[@]})); then
251+
elif ((i+1 == ${#REPLY_QUERYTREE[@]})); then
252252
local value="${__current_object[$key]}"
253253
if [ "$final_value_type" = object ]; then
254254
bash_object.util.die 'ERROR_ARGUMENTS_INCORRECT_TYPE' "Queried for $final_value_type, but found existing string '$value'"

pkg/src/traverse-set.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ bash_object.traverse-set() {
219219
*) bash_object.parse_querytree --simple "$querytree" ;;
220220
esac
221221
local i=
222-
for ((i=0; i<${#REPLIES[@]}; i++)); do
223-
local key="${REPLIES[$i]}"
222+
for ((i=0; i<${#REPLY_QUERYTREE[@]}; i++)); do
223+
local key="${REPLY_QUERYTREE[$i]}"
224224

225225
local is_index_of_array='no'
226226
if [ "${key::1}" = $'\x1C' ]; then
@@ -245,11 +245,11 @@ bash_object.traverse-set() {
245245
# If 'key' is not a member of object or index of array, error
246246
elif [ -z "${__current_object[$key]+x}" ]; then
247247
# If we are before the last element in the query, then error
248-
if ((i+1 < ${#REPLIES[@]})); then
248+
if ((i+1 < ${#REPLY_QUERYTREE[@]})); then
249249
bash_object.util.die 'ERROR_NOT_FOUND' "Key or index '$key' (querytree index '$i') does not exist"
250250
return
251251
# If we are at the last element in the query, and it doesn't exist, create it
252-
elif ((i+1 == ${#REPLIES[@]})); then
252+
elif ((i+1 == ${#REPLY_QUERYTREE[@]})); then
253253
if [ "$final_value_type" = object ]; then
254254
bash_object.util.generate_vobject_name "$root_object_name" "$querytree_stack_string"
255255
local global_object_name="$REPLY"
@@ -360,11 +360,11 @@ bash_object.traverse-set() {
360360
return
361361
fi
362362

363-
if ((i+1 < ${#REPLIES[@]})); then
363+
if ((i+1 < ${#REPLY_QUERYTREE[@]})); then
364364
# Do nothing, and continue to next element in query. We already check for the
365365
# validity of the virtual object above, so no need to do anything here
366366
:
367-
elif ((i+1 == ${#REPLIES[@]})); then
367+
elif ((i+1 == ${#REPLY_QUERYTREE[@]})); then
368368
# We are last element of query, but do not set the object there is one that already exists
369369
if [ "$final_value_type" = object ]; then
370370
case "$vmd_dtype" in
@@ -416,10 +416,10 @@ bash_object.traverse-set() {
416416
bash_object.trace_print 2 "BLOCK: STRING"
417417
fi
418418

419-
if ((i+1 < ${#REPLIES[@]})); then
419+
if ((i+1 < ${#REPLY_QUERYTREE[@]})); then
420420
bash_object.util.die 'ERROR_NOT_FOUND' "The passed querytree implies that '$key' accesses an object or array, but a string with a value of '$key_value' was found instead"
421421
return
422-
elif ((i+1 == ${#REPLIES[@]})); then
422+
elif ((i+1 == ${#REPLY_QUERYTREE[@]})); then
423423
local value="${__current_object[$key]}"
424424
if [ "$final_value_type" = object ]; then
425425
bash_object.util.die 'ERROR_ARGUMENTS_INCORRECT_TYPE' "Assigning an $final_value_type, but found existing string '$value'"

pkg/src/util/trace.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ bash_object.trace_loop() {
44
if [ -n "${TRACE_BASH_OBJECT_TRAVERSE+x}" ]; then
55
bash_object.trace_print 0 "-- START LOOP ITERATION"
66
bash_object.trace_print 0 "i+1: '$((i+1))'"
7-
bash_object.trace_print 0 "\${#REPLIES[@]}: ${#REPLIES[@]}"
7+
bash_object.trace_print 0 "\${#REPLY_QUERYTREE[@]}: ${#REPLY_QUERYTREE[@]}"
88
bash_object.trace_print 0 "key: '$key'"
99
bash_object.trace_print 0 "current_object_name: '$current_object_name'"
1010
bash_object.trace_print 0 "current_object=("

0 commit comments

Comments
 (0)