| 1136 | } |
| 1137 | |
| 1138 | static void json_parse_object_context(lua_State *l, json_parse_t *json) |
| 1139 | { |
| 1140 | json_token_t token; |
| 1141 | |
| 1142 | /* 3 slots required: |
| 1143 | * .., table, key, value */ |
| 1144 | json_decode_descend(l, json, 3); |
| 1145 | |
| 1146 | lua_newtable(l); |
| 1147 | |
| 1148 | json_next_token(json, &token); |
| 1149 | |
| 1150 | /* Handle empty objects */ |
| 1151 | if (token.type == T_OBJ_END) { |
| 1152 | json_decode_ascend(json); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
| 1156 | while (1) { |
| 1157 | if (token.type != T_STRING) |
| 1158 | json_throw_parse_error(l, json, "object key string", &token); |
| 1159 | |
| 1160 | /* Push key */ |
| 1161 | lua_pushlstring(l, token.value.string, token.string_len); |
| 1162 | |
| 1163 | json_next_token(json, &token); |
| 1164 | if (token.type != T_COLON) |
| 1165 | json_throw_parse_error(l, json, "colon", &token); |
| 1166 | |
| 1167 | /* Fetch value */ |
| 1168 | json_next_token(json, &token); |
| 1169 | json_process_value(l, json, &token); |
| 1170 | |
| 1171 | /* Set key = value */ |
| 1172 | lua_rawset(l, -3); |
| 1173 | |
| 1174 | json_next_token(json, &token); |
| 1175 | |
| 1176 | if (token.type == T_OBJ_END) { |
| 1177 | json_decode_ascend(json); |
| 1178 | return; |
| 1179 | } |
| 1180 | |
| 1181 | if (token.type != T_COMMA) |
| 1182 | json_throw_parse_error(l, json, "comma or object end", &token); |
| 1183 | |
| 1184 | json_next_token(json, &token); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | /* Handle the array context */ |
| 1189 | static void json_parse_array_context(lua_State *l, json_parse_t *json) |
no test coverage detected