json.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  1. /* A packrat parser generated by PackCC 1.5.0 */
  2. #ifdef _MSC_VER
  3. #undef _CRT_SECURE_NO_WARNINGS
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #endif /* _MSC_VER */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #ifndef _MSC_VER
  10. #if defined __GNUC__ && defined _WIN32 /* MinGW */
  11. #ifndef PCC_USE_SYSTEM_STRNLEN
  12. #define strnlen(str, maxlen) pcc_strnlen(str, maxlen)
  13. static size_t pcc_strnlen(const char *str, size_t maxlen) {
  14. size_t i;
  15. for (i = 0; i < maxlen && str[i]; i++);
  16. return i;
  17. }
  18. #endif /* !PCC_USE_SYSTEM_STRNLEN */
  19. #endif /* defined __GNUC__ && defined _WIN32 */
  20. #endif /* !_MSC_VER */
  21. #define PCC_DBG_EVALUATE 0
  22. #define PCC_DBG_MATCH 1
  23. #define PCC_DBG_NOMATCH 2
  24. #include "json.h"
  25. #include <stdio.h>
  26. static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
  27. #define PCC_DEBUG(event, rule, level, pos, buffer, length) \
  28. fprintf(stdout, "%*s%s %s @%d [%.*s]\n", (int)(level * 2), "", dbg_str[event], rule, (int)pos, (int)length, buffer); fflush(stdout)
  29. /* NOTE: To guarantee the output order, stderr, which can lead a race condition with stdout, is not used. */
  30. #ifndef PCC_BUFFERSIZE
  31. #define PCC_BUFFERSIZE 256
  32. #endif /* !PCC_BUFFERSIZE */
  33. #ifndef PCC_ARRAYSIZE
  34. #define PCC_ARRAYSIZE 2
  35. #endif /* !PCC_ARRAYSIZE */
  36. #define VOID_VALUE (~(size_t)0)
  37. typedef enum pcc_bool_tag {
  38. PCC_FALSE = 0,
  39. PCC_TRUE
  40. } pcc_bool_t;
  41. typedef struct pcc_char_array_tag {
  42. char *buf;
  43. size_t max;
  44. size_t len;
  45. } pcc_char_array_t;
  46. typedef struct pcc_range_tag {
  47. size_t start;
  48. size_t end;
  49. } pcc_range_t;
  50. typedef int pcc_value_t;
  51. typedef void *pcc_auxil_t;
  52. typedef struct pcc_value_table_tag {
  53. pcc_value_t *buf;
  54. size_t max;
  55. size_t len;
  56. } pcc_value_table_t;
  57. typedef struct pcc_value_refer_table_tag {
  58. pcc_value_t **buf;
  59. size_t max;
  60. size_t len;
  61. } pcc_value_refer_table_t;
  62. typedef struct pcc_capture_tag {
  63. pcc_range_t range;
  64. char *string; /* mutable */
  65. } pcc_capture_t;
  66. typedef struct pcc_capture_table_tag {
  67. pcc_capture_t *buf;
  68. size_t max;
  69. size_t len;
  70. } pcc_capture_table_t;
  71. typedef struct pcc_capture_const_table_tag {
  72. const pcc_capture_t **buf;
  73. size_t max;
  74. size_t len;
  75. } pcc_capture_const_table_t;
  76. typedef struct pcc_thunk_tag pcc_thunk_t;
  77. typedef struct pcc_thunk_array_tag pcc_thunk_array_t;
  78. typedef void (*pcc_action_t)(json_context_t *, pcc_thunk_t *, pcc_value_t *);
  79. typedef enum pcc_thunk_type_tag {
  80. PCC_THUNK_LEAF,
  81. PCC_THUNK_NODE
  82. } pcc_thunk_type_t;
  83. typedef struct pcc_thunk_leaf_tag {
  84. pcc_value_refer_table_t values;
  85. pcc_capture_const_table_t capts;
  86. pcc_capture_t capt0;
  87. pcc_action_t action;
  88. } pcc_thunk_leaf_t;
  89. typedef struct pcc_thunk_node_tag {
  90. const pcc_thunk_array_t *thunks; /* just a reference */
  91. pcc_value_t *value; /* just a reference */
  92. } pcc_thunk_node_t;
  93. typedef union pcc_thunk_data_tag {
  94. pcc_thunk_leaf_t leaf;
  95. pcc_thunk_node_t node;
  96. } pcc_thunk_data_t;
  97. struct pcc_thunk_tag {
  98. pcc_thunk_type_t type;
  99. pcc_thunk_data_t data;
  100. };
  101. struct pcc_thunk_array_tag {
  102. pcc_thunk_t **buf;
  103. size_t max;
  104. size_t len;
  105. };
  106. typedef struct pcc_thunk_chunk_tag {
  107. pcc_value_table_t values;
  108. pcc_capture_table_t capts;
  109. pcc_thunk_array_t thunks;
  110. size_t pos; /* the starting position in the character buffer */
  111. } pcc_thunk_chunk_t;
  112. typedef struct pcc_lr_entry_tag pcc_lr_entry_t;
  113. typedef enum pcc_lr_answer_type_tag {
  114. PCC_LR_ANSWER_LR,
  115. PCC_LR_ANSWER_CHUNK
  116. } pcc_lr_answer_type_t;
  117. typedef union pcc_lr_answer_data_tag {
  118. pcc_lr_entry_t *lr;
  119. pcc_thunk_chunk_t *chunk;
  120. } pcc_lr_answer_data_t;
  121. typedef struct pcc_lr_answer_tag pcc_lr_answer_t;
  122. struct pcc_lr_answer_tag {
  123. pcc_lr_answer_type_t type;
  124. pcc_lr_answer_data_t data;
  125. size_t pos; /* the absolute position in the input */
  126. pcc_lr_answer_t *hold;
  127. };
  128. typedef pcc_thunk_chunk_t *(*pcc_rule_t)(json_context_t *);
  129. typedef struct pcc_rule_set_tag {
  130. pcc_rule_t *buf;
  131. size_t max;
  132. size_t len;
  133. } pcc_rule_set_t;
  134. typedef struct pcc_lr_head_tag pcc_lr_head_t;
  135. struct pcc_lr_head_tag {
  136. pcc_rule_t rule;
  137. pcc_rule_set_t invol;
  138. pcc_rule_set_t eval;
  139. pcc_lr_head_t *hold;
  140. };
  141. typedef struct pcc_lr_memo_tag {
  142. pcc_rule_t rule;
  143. pcc_lr_answer_t *answer;
  144. } pcc_lr_memo_t;
  145. typedef struct pcc_lr_memo_map_tag {
  146. pcc_lr_memo_t *buf;
  147. size_t max;
  148. size_t len;
  149. } pcc_lr_memo_map_t;
  150. typedef struct pcc_lr_table_entry_tag {
  151. pcc_lr_head_t *head; /* just a reference */
  152. pcc_lr_memo_map_t memos;
  153. pcc_lr_answer_t *hold_a;
  154. pcc_lr_head_t *hold_h;
  155. } pcc_lr_table_entry_t;
  156. typedef struct pcc_lr_table_tag {
  157. pcc_lr_table_entry_t **buf;
  158. size_t max;
  159. size_t len;
  160. } pcc_lr_table_t;
  161. struct pcc_lr_entry_tag {
  162. pcc_rule_t rule;
  163. pcc_thunk_chunk_t *seed; /* just a reference */
  164. pcc_lr_head_t *head; /* just a reference */
  165. };
  166. typedef struct pcc_lr_stack_tag {
  167. pcc_lr_entry_t **buf;
  168. size_t max;
  169. size_t len;
  170. } pcc_lr_stack_t;
  171. struct json_context_tag {
  172. size_t pos; /* the position in the input of the first character currently buffered */
  173. size_t cur; /* the current parsing position in the character buffer */
  174. size_t level;
  175. pcc_char_array_t buffer;
  176. pcc_lr_table_t lrtable;
  177. pcc_lr_stack_t lrstack;
  178. pcc_auxil_t auxil;
  179. };
  180. #ifndef PCC_ERROR
  181. #define PCC_ERROR(auxil) pcc_error()
  182. static void pcc_error(void) {
  183. fprintf(stderr, "Syntax error\n");
  184. exit(1);
  185. }
  186. #endif /* !PCC_ERROR */
  187. #ifndef PCC_GETCHAR
  188. #define PCC_GETCHAR(auxil) getchar()
  189. #endif /* !PCC_GETCHAR */
  190. #ifndef PCC_MALLOC
  191. #define PCC_MALLOC(auxil, size) pcc_malloc_e(size)
  192. static void *pcc_malloc_e(size_t size) {
  193. void *const p = malloc(size);
  194. if (p == NULL) {
  195. fprintf(stderr, "Out of memory\n");
  196. exit(1);
  197. }
  198. return p;
  199. }
  200. #endif /* !PCC_MALLOC */
  201. #ifndef PCC_REALLOC
  202. #define PCC_REALLOC(auxil, ptr, size) pcc_realloc_e(ptr, size)
  203. static void *pcc_realloc_e(void *ptr, size_t size) {
  204. void *const p = realloc(ptr, size);
  205. if (p == NULL) {
  206. fprintf(stderr, "Out of memory\n");
  207. exit(1);
  208. }
  209. return p;
  210. }
  211. #endif /* !PCC_REALLOC */
  212. #ifndef PCC_FREE
  213. #define PCC_FREE(auxil, ptr) free(ptr)
  214. #endif /* !PCC_FREE */
  215. #ifndef PCC_DEBUG
  216. #define PCC_DEBUG(event, rule, level, pos, buffer, length) ((void)0)
  217. #endif /* !PCC_DEBUG */
  218. static char *pcc_strndup_e(pcc_auxil_t auxil, const char *str, size_t len) {
  219. const size_t m = strnlen(str, len);
  220. char *const s = (char *)PCC_MALLOC(auxil, m + 1);
  221. if (auxil) { }
  222. memcpy(s, str, m);
  223. s[m] = '\0';
  224. return s;
  225. }
  226. static void pcc_char_array__init(pcc_auxil_t auxil, pcc_char_array_t *array, size_t max) {
  227. array->len = 0;
  228. array->max = max;
  229. if (auxil) { }
  230. array->buf = (char *)PCC_MALLOC(auxil, array->max);
  231. }
  232. static void pcc_char_array__add(pcc_auxil_t auxil, pcc_char_array_t *array, char ch) {
  233. if (array->max <= array->len) {
  234. const size_t n = array->len + 1;
  235. size_t m = array->max;
  236. if (m == 0) m = 1;
  237. while (m < n && m != 0) m <<= 1;
  238. if (m == 0) m = n;
  239. if (auxil) { }
  240. array->buf = (char *)PCC_REALLOC(auxil, array->buf, m);
  241. array->max = m;
  242. }
  243. array->buf[array->len++] = ch;
  244. }
  245. static void pcc_char_array__term(pcc_auxil_t auxil, pcc_char_array_t *array) {
  246. PCC_FREE(auxil, array->buf);
  247. }
  248. static void pcc_value_table__init(pcc_auxil_t auxil, pcc_value_table_t *table, size_t max) {
  249. table->len = 0;
  250. table->max = max;
  251. table->buf = (pcc_value_t *)PCC_MALLOC(auxil, sizeof(pcc_value_t) * table->max);
  252. if (auxil) { }
  253. return;
  254. }
  255. static void pcc_value_table__resize(pcc_auxil_t auxil, pcc_value_table_t *table, size_t len) {
  256. if (table->max < len) {
  257. size_t m = table->max;
  258. if (m == 0) m = 1;
  259. while (m < len && m != 0) m <<= 1;
  260. if (m == 0) m = len;
  261. table->buf = (pcc_value_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t) * m);
  262. table->max = m;
  263. }
  264. table->len = len;
  265. }
  266. static void pcc_value_table__term(pcc_auxil_t auxil, pcc_value_table_t *table) {
  267. PCC_FREE(auxil, table->buf);
  268. }
  269. static void pcc_value_refer_table__init(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t max) {
  270. table->len = 0;
  271. table->max = max;
  272. table->buf = (pcc_value_t **)PCC_MALLOC(auxil, sizeof(pcc_value_t *) * table->max);
  273. }
  274. static void pcc_value_refer_table__resize(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t len) {
  275. size_t i;
  276. if (table->max < len) {
  277. size_t m = table->max;
  278. if (m == 0) m = 1;
  279. while (m < len && m != 0) m <<= 1;
  280. if (m == 0) m = len;
  281. table->buf = (pcc_value_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t *) * m);
  282. table->max = m;
  283. }
  284. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  285. table->len = len;
  286. }
  287. static void pcc_value_refer_table__term(pcc_auxil_t auxil, pcc_value_refer_table_t *table) {
  288. PCC_FREE(auxil, table->buf);
  289. }
  290. static void pcc_capture_table__init(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t max) {
  291. table->len = 0;
  292. table->max = max;
  293. table->buf = (pcc_capture_t *)PCC_MALLOC(auxil, sizeof(pcc_capture_t) * table->max);
  294. }
  295. static void pcc_capture_table__resize(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t len) {
  296. size_t i;
  297. for (i = len; i < table->len; i++) PCC_FREE(auxil, table->buf[i].string);
  298. if (table->max < len) {
  299. size_t m = table->max;
  300. if (m == 0) m = 1;
  301. while (m < len && m != 0) m <<= 1;
  302. if (m == 0) m = len;
  303. table->buf = (pcc_capture_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_capture_t) * m);
  304. table->max = m;
  305. }
  306. for (i = table->len; i < len; i++) {
  307. table->buf[i].range.start = 0;
  308. table->buf[i].range.end = 0;
  309. table->buf[i].string = NULL;
  310. }
  311. table->len = len;
  312. }
  313. static void pcc_capture_table__term(pcc_auxil_t auxil, pcc_capture_table_t *table) {
  314. while (table->len > 0) {
  315. table->len--;
  316. PCC_FREE(auxil, table->buf[table->len].string);
  317. }
  318. PCC_FREE(auxil, table->buf);
  319. }
  320. static void pcc_capture_const_table__init(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t max) {
  321. table->len = 0;
  322. table->max = max;
  323. table->buf = (const pcc_capture_t **)PCC_MALLOC(auxil, sizeof(const pcc_capture_t *) * table->max);
  324. }
  325. static void pcc_capture_const_table__resize(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t len) {
  326. size_t i;
  327. if (table->max < len) {
  328. size_t m = table->max;
  329. if (m == 0) m = 1;
  330. while (m < len && m != 0) m <<= 1;
  331. if (m == 0) m = len;
  332. table->buf = (const pcc_capture_t **)PCC_REALLOC(auxil, (pcc_capture_t **)table->buf, sizeof(const pcc_capture_t *) * m);
  333. table->max = m;
  334. }
  335. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  336. table->len = len;
  337. }
  338. static void pcc_capture_const_table__term(pcc_auxil_t auxil, pcc_capture_const_table_t *table) {
  339. PCC_FREE(auxil, table->buf);
  340. }
  341. static pcc_thunk_t *pcc_thunk__create_leaf(pcc_auxil_t auxil, pcc_action_t action, size_t valuec, size_t captc) {
  342. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  343. thunk->type = PCC_THUNK_LEAF;
  344. pcc_value_refer_table__init(auxil, &thunk->data.leaf.values, valuec);
  345. pcc_value_refer_table__resize(auxil, &thunk->data.leaf.values, valuec);
  346. pcc_capture_const_table__init(auxil, &thunk->data.leaf.capts, captc);
  347. pcc_capture_const_table__resize(auxil, &thunk->data.leaf.capts, captc);
  348. thunk->data.leaf.capt0.range.start = 0;
  349. thunk->data.leaf.capt0.range.end = 0;
  350. thunk->data.leaf.capt0.string = NULL;
  351. thunk->data.leaf.action = action;
  352. return thunk;
  353. }
  354. static pcc_thunk_t *pcc_thunk__create_node(pcc_auxil_t auxil, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  355. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  356. thunk->type = PCC_THUNK_NODE;
  357. thunk->data.node.thunks = thunks;
  358. thunk->data.node.value = value;
  359. return thunk;
  360. }
  361. static void pcc_thunk__destroy(pcc_auxil_t auxil, pcc_thunk_t *thunk) {
  362. if (thunk == NULL) return;
  363. switch (thunk->type) {
  364. case PCC_THUNK_LEAF:
  365. PCC_FREE(auxil, thunk->data.leaf.capt0.string);
  366. pcc_capture_const_table__term(auxil, &thunk->data.leaf.capts);
  367. pcc_value_refer_table__term(auxil, &thunk->data.leaf.values);
  368. break;
  369. case PCC_THUNK_NODE:
  370. break;
  371. default: /* unknown */
  372. break;
  373. }
  374. PCC_FREE(auxil, thunk);
  375. }
  376. static void pcc_thunk_array__init(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t max) {
  377. array->len = 0;
  378. array->max = max;
  379. array->buf = (pcc_thunk_t **)PCC_MALLOC(auxil, sizeof(pcc_thunk_t *) * array->max);
  380. }
  381. static void pcc_thunk_array__add(pcc_auxil_t auxil, pcc_thunk_array_t *array, pcc_thunk_t *thunk) {
  382. if (array->max <= array->len) {
  383. const size_t n = array->len + 1;
  384. size_t m = array->max;
  385. if (m == 0) m = 1;
  386. while (m < n && m != 0) m <<= 1;
  387. if (m == 0) m = n;
  388. array->buf = (pcc_thunk_t **)PCC_REALLOC(auxil, array->buf, sizeof(pcc_thunk_t *) * m);
  389. array->max = m;
  390. }
  391. array->buf[array->len++] = thunk;
  392. }
  393. static void pcc_thunk_array__revert(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t len) {
  394. while (array->len > len) {
  395. array->len--;
  396. pcc_thunk__destroy(auxil, array->buf[array->len]);
  397. }
  398. }
  399. static void pcc_thunk_array__term(pcc_auxil_t auxil, pcc_thunk_array_t *array) {
  400. while (array->len > 0) {
  401. array->len--;
  402. pcc_thunk__destroy(auxil, array->buf[array->len]);
  403. }
  404. PCC_FREE(auxil, array->buf);
  405. }
  406. static pcc_thunk_chunk_t *pcc_thunk_chunk__create(pcc_auxil_t auxil) {
  407. pcc_thunk_chunk_t *const chunk = (pcc_thunk_chunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_chunk_t));
  408. pcc_value_table__init(auxil, &chunk->values, PCC_ARRAYSIZE);
  409. pcc_capture_table__init(auxil, &chunk->capts, PCC_ARRAYSIZE);
  410. pcc_thunk_array__init(auxil, &chunk->thunks, PCC_ARRAYSIZE);
  411. chunk->pos = 0;
  412. return chunk;
  413. }
  414. static void pcc_thunk_chunk__destroy(pcc_auxil_t auxil, pcc_thunk_chunk_t *chunk) {
  415. if (chunk == NULL) return;
  416. pcc_thunk_array__term(auxil, &chunk->thunks);
  417. pcc_capture_table__term(auxil, &chunk->capts);
  418. pcc_value_table__term(auxil, &chunk->values);
  419. PCC_FREE(auxil, chunk);
  420. }
  421. static void pcc_rule_set__init(pcc_auxil_t auxil, pcc_rule_set_t *set, size_t max) {
  422. set->len = 0;
  423. set->max = max;
  424. set->buf = (pcc_rule_t *)PCC_MALLOC(auxil, sizeof(pcc_rule_t) * set->max);
  425. }
  426. static size_t pcc_rule_set__index(pcc_auxil_t auxil, const pcc_rule_set_t *set, pcc_rule_t rule) {
  427. size_t i;
  428. for (i = 0; i < set->len; i++) {
  429. if (set->buf[i] == rule) return i;
  430. }
  431. return VOID_VALUE;
  432. }
  433. static pcc_bool_t pcc_rule_set__add(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  434. const size_t i = pcc_rule_set__index(auxil, set, rule);
  435. if (i != VOID_VALUE) return PCC_FALSE;
  436. if (set->max <= set->len) {
  437. const size_t n = set->len + 1;
  438. size_t m = set->max;
  439. if (m == 0) m = 1;
  440. while (m < n && m != 0) m <<= 1;
  441. if (m == 0) m = n;
  442. set->buf = (pcc_rule_t *)PCC_REALLOC(auxil, set->buf, sizeof(pcc_rule_t) * m);
  443. set->max = m;
  444. }
  445. set->buf[set->len++] = rule;
  446. return PCC_TRUE;
  447. }
  448. static pcc_bool_t pcc_rule_set__remove(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  449. const size_t i = pcc_rule_set__index(auxil, set, rule);
  450. if (i == VOID_VALUE) return PCC_FALSE;
  451. memmove(set->buf + i, set->buf + (i + 1), sizeof(pcc_rule_t) * (set->len - (i + 1)));
  452. return PCC_TRUE;
  453. }
  454. static void pcc_rule_set__clear(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  455. set->len = 0;
  456. }
  457. static void pcc_rule_set__copy(pcc_auxil_t auxil, pcc_rule_set_t *set, const pcc_rule_set_t *src) {
  458. size_t i;
  459. pcc_rule_set__clear(auxil, set);
  460. for (i = 0; i < src->len; i++) {
  461. pcc_rule_set__add(auxil, set, src->buf[i]);
  462. }
  463. }
  464. static void pcc_rule_set__term(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  465. PCC_FREE(auxil, set->buf);
  466. }
  467. static pcc_lr_head_t *pcc_lr_head__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  468. pcc_lr_head_t *const head = (pcc_lr_head_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_head_t));
  469. head->rule = rule;
  470. pcc_rule_set__init(auxil, &head->invol, PCC_ARRAYSIZE);
  471. pcc_rule_set__init(auxil, &head->eval, PCC_ARRAYSIZE);
  472. head->hold = NULL;
  473. return head;
  474. }
  475. static void pcc_lr_head__destroy(pcc_auxil_t auxil, pcc_lr_head_t *head) {
  476. if (head == NULL) return;
  477. pcc_lr_head__destroy(auxil, head->hold);
  478. pcc_rule_set__term(auxil, &head->eval);
  479. pcc_rule_set__term(auxil, &head->invol);
  480. PCC_FREE(auxil, head);
  481. }
  482. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr);
  483. static pcc_lr_answer_t *pcc_lr_answer__create(pcc_auxil_t auxil, pcc_lr_answer_type_t type, size_t pos) {
  484. pcc_lr_answer_t *answer = (pcc_lr_answer_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_answer_t));
  485. answer->type = type;
  486. answer->pos = pos;
  487. answer->hold = NULL;
  488. switch (answer->type) {
  489. case PCC_LR_ANSWER_LR:
  490. answer->data.lr = NULL;
  491. break;
  492. case PCC_LR_ANSWER_CHUNK:
  493. answer->data.chunk = NULL;
  494. break;
  495. default: /* unknown */
  496. PCC_FREE(auxil, answer);
  497. answer = NULL;
  498. }
  499. return answer;
  500. }
  501. static void pcc_lr_answer__set_chunk(pcc_auxil_t auxil, pcc_lr_answer_t *answer, pcc_thunk_chunk_t *chunk) {
  502. pcc_lr_answer_t *const a = pcc_lr_answer__create(auxil, answer->type, answer->pos);
  503. switch (answer->type) {
  504. case PCC_LR_ANSWER_LR:
  505. a->data.lr = answer->data.lr;
  506. break;
  507. case PCC_LR_ANSWER_CHUNK:
  508. a->data.chunk = answer->data.chunk;
  509. break;
  510. default: /* unknown */
  511. break;
  512. }
  513. a->hold = answer->hold;
  514. answer->hold = a;
  515. answer->type = PCC_LR_ANSWER_CHUNK;
  516. answer->data.chunk = chunk;
  517. }
  518. static void pcc_lr_answer__destroy(pcc_auxil_t auxil, pcc_lr_answer_t *answer) {
  519. if (answer == NULL) return;
  520. pcc_lr_answer__destroy(auxil, answer->hold);
  521. switch (answer->type) {
  522. case PCC_LR_ANSWER_LR:
  523. pcc_lr_entry__destroy(auxil, answer->data.lr);
  524. break;
  525. case PCC_LR_ANSWER_CHUNK:
  526. pcc_thunk_chunk__destroy(auxil, answer->data.chunk);
  527. break;
  528. default: /* unknown */
  529. break;
  530. }
  531. PCC_FREE(auxil, answer);
  532. }
  533. static void pcc_lr_memo_map__init(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, size_t max) {
  534. map->len = 0;
  535. map->max = max;
  536. map->buf = (pcc_lr_memo_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_memo_t) * map->max);
  537. }
  538. static size_t pcc_lr_memo_map__index(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  539. size_t i;
  540. for (i = 0; i < map->len; i++) {
  541. if (map->buf[i].rule == rule) return i;
  542. }
  543. return VOID_VALUE;
  544. }
  545. static void pcc_lr_memo_map__put(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule, pcc_lr_answer_t *answer) {
  546. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  547. if (i != VOID_VALUE) {
  548. pcc_lr_answer__destroy(auxil, map->buf[i].answer);
  549. map->buf[i].answer = answer;
  550. }
  551. else {
  552. if (map->max <= map->len) {
  553. const size_t n = map->len + 1;
  554. size_t m = map->max;
  555. if (m == 0) m = 1;
  556. while (m < n && m != 0) m <<= 1;
  557. if (m == 0) m = n;
  558. map->buf = (pcc_lr_memo_t *)PCC_REALLOC(auxil, map->buf, sizeof(pcc_lr_memo_t) * m);
  559. map->max = m;
  560. }
  561. map->buf[map->len].rule = rule;
  562. map->buf[map->len].answer = answer;
  563. map->len++;
  564. }
  565. }
  566. static pcc_lr_answer_t *pcc_lr_memo_map__get(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  567. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  568. return (i != VOID_VALUE) ? map->buf[i].answer : NULL;
  569. }
  570. static void pcc_lr_memo_map__term(pcc_auxil_t auxil, pcc_lr_memo_map_t *map) {
  571. while (map->len > 0) {
  572. map->len--;
  573. pcc_lr_answer__destroy(auxil, map->buf[map->len].answer);
  574. }
  575. PCC_FREE(auxil, map->buf);
  576. }
  577. static pcc_lr_table_entry_t *pcc_lr_table_entry__create(pcc_auxil_t auxil) {
  578. pcc_lr_table_entry_t *const entry = (pcc_lr_table_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t));
  579. entry->head = NULL;
  580. pcc_lr_memo_map__init(auxil, &entry->memos, PCC_ARRAYSIZE);
  581. entry->hold_a = NULL;
  582. entry->hold_h = NULL;
  583. return entry;
  584. }
  585. static void pcc_lr_table_entry__destroy(pcc_auxil_t auxil, pcc_lr_table_entry_t *entry) {
  586. if (entry == NULL) return;
  587. pcc_lr_head__destroy(auxil, entry->hold_h);
  588. pcc_lr_answer__destroy(auxil, entry->hold_a);
  589. pcc_lr_memo_map__term(auxil, &entry->memos);
  590. PCC_FREE(auxil, entry);
  591. }
  592. static void pcc_lr_table__init(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t max) {
  593. table->len = 0;
  594. table->max = max;
  595. table->buf = (pcc_lr_table_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t *) * table->max);
  596. }
  597. static void pcc_lr_table__resize(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t len) {
  598. size_t i;
  599. for (i = len; i < table->len; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  600. if (table->max < len) {
  601. size_t m = table->max;
  602. if (m == 0) m = 1;
  603. while (m < len && m != 0) m <<= 1;
  604. if (m == 0) m = len;
  605. table->buf = (pcc_lr_table_entry_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_lr_table_entry_t *) * m);
  606. table->max = m;
  607. }
  608. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  609. table->len = len;
  610. }
  611. static void pcc_lr_table__set_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  612. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  613. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  614. table->buf[index]->head = head;
  615. }
  616. static void pcc_lr_table__hold_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  617. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  618. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  619. head->hold = table->buf[index]->hold_h;
  620. table->buf[index]->hold_h = head;
  621. }
  622. static void pcc_lr_table__set_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_rule_t rule, pcc_lr_answer_t *answer) {
  623. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  624. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  625. pcc_lr_memo_map__put(auxil, &table->buf[index]->memos, rule, answer);
  626. }
  627. static void pcc_lr_table__hold_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_answer_t *answer) {
  628. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  629. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  630. answer->hold = table->buf[index]->hold_a;
  631. table->buf[index]->hold_a = answer;
  632. }
  633. static pcc_lr_head_t *pcc_lr_table__get_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index) {
  634. if (index >= table->len || table->buf[index] == NULL) return NULL;
  635. return table->buf[index]->head;
  636. }
  637. static pcc_lr_answer_t *pcc_lr_table__get_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_rule_t rule) {
  638. if (index >= table->len || table->buf[index] == NULL) return NULL;
  639. return pcc_lr_memo_map__get(auxil, &table->buf[index]->memos, rule);
  640. }
  641. static void pcc_lr_table__shift(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t count) {
  642. size_t i;
  643. if (count > table->len) count = table->len;
  644. for (i = 0; i < count; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  645. memmove(table->buf, table->buf + count, sizeof(pcc_lr_table_entry_t *) * (table->len - count));
  646. table->len -= count;
  647. }
  648. static void pcc_lr_table__term(pcc_auxil_t auxil, pcc_lr_table_t *table) {
  649. while (table->len > 0) {
  650. table->len--;
  651. pcc_lr_table_entry__destroy(auxil, table->buf[table->len]);
  652. }
  653. PCC_FREE(auxil, table->buf);
  654. }
  655. static pcc_lr_entry_t *pcc_lr_entry__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  656. pcc_lr_entry_t *const lr = (pcc_lr_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t));
  657. lr->rule = rule;
  658. lr->seed = NULL;
  659. lr->head = NULL;
  660. return lr;
  661. }
  662. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr) {
  663. PCC_FREE(auxil, lr);
  664. }
  665. static void pcc_lr_stack__init(pcc_auxil_t auxil, pcc_lr_stack_t *stack, size_t max) {
  666. stack->len = 0;
  667. stack->max = max;
  668. stack->buf = (pcc_lr_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t *) * stack->max);
  669. }
  670. static void pcc_lr_stack__push(pcc_auxil_t auxil, pcc_lr_stack_t *stack, pcc_lr_entry_t *lr) {
  671. if (stack->max <= stack->len) {
  672. const size_t n = stack->len + 1;
  673. size_t m = stack->max;
  674. if (m == 0) m = 1;
  675. while (m < n && m != 0) m <<= 1;
  676. if (m == 0) m = n;
  677. stack->buf = (pcc_lr_entry_t **)PCC_REALLOC(auxil, stack->buf, sizeof(pcc_lr_entry_t *) * m);
  678. stack->max = m;
  679. }
  680. stack->buf[stack->len++] = lr;
  681. }
  682. static pcc_lr_entry_t *pcc_lr_stack__pop(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  683. return stack->buf[--stack->len];
  684. }
  685. static void pcc_lr_stack__term(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  686. PCC_FREE(auxil, stack->buf);
  687. }
  688. static json_context_t *pcc_context__create(pcc_auxil_t auxil) {
  689. json_context_t *const ctx = (json_context_t *)PCC_MALLOC(auxil, sizeof(json_context_t));
  690. ctx->pos = 0;
  691. ctx->cur = 0;
  692. ctx->level = 0;
  693. pcc_char_array__init(auxil, &ctx->buffer, PCC_BUFFERSIZE);
  694. pcc_lr_table__init(auxil, &ctx->lrtable, PCC_BUFFERSIZE);
  695. pcc_lr_stack__init(auxil, &ctx->lrstack, PCC_ARRAYSIZE);
  696. ctx->auxil = auxil;
  697. return ctx;
  698. }
  699. static void pcc_context__destroy(json_context_t *ctx) {
  700. if (ctx == NULL) return;
  701. pcc_lr_stack__term(ctx->auxil, &ctx->lrstack);
  702. pcc_lr_table__term(ctx->auxil, &ctx->lrtable);
  703. pcc_char_array__term(ctx->auxil, &ctx->buffer);
  704. PCC_FREE(ctx->auxil, ctx);
  705. }
  706. static size_t pcc_refill_buffer(json_context_t *ctx, size_t num) {
  707. if (ctx->buffer.len >= ctx->cur + num) return ctx->buffer.len - ctx->cur;
  708. while (ctx->buffer.len < ctx->cur + num) {
  709. const int c = PCC_GETCHAR(ctx->auxil);
  710. if (c == EOF) break;
  711. pcc_char_array__add(ctx->auxil, &ctx->buffer, (char)c);
  712. }
  713. return ctx->buffer.len - ctx->cur;
  714. }
  715. static void pcc_commit_buffer(json_context_t *ctx) {
  716. memmove(ctx->buffer.buf, ctx->buffer.buf + ctx->cur, ctx->buffer.len - ctx->cur);
  717. ctx->buffer.len -= ctx->cur;
  718. ctx->pos += ctx->cur;
  719. pcc_lr_table__shift(ctx->auxil, &ctx->lrtable, ctx->cur);
  720. ctx->cur = 0;
  721. }
  722. static const char *pcc_get_capture_string(json_context_t *ctx, const pcc_capture_t *capt) {
  723. if (capt->string == NULL)
  724. ((pcc_capture_t *)capt)->string =
  725. pcc_strndup_e(ctx->auxil, ctx->buffer.buf + capt->range.start, capt->range.end - capt->range.start);
  726. return capt->string;
  727. }
  728. static size_t pcc_get_char_as_utf32(json_context_t *ctx, int *out) { /* with checking UTF-8 validity */
  729. int c, u;
  730. size_t n;
  731. if (pcc_refill_buffer(ctx, 1) < 1) return 0;
  732. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur];
  733. n = (c < 0x80) ? 1 :
  734. ((c & 0xe0) == 0xc0) ? 2 :
  735. ((c & 0xf0) == 0xe0) ? 3 :
  736. ((c & 0xf8) == 0xf0) ? 4 : 0;
  737. if (n < 1) return 0;
  738. if (pcc_refill_buffer(ctx, n) < n) return 0;
  739. switch (n) {
  740. case 1:
  741. u = c;
  742. break;
  743. case 2:
  744. u = c & 0x1f;
  745. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  746. if ((c & 0xc0) != 0x80) return 0;
  747. u <<= 6; u |= c & 0x3f;
  748. if (u < 0x80) return 0;
  749. break;
  750. case 3:
  751. u = c & 0x0f;
  752. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  753. if ((c & 0xc0) != 0x80) return 0;
  754. u <<= 6; u |= c & 0x3f;
  755. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  756. if ((c & 0xc0) != 0x80) return 0;
  757. u <<= 6; u |= c & 0x3f;
  758. if (u < 0x800) return 0;
  759. break;
  760. case 4:
  761. u = c & 0x07;
  762. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  763. if ((c & 0xc0) != 0x80) return 0;
  764. u <<= 6; u |= c & 0x3f;
  765. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  766. if ((c & 0xc0) != 0x80) return 0;
  767. u <<= 6; u |= c & 0x3f;
  768. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 3];
  769. if ((c & 0xc0) != 0x80) return 0;
  770. u <<= 6; u |= c & 0x3f;
  771. if (u < 0x10000 || u > 0x10ffff) return 0;
  772. break;
  773. default:
  774. return 0;
  775. }
  776. if (out) *out = u;
  777. return n;
  778. }
  779. static pcc_bool_t pcc_apply_rule(json_context_t *ctx, pcc_rule_t rule, pcc_thunk_array_t *thunks, pcc_value_t *value) {
  780. static pcc_value_t null;
  781. pcc_thunk_chunk_t *c = NULL;
  782. const size_t p = ctx->pos + ctx->cur;
  783. pcc_bool_t b = PCC_TRUE;
  784. pcc_lr_answer_t *a = pcc_lr_table__get_answer(ctx->auxil, &ctx->lrtable, p, rule);
  785. pcc_lr_head_t *h = pcc_lr_table__get_head(ctx->auxil, &ctx->lrtable, p);
  786. if (h != NULL) {
  787. if (a == NULL && rule != h->rule && pcc_rule_set__index(ctx->auxil, &h->invol, rule) == VOID_VALUE) {
  788. b = PCC_FALSE;
  789. c = NULL;
  790. }
  791. else if (pcc_rule_set__remove(ctx->auxil, &h->eval, rule)) {
  792. b = PCC_FALSE;
  793. c = rule(ctx);
  794. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  795. a->data.chunk = c;
  796. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  797. }
  798. }
  799. if (b) {
  800. if (a != NULL) {
  801. ctx->cur = a->pos - ctx->pos;
  802. switch (a->type) {
  803. case PCC_LR_ANSWER_LR:
  804. if (a->data.lr->head == NULL) {
  805. a->data.lr->head = pcc_lr_head__create(ctx->auxil, rule);
  806. pcc_lr_table__hold_head(ctx->auxil, &ctx->lrtable, p, a->data.lr->head);
  807. }
  808. {
  809. size_t i = ctx->lrstack.len;
  810. while (i > 0) {
  811. i--;
  812. if (ctx->lrstack.buf[i]->head == a->data.lr->head) break;
  813. ctx->lrstack.buf[i]->head = a->data.lr->head;
  814. pcc_rule_set__add(ctx->auxil, &a->data.lr->head->invol, ctx->lrstack.buf[i]->rule);
  815. }
  816. }
  817. c = a->data.lr->seed;
  818. break;
  819. case PCC_LR_ANSWER_CHUNK:
  820. c = a->data.chunk;
  821. break;
  822. default: /* unknown */
  823. break;
  824. }
  825. }
  826. else {
  827. pcc_lr_entry_t *const e = pcc_lr_entry__create(ctx->auxil, rule);
  828. pcc_lr_stack__push(ctx->auxil, &ctx->lrstack, e);
  829. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_LR, p);
  830. a->data.lr = e;
  831. pcc_lr_table__set_answer(ctx->auxil, &ctx->lrtable, p, rule, a);
  832. c = rule(ctx);
  833. pcc_lr_stack__pop(ctx->auxil, &ctx->lrstack);
  834. a->pos = ctx->pos + ctx->cur;
  835. if (e->head == NULL) {
  836. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  837. }
  838. else {
  839. e->seed = c;
  840. h = a->data.lr->head;
  841. if (h->rule != rule) {
  842. c = a->data.lr->seed;
  843. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  844. a->data.chunk = c;
  845. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  846. }
  847. else {
  848. pcc_lr_answer__set_chunk(ctx->auxil, a, a->data.lr->seed);
  849. if (a->data.chunk == NULL) {
  850. c = NULL;
  851. }
  852. else {
  853. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, h);
  854. for (;;) {
  855. ctx->cur = p - ctx->pos;
  856. pcc_rule_set__copy(ctx->auxil, &h->eval, &h->invol);
  857. c = rule(ctx);
  858. if (c == NULL || ctx->pos + ctx->cur <= a->pos) break;
  859. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  860. a->pos = ctx->pos + ctx->cur;
  861. }
  862. pcc_thunk_chunk__destroy(ctx->auxil, c);
  863. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, NULL);
  864. ctx->cur = a->pos - ctx->pos;
  865. c = a->data.chunk;
  866. }
  867. }
  868. }
  869. }
  870. }
  871. if (c == NULL) return PCC_FALSE;
  872. if (value == NULL) value = &null;
  873. memset(value, 0, sizeof(pcc_value_t)); /* in case */
  874. pcc_thunk_array__add(ctx->auxil, thunks, pcc_thunk__create_node(ctx->auxil, &c->thunks, value));
  875. return PCC_TRUE;
  876. }
  877. static void pcc_do_action(json_context_t *ctx, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  878. size_t i;
  879. for (i = 0; i < thunks->len; i++) {
  880. pcc_thunk_t *const thunk = thunks->buf[i];
  881. switch (thunk->type) {
  882. case PCC_THUNK_LEAF:
  883. thunk->data.leaf.action(ctx, thunk, value);
  884. break;
  885. case PCC_THUNK_NODE:
  886. pcc_do_action(ctx, thunk->data.node.thunks, thunk->data.node.value);
  887. break;
  888. default: /* unknown */
  889. break;
  890. }
  891. }
  892. }
  893. static void pcc_action_endofline_0(json_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  894. #define auxil (__pcc_ctx->auxil)
  895. #define __ (*__pcc_out)
  896. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  897. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  898. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  899. #undef _0e
  900. #undef _0s
  901. #undef _0
  902. #undef __
  903. #undef auxil
  904. }
  905. static pcc_thunk_chunk_t *pcc_evaluate_rule_JSON(json_context_t *ctx);
  906. static pcc_thunk_chunk_t *pcc_evaluate_rule_JSONObject(json_context_t *ctx);
  907. static pcc_thunk_chunk_t *pcc_evaluate_rule_Pair(json_context_t *ctx);
  908. static pcc_thunk_chunk_t *pcc_evaluate_rule_Array(json_context_t *ctx);
  909. static pcc_thunk_chunk_t *pcc_evaluate_rule_Value(json_context_t *ctx);
  910. static pcc_thunk_chunk_t *pcc_evaluate_rule_True(json_context_t *ctx);
  911. static pcc_thunk_chunk_t *pcc_evaluate_rule_False(json_context_t *ctx);
  912. static pcc_thunk_chunk_t *pcc_evaluate_rule_Null(json_context_t *ctx);
  913. static pcc_thunk_chunk_t *pcc_evaluate_rule_String(json_context_t *ctx);
  914. static pcc_thunk_chunk_t *pcc_evaluate_rule_Char(json_context_t *ctx);
  915. static pcc_thunk_chunk_t *pcc_evaluate_rule_Number(json_context_t *ctx);
  916. static pcc_thunk_chunk_t *pcc_evaluate_rule_decimal_point(json_context_t *ctx);
  917. static pcc_thunk_chunk_t *pcc_evaluate_rule_digit1_9(json_context_t *ctx);
  918. static pcc_thunk_chunk_t *pcc_evaluate_rule_e(json_context_t *ctx);
  919. static pcc_thunk_chunk_t *pcc_evaluate_rule_exp(json_context_t *ctx);
  920. static pcc_thunk_chunk_t *pcc_evaluate_rule_frac(json_context_t *ctx);
  921. static pcc_thunk_chunk_t *pcc_evaluate_rule_int(json_context_t *ctx);
  922. static pcc_thunk_chunk_t *pcc_evaluate_rule_minus(json_context_t *ctx);
  923. static pcc_thunk_chunk_t *pcc_evaluate_rule_plus(json_context_t *ctx);
  924. static pcc_thunk_chunk_t *pcc_evaluate_rule_zero(json_context_t *ctx);
  925. static pcc_thunk_chunk_t *pcc_evaluate_rule_Digit(json_context_t *ctx);
  926. static pcc_thunk_chunk_t *pcc_evaluate_rule_Hex(json_context_t *ctx);
  927. static pcc_thunk_chunk_t *pcc_evaluate_rule__(json_context_t *ctx);
  928. static pcc_thunk_chunk_t *pcc_evaluate_rule_space(json_context_t *ctx);
  929. static pcc_thunk_chunk_t *pcc_evaluate_rule_comment(json_context_t *ctx);
  930. static pcc_thunk_chunk_t *pcc_evaluate_rule_endofline(json_context_t *ctx);
  931. static pcc_thunk_chunk_t *pcc_evaluate_rule_JSON(json_context_t *ctx) {
  932. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  933. chunk->pos = ctx->cur;
  934. PCC_DEBUG(PCC_DBG_EVALUATE, "JSON", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  935. ctx->level++;
  936. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  937. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  938. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_JSONObject, &chunk->thunks, NULL)) goto L0000;
  939. {
  940. const size_t p = ctx->cur;
  941. const size_t n = chunk->thunks.len;
  942. {
  943. int u;
  944. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  945. if (n == 0) goto L0001;
  946. ctx->cur += n;
  947. }
  948. ctx->cur = p;
  949. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  950. goto L0000;
  951. L0001:;
  952. ctx->cur = p;
  953. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  954. }
  955. ctx->level--;
  956. PCC_DEBUG(PCC_DBG_MATCH, "JSON", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  957. return chunk;
  958. L0000:;
  959. ctx->level--;
  960. PCC_DEBUG(PCC_DBG_NOMATCH, "JSON", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  961. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  962. return NULL;
  963. }
  964. static pcc_thunk_chunk_t *pcc_evaluate_rule_JSONObject(json_context_t *ctx) {
  965. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  966. chunk->pos = ctx->cur;
  967. PCC_DEBUG(PCC_DBG_EVALUATE, "JSONObject", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  968. ctx->level++;
  969. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  970. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  971. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  972. if (
  973. pcc_refill_buffer(ctx, 1) < 1 ||
  974. ctx->buffer.buf[ctx->cur] != '{'
  975. ) goto L0000;
  976. ctx->cur++;
  977. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  978. {
  979. int i;
  980. for (i = 0;; i++) {
  981. const size_t p = ctx->cur;
  982. const size_t n = chunk->thunks.len;
  983. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Pair, &chunk->thunks, NULL)) goto L0001;
  984. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0001;
  985. {
  986. int i;
  987. for (i = 0;; i++) {
  988. const size_t p = ctx->cur;
  989. const size_t n = chunk->thunks.len;
  990. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  991. if (
  992. pcc_refill_buffer(ctx, 1) < 1 ||
  993. ctx->buffer.buf[ctx->cur] != ','
  994. ) goto L0002;
  995. ctx->cur++;
  996. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  997. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Pair, &chunk->thunks, NULL)) goto L0002;
  998. if (ctx->cur == p) break;
  999. continue;
  1000. L0002:;
  1001. ctx->cur = p;
  1002. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1003. break;
  1004. }
  1005. }
  1006. if (ctx->cur == p) break;
  1007. continue;
  1008. L0001:;
  1009. ctx->cur = p;
  1010. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1011. break;
  1012. }
  1013. }
  1014. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1015. if (
  1016. pcc_refill_buffer(ctx, 1) < 1 ||
  1017. ctx->buffer.buf[ctx->cur] != '}'
  1018. ) goto L0000;
  1019. ctx->cur++;
  1020. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1021. ctx->level--;
  1022. PCC_DEBUG(PCC_DBG_MATCH, "JSONObject", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1023. return chunk;
  1024. L0000:;
  1025. ctx->level--;
  1026. PCC_DEBUG(PCC_DBG_NOMATCH, "JSONObject", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1027. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1028. return NULL;
  1029. }
  1030. static pcc_thunk_chunk_t *pcc_evaluate_rule_Pair(json_context_t *ctx) {
  1031. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1032. chunk->pos = ctx->cur;
  1033. PCC_DEBUG(PCC_DBG_EVALUATE, "Pair", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1034. ctx->level++;
  1035. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1036. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1037. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_String, &chunk->thunks, NULL)) goto L0000;
  1038. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1039. if (
  1040. pcc_refill_buffer(ctx, 1) < 1 ||
  1041. ctx->buffer.buf[ctx->cur] != ':'
  1042. ) goto L0000;
  1043. ctx->cur++;
  1044. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1045. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Value, &chunk->thunks, NULL)) goto L0000;
  1046. ctx->level--;
  1047. PCC_DEBUG(PCC_DBG_MATCH, "Pair", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1048. return chunk;
  1049. L0000:;
  1050. ctx->level--;
  1051. PCC_DEBUG(PCC_DBG_NOMATCH, "Pair", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1052. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1053. return NULL;
  1054. }
  1055. static pcc_thunk_chunk_t *pcc_evaluate_rule_Array(json_context_t *ctx) {
  1056. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1057. chunk->pos = ctx->cur;
  1058. PCC_DEBUG(PCC_DBG_EVALUATE, "Array", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1059. ctx->level++;
  1060. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1061. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1062. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1063. if (
  1064. pcc_refill_buffer(ctx, 1) < 1 ||
  1065. ctx->buffer.buf[ctx->cur] != '['
  1066. ) goto L0000;
  1067. ctx->cur++;
  1068. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1069. {
  1070. const size_t p = ctx->cur;
  1071. const size_t n = chunk->thunks.len;
  1072. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Value, &chunk->thunks, NULL)) goto L0001;
  1073. {
  1074. int i;
  1075. for (i = 0;; i++) {
  1076. const size_t p = ctx->cur;
  1077. const size_t n = chunk->thunks.len;
  1078. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1079. if (
  1080. pcc_refill_buffer(ctx, 1) < 1 ||
  1081. ctx->buffer.buf[ctx->cur] != ','
  1082. ) goto L0002;
  1083. ctx->cur++;
  1084. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1085. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Value, &chunk->thunks, NULL)) goto L0002;
  1086. if (ctx->cur == p) break;
  1087. continue;
  1088. L0002:;
  1089. ctx->cur = p;
  1090. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1091. break;
  1092. }
  1093. }
  1094. goto L0003;
  1095. L0001:;
  1096. ctx->cur = p;
  1097. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1098. L0003:;
  1099. }
  1100. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1101. if (
  1102. pcc_refill_buffer(ctx, 1) < 1 ||
  1103. ctx->buffer.buf[ctx->cur] != ']'
  1104. ) goto L0000;
  1105. ctx->cur++;
  1106. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1107. ctx->level--;
  1108. PCC_DEBUG(PCC_DBG_MATCH, "Array", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1109. return chunk;
  1110. L0000:;
  1111. ctx->level--;
  1112. PCC_DEBUG(PCC_DBG_NOMATCH, "Array", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1113. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1114. return NULL;
  1115. }
  1116. static pcc_thunk_chunk_t *pcc_evaluate_rule_Value(json_context_t *ctx) {
  1117. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1118. chunk->pos = ctx->cur;
  1119. PCC_DEBUG(PCC_DBG_EVALUATE, "Value", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1120. ctx->level++;
  1121. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1122. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1123. {
  1124. const size_t p = ctx->cur;
  1125. const size_t n = chunk->thunks.len;
  1126. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_String, &chunk->thunks, NULL)) goto L0002;
  1127. goto L0001;
  1128. L0002:;
  1129. ctx->cur = p;
  1130. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1131. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Number, &chunk->thunks, NULL)) goto L0003;
  1132. goto L0001;
  1133. L0003:;
  1134. ctx->cur = p;
  1135. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1136. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_JSONObject, &chunk->thunks, NULL)) goto L0004;
  1137. goto L0001;
  1138. L0004:;
  1139. ctx->cur = p;
  1140. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1141. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Array, &chunk->thunks, NULL)) goto L0005;
  1142. goto L0001;
  1143. L0005:;
  1144. ctx->cur = p;
  1145. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1146. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_True, &chunk->thunks, NULL)) goto L0006;
  1147. goto L0001;
  1148. L0006:;
  1149. ctx->cur = p;
  1150. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1151. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_False, &chunk->thunks, NULL)) goto L0007;
  1152. goto L0001;
  1153. L0007:;
  1154. ctx->cur = p;
  1155. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1156. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Null, &chunk->thunks, NULL)) goto L0008;
  1157. goto L0001;
  1158. L0008:;
  1159. ctx->cur = p;
  1160. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1161. goto L0000;
  1162. L0001:;
  1163. }
  1164. ctx->level--;
  1165. PCC_DEBUG(PCC_DBG_MATCH, "Value", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1166. return chunk;
  1167. L0000:;
  1168. ctx->level--;
  1169. PCC_DEBUG(PCC_DBG_NOMATCH, "Value", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1170. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1171. return NULL;
  1172. }
  1173. static pcc_thunk_chunk_t *pcc_evaluate_rule_True(json_context_t *ctx) {
  1174. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1175. chunk->pos = ctx->cur;
  1176. PCC_DEBUG(PCC_DBG_EVALUATE, "True", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1177. ctx->level++;
  1178. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1179. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1180. if (
  1181. pcc_refill_buffer(ctx, 4) < 4 ||
  1182. (ctx->buffer.buf + ctx->cur)[0] != 't' ||
  1183. (ctx->buffer.buf + ctx->cur)[1] != 'r' ||
  1184. (ctx->buffer.buf + ctx->cur)[2] != 'u' ||
  1185. (ctx->buffer.buf + ctx->cur)[3] != 'e'
  1186. ) goto L0000;
  1187. ctx->cur += 4;
  1188. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1189. ctx->level--;
  1190. PCC_DEBUG(PCC_DBG_MATCH, "True", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1191. return chunk;
  1192. L0000:;
  1193. ctx->level--;
  1194. PCC_DEBUG(PCC_DBG_NOMATCH, "True", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1195. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1196. return NULL;
  1197. }
  1198. static pcc_thunk_chunk_t *pcc_evaluate_rule_False(json_context_t *ctx) {
  1199. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1200. chunk->pos = ctx->cur;
  1201. PCC_DEBUG(PCC_DBG_EVALUATE, "False", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1202. ctx->level++;
  1203. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1204. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1205. if (
  1206. pcc_refill_buffer(ctx, 5) < 5 ||
  1207. (ctx->buffer.buf + ctx->cur)[0] != 'f' ||
  1208. (ctx->buffer.buf + ctx->cur)[1] != 'a' ||
  1209. (ctx->buffer.buf + ctx->cur)[2] != 'l' ||
  1210. (ctx->buffer.buf + ctx->cur)[3] != 's' ||
  1211. (ctx->buffer.buf + ctx->cur)[4] != 'e'
  1212. ) goto L0000;
  1213. ctx->cur += 5;
  1214. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1215. ctx->level--;
  1216. PCC_DEBUG(PCC_DBG_MATCH, "False", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1217. return chunk;
  1218. L0000:;
  1219. ctx->level--;
  1220. PCC_DEBUG(PCC_DBG_NOMATCH, "False", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1221. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1222. return NULL;
  1223. }
  1224. static pcc_thunk_chunk_t *pcc_evaluate_rule_Null(json_context_t *ctx) {
  1225. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1226. chunk->pos = ctx->cur;
  1227. PCC_DEBUG(PCC_DBG_EVALUATE, "Null", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1228. ctx->level++;
  1229. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1230. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1231. if (
  1232. pcc_refill_buffer(ctx, 4) < 4 ||
  1233. (ctx->buffer.buf + ctx->cur)[0] != 'n' ||
  1234. (ctx->buffer.buf + ctx->cur)[1] != 'u' ||
  1235. (ctx->buffer.buf + ctx->cur)[2] != 'l' ||
  1236. (ctx->buffer.buf + ctx->cur)[3] != 'l'
  1237. ) goto L0000;
  1238. ctx->cur += 4;
  1239. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1240. ctx->level--;
  1241. PCC_DEBUG(PCC_DBG_MATCH, "Null", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1242. return chunk;
  1243. L0000:;
  1244. ctx->level--;
  1245. PCC_DEBUG(PCC_DBG_NOMATCH, "Null", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1246. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1247. return NULL;
  1248. }
  1249. static pcc_thunk_chunk_t *pcc_evaluate_rule_String(json_context_t *ctx) {
  1250. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1251. chunk->pos = ctx->cur;
  1252. PCC_DEBUG(PCC_DBG_EVALUATE, "String", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1253. ctx->level++;
  1254. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1255. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1256. if (
  1257. pcc_refill_buffer(ctx, 1) < 1 ||
  1258. ctx->buffer.buf[ctx->cur] != '\"'
  1259. ) goto L0000;
  1260. ctx->cur++;
  1261. {
  1262. int i;
  1263. for (i = 0;; i++) {
  1264. const size_t p = ctx->cur;
  1265. const size_t n = chunk->thunks.len;
  1266. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Char, &chunk->thunks, NULL)) goto L0001;
  1267. if (ctx->cur == p) break;
  1268. continue;
  1269. L0001:;
  1270. ctx->cur = p;
  1271. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1272. break;
  1273. }
  1274. }
  1275. if (
  1276. pcc_refill_buffer(ctx, 1) < 1 ||
  1277. ctx->buffer.buf[ctx->cur] != '\"'
  1278. ) goto L0000;
  1279. ctx->cur++;
  1280. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1281. ctx->level--;
  1282. PCC_DEBUG(PCC_DBG_MATCH, "String", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1283. return chunk;
  1284. L0000:;
  1285. ctx->level--;
  1286. PCC_DEBUG(PCC_DBG_NOMATCH, "String", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1287. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1288. return NULL;
  1289. }
  1290. static pcc_thunk_chunk_t *pcc_evaluate_rule_Char(json_context_t *ctx) {
  1291. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1292. chunk->pos = ctx->cur;
  1293. PCC_DEBUG(PCC_DBG_EVALUATE, "Char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1294. ctx->level++;
  1295. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1296. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1297. {
  1298. const size_t p = ctx->cur;
  1299. const size_t n = chunk->thunks.len;
  1300. if (
  1301. pcc_refill_buffer(ctx, 1) < 1 ||
  1302. ctx->buffer.buf[ctx->cur] != '\\'
  1303. ) goto L0002;
  1304. ctx->cur++;
  1305. if (
  1306. pcc_refill_buffer(ctx, 1) < 1 ||
  1307. ctx->buffer.buf[ctx->cur] != '\"'
  1308. ) goto L0002;
  1309. ctx->cur++;
  1310. goto L0001;
  1311. L0002:;
  1312. ctx->cur = p;
  1313. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1314. if (
  1315. pcc_refill_buffer(ctx, 1) < 1 ||
  1316. ctx->buffer.buf[ctx->cur] != '\\'
  1317. ) goto L0003;
  1318. ctx->cur++;
  1319. if (
  1320. pcc_refill_buffer(ctx, 1) < 1 ||
  1321. ctx->buffer.buf[ctx->cur] != '\\'
  1322. ) goto L0003;
  1323. ctx->cur++;
  1324. goto L0001;
  1325. L0003:;
  1326. ctx->cur = p;
  1327. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1328. if (
  1329. pcc_refill_buffer(ctx, 1) < 1 ||
  1330. ctx->buffer.buf[ctx->cur] != '\\'
  1331. ) goto L0004;
  1332. ctx->cur++;
  1333. if (
  1334. pcc_refill_buffer(ctx, 1) < 1 ||
  1335. ctx->buffer.buf[ctx->cur] != '/'
  1336. ) goto L0004;
  1337. ctx->cur++;
  1338. goto L0001;
  1339. L0004:;
  1340. ctx->cur = p;
  1341. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1342. if (
  1343. pcc_refill_buffer(ctx, 1) < 1 ||
  1344. ctx->buffer.buf[ctx->cur] != '\\'
  1345. ) goto L0005;
  1346. ctx->cur++;
  1347. if (
  1348. pcc_refill_buffer(ctx, 1) < 1 ||
  1349. ctx->buffer.buf[ctx->cur] != 'b'
  1350. ) goto L0005;
  1351. ctx->cur++;
  1352. goto L0001;
  1353. L0005:;
  1354. ctx->cur = p;
  1355. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1356. if (
  1357. pcc_refill_buffer(ctx, 1) < 1 ||
  1358. ctx->buffer.buf[ctx->cur] != '\\'
  1359. ) goto L0006;
  1360. ctx->cur++;
  1361. if (
  1362. pcc_refill_buffer(ctx, 1) < 1 ||
  1363. ctx->buffer.buf[ctx->cur] != 'f'
  1364. ) goto L0006;
  1365. ctx->cur++;
  1366. goto L0001;
  1367. L0006:;
  1368. ctx->cur = p;
  1369. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1370. if (
  1371. pcc_refill_buffer(ctx, 1) < 1 ||
  1372. ctx->buffer.buf[ctx->cur] != '\\'
  1373. ) goto L0007;
  1374. ctx->cur++;
  1375. if (
  1376. pcc_refill_buffer(ctx, 1) < 1 ||
  1377. ctx->buffer.buf[ctx->cur] != 'n'
  1378. ) goto L0007;
  1379. ctx->cur++;
  1380. goto L0001;
  1381. L0007:;
  1382. ctx->cur = p;
  1383. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1384. if (
  1385. pcc_refill_buffer(ctx, 1) < 1 ||
  1386. ctx->buffer.buf[ctx->cur] != '\\'
  1387. ) goto L0008;
  1388. ctx->cur++;
  1389. if (
  1390. pcc_refill_buffer(ctx, 1) < 1 ||
  1391. ctx->buffer.buf[ctx->cur] != 'r'
  1392. ) goto L0008;
  1393. ctx->cur++;
  1394. goto L0001;
  1395. L0008:;
  1396. ctx->cur = p;
  1397. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1398. if (
  1399. pcc_refill_buffer(ctx, 1) < 1 ||
  1400. ctx->buffer.buf[ctx->cur] != '\\'
  1401. ) goto L0009;
  1402. ctx->cur++;
  1403. if (
  1404. pcc_refill_buffer(ctx, 1) < 1 ||
  1405. ctx->buffer.buf[ctx->cur] != 't'
  1406. ) goto L0009;
  1407. ctx->cur++;
  1408. goto L0001;
  1409. L0009:;
  1410. ctx->cur = p;
  1411. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1412. if (
  1413. pcc_refill_buffer(ctx, 1) < 1 ||
  1414. ctx->buffer.buf[ctx->cur] != '\\'
  1415. ) goto L0010;
  1416. ctx->cur++;
  1417. if (
  1418. pcc_refill_buffer(ctx, 1) < 1 ||
  1419. ctx->buffer.buf[ctx->cur] != 'u'
  1420. ) goto L0010;
  1421. ctx->cur++;
  1422. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Hex, &chunk->thunks, NULL)) goto L0010;
  1423. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Hex, &chunk->thunks, NULL)) goto L0010;
  1424. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Hex, &chunk->thunks, NULL)) goto L0010;
  1425. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Hex, &chunk->thunks, NULL)) goto L0010;
  1426. goto L0001;
  1427. L0010:;
  1428. ctx->cur = p;
  1429. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1430. {
  1431. const size_t p = ctx->cur;
  1432. const size_t n = chunk->thunks.len;
  1433. if (
  1434. pcc_refill_buffer(ctx, 1) < 1 ||
  1435. ctx->buffer.buf[ctx->cur] != '\"'
  1436. ) goto L0012;
  1437. ctx->cur++;
  1438. ctx->cur = p;
  1439. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1440. goto L0011;
  1441. L0012:;
  1442. ctx->cur = p;
  1443. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1444. }
  1445. {
  1446. int u;
  1447. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1448. if (n == 0) goto L0011;
  1449. ctx->cur += n;
  1450. }
  1451. goto L0001;
  1452. L0011:;
  1453. ctx->cur = p;
  1454. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1455. goto L0000;
  1456. L0001:;
  1457. }
  1458. ctx->level--;
  1459. PCC_DEBUG(PCC_DBG_MATCH, "Char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1460. return chunk;
  1461. L0000:;
  1462. ctx->level--;
  1463. PCC_DEBUG(PCC_DBG_NOMATCH, "Char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1464. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1465. return NULL;
  1466. }
  1467. static pcc_thunk_chunk_t *pcc_evaluate_rule_Number(json_context_t *ctx) {
  1468. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1469. chunk->pos = ctx->cur;
  1470. PCC_DEBUG(PCC_DBG_EVALUATE, "Number", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1471. ctx->level++;
  1472. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1473. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1474. {
  1475. const size_t p = ctx->cur;
  1476. const size_t n = chunk->thunks.len;
  1477. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_minus, &chunk->thunks, NULL)) goto L0001;
  1478. goto L0002;
  1479. L0001:;
  1480. ctx->cur = p;
  1481. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1482. L0002:;
  1483. }
  1484. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_int, &chunk->thunks, NULL)) goto L0000;
  1485. {
  1486. const size_t p = ctx->cur;
  1487. const size_t n = chunk->thunks.len;
  1488. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_frac, &chunk->thunks, NULL)) goto L0003;
  1489. goto L0004;
  1490. L0003:;
  1491. ctx->cur = p;
  1492. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1493. L0004:;
  1494. }
  1495. {
  1496. const size_t p = ctx->cur;
  1497. const size_t n = chunk->thunks.len;
  1498. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_exp, &chunk->thunks, NULL)) goto L0005;
  1499. goto L0006;
  1500. L0005:;
  1501. ctx->cur = p;
  1502. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1503. L0006:;
  1504. }
  1505. ctx->level--;
  1506. PCC_DEBUG(PCC_DBG_MATCH, "Number", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1507. return chunk;
  1508. L0000:;
  1509. ctx->level--;
  1510. PCC_DEBUG(PCC_DBG_NOMATCH, "Number", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1511. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1512. return NULL;
  1513. }
  1514. static pcc_thunk_chunk_t *pcc_evaluate_rule_decimal_point(json_context_t *ctx) {
  1515. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1516. chunk->pos = ctx->cur;
  1517. PCC_DEBUG(PCC_DBG_EVALUATE, "decimal_point", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1518. ctx->level++;
  1519. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1520. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1521. if (
  1522. pcc_refill_buffer(ctx, 1) < 1 ||
  1523. ctx->buffer.buf[ctx->cur] != '.'
  1524. ) goto L0000;
  1525. ctx->cur++;
  1526. ctx->level--;
  1527. PCC_DEBUG(PCC_DBG_MATCH, "decimal_point", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1528. return chunk;
  1529. L0000:;
  1530. ctx->level--;
  1531. PCC_DEBUG(PCC_DBG_NOMATCH, "decimal_point", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1532. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1533. return NULL;
  1534. }
  1535. static pcc_thunk_chunk_t *pcc_evaluate_rule_digit1_9(json_context_t *ctx) {
  1536. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1537. chunk->pos = ctx->cur;
  1538. PCC_DEBUG(PCC_DBG_EVALUATE, "digit1_9", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1539. ctx->level++;
  1540. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1541. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1542. {
  1543. int u;
  1544. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1545. if (n == 0) goto L0000;
  1546. if (!(
  1547. (u >= 0x000031 && u <= 0x000039)
  1548. )) goto L0000;
  1549. ctx->cur += n;
  1550. }
  1551. ctx->level--;
  1552. PCC_DEBUG(PCC_DBG_MATCH, "digit1_9", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1553. return chunk;
  1554. L0000:;
  1555. ctx->level--;
  1556. PCC_DEBUG(PCC_DBG_NOMATCH, "digit1_9", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1557. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1558. return NULL;
  1559. }
  1560. static pcc_thunk_chunk_t *pcc_evaluate_rule_e(json_context_t *ctx) {
  1561. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1562. chunk->pos = ctx->cur;
  1563. PCC_DEBUG(PCC_DBG_EVALUATE, "e", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1564. ctx->level++;
  1565. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1566. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1567. {
  1568. int u;
  1569. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1570. if (n == 0) goto L0000;
  1571. if (!(
  1572. u == 0x000027 ||
  1573. u == 0x000065 ||
  1574. u == 0x000027 ||
  1575. u == 0x000027 ||
  1576. u == 0x000045 ||
  1577. u == 0x000027
  1578. )) goto L0000;
  1579. ctx->cur += n;
  1580. }
  1581. ctx->level--;
  1582. PCC_DEBUG(PCC_DBG_MATCH, "e", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1583. return chunk;
  1584. L0000:;
  1585. ctx->level--;
  1586. PCC_DEBUG(PCC_DBG_NOMATCH, "e", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1587. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1588. return NULL;
  1589. }
  1590. static pcc_thunk_chunk_t *pcc_evaluate_rule_exp(json_context_t *ctx) {
  1591. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1592. chunk->pos = ctx->cur;
  1593. PCC_DEBUG(PCC_DBG_EVALUATE, "exp", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1594. ctx->level++;
  1595. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1596. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1597. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_e, &chunk->thunks, NULL)) goto L0000;
  1598. {
  1599. const size_t p = ctx->cur;
  1600. const size_t n = chunk->thunks.len;
  1601. {
  1602. const size_t p = ctx->cur;
  1603. const size_t n = chunk->thunks.len;
  1604. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_minus, &chunk->thunks, NULL)) goto L0003;
  1605. goto L0002;
  1606. L0003:;
  1607. ctx->cur = p;
  1608. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1609. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_plus, &chunk->thunks, NULL)) goto L0004;
  1610. goto L0002;
  1611. L0004:;
  1612. ctx->cur = p;
  1613. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1614. goto L0001;
  1615. L0002:;
  1616. }
  1617. goto L0005;
  1618. L0001:;
  1619. ctx->cur = p;
  1620. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1621. L0005:;
  1622. }
  1623. {
  1624. const size_t p0 = ctx->cur;
  1625. const size_t n0 = chunk->thunks.len;
  1626. int i;
  1627. for (i = 0;; i++) {
  1628. const size_t p = ctx->cur;
  1629. const size_t n = chunk->thunks.len;
  1630. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Digit, &chunk->thunks, NULL)) goto L0006;
  1631. if (ctx->cur == p) break;
  1632. continue;
  1633. L0006:;
  1634. ctx->cur = p;
  1635. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1636. break;
  1637. }
  1638. if (i < 1) {
  1639. ctx->cur = p0;
  1640. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  1641. goto L0000;
  1642. }
  1643. }
  1644. ctx->level--;
  1645. PCC_DEBUG(PCC_DBG_MATCH, "exp", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1646. return chunk;
  1647. L0000:;
  1648. ctx->level--;
  1649. PCC_DEBUG(PCC_DBG_NOMATCH, "exp", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1650. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1651. return NULL;
  1652. }
  1653. static pcc_thunk_chunk_t *pcc_evaluate_rule_frac(json_context_t *ctx) {
  1654. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1655. chunk->pos = ctx->cur;
  1656. PCC_DEBUG(PCC_DBG_EVALUATE, "frac", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1657. ctx->level++;
  1658. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1659. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1660. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_decimal_point, &chunk->thunks, NULL)) goto L0000;
  1661. {
  1662. const size_t p0 = ctx->cur;
  1663. const size_t n0 = chunk->thunks.len;
  1664. int i;
  1665. for (i = 0;; i++) {
  1666. const size_t p = ctx->cur;
  1667. const size_t n = chunk->thunks.len;
  1668. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Digit, &chunk->thunks, NULL)) goto L0001;
  1669. if (ctx->cur == p) break;
  1670. continue;
  1671. L0001:;
  1672. ctx->cur = p;
  1673. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1674. break;
  1675. }
  1676. if (i < 1) {
  1677. ctx->cur = p0;
  1678. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  1679. goto L0000;
  1680. }
  1681. }
  1682. ctx->level--;
  1683. PCC_DEBUG(PCC_DBG_MATCH, "frac", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1684. return chunk;
  1685. L0000:;
  1686. ctx->level--;
  1687. PCC_DEBUG(PCC_DBG_NOMATCH, "frac", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1688. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1689. return NULL;
  1690. }
  1691. static pcc_thunk_chunk_t *pcc_evaluate_rule_int(json_context_t *ctx) {
  1692. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1693. chunk->pos = ctx->cur;
  1694. PCC_DEBUG(PCC_DBG_EVALUATE, "int", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1695. ctx->level++;
  1696. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1697. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1698. {
  1699. const size_t p = ctx->cur;
  1700. const size_t n = chunk->thunks.len;
  1701. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_zero, &chunk->thunks, NULL)) goto L0002;
  1702. goto L0001;
  1703. L0002:;
  1704. ctx->cur = p;
  1705. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1706. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_digit1_9, &chunk->thunks, NULL)) goto L0003;
  1707. {
  1708. int i;
  1709. for (i = 0;; i++) {
  1710. const size_t p = ctx->cur;
  1711. const size_t n = chunk->thunks.len;
  1712. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_Digit, &chunk->thunks, NULL)) goto L0004;
  1713. if (ctx->cur == p) break;
  1714. continue;
  1715. L0004:;
  1716. ctx->cur = p;
  1717. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1718. break;
  1719. }
  1720. }
  1721. goto L0001;
  1722. L0003:;
  1723. ctx->cur = p;
  1724. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1725. goto L0000;
  1726. L0001:;
  1727. }
  1728. ctx->level--;
  1729. PCC_DEBUG(PCC_DBG_MATCH, "int", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1730. return chunk;
  1731. L0000:;
  1732. ctx->level--;
  1733. PCC_DEBUG(PCC_DBG_NOMATCH, "int", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1734. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1735. return NULL;
  1736. }
  1737. static pcc_thunk_chunk_t *pcc_evaluate_rule_minus(json_context_t *ctx) {
  1738. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1739. chunk->pos = ctx->cur;
  1740. PCC_DEBUG(PCC_DBG_EVALUATE, "minus", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1741. ctx->level++;
  1742. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1743. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1744. if (
  1745. pcc_refill_buffer(ctx, 1) < 1 ||
  1746. ctx->buffer.buf[ctx->cur] != '-'
  1747. ) goto L0000;
  1748. ctx->cur++;
  1749. ctx->level--;
  1750. PCC_DEBUG(PCC_DBG_MATCH, "minus", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1751. return chunk;
  1752. L0000:;
  1753. ctx->level--;
  1754. PCC_DEBUG(PCC_DBG_NOMATCH, "minus", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1755. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1756. return NULL;
  1757. }
  1758. static pcc_thunk_chunk_t *pcc_evaluate_rule_plus(json_context_t *ctx) {
  1759. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1760. chunk->pos = ctx->cur;
  1761. PCC_DEBUG(PCC_DBG_EVALUATE, "plus", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1762. ctx->level++;
  1763. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1764. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1765. if (
  1766. pcc_refill_buffer(ctx, 1) < 1 ||
  1767. ctx->buffer.buf[ctx->cur] != '+'
  1768. ) goto L0000;
  1769. ctx->cur++;
  1770. ctx->level--;
  1771. PCC_DEBUG(PCC_DBG_MATCH, "plus", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1772. return chunk;
  1773. L0000:;
  1774. ctx->level--;
  1775. PCC_DEBUG(PCC_DBG_NOMATCH, "plus", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1776. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1777. return NULL;
  1778. }
  1779. static pcc_thunk_chunk_t *pcc_evaluate_rule_zero(json_context_t *ctx) {
  1780. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1781. chunk->pos = ctx->cur;
  1782. PCC_DEBUG(PCC_DBG_EVALUATE, "zero", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1783. ctx->level++;
  1784. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1785. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1786. if (
  1787. pcc_refill_buffer(ctx, 1) < 1 ||
  1788. ctx->buffer.buf[ctx->cur] != '0'
  1789. ) goto L0000;
  1790. ctx->cur++;
  1791. ctx->level--;
  1792. PCC_DEBUG(PCC_DBG_MATCH, "zero", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1793. return chunk;
  1794. L0000:;
  1795. ctx->level--;
  1796. PCC_DEBUG(PCC_DBG_NOMATCH, "zero", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1797. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1798. return NULL;
  1799. }
  1800. static pcc_thunk_chunk_t *pcc_evaluate_rule_Digit(json_context_t *ctx) {
  1801. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1802. chunk->pos = ctx->cur;
  1803. PCC_DEBUG(PCC_DBG_EVALUATE, "Digit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1804. ctx->level++;
  1805. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1806. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1807. {
  1808. int u;
  1809. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1810. if (n == 0) goto L0000;
  1811. if (!(
  1812. (u >= 0x000030 && u <= 0x000039)
  1813. )) goto L0000;
  1814. ctx->cur += n;
  1815. }
  1816. ctx->level--;
  1817. PCC_DEBUG(PCC_DBG_MATCH, "Digit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1818. return chunk;
  1819. L0000:;
  1820. ctx->level--;
  1821. PCC_DEBUG(PCC_DBG_NOMATCH, "Digit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1822. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1823. return NULL;
  1824. }
  1825. static pcc_thunk_chunk_t *pcc_evaluate_rule_Hex(json_context_t *ctx) {
  1826. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1827. chunk->pos = ctx->cur;
  1828. PCC_DEBUG(PCC_DBG_EVALUATE, "Hex", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1829. ctx->level++;
  1830. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1831. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1832. {
  1833. int u;
  1834. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1835. if (n == 0) goto L0000;
  1836. if (!(
  1837. (u >= 0x000030 && u <= 0x000039) ||
  1838. (u >= 0x000041 && u <= 0x000046) ||
  1839. (u >= 0x000061 && u <= 0x000066)
  1840. )) goto L0000;
  1841. ctx->cur += n;
  1842. }
  1843. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1844. ctx->level--;
  1845. PCC_DEBUG(PCC_DBG_MATCH, "Hex", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1846. return chunk;
  1847. L0000:;
  1848. ctx->level--;
  1849. PCC_DEBUG(PCC_DBG_NOMATCH, "Hex", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1850. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1851. return NULL;
  1852. }
  1853. static pcc_thunk_chunk_t *pcc_evaluate_rule__(json_context_t *ctx) {
  1854. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1855. chunk->pos = ctx->cur;
  1856. PCC_DEBUG(PCC_DBG_EVALUATE, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1857. ctx->level++;
  1858. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1859. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1860. {
  1861. int i;
  1862. for (i = 0;; i++) {
  1863. const size_t p = ctx->cur;
  1864. const size_t n = chunk->thunks.len;
  1865. {
  1866. const size_t p = ctx->cur;
  1867. const size_t n = chunk->thunks.len;
  1868. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_space, &chunk->thunks, NULL)) goto L0003;
  1869. goto L0002;
  1870. L0003:;
  1871. ctx->cur = p;
  1872. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1873. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_comment, &chunk->thunks, NULL)) goto L0004;
  1874. goto L0002;
  1875. L0004:;
  1876. ctx->cur = p;
  1877. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1878. goto L0001;
  1879. L0002:;
  1880. }
  1881. if (ctx->cur == p) break;
  1882. continue;
  1883. L0001:;
  1884. ctx->cur = p;
  1885. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1886. break;
  1887. }
  1888. }
  1889. ctx->level--;
  1890. PCC_DEBUG(PCC_DBG_MATCH, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1891. return chunk;
  1892. }
  1893. static pcc_thunk_chunk_t *pcc_evaluate_rule_space(json_context_t *ctx) {
  1894. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1895. chunk->pos = ctx->cur;
  1896. PCC_DEBUG(PCC_DBG_EVALUATE, "space", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1897. ctx->level++;
  1898. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1899. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1900. {
  1901. const size_t p = ctx->cur;
  1902. const size_t n = chunk->thunks.len;
  1903. if (
  1904. pcc_refill_buffer(ctx, 1) < 1 ||
  1905. ctx->buffer.buf[ctx->cur] != ' '
  1906. ) goto L0002;
  1907. ctx->cur++;
  1908. goto L0001;
  1909. L0002:;
  1910. ctx->cur = p;
  1911. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1912. if (
  1913. pcc_refill_buffer(ctx, 1) < 1 ||
  1914. ctx->buffer.buf[ctx->cur] != '\t'
  1915. ) goto L0003;
  1916. ctx->cur++;
  1917. goto L0001;
  1918. L0003:;
  1919. ctx->cur = p;
  1920. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1921. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0004;
  1922. goto L0001;
  1923. L0004:;
  1924. ctx->cur = p;
  1925. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1926. goto L0000;
  1927. L0001:;
  1928. }
  1929. ctx->level--;
  1930. PCC_DEBUG(PCC_DBG_MATCH, "space", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1931. return chunk;
  1932. L0000:;
  1933. ctx->level--;
  1934. PCC_DEBUG(PCC_DBG_NOMATCH, "space", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1935. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1936. return NULL;
  1937. }
  1938. static pcc_thunk_chunk_t *pcc_evaluate_rule_comment(json_context_t *ctx) {
  1939. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1940. chunk->pos = ctx->cur;
  1941. PCC_DEBUG(PCC_DBG_EVALUATE, "comment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1942. ctx->level++;
  1943. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1944. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1945. if (
  1946. pcc_refill_buffer(ctx, 1) < 1 ||
  1947. ctx->buffer.buf[ctx->cur] != '#'
  1948. ) goto L0000;
  1949. ctx->cur++;
  1950. {
  1951. int i;
  1952. for (i = 0;; i++) {
  1953. const size_t p = ctx->cur;
  1954. const size_t n = chunk->thunks.len;
  1955. {
  1956. const size_t p = ctx->cur;
  1957. const size_t n = chunk->thunks.len;
  1958. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0002;
  1959. ctx->cur = p;
  1960. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1961. goto L0001;
  1962. L0002:;
  1963. ctx->cur = p;
  1964. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1965. }
  1966. {
  1967. int u;
  1968. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1969. if (n == 0) goto L0001;
  1970. ctx->cur += n;
  1971. }
  1972. if (ctx->cur == p) break;
  1973. continue;
  1974. L0001:;
  1975. ctx->cur = p;
  1976. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1977. break;
  1978. }
  1979. }
  1980. ctx->level--;
  1981. PCC_DEBUG(PCC_DBG_MATCH, "comment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1982. return chunk;
  1983. L0000:;
  1984. ctx->level--;
  1985. PCC_DEBUG(PCC_DBG_NOMATCH, "comment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1986. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1987. return NULL;
  1988. }
  1989. static pcc_thunk_chunk_t *pcc_evaluate_rule_endofline(json_context_t *ctx) {
  1990. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1991. chunk->pos = ctx->cur;
  1992. PCC_DEBUG(PCC_DBG_EVALUATE, "endofline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1993. ctx->level++;
  1994. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1995. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1996. {
  1997. const size_t p = ctx->cur;
  1998. const size_t n = chunk->thunks.len;
  1999. if (
  2000. pcc_refill_buffer(ctx, 2) < 2 ||
  2001. (ctx->buffer.buf + ctx->cur)[0] != '\r' ||
  2002. (ctx->buffer.buf + ctx->cur)[1] != '\n'
  2003. ) goto L0002;
  2004. ctx->cur += 2;
  2005. goto L0001;
  2006. L0002:;
  2007. ctx->cur = p;
  2008. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2009. if (
  2010. pcc_refill_buffer(ctx, 1) < 1 ||
  2011. ctx->buffer.buf[ctx->cur] != '\n'
  2012. ) goto L0003;
  2013. ctx->cur++;
  2014. goto L0001;
  2015. L0003:;
  2016. ctx->cur = p;
  2017. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2018. if (
  2019. pcc_refill_buffer(ctx, 1) < 1 ||
  2020. ctx->buffer.buf[ctx->cur] != '\r'
  2021. ) goto L0004;
  2022. ctx->cur++;
  2023. goto L0001;
  2024. L0004:;
  2025. ctx->cur = p;
  2026. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2027. if (
  2028. pcc_refill_buffer(ctx, 2) < 2 ||
  2029. (ctx->buffer.buf + ctx->cur)[0] != '\n' ||
  2030. (ctx->buffer.buf + ctx->cur)[1] != '\r'
  2031. ) goto L0005;
  2032. ctx->cur += 2;
  2033. goto L0001;
  2034. L0005:;
  2035. ctx->cur = p;
  2036. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2037. goto L0000;
  2038. L0001:;
  2039. }
  2040. {
  2041. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_endofline_0, 0, 0);
  2042. thunk->data.leaf.capt0.range.start = chunk->pos;
  2043. thunk->data.leaf.capt0.range.end = ctx->cur;
  2044. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2045. }
  2046. ctx->level--;
  2047. PCC_DEBUG(PCC_DBG_MATCH, "endofline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2048. return chunk;
  2049. L0000:;
  2050. ctx->level--;
  2051. PCC_DEBUG(PCC_DBG_NOMATCH, "endofline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2052. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2053. return NULL;
  2054. }
  2055. json_context_t *json_create(void *auxil) {
  2056. return pcc_context__create(auxil);
  2057. }
  2058. int json_parse(json_context_t *ctx, int *ret) {
  2059. pcc_thunk_array_t thunks;
  2060. pcc_thunk_array__init(ctx->auxil, &thunks, PCC_ARRAYSIZE);
  2061. if (pcc_apply_rule(ctx, pcc_evaluate_rule_JSON, &thunks, ret))
  2062. pcc_do_action(ctx, &thunks, ret);
  2063. else
  2064. PCC_ERROR(ctx->auxil);
  2065. pcc_commit_buffer(ctx);
  2066. pcc_thunk_array__term(ctx->auxil, &thunks);
  2067. return pcc_refill_buffer(ctx, 1) >= 1;
  2068. }
  2069. void json_destroy(json_context_t *ctx) {
  2070. pcc_context__destroy(ctx);
  2071. }
  2072. int main() {
  2073. json_context_t *ctx = json_create(NULL);
  2074. while (json_parse(ctx, NULL)){;}
  2075. json_destroy(ctx);
  2076. return 0;
  2077. }