39 #define __FILE_ID__ "yjson" 44 #define atoi parseUInt 49 #if defined(__BORLANDC__) 59 #ifdef DEBUG_JSON_PARSE 60 const char* yJsonStateStr[] = {
62 "YJSON_HTTP_READ_CODE",
63 "YJSON_HTTP_READ_MSG",
70 "YJSON_PARSE_STRINGQ",
71 "YJSON_PARSE_STRINGCONT",
72 "YJSON_PARSE_STRINGCONTQ",
75 "YJSON_PARSE_MEMBSTART",
76 "YJSON_PARSE_MEMBNAME",
77 "YJSON_PARSE_MEMBCOL",
105 while(src < end && (c = *src) !=
' ' && c !=
'O' && c !=
'\r') src++;
106 if(src >= end)
goto done;
112 while(src < end && pt < ept && (c = *src) !=
' ' && c !=
'O' && c !=
'\r') {
113 if(c < '0' || c >
'9')
goto push_error;
117 if(src >= end)
goto done;
118 if(pt >= ept)
goto push_error;
120 else if(c ==
'O' && pt == j->
token) {
122 *pt++ =
'2';*pt++ =
'0';*pt++ =
'0';
130 while(src < end && pt < ept && (c = *src) !=
'\r' && c !=
'\n') {
134 if(src >= end)
goto done;
141 while(src < end && pt < j->token+2) {
143 if(c ==
'\n') *pt++ =
'\n';
144 else if(c !=
'\r') pt = j->
token;
146 if(src >= end)
goto done;
155 while(src < end && ((c = *src) ==
' ' || c ==
'\r' || c ==
'\n')) src++;
156 if(src >= end)
goto done;
159 #ifndef YAPI_IN_YDEVICE 166 #ifndef YAPI_IN_YDEVICE 172 #ifndef YAPI_IN_YDEVICE 177 else if(c==
'-' || (c >=
'0' && c <=
'9')) {
178 #ifndef YAPI_IN_YDEVICE 183 else if(c >=
'A' && c <=
'z') {
184 #ifndef YAPI_IN_YDEVICE 190 else goto push_error;
194 while(src < end && pt < ept && (c = *src) >=
'A' && c <=
'z') {
198 if(src >= end)
goto done;
199 if(pt >= ept)
goto push_error;
203 #ifndef YAPI_IN_YDEVICE 209 while(src < end && pt < ept && ( (c = *src)==
'-' || (c >=
'0' && c <=
'9') )) {
213 if(src >= end)
goto done;
214 if(pt >= ept)
goto push_error;
218 while(src < end && pt < ept && (c = *src) !=
'"' && c !=
'\\') {
222 if(src >= end)
goto done;
231 if(c ==
'"')
goto token_done;
240 if(src >= end)
goto done;
243 case 'r': *pt++ =
'\r';
break;
244 case 'n': *pt++ =
'\n';
break;
245 case 't': *pt++ =
'\t';
break;
256 while(src < end && (*src ==
' ' || *src ==
'\r' || *src ==
'\n')) src++;
257 if(src >= end)
goto done;
276 while(src < end && ((c = *src) ==
' ' || c ==
'\r' || c ==
'\n')) src++;
277 if(src >= end)
goto done;
282 if(c !=
'"')
goto push_error;
288 while(src < end && pt < ept && (c = *src) !=
'"') {
292 if(src >= end)
goto done;
293 if(pt >= ept)
goto push_error;
300 while(src < end && ((c = *src) ==
' ' || c ==
'\r' || c ==
'\n')) src++;
301 if(src >= end)
goto done;
302 if(c !=
':')
goto push_error;
307 while(src < end && ((c = *src) ==
' ' || c ==
'\r' || c ==
'\n')) src++;
310 if(src >= end)
goto done;
313 else if(c ==
'}')
goto un_nest;
314 else goto push_error;
323 else goto push_error;
327 if(src < end)
goto push_error;
373 void yJsonInitEx(yJsonStateMachineEx *j,
const char *jzon,
int jzon_len,
const char *ref,
int ref_len)
376 memset(j, 0,
sizeof(yJsonStateMachineEx));
378 j->jzon.end = jzon + jzon_len;
382 j->ref.end = ref + ref_len;
385 j->sst = JZON_PARSE_SYNCRO;
392 if (j->ref.src == NULL) {
395 j->next = j->jzon.next;
396 memcpy(j->token, j->jzon.token,
sizeof(j->token));
401 case JZON_PARSE_SYNCRO:
413 j->sst = JZON_PARSE_ONLY_REF;
415 j->sst_stack[j->depth++] = j->sst;
419 j->next = j->ref.next;
420 memcpy(j->token, j->ref.token,
sizeof(j->token));
426 j->sst = JZON_PARSE_ONLY_YZON;
431 j->next = j->jzon.next;
432 memcpy(j->token, j->jzon.token,
sizeof(j->token));
434 j->sst = j->sst_stack[j->depth - 1];
439 case JZON_PARSE_ONLY_REF:
445 j->next = j->ref.next;
446 memcpy(j->token, j->ref.token,
sizeof(j->token));
448 j->sst = JZON_PARSE_SYNCRO;
451 case JZON_PARSE_ONLY_YZON:
457 j->next = j->jzon.next;
458 memcpy(j->token, j->jzon.token,
sizeof(j->token));
460 j->sst = JZON_PARSE_SYNCRO;
469 void yJsonSkipEx(yJsonStateMachineEx *j,
int nitems)
471 if (j->ref.src == NULL) {
472 j->jzon.skipcnt += nitems;
476 case JZON_PARSE_SYNCRO:
477 j->ref.skipcnt += nitems;
478 j->jzon.skipcnt += nitems;
481 case JZON_PARSE_ONLY_REF:
482 j->ref.skipcnt += nitems;
484 case JZON_PARSE_ONLY_YZON:
485 j->jzon.skipcnt += nitems;
_FAR const char * state_start
yJsonRetCode yJsonParse(yJsonStateMachine *j)
void yJsonSkip(yJsonStateMachine *j, int nitems)
yJsonState stack[YJSON_MAX_DEPTH]
_FAR const char * state_end