gccda.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748
  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 "gccda.h"
  25. #include <stdio.h>
  26. static int nlines = 1;
  27. static char * funcname = "";
  28. static char * funcuid = "";
  29. static char *bbnum = "";
  30. static char *bbprevnum = "";
  31. static char *bbnextnum = "";
  32. static char *bbprefflags = "";
  33. static char *bbpred = "";
  34. static int debug = 0;
  35. static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
  36. #define PCC_DEBUG(event, rule, level, pos, buffer, length) \
  37. if (debug) { fprintf(stdout, "%*s%s %s @%d [%.*s]\n", (int)(level * 2), "", dbg_str[event], rule, (int)pos, (int)length, buffer); fflush(stdout); }
  38. /* NOTE: To guarantee the output order, stderr, which can lead a race condition with stdout, is not used. */
  39. static void pstartfunc (void)
  40. {
  41. if (funcname) {
  42. if(strlen(funcname)) {
  43. /* set end/start with fixed bb numbers 0 and 1 */
  44. printf (" \"%s_%s_bb0\"[label=\"%s()\\nENTRY\"];\n", funcname,funcuid,funcname);
  45. printf (" \"%s_%s_bb1\"[label=\"%s()\\nEXIT\"];\n", funcname,funcuid,funcname);
  46. }
  47. }
  48. return;
  49. }
  50. static void pbbnum (void)
  51. {
  52. printf (" \"%s_%s_bb%s\"[label=\"Block %s\"];\n", funcname,funcuid,bbnum,bbnum);
  53. return;
  54. }
  55. static void pbbprev (void)
  56. {
  57. if (0) { printf (" \"%s_%s_bb%s\" -> \"%s_%s_bb%s\"[label=\"%s\"];\n", funcname,funcuid,bbprevnum,funcname,funcuid,bbnum,bbprefflags); }
  58. if (0) { printf (" \"%s_%s_bb%s\" -> \"%s_%s_bb%s\"[label=\"%s\"];\n", funcname,funcuid,bbnum,funcname,funcuid,bbnextnum,bbprefflags); }
  59. return;
  60. }
  61. static void pbbend (void)
  62. {
  63. printf (" \"%s_%s_bb%s\" -> \"%s_%s_bb1\";\n", funcname,funcuid,bbnum,funcname,funcuid);
  64. return;
  65. }
  66. static void pbbpred (void)
  67. {
  68. char *s = "";
  69. if(strcmp (bbpred,"ENTRY")==0) {
  70. s = "0";
  71. }else {
  72. s = bbpred;
  73. }
  74. printf (" \"%s_%s_bb%s\" -> \"%s_%s_bb%s\";\n", funcname,funcuid,s,funcname,funcuid,bbnum);
  75. return;
  76. }
  77. #ifndef PCC_BUFFERSIZE
  78. #define PCC_BUFFERSIZE 256
  79. #endif /* !PCC_BUFFERSIZE */
  80. #ifndef PCC_ARRAYSIZE
  81. #define PCC_ARRAYSIZE 2
  82. #endif /* !PCC_ARRAYSIZE */
  83. #define VOID_VALUE (~(size_t)0)
  84. typedef enum pcc_bool_tag {
  85. PCC_FALSE = 0,
  86. PCC_TRUE
  87. } pcc_bool_t;
  88. typedef struct pcc_char_array_tag {
  89. char *buf;
  90. size_t max;
  91. size_t len;
  92. } pcc_char_array_t;
  93. typedef struct pcc_range_tag {
  94. size_t start;
  95. size_t end;
  96. } pcc_range_t;
  97. typedef int pcc_value_t;
  98. typedef void *pcc_auxil_t;
  99. typedef struct pcc_value_table_tag {
  100. pcc_value_t *buf;
  101. size_t max;
  102. size_t len;
  103. } pcc_value_table_t;
  104. typedef struct pcc_value_refer_table_tag {
  105. pcc_value_t **buf;
  106. size_t max;
  107. size_t len;
  108. } pcc_value_refer_table_t;
  109. typedef struct pcc_capture_tag {
  110. pcc_range_t range;
  111. char *string; /* mutable */
  112. } pcc_capture_t;
  113. typedef struct pcc_capture_table_tag {
  114. pcc_capture_t *buf;
  115. size_t max;
  116. size_t len;
  117. } pcc_capture_table_t;
  118. typedef struct pcc_capture_const_table_tag {
  119. const pcc_capture_t **buf;
  120. size_t max;
  121. size_t len;
  122. } pcc_capture_const_table_t;
  123. typedef struct pcc_thunk_tag pcc_thunk_t;
  124. typedef struct pcc_thunk_array_tag pcc_thunk_array_t;
  125. typedef void (*pcc_action_t)(gccda_context_t *, pcc_thunk_t *, pcc_value_t *);
  126. typedef enum pcc_thunk_type_tag {
  127. PCC_THUNK_LEAF,
  128. PCC_THUNK_NODE
  129. } pcc_thunk_type_t;
  130. typedef struct pcc_thunk_leaf_tag {
  131. pcc_value_refer_table_t values;
  132. pcc_capture_const_table_t capts;
  133. pcc_capture_t capt0;
  134. pcc_action_t action;
  135. } pcc_thunk_leaf_t;
  136. typedef struct pcc_thunk_node_tag {
  137. const pcc_thunk_array_t *thunks; /* just a reference */
  138. pcc_value_t *value; /* just a reference */
  139. } pcc_thunk_node_t;
  140. typedef union pcc_thunk_data_tag {
  141. pcc_thunk_leaf_t leaf;
  142. pcc_thunk_node_t node;
  143. } pcc_thunk_data_t;
  144. struct pcc_thunk_tag {
  145. pcc_thunk_type_t type;
  146. pcc_thunk_data_t data;
  147. };
  148. struct pcc_thunk_array_tag {
  149. pcc_thunk_t **buf;
  150. size_t max;
  151. size_t len;
  152. };
  153. typedef struct pcc_thunk_chunk_tag {
  154. pcc_value_table_t values;
  155. pcc_capture_table_t capts;
  156. pcc_thunk_array_t thunks;
  157. size_t pos; /* the starting position in the character buffer */
  158. } pcc_thunk_chunk_t;
  159. typedef struct pcc_lr_entry_tag pcc_lr_entry_t;
  160. typedef enum pcc_lr_answer_type_tag {
  161. PCC_LR_ANSWER_LR,
  162. PCC_LR_ANSWER_CHUNK
  163. } pcc_lr_answer_type_t;
  164. typedef union pcc_lr_answer_data_tag {
  165. pcc_lr_entry_t *lr;
  166. pcc_thunk_chunk_t *chunk;
  167. } pcc_lr_answer_data_t;
  168. typedef struct pcc_lr_answer_tag pcc_lr_answer_t;
  169. struct pcc_lr_answer_tag {
  170. pcc_lr_answer_type_t type;
  171. pcc_lr_answer_data_t data;
  172. size_t pos; /* the absolute position in the input */
  173. pcc_lr_answer_t *hold;
  174. };
  175. typedef pcc_thunk_chunk_t *(*pcc_rule_t)(gccda_context_t *);
  176. typedef struct pcc_rule_set_tag {
  177. pcc_rule_t *buf;
  178. size_t max;
  179. size_t len;
  180. } pcc_rule_set_t;
  181. typedef struct pcc_lr_head_tag pcc_lr_head_t;
  182. struct pcc_lr_head_tag {
  183. pcc_rule_t rule;
  184. pcc_rule_set_t invol;
  185. pcc_rule_set_t eval;
  186. pcc_lr_head_t *hold;
  187. };
  188. typedef struct pcc_lr_memo_tag {
  189. pcc_rule_t rule;
  190. pcc_lr_answer_t *answer;
  191. } pcc_lr_memo_t;
  192. typedef struct pcc_lr_memo_map_tag {
  193. pcc_lr_memo_t *buf;
  194. size_t max;
  195. size_t len;
  196. } pcc_lr_memo_map_t;
  197. typedef struct pcc_lr_table_entry_tag {
  198. pcc_lr_head_t *head; /* just a reference */
  199. pcc_lr_memo_map_t memos;
  200. pcc_lr_answer_t *hold_a;
  201. pcc_lr_head_t *hold_h;
  202. } pcc_lr_table_entry_t;
  203. typedef struct pcc_lr_table_tag {
  204. pcc_lr_table_entry_t **buf;
  205. size_t max;
  206. size_t len;
  207. } pcc_lr_table_t;
  208. struct pcc_lr_entry_tag {
  209. pcc_rule_t rule;
  210. pcc_thunk_chunk_t *seed; /* just a reference */
  211. pcc_lr_head_t *head; /* just a reference */
  212. };
  213. typedef struct pcc_lr_stack_tag {
  214. pcc_lr_entry_t **buf;
  215. size_t max;
  216. size_t len;
  217. } pcc_lr_stack_t;
  218. struct gccda_context_tag {
  219. size_t pos; /* the position in the input of the first character currently buffered */
  220. size_t cur; /* the current parsing position in the character buffer */
  221. size_t level;
  222. pcc_char_array_t buffer;
  223. pcc_lr_table_t lrtable;
  224. pcc_lr_stack_t lrstack;
  225. pcc_auxil_t auxil;
  226. };
  227. #ifndef PCC_ERROR
  228. #define PCC_ERROR(auxil) pcc_error()
  229. static void pcc_error(void) {
  230. fprintf(stderr, "Syntax error\n");
  231. exit(1);
  232. }
  233. #endif /* !PCC_ERROR */
  234. #ifndef PCC_GETCHAR
  235. #define PCC_GETCHAR(auxil) getchar()
  236. #endif /* !PCC_GETCHAR */
  237. #ifndef PCC_MALLOC
  238. #define PCC_MALLOC(auxil, size) pcc_malloc_e(size)
  239. static void *pcc_malloc_e(size_t size) {
  240. void *const p = malloc(size);
  241. if (p == NULL) {
  242. fprintf(stderr, "Out of memory\n");
  243. exit(1);
  244. }
  245. return p;
  246. }
  247. #endif /* !PCC_MALLOC */
  248. #ifndef PCC_REALLOC
  249. #define PCC_REALLOC(auxil, ptr, size) pcc_realloc_e(ptr, size)
  250. static void *pcc_realloc_e(void *ptr, size_t size) {
  251. void *const p = realloc(ptr, size);
  252. if (p == NULL) {
  253. fprintf(stderr, "Out of memory\n");
  254. exit(1);
  255. }
  256. return p;
  257. }
  258. #endif /* !PCC_REALLOC */
  259. #ifndef PCC_FREE
  260. #define PCC_FREE(auxil, ptr) free(ptr)
  261. #endif /* !PCC_FREE */
  262. #ifndef PCC_DEBUG
  263. #define PCC_DEBUG(event, rule, level, pos, buffer, length) ((void)0)
  264. #endif /* !PCC_DEBUG */
  265. static char *pcc_strndup_e(pcc_auxil_t auxil, const char *str, size_t len) {
  266. const size_t m = strnlen(str, len);
  267. char *const s = (char *)PCC_MALLOC(auxil, m + 1);
  268. if (auxil) { }
  269. memcpy(s, str, m);
  270. s[m] = '\0';
  271. return s;
  272. }
  273. static void pcc_char_array__init(pcc_auxil_t auxil, pcc_char_array_t *array, size_t max) {
  274. array->len = 0;
  275. array->max = max;
  276. if (auxil) { }
  277. array->buf = (char *)PCC_MALLOC(auxil, array->max);
  278. }
  279. static void pcc_char_array__add(pcc_auxil_t auxil, pcc_char_array_t *array, char ch) {
  280. if (array->max <= array->len) {
  281. const size_t n = array->len + 1;
  282. size_t m = array->max;
  283. if (m == 0) m = 1;
  284. while (m < n && m != 0) m <<= 1;
  285. if (m == 0) m = n;
  286. if (auxil) { }
  287. array->buf = (char *)PCC_REALLOC(auxil, array->buf, m);
  288. array->max = m;
  289. }
  290. array->buf[array->len++] = ch;
  291. }
  292. static void pcc_char_array__term(pcc_auxil_t auxil, pcc_char_array_t *array) {
  293. PCC_FREE(auxil, array->buf);
  294. }
  295. static void pcc_value_table__init(pcc_auxil_t auxil, pcc_value_table_t *table, size_t max) {
  296. table->len = 0;
  297. table->max = max;
  298. table->buf = (pcc_value_t *)PCC_MALLOC(auxil, sizeof(pcc_value_t) * table->max);
  299. if (auxil) { }
  300. return;
  301. }
  302. static void pcc_value_table__resize(pcc_auxil_t auxil, pcc_value_table_t *table, size_t len) {
  303. if (table->max < len) {
  304. size_t m = table->max;
  305. if (m == 0) m = 1;
  306. while (m < len && m != 0) m <<= 1;
  307. if (m == 0) m = len;
  308. table->buf = (pcc_value_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t) * m);
  309. table->max = m;
  310. }
  311. table->len = len;
  312. }
  313. static void pcc_value_table__term(pcc_auxil_t auxil, pcc_value_table_t *table) {
  314. PCC_FREE(auxil, table->buf);
  315. }
  316. static void pcc_value_refer_table__init(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t max) {
  317. table->len = 0;
  318. table->max = max;
  319. table->buf = (pcc_value_t **)PCC_MALLOC(auxil, sizeof(pcc_value_t *) * table->max);
  320. }
  321. static void pcc_value_refer_table__resize(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t len) {
  322. size_t i;
  323. if (table->max < len) {
  324. size_t m = table->max;
  325. if (m == 0) m = 1;
  326. while (m < len && m != 0) m <<= 1;
  327. if (m == 0) m = len;
  328. table->buf = (pcc_value_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t *) * m);
  329. table->max = m;
  330. }
  331. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  332. table->len = len;
  333. }
  334. static void pcc_value_refer_table__term(pcc_auxil_t auxil, pcc_value_refer_table_t *table) {
  335. PCC_FREE(auxil, table->buf);
  336. }
  337. static void pcc_capture_table__init(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t max) {
  338. table->len = 0;
  339. table->max = max;
  340. table->buf = (pcc_capture_t *)PCC_MALLOC(auxil, sizeof(pcc_capture_t) * table->max);
  341. }
  342. static void pcc_capture_table__resize(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t len) {
  343. size_t i;
  344. for (i = len; i < table->len; i++) PCC_FREE(auxil, table->buf[i].string);
  345. if (table->max < len) {
  346. size_t m = table->max;
  347. if (m == 0) m = 1;
  348. while (m < len && m != 0) m <<= 1;
  349. if (m == 0) m = len;
  350. table->buf = (pcc_capture_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_capture_t) * m);
  351. table->max = m;
  352. }
  353. for (i = table->len; i < len; i++) {
  354. table->buf[i].range.start = 0;
  355. table->buf[i].range.end = 0;
  356. table->buf[i].string = NULL;
  357. }
  358. table->len = len;
  359. }
  360. static void pcc_capture_table__term(pcc_auxil_t auxil, pcc_capture_table_t *table) {
  361. while (table->len > 0) {
  362. table->len--;
  363. PCC_FREE(auxil, table->buf[table->len].string);
  364. }
  365. PCC_FREE(auxil, table->buf);
  366. }
  367. static void pcc_capture_const_table__init(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t max) {
  368. table->len = 0;
  369. table->max = max;
  370. table->buf = (const pcc_capture_t **)PCC_MALLOC(auxil, sizeof(const pcc_capture_t *) * table->max);
  371. }
  372. static void pcc_capture_const_table__resize(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t len) {
  373. size_t i;
  374. if (table->max < len) {
  375. size_t m = table->max;
  376. if (m == 0) m = 1;
  377. while (m < len && m != 0) m <<= 1;
  378. if (m == 0) m = len;
  379. table->buf = (const pcc_capture_t **)PCC_REALLOC(auxil, (pcc_capture_t **)table->buf, sizeof(const pcc_capture_t *) * m);
  380. table->max = m;
  381. }
  382. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  383. table->len = len;
  384. }
  385. static void pcc_capture_const_table__term(pcc_auxil_t auxil, pcc_capture_const_table_t *table) {
  386. PCC_FREE(auxil, table->buf);
  387. }
  388. static pcc_thunk_t *pcc_thunk__create_leaf(pcc_auxil_t auxil, pcc_action_t action, size_t valuec, size_t captc) {
  389. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  390. thunk->type = PCC_THUNK_LEAF;
  391. pcc_value_refer_table__init(auxil, &thunk->data.leaf.values, valuec);
  392. pcc_value_refer_table__resize(auxil, &thunk->data.leaf.values, valuec);
  393. pcc_capture_const_table__init(auxil, &thunk->data.leaf.capts, captc);
  394. pcc_capture_const_table__resize(auxil, &thunk->data.leaf.capts, captc);
  395. thunk->data.leaf.capt0.range.start = 0;
  396. thunk->data.leaf.capt0.range.end = 0;
  397. thunk->data.leaf.capt0.string = NULL;
  398. thunk->data.leaf.action = action;
  399. return thunk;
  400. }
  401. static pcc_thunk_t *pcc_thunk__create_node(pcc_auxil_t auxil, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  402. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  403. thunk->type = PCC_THUNK_NODE;
  404. thunk->data.node.thunks = thunks;
  405. thunk->data.node.value = value;
  406. return thunk;
  407. }
  408. static void pcc_thunk__destroy(pcc_auxil_t auxil, pcc_thunk_t *thunk) {
  409. if (thunk == NULL) return;
  410. switch (thunk->type) {
  411. case PCC_THUNK_LEAF:
  412. PCC_FREE(auxil, thunk->data.leaf.capt0.string);
  413. pcc_capture_const_table__term(auxil, &thunk->data.leaf.capts);
  414. pcc_value_refer_table__term(auxil, &thunk->data.leaf.values);
  415. break;
  416. case PCC_THUNK_NODE:
  417. break;
  418. default: /* unknown */
  419. break;
  420. }
  421. PCC_FREE(auxil, thunk);
  422. }
  423. static void pcc_thunk_array__init(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t max) {
  424. array->len = 0;
  425. array->max = max;
  426. array->buf = (pcc_thunk_t **)PCC_MALLOC(auxil, sizeof(pcc_thunk_t *) * array->max);
  427. }
  428. static void pcc_thunk_array__add(pcc_auxil_t auxil, pcc_thunk_array_t *array, pcc_thunk_t *thunk) {
  429. if (array->max <= array->len) {
  430. const size_t n = array->len + 1;
  431. size_t m = array->max;
  432. if (m == 0) m = 1;
  433. while (m < n && m != 0) m <<= 1;
  434. if (m == 0) m = n;
  435. array->buf = (pcc_thunk_t **)PCC_REALLOC(auxil, array->buf, sizeof(pcc_thunk_t *) * m);
  436. array->max = m;
  437. }
  438. array->buf[array->len++] = thunk;
  439. }
  440. static void pcc_thunk_array__revert(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t len) {
  441. while (array->len > len) {
  442. array->len--;
  443. pcc_thunk__destroy(auxil, array->buf[array->len]);
  444. }
  445. }
  446. static void pcc_thunk_array__term(pcc_auxil_t auxil, pcc_thunk_array_t *array) {
  447. while (array->len > 0) {
  448. array->len--;
  449. pcc_thunk__destroy(auxil, array->buf[array->len]);
  450. }
  451. PCC_FREE(auxil, array->buf);
  452. }
  453. static pcc_thunk_chunk_t *pcc_thunk_chunk__create(pcc_auxil_t auxil) {
  454. pcc_thunk_chunk_t *const chunk = (pcc_thunk_chunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_chunk_t));
  455. pcc_value_table__init(auxil, &chunk->values, PCC_ARRAYSIZE);
  456. pcc_capture_table__init(auxil, &chunk->capts, PCC_ARRAYSIZE);
  457. pcc_thunk_array__init(auxil, &chunk->thunks, PCC_ARRAYSIZE);
  458. chunk->pos = 0;
  459. return chunk;
  460. }
  461. static void pcc_thunk_chunk__destroy(pcc_auxil_t auxil, pcc_thunk_chunk_t *chunk) {
  462. if (chunk == NULL) return;
  463. pcc_thunk_array__term(auxil, &chunk->thunks);
  464. pcc_capture_table__term(auxil, &chunk->capts);
  465. pcc_value_table__term(auxil, &chunk->values);
  466. PCC_FREE(auxil, chunk);
  467. }
  468. static void pcc_rule_set__init(pcc_auxil_t auxil, pcc_rule_set_t *set, size_t max) {
  469. set->len = 0;
  470. set->max = max;
  471. set->buf = (pcc_rule_t *)PCC_MALLOC(auxil, sizeof(pcc_rule_t) * set->max);
  472. }
  473. static size_t pcc_rule_set__index(pcc_auxil_t auxil, const pcc_rule_set_t *set, pcc_rule_t rule) {
  474. size_t i;
  475. for (i = 0; i < set->len; i++) {
  476. if (set->buf[i] == rule) return i;
  477. }
  478. return VOID_VALUE;
  479. }
  480. static pcc_bool_t pcc_rule_set__add(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  481. const size_t i = pcc_rule_set__index(auxil, set, rule);
  482. if (i != VOID_VALUE) return PCC_FALSE;
  483. if (set->max <= set->len) {
  484. const size_t n = set->len + 1;
  485. size_t m = set->max;
  486. if (m == 0) m = 1;
  487. while (m < n && m != 0) m <<= 1;
  488. if (m == 0) m = n;
  489. set->buf = (pcc_rule_t *)PCC_REALLOC(auxil, set->buf, sizeof(pcc_rule_t) * m);
  490. set->max = m;
  491. }
  492. set->buf[set->len++] = rule;
  493. return PCC_TRUE;
  494. }
  495. static pcc_bool_t pcc_rule_set__remove(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  496. const size_t i = pcc_rule_set__index(auxil, set, rule);
  497. if (i == VOID_VALUE) return PCC_FALSE;
  498. memmove(set->buf + i, set->buf + (i + 1), sizeof(pcc_rule_t) * (set->len - (i + 1)));
  499. return PCC_TRUE;
  500. }
  501. static void pcc_rule_set__clear(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  502. set->len = 0;
  503. }
  504. static void pcc_rule_set__copy(pcc_auxil_t auxil, pcc_rule_set_t *set, const pcc_rule_set_t *src) {
  505. size_t i;
  506. pcc_rule_set__clear(auxil, set);
  507. for (i = 0; i < src->len; i++) {
  508. pcc_rule_set__add(auxil, set, src->buf[i]);
  509. }
  510. }
  511. static void pcc_rule_set__term(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  512. PCC_FREE(auxil, set->buf);
  513. }
  514. static pcc_lr_head_t *pcc_lr_head__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  515. pcc_lr_head_t *const head = (pcc_lr_head_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_head_t));
  516. head->rule = rule;
  517. pcc_rule_set__init(auxil, &head->invol, PCC_ARRAYSIZE);
  518. pcc_rule_set__init(auxil, &head->eval, PCC_ARRAYSIZE);
  519. head->hold = NULL;
  520. return head;
  521. }
  522. static void pcc_lr_head__destroy(pcc_auxil_t auxil, pcc_lr_head_t *head) {
  523. if (head == NULL) return;
  524. pcc_lr_head__destroy(auxil, head->hold);
  525. pcc_rule_set__term(auxil, &head->eval);
  526. pcc_rule_set__term(auxil, &head->invol);
  527. PCC_FREE(auxil, head);
  528. }
  529. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr);
  530. static pcc_lr_answer_t *pcc_lr_answer__create(pcc_auxil_t auxil, pcc_lr_answer_type_t type, size_t pos) {
  531. pcc_lr_answer_t *answer = (pcc_lr_answer_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_answer_t));
  532. answer->type = type;
  533. answer->pos = pos;
  534. answer->hold = NULL;
  535. switch (answer->type) {
  536. case PCC_LR_ANSWER_LR:
  537. answer->data.lr = NULL;
  538. break;
  539. case PCC_LR_ANSWER_CHUNK:
  540. answer->data.chunk = NULL;
  541. break;
  542. default: /* unknown */
  543. PCC_FREE(auxil, answer);
  544. answer = NULL;
  545. }
  546. return answer;
  547. }
  548. static void pcc_lr_answer__set_chunk(pcc_auxil_t auxil, pcc_lr_answer_t *answer, pcc_thunk_chunk_t *chunk) {
  549. pcc_lr_answer_t *const a = pcc_lr_answer__create(auxil, answer->type, answer->pos);
  550. switch (answer->type) {
  551. case PCC_LR_ANSWER_LR:
  552. a->data.lr = answer->data.lr;
  553. break;
  554. case PCC_LR_ANSWER_CHUNK:
  555. a->data.chunk = answer->data.chunk;
  556. break;
  557. default: /* unknown */
  558. break;
  559. }
  560. a->hold = answer->hold;
  561. answer->hold = a;
  562. answer->type = PCC_LR_ANSWER_CHUNK;
  563. answer->data.chunk = chunk;
  564. }
  565. static void pcc_lr_answer__destroy(pcc_auxil_t auxil, pcc_lr_answer_t *answer) {
  566. if (answer == NULL) return;
  567. pcc_lr_answer__destroy(auxil, answer->hold);
  568. switch (answer->type) {
  569. case PCC_LR_ANSWER_LR:
  570. pcc_lr_entry__destroy(auxil, answer->data.lr);
  571. break;
  572. case PCC_LR_ANSWER_CHUNK:
  573. pcc_thunk_chunk__destroy(auxil, answer->data.chunk);
  574. break;
  575. default: /* unknown */
  576. break;
  577. }
  578. PCC_FREE(auxil, answer);
  579. }
  580. static void pcc_lr_memo_map__init(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, size_t max) {
  581. map->len = 0;
  582. map->max = max;
  583. map->buf = (pcc_lr_memo_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_memo_t) * map->max);
  584. }
  585. static size_t pcc_lr_memo_map__index(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  586. size_t i;
  587. for (i = 0; i < map->len; i++) {
  588. if (map->buf[i].rule == rule) return i;
  589. }
  590. return VOID_VALUE;
  591. }
  592. 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) {
  593. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  594. if (i != VOID_VALUE) {
  595. pcc_lr_answer__destroy(auxil, map->buf[i].answer);
  596. map->buf[i].answer = answer;
  597. }
  598. else {
  599. if (map->max <= map->len) {
  600. const size_t n = map->len + 1;
  601. size_t m = map->max;
  602. if (m == 0) m = 1;
  603. while (m < n && m != 0) m <<= 1;
  604. if (m == 0) m = n;
  605. map->buf = (pcc_lr_memo_t *)PCC_REALLOC(auxil, map->buf, sizeof(pcc_lr_memo_t) * m);
  606. map->max = m;
  607. }
  608. map->buf[map->len].rule = rule;
  609. map->buf[map->len].answer = answer;
  610. map->len++;
  611. }
  612. }
  613. static pcc_lr_answer_t *pcc_lr_memo_map__get(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  614. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  615. return (i != VOID_VALUE) ? map->buf[i].answer : NULL;
  616. }
  617. static void pcc_lr_memo_map__term(pcc_auxil_t auxil, pcc_lr_memo_map_t *map) {
  618. while (map->len > 0) {
  619. map->len--;
  620. pcc_lr_answer__destroy(auxil, map->buf[map->len].answer);
  621. }
  622. PCC_FREE(auxil, map->buf);
  623. }
  624. static pcc_lr_table_entry_t *pcc_lr_table_entry__create(pcc_auxil_t auxil) {
  625. pcc_lr_table_entry_t *const entry = (pcc_lr_table_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t));
  626. entry->head = NULL;
  627. pcc_lr_memo_map__init(auxil, &entry->memos, PCC_ARRAYSIZE);
  628. entry->hold_a = NULL;
  629. entry->hold_h = NULL;
  630. return entry;
  631. }
  632. static void pcc_lr_table_entry__destroy(pcc_auxil_t auxil, pcc_lr_table_entry_t *entry) {
  633. if (entry == NULL) return;
  634. pcc_lr_head__destroy(auxil, entry->hold_h);
  635. pcc_lr_answer__destroy(auxil, entry->hold_a);
  636. pcc_lr_memo_map__term(auxil, &entry->memos);
  637. PCC_FREE(auxil, entry);
  638. }
  639. static void pcc_lr_table__init(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t max) {
  640. table->len = 0;
  641. table->max = max;
  642. table->buf = (pcc_lr_table_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t *) * table->max);
  643. }
  644. static void pcc_lr_table__resize(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t len) {
  645. size_t i;
  646. for (i = len; i < table->len; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  647. if (table->max < len) {
  648. size_t m = table->max;
  649. if (m == 0) m = 1;
  650. while (m < len && m != 0) m <<= 1;
  651. if (m == 0) m = len;
  652. table->buf = (pcc_lr_table_entry_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_lr_table_entry_t *) * m);
  653. table->max = m;
  654. }
  655. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  656. table->len = len;
  657. }
  658. static void pcc_lr_table__set_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  659. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  660. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  661. table->buf[index]->head = head;
  662. }
  663. static void pcc_lr_table__hold_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  664. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  665. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  666. head->hold = table->buf[index]->hold_h;
  667. table->buf[index]->hold_h = head;
  668. }
  669. 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) {
  670. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  671. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  672. pcc_lr_memo_map__put(auxil, &table->buf[index]->memos, rule, answer);
  673. }
  674. static void pcc_lr_table__hold_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_answer_t *answer) {
  675. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  676. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  677. answer->hold = table->buf[index]->hold_a;
  678. table->buf[index]->hold_a = answer;
  679. }
  680. static pcc_lr_head_t *pcc_lr_table__get_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index) {
  681. if (index >= table->len || table->buf[index] == NULL) return NULL;
  682. return table->buf[index]->head;
  683. }
  684. 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) {
  685. if (index >= table->len || table->buf[index] == NULL) return NULL;
  686. return pcc_lr_memo_map__get(auxil, &table->buf[index]->memos, rule);
  687. }
  688. static void pcc_lr_table__shift(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t count) {
  689. size_t i;
  690. if (count > table->len) count = table->len;
  691. for (i = 0; i < count; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  692. memmove(table->buf, table->buf + count, sizeof(pcc_lr_table_entry_t *) * (table->len - count));
  693. table->len -= count;
  694. }
  695. static void pcc_lr_table__term(pcc_auxil_t auxil, pcc_lr_table_t *table) {
  696. while (table->len > 0) {
  697. table->len--;
  698. pcc_lr_table_entry__destroy(auxil, table->buf[table->len]);
  699. }
  700. PCC_FREE(auxil, table->buf);
  701. }
  702. static pcc_lr_entry_t *pcc_lr_entry__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  703. pcc_lr_entry_t *const lr = (pcc_lr_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t));
  704. lr->rule = rule;
  705. lr->seed = NULL;
  706. lr->head = NULL;
  707. return lr;
  708. }
  709. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr) {
  710. PCC_FREE(auxil, lr);
  711. }
  712. static void pcc_lr_stack__init(pcc_auxil_t auxil, pcc_lr_stack_t *stack, size_t max) {
  713. stack->len = 0;
  714. stack->max = max;
  715. stack->buf = (pcc_lr_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t *) * stack->max);
  716. }
  717. static void pcc_lr_stack__push(pcc_auxil_t auxil, pcc_lr_stack_t *stack, pcc_lr_entry_t *lr) {
  718. if (stack->max <= stack->len) {
  719. const size_t n = stack->len + 1;
  720. size_t m = stack->max;
  721. if (m == 0) m = 1;
  722. while (m < n && m != 0) m <<= 1;
  723. if (m == 0) m = n;
  724. stack->buf = (pcc_lr_entry_t **)PCC_REALLOC(auxil, stack->buf, sizeof(pcc_lr_entry_t *) * m);
  725. stack->max = m;
  726. }
  727. stack->buf[stack->len++] = lr;
  728. }
  729. static pcc_lr_entry_t *pcc_lr_stack__pop(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  730. return stack->buf[--stack->len];
  731. }
  732. static void pcc_lr_stack__term(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  733. PCC_FREE(auxil, stack->buf);
  734. }
  735. static gccda_context_t *pcc_context__create(pcc_auxil_t auxil) {
  736. gccda_context_t *const ctx = (gccda_context_t *)PCC_MALLOC(auxil, sizeof(gccda_context_t));
  737. ctx->pos = 0;
  738. ctx->cur = 0;
  739. ctx->level = 0;
  740. pcc_char_array__init(auxil, &ctx->buffer, PCC_BUFFERSIZE);
  741. pcc_lr_table__init(auxil, &ctx->lrtable, PCC_BUFFERSIZE);
  742. pcc_lr_stack__init(auxil, &ctx->lrstack, PCC_ARRAYSIZE);
  743. ctx->auxil = auxil;
  744. return ctx;
  745. }
  746. static void pcc_context__destroy(gccda_context_t *ctx) {
  747. if (ctx == NULL) return;
  748. pcc_lr_stack__term(ctx->auxil, &ctx->lrstack);
  749. pcc_lr_table__term(ctx->auxil, &ctx->lrtable);
  750. pcc_char_array__term(ctx->auxil, &ctx->buffer);
  751. PCC_FREE(ctx->auxil, ctx);
  752. }
  753. static size_t pcc_refill_buffer(gccda_context_t *ctx, size_t num) {
  754. if (ctx->buffer.len >= ctx->cur + num) return ctx->buffer.len - ctx->cur;
  755. while (ctx->buffer.len < ctx->cur + num) {
  756. const int c = PCC_GETCHAR(ctx->auxil);
  757. if (c == EOF) break;
  758. pcc_char_array__add(ctx->auxil, &ctx->buffer, (char)c);
  759. }
  760. return ctx->buffer.len - ctx->cur;
  761. }
  762. static void pcc_commit_buffer(gccda_context_t *ctx) {
  763. memmove(ctx->buffer.buf, ctx->buffer.buf + ctx->cur, ctx->buffer.len - ctx->cur);
  764. ctx->buffer.len -= ctx->cur;
  765. ctx->pos += ctx->cur;
  766. pcc_lr_table__shift(ctx->auxil, &ctx->lrtable, ctx->cur);
  767. ctx->cur = 0;
  768. }
  769. static const char *pcc_get_capture_string(gccda_context_t *ctx, const pcc_capture_t *capt) {
  770. if (capt->string == NULL)
  771. ((pcc_capture_t *)capt)->string =
  772. pcc_strndup_e(ctx->auxil, ctx->buffer.buf + capt->range.start, capt->range.end - capt->range.start);
  773. return capt->string;
  774. }
  775. static size_t pcc_get_char_as_utf32(gccda_context_t *ctx, int *out) { /* with checking UTF-8 validity */
  776. int c, u;
  777. size_t n;
  778. if (pcc_refill_buffer(ctx, 1) < 1) return 0;
  779. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur];
  780. n = (c < 0x80) ? 1 :
  781. ((c & 0xe0) == 0xc0) ? 2 :
  782. ((c & 0xf0) == 0xe0) ? 3 :
  783. ((c & 0xf8) == 0xf0) ? 4 : 0;
  784. if (n < 1) return 0;
  785. if (pcc_refill_buffer(ctx, n) < n) return 0;
  786. switch (n) {
  787. case 1:
  788. u = c;
  789. break;
  790. case 2:
  791. u = c & 0x1f;
  792. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  793. if ((c & 0xc0) != 0x80) return 0;
  794. u <<= 6; u |= c & 0x3f;
  795. if (u < 0x80) return 0;
  796. break;
  797. case 3:
  798. u = c & 0x0f;
  799. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  800. if ((c & 0xc0) != 0x80) return 0;
  801. u <<= 6; u |= c & 0x3f;
  802. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  803. if ((c & 0xc0) != 0x80) return 0;
  804. u <<= 6; u |= c & 0x3f;
  805. if (u < 0x800) return 0;
  806. break;
  807. case 4:
  808. u = c & 0x07;
  809. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  810. if ((c & 0xc0) != 0x80) return 0;
  811. u <<= 6; u |= c & 0x3f;
  812. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  813. if ((c & 0xc0) != 0x80) return 0;
  814. u <<= 6; u |= c & 0x3f;
  815. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 3];
  816. if ((c & 0xc0) != 0x80) return 0;
  817. u <<= 6; u |= c & 0x3f;
  818. if (u < 0x10000 || u > 0x10ffff) return 0;
  819. break;
  820. default:
  821. return 0;
  822. }
  823. if (out) *out = u;
  824. return n;
  825. }
  826. static pcc_bool_t pcc_apply_rule(gccda_context_t *ctx, pcc_rule_t rule, pcc_thunk_array_t *thunks, pcc_value_t *value) {
  827. static pcc_value_t null;
  828. pcc_thunk_chunk_t *c = NULL;
  829. const size_t p = ctx->pos + ctx->cur;
  830. pcc_bool_t b = PCC_TRUE;
  831. pcc_lr_answer_t *a = pcc_lr_table__get_answer(ctx->auxil, &ctx->lrtable, p, rule);
  832. pcc_lr_head_t *h = pcc_lr_table__get_head(ctx->auxil, &ctx->lrtable, p);
  833. if (h != NULL) {
  834. if (a == NULL && rule != h->rule && pcc_rule_set__index(ctx->auxil, &h->invol, rule) == VOID_VALUE) {
  835. b = PCC_FALSE;
  836. c = NULL;
  837. }
  838. else if (pcc_rule_set__remove(ctx->auxil, &h->eval, rule)) {
  839. b = PCC_FALSE;
  840. c = rule(ctx);
  841. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  842. a->data.chunk = c;
  843. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  844. }
  845. }
  846. if (b) {
  847. if (a != NULL) {
  848. ctx->cur = a->pos - ctx->pos;
  849. switch (a->type) {
  850. case PCC_LR_ANSWER_LR:
  851. if (a->data.lr->head == NULL) {
  852. a->data.lr->head = pcc_lr_head__create(ctx->auxil, rule);
  853. pcc_lr_table__hold_head(ctx->auxil, &ctx->lrtable, p, a->data.lr->head);
  854. }
  855. {
  856. size_t i = ctx->lrstack.len;
  857. while (i > 0) {
  858. i--;
  859. if (ctx->lrstack.buf[i]->head == a->data.lr->head) break;
  860. ctx->lrstack.buf[i]->head = a->data.lr->head;
  861. pcc_rule_set__add(ctx->auxil, &a->data.lr->head->invol, ctx->lrstack.buf[i]->rule);
  862. }
  863. }
  864. c = a->data.lr->seed;
  865. break;
  866. case PCC_LR_ANSWER_CHUNK:
  867. c = a->data.chunk;
  868. break;
  869. default: /* unknown */
  870. break;
  871. }
  872. }
  873. else {
  874. pcc_lr_entry_t *const e = pcc_lr_entry__create(ctx->auxil, rule);
  875. pcc_lr_stack__push(ctx->auxil, &ctx->lrstack, e);
  876. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_LR, p);
  877. a->data.lr = e;
  878. pcc_lr_table__set_answer(ctx->auxil, &ctx->lrtable, p, rule, a);
  879. c = rule(ctx);
  880. pcc_lr_stack__pop(ctx->auxil, &ctx->lrstack);
  881. a->pos = ctx->pos + ctx->cur;
  882. if (e->head == NULL) {
  883. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  884. }
  885. else {
  886. e->seed = c;
  887. h = a->data.lr->head;
  888. if (h->rule != rule) {
  889. c = a->data.lr->seed;
  890. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  891. a->data.chunk = c;
  892. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  893. }
  894. else {
  895. pcc_lr_answer__set_chunk(ctx->auxil, a, a->data.lr->seed);
  896. if (a->data.chunk == NULL) {
  897. c = NULL;
  898. }
  899. else {
  900. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, h);
  901. for (;;) {
  902. ctx->cur = p - ctx->pos;
  903. pcc_rule_set__copy(ctx->auxil, &h->eval, &h->invol);
  904. c = rule(ctx);
  905. if (c == NULL || ctx->pos + ctx->cur <= a->pos) break;
  906. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  907. a->pos = ctx->pos + ctx->cur;
  908. }
  909. pcc_thunk_chunk__destroy(ctx->auxil, c);
  910. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, NULL);
  911. ctx->cur = a->pos - ctx->pos;
  912. c = a->data.chunk;
  913. }
  914. }
  915. }
  916. }
  917. }
  918. if (c == NULL) return PCC_FALSE;
  919. if (value == NULL) value = &null;
  920. memset(value, 0, sizeof(pcc_value_t)); /* in case */
  921. pcc_thunk_array__add(ctx->auxil, thunks, pcc_thunk__create_node(ctx->auxil, &c->thunks, value));
  922. return PCC_TRUE;
  923. }
  924. static void pcc_do_action(gccda_context_t *ctx, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  925. size_t i;
  926. for (i = 0; i < thunks->len; i++) {
  927. pcc_thunk_t *const thunk = thunks->buf[i];
  928. switch (thunk->type) {
  929. case PCC_THUNK_LEAF:
  930. thunk->data.leaf.action(ctx, thunk, value);
  931. break;
  932. case PCC_THUNK_NODE:
  933. pcc_do_action(ctx, thunk->data.node.thunks, thunk->data.node.value);
  934. break;
  935. default: /* unknown */
  936. break;
  937. }
  938. }
  939. }
  940. static void pcc_action_bbsuccend_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  941. #define auxil (__pcc_ctx->auxil)
  942. #define __ (*__pcc_out)
  943. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  944. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  945. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  946. pbbend ();
  947. #undef _0e
  948. #undef _0s
  949. #undef _0
  950. #undef __
  951. #undef auxil
  952. }
  953. static void pcc_action_prednum2_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  954. #define auxil (__pcc_ctx->auxil)
  955. #define __ (*__pcc_out)
  956. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  957. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  958. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  959. bbpred = strdup (_0); if (0) printf("// \"%s\" prednum line %d\n",_0,nlines); pbbpred();
  960. #undef _0e
  961. #undef _0s
  962. #undef _0
  963. #undef __
  964. #undef auxil
  965. }
  966. static void pcc_action_bbprev_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  967. #define auxil (__pcc_ctx->auxil)
  968. #define __ (*__pcc_out)
  969. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  970. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  971. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  972. pbbprev();
  973. #undef _0e
  974. #undef _0s
  975. #undef _0
  976. #undef __
  977. #undef auxil
  978. }
  979. static void pcc_action_prefflags_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  980. #define auxil (__pcc_ctx->auxil)
  981. #define __ (*__pcc_out)
  982. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  983. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  984. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  985. bbprefflags = strdup (_0);
  986. #undef _0e
  987. #undef _0s
  988. #undef _0
  989. #undef __
  990. #undef auxil
  991. }
  992. static void pcc_action_nextnum_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  993. #define auxil (__pcc_ctx->auxil)
  994. #define __ (*__pcc_out)
  995. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  996. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  997. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  998. bbnextnum = strdup (_0);
  999. #undef _0e
  1000. #undef _0s
  1001. #undef _0
  1002. #undef __
  1003. #undef auxil
  1004. }
  1005. static void pcc_action_prevnum_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  1006. #define auxil (__pcc_ctx->auxil)
  1007. #define __ (*__pcc_out)
  1008. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  1009. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  1010. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  1011. bbprevnum = strdup (_0);
  1012. #undef _0e
  1013. #undef _0s
  1014. #undef _0
  1015. #undef __
  1016. #undef auxil
  1017. }
  1018. static void pcc_action_bbnum_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  1019. #define auxil (__pcc_ctx->auxil)
  1020. #define __ (*__pcc_out)
  1021. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  1022. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  1023. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  1024. bbnum = strdup (_0); if (0) printf("// %s\n",_0); pbbnum();
  1025. #undef _0e
  1026. #undef _0s
  1027. #undef _0
  1028. #undef __
  1029. #undef auxil
  1030. }
  1031. static void pcc_action_func_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  1032. #define auxil (__pcc_ctx->auxil)
  1033. #define __ (*__pcc_out)
  1034. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  1035. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  1036. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  1037. pstartfunc();
  1038. #undef _0e
  1039. #undef _0s
  1040. #undef _0
  1041. #undef __
  1042. #undef auxil
  1043. }
  1044. static void pcc_action_funcname_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  1045. #define auxil (__pcc_ctx->auxil)
  1046. #define __ (*__pcc_out)
  1047. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  1048. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  1049. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  1050. if (0) printf("// %s\n",_0); funcname = strdup(_0);
  1051. #undef _0e
  1052. #undef _0s
  1053. #undef _0
  1054. #undef __
  1055. #undef auxil
  1056. }
  1057. static void pcc_action_fuid_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  1058. #define auxil (__pcc_ctx->auxil)
  1059. #define __ (*__pcc_out)
  1060. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  1061. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  1062. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  1063. if (0) printf("// %s\n",_0); funcuid = strdup(_0);
  1064. #undef _0e
  1065. #undef _0s
  1066. #undef _0
  1067. #undef __
  1068. #undef auxil
  1069. }
  1070. static void pcc_action_endofline_0(gccda_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  1071. #define auxil (__pcc_ctx->auxil)
  1072. #define __ (*__pcc_out)
  1073. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  1074. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  1075. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  1076. nlines++;
  1077. #undef _0e
  1078. #undef _0s
  1079. #undef _0
  1080. #undef __
  1081. #undef auxil
  1082. }
  1083. static pcc_thunk_chunk_t *pcc_evaluate_rule_file(gccda_context_t *ctx);
  1084. static pcc_thunk_chunk_t *pcc_evaluate_rule_lines(gccda_context_t *ctx);
  1085. static pcc_thunk_chunk_t *pcc_evaluate_rule_line(gccda_context_t *ctx);
  1086. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbsuccend(gccda_context_t *ctx);
  1087. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbsucc(gccda_context_t *ctx);
  1088. static pcc_thunk_chunk_t *pcc_evaluate_rule_succlines(gccda_context_t *ctx);
  1089. static pcc_thunk_chunk_t *pcc_evaluate_rule_succline(gccda_context_t *ctx);
  1090. static pcc_thunk_chunk_t *pcc_evaluate_rule_succline2(gccda_context_t *ctx);
  1091. static pcc_thunk_chunk_t *pcc_evaluate_rule_succnum(gccda_context_t *ctx);
  1092. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbpred(gccda_context_t *ctx);
  1093. static pcc_thunk_chunk_t *pcc_evaluate_rule_predlines(gccda_context_t *ctx);
  1094. static pcc_thunk_chunk_t *pcc_evaluate_rule_predline(gccda_context_t *ctx);
  1095. static pcc_thunk_chunk_t *pcc_evaluate_rule_predline2(gccda_context_t *ctx);
  1096. static pcc_thunk_chunk_t *pcc_evaluate_rule_prednum(gccda_context_t *ctx);
  1097. static pcc_thunk_chunk_t *pcc_evaluate_rule_prednum2(gccda_context_t *ctx);
  1098. static pcc_thunk_chunk_t *pcc_evaluate_rule_prenum3(gccda_context_t *ctx);
  1099. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbprev(gccda_context_t *ctx);
  1100. static pcc_thunk_chunk_t *pcc_evaluate_rule_prefflags(gccda_context_t *ctx);
  1101. static pcc_thunk_chunk_t *pcc_evaluate_rule_nextnum(gccda_context_t *ctx);
  1102. static pcc_thunk_chunk_t *pcc_evaluate_rule_prevnum(gccda_context_t *ctx);
  1103. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbstart(gccda_context_t *ctx);
  1104. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbnum(gccda_context_t *ctx);
  1105. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbrest(gccda_context_t *ctx);
  1106. static pcc_thunk_chunk_t *pcc_evaluate_rule_func(gccda_context_t *ctx);
  1107. static pcc_thunk_chunk_t *pcc_evaluate_rule_funcname(gccda_context_t *ctx);
  1108. static pcc_thunk_chunk_t *pcc_evaluate_rule_funcuid(gccda_context_t *ctx);
  1109. static pcc_thunk_chunk_t *pcc_evaluate_rule_fuid(gccda_context_t *ctx);
  1110. static pcc_thunk_chunk_t *pcc_evaluate_rule_funcrest(gccda_context_t *ctx);
  1111. static pcc_thunk_chunk_t *pcc_evaluate_rule__(gccda_context_t *ctx);
  1112. static pcc_thunk_chunk_t *pcc_evaluate_rule_space(gccda_context_t *ctx);
  1113. static pcc_thunk_chunk_t *pcc_evaluate_rule_endofline(gccda_context_t *ctx);
  1114. static pcc_thunk_chunk_t *pcc_evaluate_rule_file(gccda_context_t *ctx) {
  1115. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1116. chunk->pos = ctx->cur;
  1117. PCC_DEBUG(PCC_DBG_EVALUATE, "file", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1118. ctx->level++;
  1119. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1120. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1121. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1122. {
  1123. int i;
  1124. for (i = 0;; i++) {
  1125. const size_t p = ctx->cur;
  1126. const size_t n = chunk->thunks.len;
  1127. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_lines, &chunk->thunks, NULL)) goto L0001;
  1128. if (ctx->cur == p) break;
  1129. continue;
  1130. L0001:;
  1131. ctx->cur = p;
  1132. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1133. break;
  1134. }
  1135. }
  1136. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1137. {
  1138. const size_t p = ctx->cur;
  1139. const size_t n = chunk->thunks.len;
  1140. {
  1141. int u;
  1142. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1143. if (n == 0) goto L0002;
  1144. ctx->cur += n;
  1145. }
  1146. ctx->cur = p;
  1147. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1148. goto L0000;
  1149. L0002:;
  1150. ctx->cur = p;
  1151. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1152. }
  1153. ctx->level--;
  1154. PCC_DEBUG(PCC_DBG_MATCH, "file", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1155. return chunk;
  1156. L0000:;
  1157. ctx->level--;
  1158. PCC_DEBUG(PCC_DBG_NOMATCH, "file", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1159. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1160. return NULL;
  1161. }
  1162. static pcc_thunk_chunk_t *pcc_evaluate_rule_lines(gccda_context_t *ctx) {
  1163. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1164. chunk->pos = ctx->cur;
  1165. PCC_DEBUG(PCC_DBG_EVALUATE, "lines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1166. ctx->level++;
  1167. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1168. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1169. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_line, &chunk->thunks, NULL)) goto L0000;
  1170. ctx->level--;
  1171. PCC_DEBUG(PCC_DBG_MATCH, "lines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1172. return chunk;
  1173. L0000:;
  1174. ctx->level--;
  1175. PCC_DEBUG(PCC_DBG_NOMATCH, "lines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1176. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1177. return NULL;
  1178. }
  1179. static pcc_thunk_chunk_t *pcc_evaluate_rule_line(gccda_context_t *ctx) {
  1180. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1181. chunk->pos = ctx->cur;
  1182. PCC_DEBUG(PCC_DBG_EVALUATE, "line", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1183. ctx->level++;
  1184. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1185. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1186. {
  1187. const size_t p = ctx->cur;
  1188. const size_t n = chunk->thunks.len;
  1189. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_func, &chunk->thunks, NULL)) goto L0002;
  1190. goto L0001;
  1191. L0002:;
  1192. ctx->cur = p;
  1193. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1194. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_bbstart, &chunk->thunks, NULL)) goto L0003;
  1195. goto L0001;
  1196. L0003:;
  1197. ctx->cur = p;
  1198. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1199. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_bbsuccend, &chunk->thunks, NULL)) goto L0004;
  1200. goto L0001;
  1201. L0004:;
  1202. ctx->cur = p;
  1203. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1204. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_bbsucc, &chunk->thunks, NULL)) goto L0005;
  1205. goto L0001;
  1206. L0005:;
  1207. ctx->cur = p;
  1208. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1209. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_bbprev, &chunk->thunks, NULL)) goto L0006;
  1210. goto L0001;
  1211. L0006:;
  1212. ctx->cur = p;
  1213. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1214. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_bbpred, &chunk->thunks, NULL)) goto L0007;
  1215. goto L0001;
  1216. L0007:;
  1217. ctx->cur = p;
  1218. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1219. {
  1220. int i;
  1221. for (i = 0;; i++) {
  1222. const size_t p = ctx->cur;
  1223. const size_t n = chunk->thunks.len;
  1224. {
  1225. const size_t p = ctx->cur;
  1226. const size_t n = chunk->thunks.len;
  1227. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0010;
  1228. ctx->cur = p;
  1229. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1230. goto L0009;
  1231. L0010:;
  1232. ctx->cur = p;
  1233. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1234. }
  1235. {
  1236. int u;
  1237. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1238. if (n == 0) goto L0009;
  1239. ctx->cur += n;
  1240. }
  1241. if (ctx->cur == p) break;
  1242. continue;
  1243. L0009:;
  1244. ctx->cur = p;
  1245. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1246. break;
  1247. }
  1248. }
  1249. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0008;
  1250. goto L0001;
  1251. L0008:;
  1252. ctx->cur = p;
  1253. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1254. goto L0000;
  1255. L0001:;
  1256. }
  1257. ctx->level--;
  1258. PCC_DEBUG(PCC_DBG_MATCH, "line", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1259. return chunk;
  1260. L0000:;
  1261. ctx->level--;
  1262. PCC_DEBUG(PCC_DBG_NOMATCH, "line", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1263. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1264. return NULL;
  1265. }
  1266. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbsuccend(gccda_context_t *ctx) {
  1267. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1268. chunk->pos = ctx->cur;
  1269. PCC_DEBUG(PCC_DBG_EVALUATE, "bbsuccend", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1270. ctx->level++;
  1271. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1272. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1273. if (
  1274. pcc_refill_buffer(ctx, 20) < 20 ||
  1275. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  1276. (ctx->buffer.buf + ctx->cur)[1] != ';' ||
  1277. (ctx->buffer.buf + ctx->cur)[2] != ' ' ||
  1278. (ctx->buffer.buf + ctx->cur)[3] != ' ' ||
  1279. (ctx->buffer.buf + ctx->cur)[4] != 's' ||
  1280. (ctx->buffer.buf + ctx->cur)[5] != 'u' ||
  1281. (ctx->buffer.buf + ctx->cur)[6] != 'c' ||
  1282. (ctx->buffer.buf + ctx->cur)[7] != 'c' ||
  1283. (ctx->buffer.buf + ctx->cur)[8] != ':' ||
  1284. (ctx->buffer.buf + ctx->cur)[9] != ' ' ||
  1285. (ctx->buffer.buf + ctx->cur)[10] != ' ' ||
  1286. (ctx->buffer.buf + ctx->cur)[11] != ' ' ||
  1287. (ctx->buffer.buf + ctx->cur)[12] != ' ' ||
  1288. (ctx->buffer.buf + ctx->cur)[13] != ' ' ||
  1289. (ctx->buffer.buf + ctx->cur)[14] != ' ' ||
  1290. (ctx->buffer.buf + ctx->cur)[15] != ' ' ||
  1291. (ctx->buffer.buf + ctx->cur)[16] != 'E' ||
  1292. (ctx->buffer.buf + ctx->cur)[17] != 'X' ||
  1293. (ctx->buffer.buf + ctx->cur)[18] != 'I' ||
  1294. (ctx->buffer.buf + ctx->cur)[19] != 'T'
  1295. ) goto L0000;
  1296. ctx->cur += 20;
  1297. {
  1298. int i;
  1299. for (i = 0;; i++) {
  1300. const size_t p = ctx->cur;
  1301. const size_t n = chunk->thunks.len;
  1302. {
  1303. const size_t p = ctx->cur;
  1304. const size_t n = chunk->thunks.len;
  1305. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0002;
  1306. ctx->cur = p;
  1307. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1308. goto L0001;
  1309. L0002:;
  1310. ctx->cur = p;
  1311. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1312. }
  1313. {
  1314. int u;
  1315. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1316. if (n == 0) goto L0001;
  1317. ctx->cur += n;
  1318. }
  1319. if (ctx->cur == p) break;
  1320. continue;
  1321. L0001:;
  1322. ctx->cur = p;
  1323. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1324. break;
  1325. }
  1326. }
  1327. {
  1328. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_bbsuccend_0, 0, 0);
  1329. thunk->data.leaf.capt0.range.start = chunk->pos;
  1330. thunk->data.leaf.capt0.range.end = ctx->cur;
  1331. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  1332. }
  1333. ctx->level--;
  1334. PCC_DEBUG(PCC_DBG_MATCH, "bbsuccend", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1335. return chunk;
  1336. L0000:;
  1337. ctx->level--;
  1338. PCC_DEBUG(PCC_DBG_NOMATCH, "bbsuccend", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1339. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1340. return NULL;
  1341. }
  1342. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbsucc(gccda_context_t *ctx) {
  1343. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1344. chunk->pos = ctx->cur;
  1345. PCC_DEBUG(PCC_DBG_EVALUATE, "bbsucc", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1346. ctx->level++;
  1347. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1348. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1349. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_succlines, &chunk->thunks, NULL)) goto L0000;
  1350. ctx->level--;
  1351. PCC_DEBUG(PCC_DBG_MATCH, "bbsucc", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1352. return chunk;
  1353. L0000:;
  1354. ctx->level--;
  1355. PCC_DEBUG(PCC_DBG_NOMATCH, "bbsucc", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1356. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1357. return NULL;
  1358. }
  1359. static pcc_thunk_chunk_t *pcc_evaluate_rule_succlines(gccda_context_t *ctx) {
  1360. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1361. chunk->pos = ctx->cur;
  1362. PCC_DEBUG(PCC_DBG_EVALUATE, "succlines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1363. ctx->level++;
  1364. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1365. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1366. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_succline, &chunk->thunks, NULL)) goto L0000;
  1367. ctx->level--;
  1368. PCC_DEBUG(PCC_DBG_MATCH, "succlines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1369. return chunk;
  1370. L0000:;
  1371. ctx->level--;
  1372. PCC_DEBUG(PCC_DBG_NOMATCH, "succlines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1373. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1374. return NULL;
  1375. }
  1376. static pcc_thunk_chunk_t *pcc_evaluate_rule_succline(gccda_context_t *ctx) {
  1377. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1378. chunk->pos = ctx->cur;
  1379. PCC_DEBUG(PCC_DBG_EVALUATE, "succline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1380. ctx->level++;
  1381. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1382. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1383. if (
  1384. pcc_refill_buffer(ctx, 16) < 16 ||
  1385. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  1386. (ctx->buffer.buf + ctx->cur)[1] != ';' ||
  1387. (ctx->buffer.buf + ctx->cur)[2] != ' ' ||
  1388. (ctx->buffer.buf + ctx->cur)[3] != ' ' ||
  1389. (ctx->buffer.buf + ctx->cur)[4] != 's' ||
  1390. (ctx->buffer.buf + ctx->cur)[5] != 'u' ||
  1391. (ctx->buffer.buf + ctx->cur)[6] != 'c' ||
  1392. (ctx->buffer.buf + ctx->cur)[7] != 'c' ||
  1393. (ctx->buffer.buf + ctx->cur)[8] != ':' ||
  1394. (ctx->buffer.buf + ctx->cur)[9] != ' ' ||
  1395. (ctx->buffer.buf + ctx->cur)[10] != ' ' ||
  1396. (ctx->buffer.buf + ctx->cur)[11] != ' ' ||
  1397. (ctx->buffer.buf + ctx->cur)[12] != ' ' ||
  1398. (ctx->buffer.buf + ctx->cur)[13] != ' ' ||
  1399. (ctx->buffer.buf + ctx->cur)[14] != ' ' ||
  1400. (ctx->buffer.buf + ctx->cur)[15] != ' '
  1401. ) goto L0000;
  1402. ctx->cur += 16;
  1403. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_succline2, &chunk->thunks, NULL)) goto L0000;
  1404. ctx->level--;
  1405. PCC_DEBUG(PCC_DBG_MATCH, "succline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1406. return chunk;
  1407. L0000:;
  1408. ctx->level--;
  1409. PCC_DEBUG(PCC_DBG_NOMATCH, "succline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1410. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1411. return NULL;
  1412. }
  1413. static pcc_thunk_chunk_t *pcc_evaluate_rule_succline2(gccda_context_t *ctx) {
  1414. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1415. chunk->pos = ctx->cur;
  1416. PCC_DEBUG(PCC_DBG_EVALUATE, "succline2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1417. ctx->level++;
  1418. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1419. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1420. {
  1421. const size_t p = ctx->cur;
  1422. const size_t n = chunk->thunks.len;
  1423. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_succnum, &chunk->thunks, NULL)) goto L0002;
  1424. goto L0001;
  1425. L0002:;
  1426. ctx->cur = p;
  1427. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1428. if (
  1429. pcc_refill_buffer(ctx, 2) < 2 ||
  1430. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  1431. (ctx->buffer.buf + ctx->cur)[1] != ';'
  1432. ) goto L0003;
  1433. ctx->cur += 2;
  1434. {
  1435. int i;
  1436. for (i = 0;; i++) {
  1437. const size_t p = ctx->cur;
  1438. const size_t n = chunk->thunks.len;
  1439. if (
  1440. pcc_refill_buffer(ctx, 1) < 1 ||
  1441. ctx->buffer.buf[ctx->cur] != ' '
  1442. ) goto L0004;
  1443. ctx->cur++;
  1444. if (ctx->cur == p) break;
  1445. continue;
  1446. L0004:;
  1447. ctx->cur = p;
  1448. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1449. break;
  1450. }
  1451. }
  1452. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_succnum, &chunk->thunks, NULL)) goto L0003;
  1453. goto L0001;
  1454. L0003:;
  1455. ctx->cur = p;
  1456. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1457. goto L0000;
  1458. L0001:;
  1459. }
  1460. ctx->level--;
  1461. PCC_DEBUG(PCC_DBG_MATCH, "succline2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1462. return chunk;
  1463. L0000:;
  1464. ctx->level--;
  1465. PCC_DEBUG(PCC_DBG_NOMATCH, "succline2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1466. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1467. return NULL;
  1468. }
  1469. static pcc_thunk_chunk_t *pcc_evaluate_rule_succnum(gccda_context_t *ctx) {
  1470. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1471. chunk->pos = ctx->cur;
  1472. PCC_DEBUG(PCC_DBG_EVALUATE, "succnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1473. ctx->level++;
  1474. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1475. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1476. {
  1477. int i;
  1478. for (i = 0;; i++) {
  1479. const size_t p = ctx->cur;
  1480. const size_t n = chunk->thunks.len;
  1481. {
  1482. const size_t p = ctx->cur;
  1483. const size_t n = chunk->thunks.len;
  1484. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0002;
  1485. ctx->cur = p;
  1486. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1487. goto L0001;
  1488. L0002:;
  1489. ctx->cur = p;
  1490. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1491. }
  1492. {
  1493. int u;
  1494. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1495. if (n == 0) goto L0001;
  1496. ctx->cur += n;
  1497. }
  1498. if (ctx->cur == p) break;
  1499. continue;
  1500. L0001:;
  1501. ctx->cur = p;
  1502. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1503. break;
  1504. }
  1505. }
  1506. ctx->level--;
  1507. PCC_DEBUG(PCC_DBG_MATCH, "succnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1508. return chunk;
  1509. }
  1510. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbpred(gccda_context_t *ctx) {
  1511. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1512. chunk->pos = ctx->cur;
  1513. PCC_DEBUG(PCC_DBG_EVALUATE, "bbpred", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1514. ctx->level++;
  1515. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1516. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1517. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_predlines, &chunk->thunks, NULL)) goto L0000;
  1518. ctx->level--;
  1519. PCC_DEBUG(PCC_DBG_MATCH, "bbpred", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1520. return chunk;
  1521. L0000:;
  1522. ctx->level--;
  1523. PCC_DEBUG(PCC_DBG_NOMATCH, "bbpred", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1524. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1525. return NULL;
  1526. }
  1527. static pcc_thunk_chunk_t *pcc_evaluate_rule_predlines(gccda_context_t *ctx) {
  1528. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1529. chunk->pos = ctx->cur;
  1530. PCC_DEBUG(PCC_DBG_EVALUATE, "predlines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1531. ctx->level++;
  1532. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1533. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1534. {
  1535. const size_t p0 = ctx->cur;
  1536. const size_t n0 = chunk->thunks.len;
  1537. int i;
  1538. for (i = 0;; i++) {
  1539. const size_t p = ctx->cur;
  1540. const size_t n = chunk->thunks.len;
  1541. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_predline, &chunk->thunks, NULL)) goto L0001;
  1542. if (ctx->cur == p) break;
  1543. continue;
  1544. L0001:;
  1545. ctx->cur = p;
  1546. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1547. break;
  1548. }
  1549. if (i < 1) {
  1550. ctx->cur = p0;
  1551. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  1552. goto L0000;
  1553. }
  1554. }
  1555. ctx->level--;
  1556. PCC_DEBUG(PCC_DBG_MATCH, "predlines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1557. return chunk;
  1558. L0000:;
  1559. ctx->level--;
  1560. PCC_DEBUG(PCC_DBG_NOMATCH, "predlines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1561. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1562. return NULL;
  1563. }
  1564. static pcc_thunk_chunk_t *pcc_evaluate_rule_predline(gccda_context_t *ctx) {
  1565. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1566. chunk->pos = ctx->cur;
  1567. PCC_DEBUG(PCC_DBG_EVALUATE, "predline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1568. ctx->level++;
  1569. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1570. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1571. if (
  1572. pcc_refill_buffer(ctx, 16) < 16 ||
  1573. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  1574. (ctx->buffer.buf + ctx->cur)[1] != ';' ||
  1575. (ctx->buffer.buf + ctx->cur)[2] != ' ' ||
  1576. (ctx->buffer.buf + ctx->cur)[3] != ' ' ||
  1577. (ctx->buffer.buf + ctx->cur)[4] != 'p' ||
  1578. (ctx->buffer.buf + ctx->cur)[5] != 'r' ||
  1579. (ctx->buffer.buf + ctx->cur)[6] != 'e' ||
  1580. (ctx->buffer.buf + ctx->cur)[7] != 'd' ||
  1581. (ctx->buffer.buf + ctx->cur)[8] != ':' ||
  1582. (ctx->buffer.buf + ctx->cur)[9] != ' ' ||
  1583. (ctx->buffer.buf + ctx->cur)[10] != ' ' ||
  1584. (ctx->buffer.buf + ctx->cur)[11] != ' ' ||
  1585. (ctx->buffer.buf + ctx->cur)[12] != ' ' ||
  1586. (ctx->buffer.buf + ctx->cur)[13] != ' ' ||
  1587. (ctx->buffer.buf + ctx->cur)[14] != ' ' ||
  1588. (ctx->buffer.buf + ctx->cur)[15] != ' '
  1589. ) goto L0000;
  1590. ctx->cur += 16;
  1591. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_prednum, &chunk->thunks, NULL)) goto L0000;
  1592. {
  1593. int i;
  1594. for (i = 0;; i++) {
  1595. const size_t p = ctx->cur;
  1596. const size_t n = chunk->thunks.len;
  1597. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_predline2, &chunk->thunks, NULL)) goto L0001;
  1598. if (ctx->cur == p) break;
  1599. continue;
  1600. L0001:;
  1601. ctx->cur = p;
  1602. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1603. break;
  1604. }
  1605. }
  1606. ctx->level--;
  1607. PCC_DEBUG(PCC_DBG_MATCH, "predline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1608. return chunk;
  1609. L0000:;
  1610. ctx->level--;
  1611. PCC_DEBUG(PCC_DBG_NOMATCH, "predline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1612. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1613. return NULL;
  1614. }
  1615. static pcc_thunk_chunk_t *pcc_evaluate_rule_predline2(gccda_context_t *ctx) {
  1616. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1617. chunk->pos = ctx->cur;
  1618. PCC_DEBUG(PCC_DBG_EVALUATE, "predline2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1619. ctx->level++;
  1620. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1621. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1622. if (
  1623. pcc_refill_buffer(ctx, 2) < 2 ||
  1624. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  1625. (ctx->buffer.buf + ctx->cur)[1] != ';'
  1626. ) goto L0000;
  1627. ctx->cur += 2;
  1628. {
  1629. int i;
  1630. for (i = 0;; i++) {
  1631. const size_t p = ctx->cur;
  1632. const size_t n = chunk->thunks.len;
  1633. if (
  1634. pcc_refill_buffer(ctx, 1) < 1 ||
  1635. ctx->buffer.buf[ctx->cur] != ' '
  1636. ) goto L0001;
  1637. ctx->cur++;
  1638. if (ctx->cur == p) break;
  1639. continue;
  1640. L0001:;
  1641. ctx->cur = p;
  1642. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1643. break;
  1644. }
  1645. }
  1646. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_prednum, &chunk->thunks, NULL)) goto L0000;
  1647. ctx->level--;
  1648. PCC_DEBUG(PCC_DBG_MATCH, "predline2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1649. return chunk;
  1650. L0000:;
  1651. ctx->level--;
  1652. PCC_DEBUG(PCC_DBG_NOMATCH, "predline2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1653. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1654. return NULL;
  1655. }
  1656. static pcc_thunk_chunk_t *pcc_evaluate_rule_prednum(gccda_context_t *ctx) {
  1657. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1658. chunk->pos = ctx->cur;
  1659. PCC_DEBUG(PCC_DBG_EVALUATE, "prednum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1660. ctx->level++;
  1661. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1662. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1663. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_prednum2, &chunk->thunks, NULL)) goto L0000;
  1664. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_prenum3, &chunk->thunks, NULL)) goto L0000;
  1665. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0000;
  1666. ctx->level--;
  1667. PCC_DEBUG(PCC_DBG_MATCH, "prednum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1668. return chunk;
  1669. L0000:;
  1670. ctx->level--;
  1671. PCC_DEBUG(PCC_DBG_NOMATCH, "prednum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1672. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1673. return NULL;
  1674. }
  1675. static pcc_thunk_chunk_t *pcc_evaluate_rule_prednum2(gccda_context_t *ctx) {
  1676. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1677. chunk->pos = ctx->cur;
  1678. PCC_DEBUG(PCC_DBG_EVALUATE, "prednum2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1679. ctx->level++;
  1680. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1681. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1682. {
  1683. int i;
  1684. for (i = 0;; i++) {
  1685. const size_t p = ctx->cur;
  1686. const size_t n = chunk->thunks.len;
  1687. {
  1688. const size_t p = ctx->cur;
  1689. const size_t n = chunk->thunks.len;
  1690. {
  1691. const size_t p = ctx->cur;
  1692. const size_t n = chunk->thunks.len;
  1693. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0004;
  1694. goto L0003;
  1695. L0004:;
  1696. ctx->cur = p;
  1697. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1698. if (
  1699. pcc_refill_buffer(ctx, 1) < 1 ||
  1700. ctx->buffer.buf[ctx->cur] != '('
  1701. ) goto L0005;
  1702. ctx->cur++;
  1703. goto L0003;
  1704. L0005:;
  1705. ctx->cur = p;
  1706. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1707. if (
  1708. pcc_refill_buffer(ctx, 1) < 1 ||
  1709. ctx->buffer.buf[ctx->cur] != ' '
  1710. ) goto L0006;
  1711. ctx->cur++;
  1712. goto L0003;
  1713. L0006:;
  1714. ctx->cur = p;
  1715. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1716. goto L0002;
  1717. L0003:;
  1718. }
  1719. ctx->cur = p;
  1720. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1721. goto L0001;
  1722. L0002:;
  1723. ctx->cur = p;
  1724. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1725. }
  1726. {
  1727. int u;
  1728. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1729. if (n == 0) goto L0001;
  1730. ctx->cur += n;
  1731. }
  1732. if (ctx->cur == p) break;
  1733. continue;
  1734. L0001:;
  1735. ctx->cur = p;
  1736. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1737. break;
  1738. }
  1739. }
  1740. {
  1741. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_prednum2_0, 0, 0);
  1742. thunk->data.leaf.capt0.range.start = chunk->pos;
  1743. thunk->data.leaf.capt0.range.end = ctx->cur;
  1744. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  1745. }
  1746. ctx->level--;
  1747. PCC_DEBUG(PCC_DBG_MATCH, "prednum2", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1748. return chunk;
  1749. }
  1750. static pcc_thunk_chunk_t *pcc_evaluate_rule_prenum3(gccda_context_t *ctx) {
  1751. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1752. chunk->pos = ctx->cur;
  1753. PCC_DEBUG(PCC_DBG_EVALUATE, "prenum3", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1754. ctx->level++;
  1755. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1756. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1757. {
  1758. int i;
  1759. for (i = 0;; i++) {
  1760. const size_t p = ctx->cur;
  1761. const size_t n = chunk->thunks.len;
  1762. {
  1763. const size_t p = ctx->cur;
  1764. const size_t n = chunk->thunks.len;
  1765. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0002;
  1766. ctx->cur = p;
  1767. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1768. goto L0001;
  1769. L0002:;
  1770. ctx->cur = p;
  1771. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1772. }
  1773. {
  1774. int u;
  1775. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1776. if (n == 0) goto L0001;
  1777. ctx->cur += n;
  1778. }
  1779. if (ctx->cur == p) break;
  1780. continue;
  1781. L0001:;
  1782. ctx->cur = p;
  1783. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1784. break;
  1785. }
  1786. }
  1787. ctx->level--;
  1788. PCC_DEBUG(PCC_DBG_MATCH, "prenum3", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1789. return chunk;
  1790. }
  1791. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbprev(gccda_context_t *ctx) {
  1792. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1793. chunk->pos = ctx->cur;
  1794. PCC_DEBUG(PCC_DBG_EVALUATE, "bbprev", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1795. ctx->level++;
  1796. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1797. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1798. if (
  1799. pcc_refill_buffer(ctx, 15) < 15 ||
  1800. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  1801. (ctx->buffer.buf + ctx->cur)[1] != ';' ||
  1802. (ctx->buffer.buf + ctx->cur)[2] != ' ' ||
  1803. (ctx->buffer.buf + ctx->cur)[3] != ' ' ||
  1804. (ctx->buffer.buf + ctx->cur)[4] != 'p' ||
  1805. (ctx->buffer.buf + ctx->cur)[5] != 'r' ||
  1806. (ctx->buffer.buf + ctx->cur)[6] != 'e' ||
  1807. (ctx->buffer.buf + ctx->cur)[7] != 'v' ||
  1808. (ctx->buffer.buf + ctx->cur)[8] != ' ' ||
  1809. (ctx->buffer.buf + ctx->cur)[9] != 'b' ||
  1810. (ctx->buffer.buf + ctx->cur)[10] != 'l' ||
  1811. (ctx->buffer.buf + ctx->cur)[11] != 'o' ||
  1812. (ctx->buffer.buf + ctx->cur)[12] != 'c' ||
  1813. (ctx->buffer.buf + ctx->cur)[13] != 'k' ||
  1814. (ctx->buffer.buf + ctx->cur)[14] != ' '
  1815. ) goto L0000;
  1816. ctx->cur += 15;
  1817. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_prevnum, &chunk->thunks, NULL)) goto L0000;
  1818. if (
  1819. pcc_refill_buffer(ctx, 13) < 13 ||
  1820. (ctx->buffer.buf + ctx->cur)[0] != ',' ||
  1821. (ctx->buffer.buf + ctx->cur)[1] != ' ' ||
  1822. (ctx->buffer.buf + ctx->cur)[2] != 'n' ||
  1823. (ctx->buffer.buf + ctx->cur)[3] != 'e' ||
  1824. (ctx->buffer.buf + ctx->cur)[4] != 'x' ||
  1825. (ctx->buffer.buf + ctx->cur)[5] != 't' ||
  1826. (ctx->buffer.buf + ctx->cur)[6] != ' ' ||
  1827. (ctx->buffer.buf + ctx->cur)[7] != 'b' ||
  1828. (ctx->buffer.buf + ctx->cur)[8] != 'l' ||
  1829. (ctx->buffer.buf + ctx->cur)[9] != 'o' ||
  1830. (ctx->buffer.buf + ctx->cur)[10] != 'c' ||
  1831. (ctx->buffer.buf + ctx->cur)[11] != 'k' ||
  1832. (ctx->buffer.buf + ctx->cur)[12] != ' '
  1833. ) goto L0000;
  1834. ctx->cur += 13;
  1835. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_nextnum, &chunk->thunks, NULL)) goto L0000;
  1836. if (
  1837. pcc_refill_buffer(ctx, 9) < 9 ||
  1838. (ctx->buffer.buf + ctx->cur)[0] != ',' ||
  1839. (ctx->buffer.buf + ctx->cur)[1] != ' ' ||
  1840. (ctx->buffer.buf + ctx->cur)[2] != 'f' ||
  1841. (ctx->buffer.buf + ctx->cur)[3] != 'l' ||
  1842. (ctx->buffer.buf + ctx->cur)[4] != 'a' ||
  1843. (ctx->buffer.buf + ctx->cur)[5] != 'g' ||
  1844. (ctx->buffer.buf + ctx->cur)[6] != 's' ||
  1845. (ctx->buffer.buf + ctx->cur)[7] != ':' ||
  1846. (ctx->buffer.buf + ctx->cur)[8] != ' '
  1847. ) goto L0000;
  1848. ctx->cur += 9;
  1849. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_prefflags, &chunk->thunks, NULL)) goto L0000;
  1850. {
  1851. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_bbprev_0, 0, 0);
  1852. thunk->data.leaf.capt0.range.start = chunk->pos;
  1853. thunk->data.leaf.capt0.range.end = ctx->cur;
  1854. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  1855. }
  1856. ctx->level--;
  1857. PCC_DEBUG(PCC_DBG_MATCH, "bbprev", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1858. return chunk;
  1859. L0000:;
  1860. ctx->level--;
  1861. PCC_DEBUG(PCC_DBG_NOMATCH, "bbprev", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1862. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1863. return NULL;
  1864. }
  1865. static pcc_thunk_chunk_t *pcc_evaluate_rule_prefflags(gccda_context_t *ctx) {
  1866. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1867. chunk->pos = ctx->cur;
  1868. PCC_DEBUG(PCC_DBG_EVALUATE, "prefflags", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1869. ctx->level++;
  1870. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1871. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1872. {
  1873. int i;
  1874. for (i = 0;; i++) {
  1875. const size_t p = ctx->cur;
  1876. const size_t n = chunk->thunks.len;
  1877. {
  1878. const size_t p = ctx->cur;
  1879. const size_t n = chunk->thunks.len;
  1880. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0002;
  1881. ctx->cur = p;
  1882. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1883. goto L0001;
  1884. L0002:;
  1885. ctx->cur = p;
  1886. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1887. }
  1888. {
  1889. int u;
  1890. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1891. if (n == 0) goto L0001;
  1892. ctx->cur += n;
  1893. }
  1894. if (ctx->cur == p) break;
  1895. continue;
  1896. L0001:;
  1897. ctx->cur = p;
  1898. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1899. break;
  1900. }
  1901. }
  1902. {
  1903. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_prefflags_0, 0, 0);
  1904. thunk->data.leaf.capt0.range.start = chunk->pos;
  1905. thunk->data.leaf.capt0.range.end = ctx->cur;
  1906. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  1907. }
  1908. ctx->level--;
  1909. PCC_DEBUG(PCC_DBG_MATCH, "prefflags", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1910. return chunk;
  1911. }
  1912. static pcc_thunk_chunk_t *pcc_evaluate_rule_nextnum(gccda_context_t *ctx) {
  1913. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1914. chunk->pos = ctx->cur;
  1915. PCC_DEBUG(PCC_DBG_EVALUATE, "nextnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1916. ctx->level++;
  1917. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1918. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1919. {
  1920. int i;
  1921. for (i = 0;; i++) {
  1922. const size_t p = ctx->cur;
  1923. const size_t n = chunk->thunks.len;
  1924. {
  1925. const size_t p = ctx->cur;
  1926. const size_t n = chunk->thunks.len;
  1927. if (
  1928. pcc_refill_buffer(ctx, 1) < 1 ||
  1929. ctx->buffer.buf[ctx->cur] != ','
  1930. ) goto L0002;
  1931. ctx->cur++;
  1932. ctx->cur = p;
  1933. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1934. goto L0001;
  1935. L0002:;
  1936. ctx->cur = p;
  1937. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1938. }
  1939. {
  1940. int u;
  1941. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1942. if (n == 0) goto L0001;
  1943. ctx->cur += n;
  1944. }
  1945. if (ctx->cur == p) break;
  1946. continue;
  1947. L0001:;
  1948. ctx->cur = p;
  1949. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1950. break;
  1951. }
  1952. }
  1953. {
  1954. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_nextnum_0, 0, 0);
  1955. thunk->data.leaf.capt0.range.start = chunk->pos;
  1956. thunk->data.leaf.capt0.range.end = ctx->cur;
  1957. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  1958. }
  1959. ctx->level--;
  1960. PCC_DEBUG(PCC_DBG_MATCH, "nextnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1961. return chunk;
  1962. }
  1963. static pcc_thunk_chunk_t *pcc_evaluate_rule_prevnum(gccda_context_t *ctx) {
  1964. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1965. chunk->pos = ctx->cur;
  1966. PCC_DEBUG(PCC_DBG_EVALUATE, "prevnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1967. ctx->level++;
  1968. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1969. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1970. {
  1971. int i;
  1972. for (i = 0;; i++) {
  1973. const size_t p = ctx->cur;
  1974. const size_t n = chunk->thunks.len;
  1975. {
  1976. const size_t p = ctx->cur;
  1977. const size_t n = chunk->thunks.len;
  1978. if (
  1979. pcc_refill_buffer(ctx, 1) < 1 ||
  1980. ctx->buffer.buf[ctx->cur] != ','
  1981. ) goto L0002;
  1982. ctx->cur++;
  1983. ctx->cur = p;
  1984. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1985. goto L0001;
  1986. L0002:;
  1987. ctx->cur = p;
  1988. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1989. }
  1990. {
  1991. int u;
  1992. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1993. if (n == 0) goto L0001;
  1994. ctx->cur += n;
  1995. }
  1996. if (ctx->cur == p) break;
  1997. continue;
  1998. L0001:;
  1999. ctx->cur = p;
  2000. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2001. break;
  2002. }
  2003. }
  2004. {
  2005. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_prevnum_0, 0, 0);
  2006. thunk->data.leaf.capt0.range.start = chunk->pos;
  2007. thunk->data.leaf.capt0.range.end = ctx->cur;
  2008. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2009. }
  2010. ctx->level--;
  2011. PCC_DEBUG(PCC_DBG_MATCH, "prevnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2012. return chunk;
  2013. }
  2014. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbstart(gccda_context_t *ctx) {
  2015. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2016. chunk->pos = ctx->cur;
  2017. PCC_DEBUG(PCC_DBG_EVALUATE, "bbstart", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2018. ctx->level++;
  2019. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2020. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2021. if (
  2022. pcc_refill_buffer(ctx, 15) < 15 ||
  2023. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  2024. (ctx->buffer.buf + ctx->cur)[1] != ';' ||
  2025. (ctx->buffer.buf + ctx->cur)[2] != ' ' ||
  2026. (ctx->buffer.buf + ctx->cur)[3] != 'b' ||
  2027. (ctx->buffer.buf + ctx->cur)[4] != 'a' ||
  2028. (ctx->buffer.buf + ctx->cur)[5] != 's' ||
  2029. (ctx->buffer.buf + ctx->cur)[6] != 'i' ||
  2030. (ctx->buffer.buf + ctx->cur)[7] != 'c' ||
  2031. (ctx->buffer.buf + ctx->cur)[8] != ' ' ||
  2032. (ctx->buffer.buf + ctx->cur)[9] != 'b' ||
  2033. (ctx->buffer.buf + ctx->cur)[10] != 'l' ||
  2034. (ctx->buffer.buf + ctx->cur)[11] != 'o' ||
  2035. (ctx->buffer.buf + ctx->cur)[12] != 'c' ||
  2036. (ctx->buffer.buf + ctx->cur)[13] != 'k' ||
  2037. (ctx->buffer.buf + ctx->cur)[14] != ' '
  2038. ) goto L0000;
  2039. ctx->cur += 15;
  2040. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_bbnum, &chunk->thunks, NULL)) goto L0000;
  2041. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_bbrest, &chunk->thunks, NULL)) goto L0000;
  2042. ctx->level--;
  2043. PCC_DEBUG(PCC_DBG_MATCH, "bbstart", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2044. return chunk;
  2045. L0000:;
  2046. ctx->level--;
  2047. PCC_DEBUG(PCC_DBG_NOMATCH, "bbstart", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2048. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2049. return NULL;
  2050. }
  2051. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbnum(gccda_context_t *ctx) {
  2052. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2053. chunk->pos = ctx->cur;
  2054. PCC_DEBUG(PCC_DBG_EVALUATE, "bbnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2055. ctx->level++;
  2056. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2057. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2058. {
  2059. int i;
  2060. for (i = 0;; i++) {
  2061. const size_t p = ctx->cur;
  2062. const size_t n = chunk->thunks.len;
  2063. {
  2064. const size_t p = ctx->cur;
  2065. const size_t n = chunk->thunks.len;
  2066. if (
  2067. pcc_refill_buffer(ctx, 1) < 1 ||
  2068. ctx->buffer.buf[ctx->cur] != ','
  2069. ) goto L0002;
  2070. ctx->cur++;
  2071. ctx->cur = p;
  2072. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2073. goto L0001;
  2074. L0002:;
  2075. ctx->cur = p;
  2076. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2077. }
  2078. {
  2079. int u;
  2080. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2081. if (n == 0) goto L0001;
  2082. ctx->cur += n;
  2083. }
  2084. if (ctx->cur == p) break;
  2085. continue;
  2086. L0001:;
  2087. ctx->cur = p;
  2088. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2089. break;
  2090. }
  2091. }
  2092. {
  2093. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_bbnum_0, 0, 0);
  2094. thunk->data.leaf.capt0.range.start = chunk->pos;
  2095. thunk->data.leaf.capt0.range.end = ctx->cur;
  2096. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2097. }
  2098. ctx->level--;
  2099. PCC_DEBUG(PCC_DBG_MATCH, "bbnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2100. return chunk;
  2101. }
  2102. static pcc_thunk_chunk_t *pcc_evaluate_rule_bbrest(gccda_context_t *ctx) {
  2103. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2104. chunk->pos = ctx->cur;
  2105. PCC_DEBUG(PCC_DBG_EVALUATE, "bbrest", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2106. ctx->level++;
  2107. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2108. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2109. {
  2110. int i;
  2111. for (i = 0;; i++) {
  2112. const size_t p = ctx->cur;
  2113. const size_t n = chunk->thunks.len;
  2114. {
  2115. const size_t p = ctx->cur;
  2116. const size_t n = chunk->thunks.len;
  2117. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0002;
  2118. ctx->cur = p;
  2119. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2120. goto L0001;
  2121. L0002:;
  2122. ctx->cur = p;
  2123. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2124. }
  2125. {
  2126. int u;
  2127. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2128. if (n == 0) goto L0001;
  2129. ctx->cur += n;
  2130. }
  2131. if (ctx->cur == p) break;
  2132. continue;
  2133. L0001:;
  2134. ctx->cur = p;
  2135. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2136. break;
  2137. }
  2138. }
  2139. ctx->level--;
  2140. PCC_DEBUG(PCC_DBG_MATCH, "bbrest", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2141. return chunk;
  2142. }
  2143. static pcc_thunk_chunk_t *pcc_evaluate_rule_func(gccda_context_t *ctx) {
  2144. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2145. chunk->pos = ctx->cur;
  2146. PCC_DEBUG(PCC_DBG_EVALUATE, "func", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2147. ctx->level++;
  2148. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2149. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2150. if (
  2151. pcc_refill_buffer(ctx, 12) < 12 ||
  2152. (ctx->buffer.buf + ctx->cur)[0] != ';' ||
  2153. (ctx->buffer.buf + ctx->cur)[1] != ';' ||
  2154. (ctx->buffer.buf + ctx->cur)[2] != ' ' ||
  2155. (ctx->buffer.buf + ctx->cur)[3] != 'F' ||
  2156. (ctx->buffer.buf + ctx->cur)[4] != 'u' ||
  2157. (ctx->buffer.buf + ctx->cur)[5] != 'n' ||
  2158. (ctx->buffer.buf + ctx->cur)[6] != 'c' ||
  2159. (ctx->buffer.buf + ctx->cur)[7] != 't' ||
  2160. (ctx->buffer.buf + ctx->cur)[8] != 'i' ||
  2161. (ctx->buffer.buf + ctx->cur)[9] != 'o' ||
  2162. (ctx->buffer.buf + ctx->cur)[10] != 'n' ||
  2163. (ctx->buffer.buf + ctx->cur)[11] != ' '
  2164. ) goto L0000;
  2165. ctx->cur += 12;
  2166. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_funcname, &chunk->thunks, NULL)) goto L0000;
  2167. if (
  2168. pcc_refill_buffer(ctx, 1) < 1 ||
  2169. ctx->buffer.buf[ctx->cur] != ' '
  2170. ) goto L0000;
  2171. ctx->cur++;
  2172. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_funcuid, &chunk->thunks, NULL)) goto L0000;
  2173. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_funcrest, &chunk->thunks, NULL)) goto L0000;
  2174. {
  2175. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_func_0, 0, 0);
  2176. thunk->data.leaf.capt0.range.start = chunk->pos;
  2177. thunk->data.leaf.capt0.range.end = ctx->cur;
  2178. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2179. }
  2180. ctx->level--;
  2181. PCC_DEBUG(PCC_DBG_MATCH, "func", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2182. return chunk;
  2183. L0000:;
  2184. ctx->level--;
  2185. PCC_DEBUG(PCC_DBG_NOMATCH, "func", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2186. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2187. return NULL;
  2188. }
  2189. static pcc_thunk_chunk_t *pcc_evaluate_rule_funcname(gccda_context_t *ctx) {
  2190. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2191. chunk->pos = ctx->cur;
  2192. PCC_DEBUG(PCC_DBG_EVALUATE, "funcname", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2193. ctx->level++;
  2194. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2195. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2196. {
  2197. int i;
  2198. for (i = 0;; i++) {
  2199. const size_t p = ctx->cur;
  2200. const size_t n = chunk->thunks.len;
  2201. {
  2202. const size_t p = ctx->cur;
  2203. const size_t n = chunk->thunks.len;
  2204. if (
  2205. pcc_refill_buffer(ctx, 1) < 1 ||
  2206. ctx->buffer.buf[ctx->cur] != ' '
  2207. ) goto L0002;
  2208. ctx->cur++;
  2209. ctx->cur = p;
  2210. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2211. goto L0001;
  2212. L0002:;
  2213. ctx->cur = p;
  2214. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2215. }
  2216. {
  2217. int u;
  2218. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2219. if (n == 0) goto L0001;
  2220. ctx->cur += n;
  2221. }
  2222. if (ctx->cur == p) break;
  2223. continue;
  2224. L0001:;
  2225. ctx->cur = p;
  2226. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2227. break;
  2228. }
  2229. }
  2230. {
  2231. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_funcname_0, 0, 0);
  2232. thunk->data.leaf.capt0.range.start = chunk->pos;
  2233. thunk->data.leaf.capt0.range.end = ctx->cur;
  2234. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2235. }
  2236. ctx->level--;
  2237. PCC_DEBUG(PCC_DBG_MATCH, "funcname", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2238. return chunk;
  2239. }
  2240. static pcc_thunk_chunk_t *pcc_evaluate_rule_funcuid(gccda_context_t *ctx) {
  2241. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2242. chunk->pos = ctx->cur;
  2243. PCC_DEBUG(PCC_DBG_EVALUATE, "funcuid", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2244. ctx->level++;
  2245. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2246. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2247. {
  2248. int i;
  2249. for (i = 0;; i++) {
  2250. const size_t p = ctx->cur;
  2251. const size_t n = chunk->thunks.len;
  2252. {
  2253. const size_t p = ctx->cur;
  2254. const size_t n = chunk->thunks.len;
  2255. if (
  2256. pcc_refill_buffer(ctx, 9) < 9 ||
  2257. (ctx->buffer.buf + ctx->cur)[0] != 'd' ||
  2258. (ctx->buffer.buf + ctx->cur)[1] != 'e' ||
  2259. (ctx->buffer.buf + ctx->cur)[2] != 'c' ||
  2260. (ctx->buffer.buf + ctx->cur)[3] != 'l' ||
  2261. (ctx->buffer.buf + ctx->cur)[4] != '_' ||
  2262. (ctx->buffer.buf + ctx->cur)[5] != 'u' ||
  2263. (ctx->buffer.buf + ctx->cur)[6] != 'i' ||
  2264. (ctx->buffer.buf + ctx->cur)[7] != 'd' ||
  2265. (ctx->buffer.buf + ctx->cur)[8] != '='
  2266. ) goto L0002;
  2267. ctx->cur += 9;
  2268. ctx->cur = p;
  2269. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2270. goto L0001;
  2271. L0002:;
  2272. ctx->cur = p;
  2273. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2274. }
  2275. {
  2276. int u;
  2277. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2278. if (n == 0) goto L0001;
  2279. ctx->cur += n;
  2280. }
  2281. if (ctx->cur == p) break;
  2282. continue;
  2283. L0001:;
  2284. ctx->cur = p;
  2285. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2286. break;
  2287. }
  2288. }
  2289. if (
  2290. pcc_refill_buffer(ctx, 9) < 9 ||
  2291. (ctx->buffer.buf + ctx->cur)[0] != 'd' ||
  2292. (ctx->buffer.buf + ctx->cur)[1] != 'e' ||
  2293. (ctx->buffer.buf + ctx->cur)[2] != 'c' ||
  2294. (ctx->buffer.buf + ctx->cur)[3] != 'l' ||
  2295. (ctx->buffer.buf + ctx->cur)[4] != '_' ||
  2296. (ctx->buffer.buf + ctx->cur)[5] != 'u' ||
  2297. (ctx->buffer.buf + ctx->cur)[6] != 'i' ||
  2298. (ctx->buffer.buf + ctx->cur)[7] != 'd' ||
  2299. (ctx->buffer.buf + ctx->cur)[8] != '='
  2300. ) goto L0000;
  2301. ctx->cur += 9;
  2302. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fuid, &chunk->thunks, NULL)) goto L0000;
  2303. ctx->level--;
  2304. PCC_DEBUG(PCC_DBG_MATCH, "funcuid", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2305. return chunk;
  2306. L0000:;
  2307. ctx->level--;
  2308. PCC_DEBUG(PCC_DBG_NOMATCH, "funcuid", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2309. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2310. return NULL;
  2311. }
  2312. static pcc_thunk_chunk_t *pcc_evaluate_rule_fuid(gccda_context_t *ctx) {
  2313. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2314. chunk->pos = ctx->cur;
  2315. PCC_DEBUG(PCC_DBG_EVALUATE, "fuid", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2316. ctx->level++;
  2317. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2318. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2319. {
  2320. int i;
  2321. for (i = 0;; i++) {
  2322. const size_t p = ctx->cur;
  2323. const size_t n = chunk->thunks.len;
  2324. {
  2325. const size_t p = ctx->cur;
  2326. const size_t n = chunk->thunks.len;
  2327. if (
  2328. pcc_refill_buffer(ctx, 1) < 1 ||
  2329. ctx->buffer.buf[ctx->cur] != ','
  2330. ) goto L0002;
  2331. ctx->cur++;
  2332. ctx->cur = p;
  2333. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2334. goto L0001;
  2335. L0002:;
  2336. ctx->cur = p;
  2337. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2338. }
  2339. {
  2340. int u;
  2341. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2342. if (n == 0) goto L0001;
  2343. ctx->cur += n;
  2344. }
  2345. if (ctx->cur == p) break;
  2346. continue;
  2347. L0001:;
  2348. ctx->cur = p;
  2349. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2350. break;
  2351. }
  2352. }
  2353. {
  2354. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_fuid_0, 0, 0);
  2355. thunk->data.leaf.capt0.range.start = chunk->pos;
  2356. thunk->data.leaf.capt0.range.end = ctx->cur;
  2357. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2358. }
  2359. ctx->level--;
  2360. PCC_DEBUG(PCC_DBG_MATCH, "fuid", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2361. return chunk;
  2362. }
  2363. static pcc_thunk_chunk_t *pcc_evaluate_rule_funcrest(gccda_context_t *ctx) {
  2364. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2365. chunk->pos = ctx->cur;
  2366. PCC_DEBUG(PCC_DBG_EVALUATE, "funcrest", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2367. ctx->level++;
  2368. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2369. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2370. {
  2371. int i;
  2372. for (i = 0;; i++) {
  2373. const size_t p = ctx->cur;
  2374. const size_t n = chunk->thunks.len;
  2375. {
  2376. const size_t p = ctx->cur;
  2377. const size_t n = chunk->thunks.len;
  2378. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0002;
  2379. ctx->cur = p;
  2380. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2381. goto L0001;
  2382. L0002:;
  2383. ctx->cur = p;
  2384. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2385. }
  2386. {
  2387. int u;
  2388. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2389. if (n == 0) goto L0001;
  2390. ctx->cur += n;
  2391. }
  2392. if (ctx->cur == p) break;
  2393. continue;
  2394. L0001:;
  2395. ctx->cur = p;
  2396. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2397. break;
  2398. }
  2399. }
  2400. ctx->level--;
  2401. PCC_DEBUG(PCC_DBG_MATCH, "funcrest", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2402. return chunk;
  2403. }
  2404. static pcc_thunk_chunk_t *pcc_evaluate_rule__(gccda_context_t *ctx) {
  2405. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2406. chunk->pos = ctx->cur;
  2407. PCC_DEBUG(PCC_DBG_EVALUATE, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2408. ctx->level++;
  2409. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2410. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2411. {
  2412. int i;
  2413. for (i = 0;; i++) {
  2414. const size_t p = ctx->cur;
  2415. const size_t n = chunk->thunks.len;
  2416. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_space, &chunk->thunks, NULL)) goto L0001;
  2417. if (ctx->cur == p) break;
  2418. continue;
  2419. L0001:;
  2420. ctx->cur = p;
  2421. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2422. break;
  2423. }
  2424. }
  2425. ctx->level--;
  2426. PCC_DEBUG(PCC_DBG_MATCH, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2427. return chunk;
  2428. }
  2429. static pcc_thunk_chunk_t *pcc_evaluate_rule_space(gccda_context_t *ctx) {
  2430. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2431. chunk->pos = ctx->cur;
  2432. PCC_DEBUG(PCC_DBG_EVALUATE, "space", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2433. ctx->level++;
  2434. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2435. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2436. {
  2437. const size_t p = ctx->cur;
  2438. const size_t n = chunk->thunks.len;
  2439. if (
  2440. pcc_refill_buffer(ctx, 1) < 1 ||
  2441. ctx->buffer.buf[ctx->cur] != ' '
  2442. ) goto L0002;
  2443. ctx->cur++;
  2444. goto L0001;
  2445. L0002:;
  2446. ctx->cur = p;
  2447. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2448. if (
  2449. pcc_refill_buffer(ctx, 1) < 1 ||
  2450. ctx->buffer.buf[ctx->cur] != '\t'
  2451. ) goto L0003;
  2452. ctx->cur++;
  2453. goto L0001;
  2454. L0003:;
  2455. ctx->cur = p;
  2456. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2457. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_endofline, &chunk->thunks, NULL)) goto L0004;
  2458. goto L0001;
  2459. L0004:;
  2460. ctx->cur = p;
  2461. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2462. goto L0000;
  2463. L0001:;
  2464. }
  2465. ctx->level--;
  2466. PCC_DEBUG(PCC_DBG_MATCH, "space", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2467. return chunk;
  2468. L0000:;
  2469. ctx->level--;
  2470. PCC_DEBUG(PCC_DBG_NOMATCH, "space", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2471. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2472. return NULL;
  2473. }
  2474. static pcc_thunk_chunk_t *pcc_evaluate_rule_endofline(gccda_context_t *ctx) {
  2475. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2476. chunk->pos = ctx->cur;
  2477. PCC_DEBUG(PCC_DBG_EVALUATE, "endofline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2478. ctx->level++;
  2479. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2480. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2481. {
  2482. const size_t p = ctx->cur;
  2483. const size_t n = chunk->thunks.len;
  2484. if (
  2485. pcc_refill_buffer(ctx, 2) < 2 ||
  2486. (ctx->buffer.buf + ctx->cur)[0] != '\r' ||
  2487. (ctx->buffer.buf + ctx->cur)[1] != '\n'
  2488. ) goto L0002;
  2489. ctx->cur += 2;
  2490. goto L0001;
  2491. L0002:;
  2492. ctx->cur = p;
  2493. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2494. if (
  2495. pcc_refill_buffer(ctx, 1) < 1 ||
  2496. ctx->buffer.buf[ctx->cur] != '\n'
  2497. ) goto L0003;
  2498. ctx->cur++;
  2499. goto L0001;
  2500. L0003:;
  2501. ctx->cur = p;
  2502. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2503. if (
  2504. pcc_refill_buffer(ctx, 1) < 1 ||
  2505. ctx->buffer.buf[ctx->cur] != '\r'
  2506. ) goto L0004;
  2507. ctx->cur++;
  2508. goto L0001;
  2509. L0004:;
  2510. ctx->cur = p;
  2511. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2512. if (
  2513. pcc_refill_buffer(ctx, 2) < 2 ||
  2514. (ctx->buffer.buf + ctx->cur)[0] != '\n' ||
  2515. (ctx->buffer.buf + ctx->cur)[1] != '\r'
  2516. ) goto L0005;
  2517. ctx->cur += 2;
  2518. goto L0001;
  2519. L0005:;
  2520. ctx->cur = p;
  2521. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2522. goto L0000;
  2523. L0001:;
  2524. }
  2525. {
  2526. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_endofline_0, 0, 0);
  2527. thunk->data.leaf.capt0.range.start = chunk->pos;
  2528. thunk->data.leaf.capt0.range.end = ctx->cur;
  2529. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2530. }
  2531. ctx->level--;
  2532. PCC_DEBUG(PCC_DBG_MATCH, "endofline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2533. return chunk;
  2534. L0000:;
  2535. ctx->level--;
  2536. PCC_DEBUG(PCC_DBG_NOMATCH, "endofline", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2537. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2538. return NULL;
  2539. }
  2540. gccda_context_t *gccda_create(void *auxil) {
  2541. return pcc_context__create(auxil);
  2542. }
  2543. int gccda_parse(gccda_context_t *ctx, int *ret) {
  2544. pcc_thunk_array_t thunks;
  2545. pcc_thunk_array__init(ctx->auxil, &thunks, PCC_ARRAYSIZE);
  2546. if (pcc_apply_rule(ctx, pcc_evaluate_rule_file, &thunks, ret))
  2547. pcc_do_action(ctx, &thunks, ret);
  2548. else
  2549. PCC_ERROR(ctx->auxil);
  2550. pcc_commit_buffer(ctx);
  2551. pcc_thunk_array__term(ctx->auxil, &thunks);
  2552. return pcc_refill_buffer(ctx, 1) >= 1;
  2553. }
  2554. void gccda_destroy(gccda_context_t *ctx) {
  2555. pcc_context__destroy(ctx);
  2556. }
  2557. int main() {
  2558. gccda_context_t *ctx = gccda_create(NULL);
  2559. printf ("digraph g {\n");
  2560. while (gccda_parse(ctx, NULL)){;}
  2561. gccda_destroy(ctx);
  2562. printf("}\n/* parsed %d lines */\n",nlines);
  2563. return 0;
  2564. }