@@ -8,41 +8,53 @@ bash_json.parse() {
8
8
9
9
local -a TOKENS=()
10
10
11
- # Construct token sequence
12
- local -i col=1 row=1 i=
11
+ # 1. Construct token sequence
12
+ # 'scan_*' functions are modified in variuos 'tokenize_' functions
13
+ local scan_step_fn=' bash_json.tokenize_begin_value'
14
+ local -a scan_stack=()
15
+ local -i scan_col=1 scan_row=1
16
+
17
+ local i=
13
18
for (( i= 0 ; i< ${# content} ; ++ i)) ; do
14
19
local char=" ${content: $i : 1} "
15
20
16
- local prefix=" $col :$row :"
17
- case $char in
18
- ' {' ) TOKENS+=(" $prefix " ' TOKEN_OPEN_CURLEYBRACE' ) ;;
19
- ' }' ) TOKENS+=(" $prefix " ' TOKEN_CLOSE_CURLEYBRACE' ) ;;
20
- ' [' ) TOKENS+=(" $prefix " ' TOKEN_OPEN_SQUAREBRACKET' ) ;;
21
- ' ]' ) TOKENS+=(" $prefix " ' TOKEN_CLOSE_SQUAREBRACKET' ) ;;
22
- ' :' ) TOKENS+=(" $prefix " ' TOKEN_COLON' ) ;;
23
- ' ,' ) TOKENS+=(" $prefix " ' TOKEN_COMMA' ) ;;
24
- ' "' )
25
- local str=
26
- bash_json.tokenize_string || true
27
- TOKENS+=($' \x01 ' " ${prefix}${str} " )
28
- col+=$(( ${# str} + 1 ))
29
- ;;
30
- [[:digit:]])
31
- local str=
32
- bash_json.tokenize_number || true
33
- TOKENS+=($' \x02 ' " ${prefix}${str} " )
34
- col+=$(( ${# str} - 1 ))
35
- ;;
36
- $' \n ' )
37
- row+=1
38
- col=0
39
- ;;
40
- ' ' |$' \t ' |$' \r ' )
41
- ;;
42
- * ) core.print_die " Failed: $char "
43
- ;;
44
- esac
45
- col+=1
21
+ if " $scan_step_fn " " $char " ; then
22
+ core.print_die ' Error'
23
+ fi
24
+ # local prefix="$row:$col:"
25
+ # case $char in
26
+ # '{')
27
+ # state_stack+=('scan_begin_object')
28
+ # ;;
29
+ # # '{')TOKENS+=("$prefix"'TOKEN_OPEN_CURLEYBRACE') ;;
30
+ # # '}') TOKENS+=("$prefix"'TOKEN_CLOSE_CURLEYBRACE') ;;
31
+ # # '[') TOKENS+=("$prefix"'TOKEN_OPEN_SQUAREBRACKET') ;;
32
+ # # ']') TOKENS+=("$prefix"'TOKEN_CLOSE_SQUAREBRACKET') ;;
33
+ # # ':') TOKENS+=("$prefix"'TOKEN_COLON') ;;
34
+ # # ',') TOKENS+=("$prefix"'TOKEN_COMMA') ;;
35
+ # '"')
36
+ # local str=
37
+ # bash_json.tokenize_string || true
38
+ # TOKENS+=($'\x01'"${prefix}${str}")
39
+ # col+=$((${#str}+1))
40
+ # ;;
41
+ # [[:digit:]])
42
+ # local str=
43
+ # bash_json.tokenize_number || true
44
+ # TOKENS+=($'\x02'"${prefix}${str}")
45
+ # col+=$((${#str}-1))
46
+ # ;;
47
+ # $'\n')
48
+ # row+=1
49
+ # col=0
50
+ # ;;
51
+ # ' '|$'\t'|$'\r')
52
+ # ;;
53
+ # *) core.print_die "Failed: $char"
54
+ # ;;
55
+ # esac
56
+
57
+ scan_col+=1
46
58
done ; unset -v i
47
59
48
60
# Print token sequence
@@ -53,28 +65,32 @@ bash_json.parse() {
53
65
i=$(( i+ 1 ))
54
66
done
55
67
56
- # Construct object using token sequence
57
- if [ " ${TOKENS[0]##*: } " = ' TOKEN_OPEN_CURLEYBRACE' ]; then
58
- bash_json.parse_array_or_object " $variable_prefix " 0 ' .'
68
+ # if ((${#TOKENS[@]} == 0)); then
69
+ # core.panic "JSON file empty"
70
+ # fi
71
+
72
+ # # Construct object using token sequence
73
+ # if [ "${TOKENS[0]##*:}" = 'TOKEN_OPEN_CURLEYBRACE' ]; then
74
+ # bash_json.parse_object "$variable_prefix" 1 '.'
59
75
60
- REPLY1=$variable_prefix
61
- REPLY2=' object'
62
- elif [ " ${TOKENS[0]##*: } " = ' TOKEN_OPEN_SQUAREBRACKET' ]; then
63
- bash_json.parse_array_or_object " $variable_prefix " 0 ' .'
76
+ # REPLY1=$variable_prefix
77
+ # REPLY2='object'
78
+ # elif [ "${TOKENS[0]##*:}" = 'TOKEN_OPEN_SQUAREBRACKET' ]; then
79
+ # bash_json.parse_array_or_object "$variable_prefix" 0 '.'
64
80
65
- REPLY1=$variable_prefix
66
- REPLY2=' array'
67
- elif [ " ${TOKENS[0]:: 1} " = $' \x01 ' ]; then
68
- bash_json.parse_primitive
81
+ # REPLY1=$variable_prefix
82
+ # REPLY2='array'
83
+ # elif [ "${TOKENS[0]::1}" = $'\x01' ]; then
84
+ # bash_json.parse_primitive
69
85
70
- REPLY1=$REPLY
71
- REPLY2=' string'
72
- elif [ " ${TOKENS[0]:: 1} " = $' \x02 ' ]; then
73
- bash_json.parse_primitive
86
+ # REPLY1=$REPLY
87
+ # REPLY2='string'
88
+ # elif [ "${TOKENS[0]::1}" = $'\x02' ]; then
89
+ # bash_json.parse_primitive
74
90
75
- REPLY1=$REPLY
76
- REPLY2=' number'
77
- else
78
- core.panic ' Unexpected token'
79
- fi
91
+ # REPLY1=$REPLY
92
+ # REPLY2='number'
93
+ # else
94
+ # core.panic 'Unexpected token'
95
+ # fi
80
96
}
0 commit comments