gvplain.c 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422
  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 "gvplain.h"
  25. #include <stdio.h>
  26. static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
  27. #define PCC_DEBUG(event, rule, level, pos, buffer, length) \
  28. fprintf(stdout, "%*s%s %s @%d [%.*s]\n", (int)(level * 2), "", dbg_str[event], rule, (int)pos, (int)length, buffer); fflush(stdout)
  29. /* NOTE: To guarantee the output order, stderr, which can lead a race condition with stdout, is not used. */
  30. #ifndef PCC_BUFFERSIZE
  31. #define PCC_BUFFERSIZE 256
  32. #endif /* !PCC_BUFFERSIZE */
  33. #ifndef PCC_ARRAYSIZE
  34. #define PCC_ARRAYSIZE 2
  35. #endif /* !PCC_ARRAYSIZE */
  36. #define VOID_VALUE (~(size_t)0)
  37. typedef enum pcc_bool_tag {
  38. PCC_FALSE = 0,
  39. PCC_TRUE
  40. } pcc_bool_t;
  41. typedef struct pcc_char_array_tag {
  42. char *buf;
  43. size_t max;
  44. size_t len;
  45. } pcc_char_array_t;
  46. typedef struct pcc_range_tag {
  47. size_t start;
  48. size_t end;
  49. } pcc_range_t;
  50. typedef int pcc_value_t;
  51. typedef void *pcc_auxil_t;
  52. typedef struct pcc_value_table_tag {
  53. pcc_value_t *buf;
  54. size_t max;
  55. size_t len;
  56. } pcc_value_table_t;
  57. typedef struct pcc_value_refer_table_tag {
  58. pcc_value_t **buf;
  59. size_t max;
  60. size_t len;
  61. } pcc_value_refer_table_t;
  62. typedef struct pcc_capture_tag {
  63. pcc_range_t range;
  64. char *string; /* mutable */
  65. } pcc_capture_t;
  66. typedef struct pcc_capture_table_tag {
  67. pcc_capture_t *buf;
  68. size_t max;
  69. size_t len;
  70. } pcc_capture_table_t;
  71. typedef struct pcc_capture_const_table_tag {
  72. const pcc_capture_t **buf;
  73. size_t max;
  74. size_t len;
  75. } pcc_capture_const_table_t;
  76. typedef struct pcc_thunk_tag pcc_thunk_t;
  77. typedef struct pcc_thunk_array_tag pcc_thunk_array_t;
  78. typedef void (*pcc_action_t)(gvplain_context_t *, pcc_thunk_t *, pcc_value_t *);
  79. typedef enum pcc_thunk_type_tag {
  80. PCC_THUNK_LEAF,
  81. PCC_THUNK_NODE
  82. } pcc_thunk_type_t;
  83. typedef struct pcc_thunk_leaf_tag {
  84. pcc_value_refer_table_t values;
  85. pcc_capture_const_table_t capts;
  86. pcc_capture_t capt0;
  87. pcc_action_t action;
  88. } pcc_thunk_leaf_t;
  89. typedef struct pcc_thunk_node_tag {
  90. const pcc_thunk_array_t *thunks; /* just a reference */
  91. pcc_value_t *value; /* just a reference */
  92. } pcc_thunk_node_t;
  93. typedef union pcc_thunk_data_tag {
  94. pcc_thunk_leaf_t leaf;
  95. pcc_thunk_node_t node;
  96. } pcc_thunk_data_t;
  97. struct pcc_thunk_tag {
  98. pcc_thunk_type_t type;
  99. pcc_thunk_data_t data;
  100. };
  101. struct pcc_thunk_array_tag {
  102. pcc_thunk_t **buf;
  103. size_t max;
  104. size_t len;
  105. };
  106. typedef struct pcc_thunk_chunk_tag {
  107. pcc_value_table_t values;
  108. pcc_capture_table_t capts;
  109. pcc_thunk_array_t thunks;
  110. size_t pos; /* the starting position in the character buffer */
  111. } pcc_thunk_chunk_t;
  112. typedef struct pcc_lr_entry_tag pcc_lr_entry_t;
  113. typedef enum pcc_lr_answer_type_tag {
  114. PCC_LR_ANSWER_LR,
  115. PCC_LR_ANSWER_CHUNK
  116. } pcc_lr_answer_type_t;
  117. typedef union pcc_lr_answer_data_tag {
  118. pcc_lr_entry_t *lr;
  119. pcc_thunk_chunk_t *chunk;
  120. } pcc_lr_answer_data_t;
  121. typedef struct pcc_lr_answer_tag pcc_lr_answer_t;
  122. struct pcc_lr_answer_tag {
  123. pcc_lr_answer_type_t type;
  124. pcc_lr_answer_data_t data;
  125. size_t pos; /* the absolute position in the input */
  126. pcc_lr_answer_t *hold;
  127. };
  128. typedef pcc_thunk_chunk_t *(*pcc_rule_t)(gvplain_context_t *);
  129. typedef struct pcc_rule_set_tag {
  130. pcc_rule_t *buf;
  131. size_t max;
  132. size_t len;
  133. } pcc_rule_set_t;
  134. typedef struct pcc_lr_head_tag pcc_lr_head_t;
  135. struct pcc_lr_head_tag {
  136. pcc_rule_t rule;
  137. pcc_rule_set_t invol;
  138. pcc_rule_set_t eval;
  139. pcc_lr_head_t *hold;
  140. };
  141. typedef struct pcc_lr_memo_tag {
  142. pcc_rule_t rule;
  143. pcc_lr_answer_t *answer;
  144. } pcc_lr_memo_t;
  145. typedef struct pcc_lr_memo_map_tag {
  146. pcc_lr_memo_t *buf;
  147. size_t max;
  148. size_t len;
  149. } pcc_lr_memo_map_t;
  150. typedef struct pcc_lr_table_entry_tag {
  151. pcc_lr_head_t *head; /* just a reference */
  152. pcc_lr_memo_map_t memos;
  153. pcc_lr_answer_t *hold_a;
  154. pcc_lr_head_t *hold_h;
  155. } pcc_lr_table_entry_t;
  156. typedef struct pcc_lr_table_tag {
  157. pcc_lr_table_entry_t **buf;
  158. size_t max;
  159. size_t len;
  160. } pcc_lr_table_t;
  161. struct pcc_lr_entry_tag {
  162. pcc_rule_t rule;
  163. pcc_thunk_chunk_t *seed; /* just a reference */
  164. pcc_lr_head_t *head; /* just a reference */
  165. };
  166. typedef struct pcc_lr_stack_tag {
  167. pcc_lr_entry_t **buf;
  168. size_t max;
  169. size_t len;
  170. } pcc_lr_stack_t;
  171. struct gvplain_context_tag {
  172. size_t pos; /* the position in the input of the first character currently buffered */
  173. size_t cur; /* the current parsing position in the character buffer */
  174. size_t level;
  175. pcc_char_array_t buffer;
  176. pcc_lr_table_t lrtable;
  177. pcc_lr_stack_t lrstack;
  178. pcc_auxil_t auxil;
  179. };
  180. #ifndef PCC_ERROR
  181. #define PCC_ERROR(auxil) pcc_error()
  182. static void pcc_error(void) {
  183. fprintf(stderr, "Syntax error\n");
  184. exit(1);
  185. }
  186. #endif /* !PCC_ERROR */
  187. #ifndef PCC_GETCHAR
  188. #define PCC_GETCHAR(auxil) getchar()
  189. #endif /* !PCC_GETCHAR */
  190. #ifndef PCC_MALLOC
  191. #define PCC_MALLOC(auxil, size) pcc_malloc_e(size)
  192. static void *pcc_malloc_e(size_t size) {
  193. void *const p = malloc(size);
  194. if (p == NULL) {
  195. fprintf(stderr, "Out of memory\n");
  196. exit(1);
  197. }
  198. return p;
  199. }
  200. #endif /* !PCC_MALLOC */
  201. #ifndef PCC_REALLOC
  202. #define PCC_REALLOC(auxil, ptr, size) pcc_realloc_e(ptr, size)
  203. static void *pcc_realloc_e(void *ptr, size_t size) {
  204. void *const p = realloc(ptr, size);
  205. if (p == NULL) {
  206. fprintf(stderr, "Out of memory\n");
  207. exit(1);
  208. }
  209. return p;
  210. }
  211. #endif /* !PCC_REALLOC */
  212. #ifndef PCC_FREE
  213. #define PCC_FREE(auxil, ptr) free(ptr)
  214. #endif /* !PCC_FREE */
  215. #ifndef PCC_DEBUG
  216. #define PCC_DEBUG(event, rule, level, pos, buffer, length) ((void)0)
  217. #endif /* !PCC_DEBUG */
  218. static char *pcc_strndup_e(pcc_auxil_t auxil, const char *str, size_t len) {
  219. const size_t m = strnlen(str, len);
  220. char *const s = (char *)PCC_MALLOC(auxil, m + 1);
  221. if (auxil) { }
  222. memcpy(s, str, m);
  223. s[m] = '\0';
  224. return s;
  225. }
  226. static void pcc_char_array__init(pcc_auxil_t auxil, pcc_char_array_t *array, size_t max) {
  227. array->len = 0;
  228. array->max = max;
  229. if (auxil) { }
  230. array->buf = (char *)PCC_MALLOC(auxil, array->max);
  231. }
  232. static void pcc_char_array__add(pcc_auxil_t auxil, pcc_char_array_t *array, char ch) {
  233. if (array->max <= array->len) {
  234. const size_t n = array->len + 1;
  235. size_t m = array->max;
  236. if (m == 0) m = 1;
  237. while (m < n && m != 0) m <<= 1;
  238. if (m == 0) m = n;
  239. if (auxil) { }
  240. array->buf = (char *)PCC_REALLOC(auxil, array->buf, m);
  241. array->max = m;
  242. }
  243. array->buf[array->len++] = ch;
  244. }
  245. static void pcc_char_array__term(pcc_auxil_t auxil, pcc_char_array_t *array) {
  246. PCC_FREE(auxil, array->buf);
  247. }
  248. static void pcc_value_table__init(pcc_auxil_t auxil, pcc_value_table_t *table, size_t max) {
  249. table->len = 0;
  250. table->max = max;
  251. table->buf = (pcc_value_t *)PCC_MALLOC(auxil, sizeof(pcc_value_t) * table->max);
  252. if (auxil) { }
  253. return;
  254. }
  255. static void pcc_value_table__resize(pcc_auxil_t auxil, pcc_value_table_t *table, size_t len) {
  256. if (table->max < len) {
  257. size_t m = table->max;
  258. if (m == 0) m = 1;
  259. while (m < len && m != 0) m <<= 1;
  260. if (m == 0) m = len;
  261. table->buf = (pcc_value_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t) * m);
  262. table->max = m;
  263. }
  264. table->len = len;
  265. }
  266. static void pcc_value_table__term(pcc_auxil_t auxil, pcc_value_table_t *table) {
  267. PCC_FREE(auxil, table->buf);
  268. }
  269. static void pcc_value_refer_table__init(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t max) {
  270. table->len = 0;
  271. table->max = max;
  272. table->buf = (pcc_value_t **)PCC_MALLOC(auxil, sizeof(pcc_value_t *) * table->max);
  273. }
  274. static void pcc_value_refer_table__resize(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t len) {
  275. size_t i;
  276. if (table->max < len) {
  277. size_t m = table->max;
  278. if (m == 0) m = 1;
  279. while (m < len && m != 0) m <<= 1;
  280. if (m == 0) m = len;
  281. table->buf = (pcc_value_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t *) * m);
  282. table->max = m;
  283. }
  284. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  285. table->len = len;
  286. }
  287. static void pcc_value_refer_table__term(pcc_auxil_t auxil, pcc_value_refer_table_t *table) {
  288. PCC_FREE(auxil, table->buf);
  289. }
  290. static void pcc_capture_table__init(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t max) {
  291. table->len = 0;
  292. table->max = max;
  293. table->buf = (pcc_capture_t *)PCC_MALLOC(auxil, sizeof(pcc_capture_t) * table->max);
  294. }
  295. static void pcc_capture_table__resize(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t len) {
  296. size_t i;
  297. for (i = len; i < table->len; i++) PCC_FREE(auxil, table->buf[i].string);
  298. if (table->max < len) {
  299. size_t m = table->max;
  300. if (m == 0) m = 1;
  301. while (m < len && m != 0) m <<= 1;
  302. if (m == 0) m = len;
  303. table->buf = (pcc_capture_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_capture_t) * m);
  304. table->max = m;
  305. }
  306. for (i = table->len; i < len; i++) {
  307. table->buf[i].range.start = 0;
  308. table->buf[i].range.end = 0;
  309. table->buf[i].string = NULL;
  310. }
  311. table->len = len;
  312. }
  313. static void pcc_capture_table__term(pcc_auxil_t auxil, pcc_capture_table_t *table) {
  314. while (table->len > 0) {
  315. table->len--;
  316. PCC_FREE(auxil, table->buf[table->len].string);
  317. }
  318. PCC_FREE(auxil, table->buf);
  319. }
  320. static void pcc_capture_const_table__init(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t max) {
  321. table->len = 0;
  322. table->max = max;
  323. table->buf = (const pcc_capture_t **)PCC_MALLOC(auxil, sizeof(const pcc_capture_t *) * table->max);
  324. }
  325. static void pcc_capture_const_table__resize(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t len) {
  326. size_t i;
  327. if (table->max < len) {
  328. size_t m = table->max;
  329. if (m == 0) m = 1;
  330. while (m < len && m != 0) m <<= 1;
  331. if (m == 0) m = len;
  332. table->buf = (const pcc_capture_t **)PCC_REALLOC(auxil, (pcc_capture_t **)table->buf, sizeof(const pcc_capture_t *) * m);
  333. table->max = m;
  334. }
  335. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  336. table->len = len;
  337. }
  338. static void pcc_capture_const_table__term(pcc_auxil_t auxil, pcc_capture_const_table_t *table) {
  339. PCC_FREE(auxil, table->buf);
  340. }
  341. static pcc_thunk_t *pcc_thunk__create_leaf(pcc_auxil_t auxil, pcc_action_t action, size_t valuec, size_t captc) {
  342. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  343. thunk->type = PCC_THUNK_LEAF;
  344. pcc_value_refer_table__init(auxil, &thunk->data.leaf.values, valuec);
  345. pcc_value_refer_table__resize(auxil, &thunk->data.leaf.values, valuec);
  346. pcc_capture_const_table__init(auxil, &thunk->data.leaf.capts, captc);
  347. pcc_capture_const_table__resize(auxil, &thunk->data.leaf.capts, captc);
  348. thunk->data.leaf.capt0.range.start = 0;
  349. thunk->data.leaf.capt0.range.end = 0;
  350. thunk->data.leaf.capt0.string = NULL;
  351. thunk->data.leaf.action = action;
  352. return thunk;
  353. }
  354. static pcc_thunk_t *pcc_thunk__create_node(pcc_auxil_t auxil, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  355. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  356. thunk->type = PCC_THUNK_NODE;
  357. thunk->data.node.thunks = thunks;
  358. thunk->data.node.value = value;
  359. return thunk;
  360. }
  361. static void pcc_thunk__destroy(pcc_auxil_t auxil, pcc_thunk_t *thunk) {
  362. if (thunk == NULL) return;
  363. switch (thunk->type) {
  364. case PCC_THUNK_LEAF:
  365. PCC_FREE(auxil, thunk->data.leaf.capt0.string);
  366. pcc_capture_const_table__term(auxil, &thunk->data.leaf.capts);
  367. pcc_value_refer_table__term(auxil, &thunk->data.leaf.values);
  368. break;
  369. case PCC_THUNK_NODE:
  370. break;
  371. default: /* unknown */
  372. break;
  373. }
  374. PCC_FREE(auxil, thunk);
  375. }
  376. static void pcc_thunk_array__init(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t max) {
  377. array->len = 0;
  378. array->max = max;
  379. array->buf = (pcc_thunk_t **)PCC_MALLOC(auxil, sizeof(pcc_thunk_t *) * array->max);
  380. }
  381. static void pcc_thunk_array__add(pcc_auxil_t auxil, pcc_thunk_array_t *array, pcc_thunk_t *thunk) {
  382. if (array->max <= array->len) {
  383. const size_t n = array->len + 1;
  384. size_t m = array->max;
  385. if (m == 0) m = 1;
  386. while (m < n && m != 0) m <<= 1;
  387. if (m == 0) m = n;
  388. array->buf = (pcc_thunk_t **)PCC_REALLOC(auxil, array->buf, sizeof(pcc_thunk_t *) * m);
  389. array->max = m;
  390. }
  391. array->buf[array->len++] = thunk;
  392. }
  393. static void pcc_thunk_array__revert(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t len) {
  394. while (array->len > len) {
  395. array->len--;
  396. pcc_thunk__destroy(auxil, array->buf[array->len]);
  397. }
  398. }
  399. static void pcc_thunk_array__term(pcc_auxil_t auxil, pcc_thunk_array_t *array) {
  400. while (array->len > 0) {
  401. array->len--;
  402. pcc_thunk__destroy(auxil, array->buf[array->len]);
  403. }
  404. PCC_FREE(auxil, array->buf);
  405. }
  406. static pcc_thunk_chunk_t *pcc_thunk_chunk__create(pcc_auxil_t auxil) {
  407. pcc_thunk_chunk_t *const chunk = (pcc_thunk_chunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_chunk_t));
  408. pcc_value_table__init(auxil, &chunk->values, PCC_ARRAYSIZE);
  409. pcc_capture_table__init(auxil, &chunk->capts, PCC_ARRAYSIZE);
  410. pcc_thunk_array__init(auxil, &chunk->thunks, PCC_ARRAYSIZE);
  411. chunk->pos = 0;
  412. return chunk;
  413. }
  414. static void pcc_thunk_chunk__destroy(pcc_auxil_t auxil, pcc_thunk_chunk_t *chunk) {
  415. if (chunk == NULL) return;
  416. pcc_thunk_array__term(auxil, &chunk->thunks);
  417. pcc_capture_table__term(auxil, &chunk->capts);
  418. pcc_value_table__term(auxil, &chunk->values);
  419. PCC_FREE(auxil, chunk);
  420. }
  421. static void pcc_rule_set__init(pcc_auxil_t auxil, pcc_rule_set_t *set, size_t max) {
  422. set->len = 0;
  423. set->max = max;
  424. set->buf = (pcc_rule_t *)PCC_MALLOC(auxil, sizeof(pcc_rule_t) * set->max);
  425. }
  426. static size_t pcc_rule_set__index(pcc_auxil_t auxil, const pcc_rule_set_t *set, pcc_rule_t rule) {
  427. size_t i;
  428. for (i = 0; i < set->len; i++) {
  429. if (set->buf[i] == rule) return i;
  430. }
  431. return VOID_VALUE;
  432. }
  433. static pcc_bool_t pcc_rule_set__add(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  434. const size_t i = pcc_rule_set__index(auxil, set, rule);
  435. if (i != VOID_VALUE) return PCC_FALSE;
  436. if (set->max <= set->len) {
  437. const size_t n = set->len + 1;
  438. size_t m = set->max;
  439. if (m == 0) m = 1;
  440. while (m < n && m != 0) m <<= 1;
  441. if (m == 0) m = n;
  442. set->buf = (pcc_rule_t *)PCC_REALLOC(auxil, set->buf, sizeof(pcc_rule_t) * m);
  443. set->max = m;
  444. }
  445. set->buf[set->len++] = rule;
  446. return PCC_TRUE;
  447. }
  448. static pcc_bool_t pcc_rule_set__remove(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  449. const size_t i = pcc_rule_set__index(auxil, set, rule);
  450. if (i == VOID_VALUE) return PCC_FALSE;
  451. memmove(set->buf + i, set->buf + (i + 1), sizeof(pcc_rule_t) * (set->len - (i + 1)));
  452. return PCC_TRUE;
  453. }
  454. static void pcc_rule_set__clear(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  455. set->len = 0;
  456. }
  457. static void pcc_rule_set__copy(pcc_auxil_t auxil, pcc_rule_set_t *set, const pcc_rule_set_t *src) {
  458. size_t i;
  459. pcc_rule_set__clear(auxil, set);
  460. for (i = 0; i < src->len; i++) {
  461. pcc_rule_set__add(auxil, set, src->buf[i]);
  462. }
  463. }
  464. static void pcc_rule_set__term(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  465. PCC_FREE(auxil, set->buf);
  466. }
  467. static pcc_lr_head_t *pcc_lr_head__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  468. pcc_lr_head_t *const head = (pcc_lr_head_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_head_t));
  469. head->rule = rule;
  470. pcc_rule_set__init(auxil, &head->invol, PCC_ARRAYSIZE);
  471. pcc_rule_set__init(auxil, &head->eval, PCC_ARRAYSIZE);
  472. head->hold = NULL;
  473. return head;
  474. }
  475. static void pcc_lr_head__destroy(pcc_auxil_t auxil, pcc_lr_head_t *head) {
  476. if (head == NULL) return;
  477. pcc_lr_head__destroy(auxil, head->hold);
  478. pcc_rule_set__term(auxil, &head->eval);
  479. pcc_rule_set__term(auxil, &head->invol);
  480. PCC_FREE(auxil, head);
  481. }
  482. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr);
  483. static pcc_lr_answer_t *pcc_lr_answer__create(pcc_auxil_t auxil, pcc_lr_answer_type_t type, size_t pos) {
  484. pcc_lr_answer_t *answer = (pcc_lr_answer_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_answer_t));
  485. answer->type = type;
  486. answer->pos = pos;
  487. answer->hold = NULL;
  488. switch (answer->type) {
  489. case PCC_LR_ANSWER_LR:
  490. answer->data.lr = NULL;
  491. break;
  492. case PCC_LR_ANSWER_CHUNK:
  493. answer->data.chunk = NULL;
  494. break;
  495. default: /* unknown */
  496. PCC_FREE(auxil, answer);
  497. answer = NULL;
  498. }
  499. return answer;
  500. }
  501. static void pcc_lr_answer__set_chunk(pcc_auxil_t auxil, pcc_lr_answer_t *answer, pcc_thunk_chunk_t *chunk) {
  502. pcc_lr_answer_t *const a = pcc_lr_answer__create(auxil, answer->type, answer->pos);
  503. switch (answer->type) {
  504. case PCC_LR_ANSWER_LR:
  505. a->data.lr = answer->data.lr;
  506. break;
  507. case PCC_LR_ANSWER_CHUNK:
  508. a->data.chunk = answer->data.chunk;
  509. break;
  510. default: /* unknown */
  511. break;
  512. }
  513. a->hold = answer->hold;
  514. answer->hold = a;
  515. answer->type = PCC_LR_ANSWER_CHUNK;
  516. answer->data.chunk = chunk;
  517. }
  518. static void pcc_lr_answer__destroy(pcc_auxil_t auxil, pcc_lr_answer_t *answer) {
  519. if (answer == NULL) return;
  520. pcc_lr_answer__destroy(auxil, answer->hold);
  521. switch (answer->type) {
  522. case PCC_LR_ANSWER_LR:
  523. pcc_lr_entry__destroy(auxil, answer->data.lr);
  524. break;
  525. case PCC_LR_ANSWER_CHUNK:
  526. pcc_thunk_chunk__destroy(auxil, answer->data.chunk);
  527. break;
  528. default: /* unknown */
  529. break;
  530. }
  531. PCC_FREE(auxil, answer);
  532. }
  533. static void pcc_lr_memo_map__init(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, size_t max) {
  534. map->len = 0;
  535. map->max = max;
  536. map->buf = (pcc_lr_memo_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_memo_t) * map->max);
  537. }
  538. static size_t pcc_lr_memo_map__index(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  539. size_t i;
  540. for (i = 0; i < map->len; i++) {
  541. if (map->buf[i].rule == rule) return i;
  542. }
  543. return VOID_VALUE;
  544. }
  545. static void pcc_lr_memo_map__put(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule, pcc_lr_answer_t *answer) {
  546. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  547. if (i != VOID_VALUE) {
  548. pcc_lr_answer__destroy(auxil, map->buf[i].answer);
  549. map->buf[i].answer = answer;
  550. }
  551. else {
  552. if (map->max <= map->len) {
  553. const size_t n = map->len + 1;
  554. size_t m = map->max;
  555. if (m == 0) m = 1;
  556. while (m < n && m != 0) m <<= 1;
  557. if (m == 0) m = n;
  558. map->buf = (pcc_lr_memo_t *)PCC_REALLOC(auxil, map->buf, sizeof(pcc_lr_memo_t) * m);
  559. map->max = m;
  560. }
  561. map->buf[map->len].rule = rule;
  562. map->buf[map->len].answer = answer;
  563. map->len++;
  564. }
  565. }
  566. static pcc_lr_answer_t *pcc_lr_memo_map__get(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  567. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  568. return (i != VOID_VALUE) ? map->buf[i].answer : NULL;
  569. }
  570. static void pcc_lr_memo_map__term(pcc_auxil_t auxil, pcc_lr_memo_map_t *map) {
  571. while (map->len > 0) {
  572. map->len--;
  573. pcc_lr_answer__destroy(auxil, map->buf[map->len].answer);
  574. }
  575. PCC_FREE(auxil, map->buf);
  576. }
  577. static pcc_lr_table_entry_t *pcc_lr_table_entry__create(pcc_auxil_t auxil) {
  578. pcc_lr_table_entry_t *const entry = (pcc_lr_table_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t));
  579. entry->head = NULL;
  580. pcc_lr_memo_map__init(auxil, &entry->memos, PCC_ARRAYSIZE);
  581. entry->hold_a = NULL;
  582. entry->hold_h = NULL;
  583. return entry;
  584. }
  585. static void pcc_lr_table_entry__destroy(pcc_auxil_t auxil, pcc_lr_table_entry_t *entry) {
  586. if (entry == NULL) return;
  587. pcc_lr_head__destroy(auxil, entry->hold_h);
  588. pcc_lr_answer__destroy(auxil, entry->hold_a);
  589. pcc_lr_memo_map__term(auxil, &entry->memos);
  590. PCC_FREE(auxil, entry);
  591. }
  592. static void pcc_lr_table__init(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t max) {
  593. table->len = 0;
  594. table->max = max;
  595. table->buf = (pcc_lr_table_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t *) * table->max);
  596. }
  597. static void pcc_lr_table__resize(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t len) {
  598. size_t i;
  599. for (i = len; i < table->len; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  600. if (table->max < len) {
  601. size_t m = table->max;
  602. if (m == 0) m = 1;
  603. while (m < len && m != 0) m <<= 1;
  604. if (m == 0) m = len;
  605. table->buf = (pcc_lr_table_entry_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_lr_table_entry_t *) * m);
  606. table->max = m;
  607. }
  608. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  609. table->len = len;
  610. }
  611. static void pcc_lr_table__set_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  612. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  613. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  614. table->buf[index]->head = head;
  615. }
  616. static void pcc_lr_table__hold_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  617. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  618. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  619. head->hold = table->buf[index]->hold_h;
  620. table->buf[index]->hold_h = head;
  621. }
  622. static void pcc_lr_table__set_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_rule_t rule, pcc_lr_answer_t *answer) {
  623. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  624. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  625. pcc_lr_memo_map__put(auxil, &table->buf[index]->memos, rule, answer);
  626. }
  627. static void pcc_lr_table__hold_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_answer_t *answer) {
  628. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  629. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  630. answer->hold = table->buf[index]->hold_a;
  631. table->buf[index]->hold_a = answer;
  632. }
  633. static pcc_lr_head_t *pcc_lr_table__get_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index) {
  634. if (index >= table->len || table->buf[index] == NULL) return NULL;
  635. return table->buf[index]->head;
  636. }
  637. static pcc_lr_answer_t *pcc_lr_table__get_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_rule_t rule) {
  638. if (index >= table->len || table->buf[index] == NULL) return NULL;
  639. return pcc_lr_memo_map__get(auxil, &table->buf[index]->memos, rule);
  640. }
  641. static void pcc_lr_table__shift(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t count) {
  642. size_t i;
  643. if (count > table->len) count = table->len;
  644. for (i = 0; i < count; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  645. memmove(table->buf, table->buf + count, sizeof(pcc_lr_table_entry_t *) * (table->len - count));
  646. table->len -= count;
  647. }
  648. static void pcc_lr_table__term(pcc_auxil_t auxil, pcc_lr_table_t *table) {
  649. while (table->len > 0) {
  650. table->len--;
  651. pcc_lr_table_entry__destroy(auxil, table->buf[table->len]);
  652. }
  653. PCC_FREE(auxil, table->buf);
  654. }
  655. static pcc_lr_entry_t *pcc_lr_entry__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  656. pcc_lr_entry_t *const lr = (pcc_lr_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t));
  657. lr->rule = rule;
  658. lr->seed = NULL;
  659. lr->head = NULL;
  660. return lr;
  661. }
  662. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr) {
  663. PCC_FREE(auxil, lr);
  664. }
  665. static void pcc_lr_stack__init(pcc_auxil_t auxil, pcc_lr_stack_t *stack, size_t max) {
  666. stack->len = 0;
  667. stack->max = max;
  668. stack->buf = (pcc_lr_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t *) * stack->max);
  669. }
  670. static void pcc_lr_stack__push(pcc_auxil_t auxil, pcc_lr_stack_t *stack, pcc_lr_entry_t *lr) {
  671. if (stack->max <= stack->len) {
  672. const size_t n = stack->len + 1;
  673. size_t m = stack->max;
  674. if (m == 0) m = 1;
  675. while (m < n && m != 0) m <<= 1;
  676. if (m == 0) m = n;
  677. stack->buf = (pcc_lr_entry_t **)PCC_REALLOC(auxil, stack->buf, sizeof(pcc_lr_entry_t *) * m);
  678. stack->max = m;
  679. }
  680. stack->buf[stack->len++] = lr;
  681. }
  682. static pcc_lr_entry_t *pcc_lr_stack__pop(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  683. return stack->buf[--stack->len];
  684. }
  685. static void pcc_lr_stack__term(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  686. PCC_FREE(auxil, stack->buf);
  687. }
  688. static gvplain_context_t *pcc_context__create(pcc_auxil_t auxil) {
  689. gvplain_context_t *const ctx = (gvplain_context_t *)PCC_MALLOC(auxil, sizeof(gvplain_context_t));
  690. ctx->pos = 0;
  691. ctx->cur = 0;
  692. ctx->level = 0;
  693. pcc_char_array__init(auxil, &ctx->buffer, PCC_BUFFERSIZE);
  694. pcc_lr_table__init(auxil, &ctx->lrtable, PCC_BUFFERSIZE);
  695. pcc_lr_stack__init(auxil, &ctx->lrstack, PCC_ARRAYSIZE);
  696. ctx->auxil = auxil;
  697. return ctx;
  698. }
  699. static void pcc_context__destroy(gvplain_context_t *ctx) {
  700. if (ctx == NULL) return;
  701. pcc_lr_stack__term(ctx->auxil, &ctx->lrstack);
  702. pcc_lr_table__term(ctx->auxil, &ctx->lrtable);
  703. pcc_char_array__term(ctx->auxil, &ctx->buffer);
  704. PCC_FREE(ctx->auxil, ctx);
  705. }
  706. static size_t pcc_refill_buffer(gvplain_context_t *ctx, size_t num) {
  707. if (ctx->buffer.len >= ctx->cur + num) return ctx->buffer.len - ctx->cur;
  708. while (ctx->buffer.len < ctx->cur + num) {
  709. const int c = PCC_GETCHAR(ctx->auxil);
  710. if (c == EOF) break;
  711. pcc_char_array__add(ctx->auxil, &ctx->buffer, (char)c);
  712. }
  713. return ctx->buffer.len - ctx->cur;
  714. }
  715. static void pcc_commit_buffer(gvplain_context_t *ctx) {
  716. memmove(ctx->buffer.buf, ctx->buffer.buf + ctx->cur, ctx->buffer.len - ctx->cur);
  717. ctx->buffer.len -= ctx->cur;
  718. ctx->pos += ctx->cur;
  719. pcc_lr_table__shift(ctx->auxil, &ctx->lrtable, ctx->cur);
  720. ctx->cur = 0;
  721. }
  722. static const char *pcc_get_capture_string(gvplain_context_t *ctx, const pcc_capture_t *capt) {
  723. if (capt->string == NULL)
  724. ((pcc_capture_t *)capt)->string =
  725. pcc_strndup_e(ctx->auxil, ctx->buffer.buf + capt->range.start, capt->range.end - capt->range.start);
  726. return capt->string;
  727. }
  728. static size_t pcc_get_char_as_utf32(gvplain_context_t *ctx, int *out) { /* with checking UTF-8 validity */
  729. int c, u;
  730. size_t n;
  731. if (pcc_refill_buffer(ctx, 1) < 1) return 0;
  732. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur];
  733. n = (c < 0x80) ? 1 :
  734. ((c & 0xe0) == 0xc0) ? 2 :
  735. ((c & 0xf0) == 0xe0) ? 3 :
  736. ((c & 0xf8) == 0xf0) ? 4 : 0;
  737. if (n < 1) return 0;
  738. if (pcc_refill_buffer(ctx, n) < n) return 0;
  739. switch (n) {
  740. case 1:
  741. u = c;
  742. break;
  743. case 2:
  744. u = c & 0x1f;
  745. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  746. if ((c & 0xc0) != 0x80) return 0;
  747. u <<= 6; u |= c & 0x3f;
  748. if (u < 0x80) return 0;
  749. break;
  750. case 3:
  751. u = c & 0x0f;
  752. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  753. if ((c & 0xc0) != 0x80) return 0;
  754. u <<= 6; u |= c & 0x3f;
  755. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  756. if ((c & 0xc0) != 0x80) return 0;
  757. u <<= 6; u |= c & 0x3f;
  758. if (u < 0x800) return 0;
  759. break;
  760. case 4:
  761. u = c & 0x07;
  762. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  763. if ((c & 0xc0) != 0x80) return 0;
  764. u <<= 6; u |= c & 0x3f;
  765. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  766. if ((c & 0xc0) != 0x80) return 0;
  767. u <<= 6; u |= c & 0x3f;
  768. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 3];
  769. if ((c & 0xc0) != 0x80) return 0;
  770. u <<= 6; u |= c & 0x3f;
  771. if (u < 0x10000 || u > 0x10ffff) return 0;
  772. break;
  773. default:
  774. return 0;
  775. }
  776. if (out) *out = u;
  777. return n;
  778. }
  779. static pcc_bool_t pcc_apply_rule(gvplain_context_t *ctx, pcc_rule_t rule, pcc_thunk_array_t *thunks, pcc_value_t *value) {
  780. static pcc_value_t null;
  781. pcc_thunk_chunk_t *c = NULL;
  782. const size_t p = ctx->pos + ctx->cur;
  783. pcc_bool_t b = PCC_TRUE;
  784. pcc_lr_answer_t *a = pcc_lr_table__get_answer(ctx->auxil, &ctx->lrtable, p, rule);
  785. pcc_lr_head_t *h = pcc_lr_table__get_head(ctx->auxil, &ctx->lrtable, p);
  786. if (h != NULL) {
  787. if (a == NULL && rule != h->rule && pcc_rule_set__index(ctx->auxil, &h->invol, rule) == VOID_VALUE) {
  788. b = PCC_FALSE;
  789. c = NULL;
  790. }
  791. else if (pcc_rule_set__remove(ctx->auxil, &h->eval, rule)) {
  792. b = PCC_FALSE;
  793. c = rule(ctx);
  794. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  795. a->data.chunk = c;
  796. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  797. }
  798. }
  799. if (b) {
  800. if (a != NULL) {
  801. ctx->cur = a->pos - ctx->pos;
  802. switch (a->type) {
  803. case PCC_LR_ANSWER_LR:
  804. if (a->data.lr->head == NULL) {
  805. a->data.lr->head = pcc_lr_head__create(ctx->auxil, rule);
  806. pcc_lr_table__hold_head(ctx->auxil, &ctx->lrtable, p, a->data.lr->head);
  807. }
  808. {
  809. size_t i = ctx->lrstack.len;
  810. while (i > 0) {
  811. i--;
  812. if (ctx->lrstack.buf[i]->head == a->data.lr->head) break;
  813. ctx->lrstack.buf[i]->head = a->data.lr->head;
  814. pcc_rule_set__add(ctx->auxil, &a->data.lr->head->invol, ctx->lrstack.buf[i]->rule);
  815. }
  816. }
  817. c = a->data.lr->seed;
  818. break;
  819. case PCC_LR_ANSWER_CHUNK:
  820. c = a->data.chunk;
  821. break;
  822. default: /* unknown */
  823. break;
  824. }
  825. }
  826. else {
  827. pcc_lr_entry_t *const e = pcc_lr_entry__create(ctx->auxil, rule);
  828. pcc_lr_stack__push(ctx->auxil, &ctx->lrstack, e);
  829. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_LR, p);
  830. a->data.lr = e;
  831. pcc_lr_table__set_answer(ctx->auxil, &ctx->lrtable, p, rule, a);
  832. c = rule(ctx);
  833. pcc_lr_stack__pop(ctx->auxil, &ctx->lrstack);
  834. a->pos = ctx->pos + ctx->cur;
  835. if (e->head == NULL) {
  836. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  837. }
  838. else {
  839. e->seed = c;
  840. h = a->data.lr->head;
  841. if (h->rule != rule) {
  842. c = a->data.lr->seed;
  843. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  844. a->data.chunk = c;
  845. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  846. }
  847. else {
  848. pcc_lr_answer__set_chunk(ctx->auxil, a, a->data.lr->seed);
  849. if (a->data.chunk == NULL) {
  850. c = NULL;
  851. }
  852. else {
  853. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, h);
  854. for (;;) {
  855. ctx->cur = p - ctx->pos;
  856. pcc_rule_set__copy(ctx->auxil, &h->eval, &h->invol);
  857. c = rule(ctx);
  858. if (c == NULL || ctx->pos + ctx->cur <= a->pos) break;
  859. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  860. a->pos = ctx->pos + ctx->cur;
  861. }
  862. pcc_thunk_chunk__destroy(ctx->auxil, c);
  863. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, NULL);
  864. ctx->cur = a->pos - ctx->pos;
  865. c = a->data.chunk;
  866. }
  867. }
  868. }
  869. }
  870. }
  871. if (c == NULL) return PCC_FALSE;
  872. if (value == NULL) value = &null;
  873. memset(value, 0, sizeof(pcc_value_t)); /* in case */
  874. pcc_thunk_array__add(ctx->auxil, thunks, pcc_thunk__create_node(ctx->auxil, &c->thunks, value));
  875. return PCC_TRUE;
  876. }
  877. static void pcc_do_action(gvplain_context_t *ctx, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  878. size_t i;
  879. for (i = 0; i < thunks->len; i++) {
  880. pcc_thunk_t *const thunk = thunks->buf[i];
  881. switch (thunk->type) {
  882. case PCC_THUNK_LEAF:
  883. thunk->data.leaf.action(ctx, thunk, value);
  884. break;
  885. case PCC_THUNK_NODE:
  886. pcc_do_action(ctx, thunk->data.node.thunks, thunk->data.node.value);
  887. break;
  888. default: /* unknown */
  889. break;
  890. }
  891. }
  892. }
  893. static void pcc_action_nodes_0(gvplain_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  894. #define auxil (__pcc_ctx->auxil)
  895. #define __ (*__pcc_out)
  896. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  897. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  898. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  899. printf("node: \"%s\"\n",_0);
  900. #undef _0e
  901. #undef _0s
  902. #undef _0
  903. #undef __
  904. #undef auxil
  905. }
  906. static void pcc_action_edges_el_0(gvplain_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  907. #define auxil (__pcc_ctx->auxil)
  908. #define __ (*__pcc_out)
  909. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  910. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  911. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  912. printf("edge-with-edgelabel: \"%s\"\n",_0);
  913. #undef _0e
  914. #undef _0s
  915. #undef _0
  916. #undef __
  917. #undef auxil
  918. }
  919. static void pcc_action_edges_wl_0(gvplain_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
  920. #define auxil (__pcc_ctx->auxil)
  921. #define __ (*__pcc_out)
  922. #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
  923. #define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)
  924. #define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)
  925. printf("edge-without-edgelabel: \"%s\"\n",_0);
  926. #undef _0e
  927. #undef _0s
  928. #undef _0
  929. #undef __
  930. #undef auxil
  931. }
  932. static pcc_thunk_chunk_t *pcc_evaluate_rule_gvplain(gvplain_context_t *ctx);
  933. static pcc_thunk_chunk_t *pcc_evaluate_rule_lines(gvplain_context_t *ctx);
  934. static pcc_thunk_chunk_t *pcc_evaluate_rule_linegraph(gvplain_context_t *ctx);
  935. static pcc_thunk_chunk_t *pcc_evaluate_rule_scale(gvplain_context_t *ctx);
  936. static pcc_thunk_chunk_t *pcc_evaluate_rule_width(gvplain_context_t *ctx);
  937. static pcc_thunk_chunk_t *pcc_evaluate_rule_height(gvplain_context_t *ctx);
  938. static pcc_thunk_chunk_t *pcc_evaluate_rule_nodes(gvplain_context_t *ctx);
  939. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_name(gvplain_context_t *ctx);
  940. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_name_char(gvplain_context_t *ctx);
  941. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_x(gvplain_context_t *ctx);
  942. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_y(gvplain_context_t *ctx);
  943. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_width(gvplain_context_t *ctx);
  944. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_height(gvplain_context_t *ctx);
  945. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_label(gvplain_context_t *ctx);
  946. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_char(gvplain_context_t *ctx);
  947. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_style(gvplain_context_t *ctx);
  948. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_shape(gvplain_context_t *ctx);
  949. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_color(gvplain_context_t *ctx);
  950. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_fillcolor(gvplain_context_t *ctx);
  951. static pcc_thunk_chunk_t *pcc_evaluate_rule_edges(gvplain_context_t *ctx);
  952. static pcc_thunk_chunk_t *pcc_evaluate_rule_edges_el(gvplain_context_t *ctx);
  953. static pcc_thunk_chunk_t *pcc_evaluate_rule_edges_wl(gvplain_context_t *ctx);
  954. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_tail(gvplain_context_t *ctx);
  955. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_tail_char(gvplain_context_t *ctx);
  956. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_head(gvplain_context_t *ctx);
  957. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_head_char(gvplain_context_t *ctx);
  958. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_pair(gvplain_context_t *ctx);
  959. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_n(gvplain_context_t *ctx);
  960. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_x(gvplain_context_t *ctx);
  961. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_y(gvplain_context_t *ctx);
  962. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_style(gvplain_context_t *ctx);
  963. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_color(gvplain_context_t *ctx);
  964. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_label(gvplain_context_t *ctx);
  965. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_char(gvplain_context_t *ctx);
  966. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_xl(gvplain_context_t *ctx);
  967. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_yl(gvplain_context_t *ctx);
  968. static pcc_thunk_chunk_t *pcc_evaluate_rule_linestop(gvplain_context_t *ctx);
  969. static pcc_thunk_chunk_t *pcc_evaluate_rule_fpnum(gvplain_context_t *ctx);
  970. static pcc_thunk_chunk_t *pcc_evaluate_rule_digit(gvplain_context_t *ctx);
  971. static pcc_thunk_chunk_t *pcc_evaluate_rule_eol(gvplain_context_t *ctx);
  972. static pcc_thunk_chunk_t *pcc_evaluate_rule__(gvplain_context_t *ctx);
  973. static pcc_thunk_chunk_t *pcc_evaluate_rule_gvplain(gvplain_context_t *ctx) {
  974. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  975. chunk->pos = ctx->cur;
  976. PCC_DEBUG(PCC_DBG_EVALUATE, "gvplain", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  977. ctx->level++;
  978. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  979. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  980. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_lines, &chunk->thunks, NULL)) goto L0000;
  981. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  982. {
  983. const size_t p = ctx->cur;
  984. const size_t n = chunk->thunks.len;
  985. {
  986. int u;
  987. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  988. if (n == 0) goto L0001;
  989. ctx->cur += n;
  990. }
  991. ctx->cur = p;
  992. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  993. goto L0000;
  994. L0001:;
  995. ctx->cur = p;
  996. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  997. }
  998. ctx->level--;
  999. PCC_DEBUG(PCC_DBG_MATCH, "gvplain", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1000. return chunk;
  1001. L0000:;
  1002. ctx->level--;
  1003. PCC_DEBUG(PCC_DBG_NOMATCH, "gvplain", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1004. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1005. return NULL;
  1006. }
  1007. static pcc_thunk_chunk_t *pcc_evaluate_rule_lines(gvplain_context_t *ctx) {
  1008. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1009. chunk->pos = ctx->cur;
  1010. PCC_DEBUG(PCC_DBG_EVALUATE, "lines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1011. ctx->level++;
  1012. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1013. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1014. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_linegraph, &chunk->thunks, NULL)) goto L0000;
  1015. {
  1016. int i;
  1017. for (i = 0;; i++) {
  1018. const size_t p = ctx->cur;
  1019. const size_t n = chunk->thunks.len;
  1020. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_nodes, &chunk->thunks, NULL)) goto L0001;
  1021. if (ctx->cur == p) break;
  1022. continue;
  1023. L0001:;
  1024. ctx->cur = p;
  1025. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1026. break;
  1027. }
  1028. }
  1029. {
  1030. int i;
  1031. for (i = 0;; i++) {
  1032. const size_t p = ctx->cur;
  1033. const size_t n = chunk->thunks.len;
  1034. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edges, &chunk->thunks, NULL)) goto L0002;
  1035. if (ctx->cur == p) break;
  1036. continue;
  1037. L0002:;
  1038. ctx->cur = p;
  1039. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1040. break;
  1041. }
  1042. }
  1043. {
  1044. int i;
  1045. for (i = 0;; i++) {
  1046. const size_t p = ctx->cur;
  1047. const size_t n = chunk->thunks.len;
  1048. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_linestop, &chunk->thunks, NULL)) goto L0003;
  1049. if (ctx->cur == p) break;
  1050. continue;
  1051. L0003:;
  1052. ctx->cur = p;
  1053. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1054. break;
  1055. }
  1056. }
  1057. ctx->level--;
  1058. PCC_DEBUG(PCC_DBG_MATCH, "lines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1059. return chunk;
  1060. L0000:;
  1061. ctx->level--;
  1062. PCC_DEBUG(PCC_DBG_NOMATCH, "lines", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1063. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1064. return NULL;
  1065. }
  1066. static pcc_thunk_chunk_t *pcc_evaluate_rule_linegraph(gvplain_context_t *ctx) {
  1067. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1068. chunk->pos = ctx->cur;
  1069. PCC_DEBUG(PCC_DBG_EVALUATE, "linegraph", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1070. ctx->level++;
  1071. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1072. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1073. if (
  1074. pcc_refill_buffer(ctx, 5) < 5 ||
  1075. (ctx->buffer.buf + ctx->cur)[0] != 'g' ||
  1076. (ctx->buffer.buf + ctx->cur)[1] != 'r' ||
  1077. (ctx->buffer.buf + ctx->cur)[2] != 'a' ||
  1078. (ctx->buffer.buf + ctx->cur)[3] != 'p' ||
  1079. (ctx->buffer.buf + ctx->cur)[4] != 'h'
  1080. ) goto L0000;
  1081. ctx->cur += 5;
  1082. if (
  1083. pcc_refill_buffer(ctx, 1) < 1 ||
  1084. ctx->buffer.buf[ctx->cur] != ' '
  1085. ) goto L0000;
  1086. ctx->cur++;
  1087. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_scale, &chunk->thunks, NULL)) goto L0000;
  1088. if (
  1089. pcc_refill_buffer(ctx, 1) < 1 ||
  1090. ctx->buffer.buf[ctx->cur] != ' '
  1091. ) goto L0000;
  1092. ctx->cur++;
  1093. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_width, &chunk->thunks, NULL)) goto L0000;
  1094. if (
  1095. pcc_refill_buffer(ctx, 1) < 1 ||
  1096. ctx->buffer.buf[ctx->cur] != ' '
  1097. ) goto L0000;
  1098. ctx->cur++;
  1099. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_height, &chunk->thunks, NULL)) goto L0000;
  1100. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1101. ctx->level--;
  1102. PCC_DEBUG(PCC_DBG_MATCH, "linegraph", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1103. return chunk;
  1104. L0000:;
  1105. ctx->level--;
  1106. PCC_DEBUG(PCC_DBG_NOMATCH, "linegraph", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1107. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1108. return NULL;
  1109. }
  1110. static pcc_thunk_chunk_t *pcc_evaluate_rule_scale(gvplain_context_t *ctx) {
  1111. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1112. chunk->pos = ctx->cur;
  1113. PCC_DEBUG(PCC_DBG_EVALUATE, "scale", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1114. ctx->level++;
  1115. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1116. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1117. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  1118. ctx->level--;
  1119. PCC_DEBUG(PCC_DBG_MATCH, "scale", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1120. return chunk;
  1121. L0000:;
  1122. ctx->level--;
  1123. PCC_DEBUG(PCC_DBG_NOMATCH, "scale", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1124. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1125. return NULL;
  1126. }
  1127. static pcc_thunk_chunk_t *pcc_evaluate_rule_width(gvplain_context_t *ctx) {
  1128. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1129. chunk->pos = ctx->cur;
  1130. PCC_DEBUG(PCC_DBG_EVALUATE, "width", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1131. ctx->level++;
  1132. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1133. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1134. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  1135. ctx->level--;
  1136. PCC_DEBUG(PCC_DBG_MATCH, "width", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1137. return chunk;
  1138. L0000:;
  1139. ctx->level--;
  1140. PCC_DEBUG(PCC_DBG_NOMATCH, "width", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1141. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1142. return NULL;
  1143. }
  1144. static pcc_thunk_chunk_t *pcc_evaluate_rule_height(gvplain_context_t *ctx) {
  1145. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1146. chunk->pos = ctx->cur;
  1147. PCC_DEBUG(PCC_DBG_EVALUATE, "height", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1148. ctx->level++;
  1149. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1150. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1151. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  1152. ctx->level--;
  1153. PCC_DEBUG(PCC_DBG_MATCH, "height", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1154. return chunk;
  1155. L0000:;
  1156. ctx->level--;
  1157. PCC_DEBUG(PCC_DBG_NOMATCH, "height", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1158. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1159. return NULL;
  1160. }
  1161. static pcc_thunk_chunk_t *pcc_evaluate_rule_nodes(gvplain_context_t *ctx) {
  1162. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1163. chunk->pos = ctx->cur;
  1164. PCC_DEBUG(PCC_DBG_EVALUATE, "nodes", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1165. ctx->level++;
  1166. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1167. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1168. if (
  1169. pcc_refill_buffer(ctx, 4) < 4 ||
  1170. (ctx->buffer.buf + ctx->cur)[0] != 'n' ||
  1171. (ctx->buffer.buf + ctx->cur)[1] != 'o' ||
  1172. (ctx->buffer.buf + ctx->cur)[2] != 'd' ||
  1173. (ctx->buffer.buf + ctx->cur)[3] != 'e'
  1174. ) goto L0000;
  1175. ctx->cur += 4;
  1176. if (
  1177. pcc_refill_buffer(ctx, 1) < 1 ||
  1178. ctx->buffer.buf[ctx->cur] != ' '
  1179. ) goto L0000;
  1180. ctx->cur++;
  1181. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_name, &chunk->thunks, NULL)) goto L0000;
  1182. if (
  1183. pcc_refill_buffer(ctx, 1) < 1 ||
  1184. ctx->buffer.buf[ctx->cur] != ' '
  1185. ) goto L0000;
  1186. ctx->cur++;
  1187. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_x, &chunk->thunks, NULL)) goto L0000;
  1188. if (
  1189. pcc_refill_buffer(ctx, 1) < 1 ||
  1190. ctx->buffer.buf[ctx->cur] != ' '
  1191. ) goto L0000;
  1192. ctx->cur++;
  1193. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_y, &chunk->thunks, NULL)) goto L0000;
  1194. if (
  1195. pcc_refill_buffer(ctx, 1) < 1 ||
  1196. ctx->buffer.buf[ctx->cur] != ' '
  1197. ) goto L0000;
  1198. ctx->cur++;
  1199. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_width, &chunk->thunks, NULL)) goto L0000;
  1200. if (
  1201. pcc_refill_buffer(ctx, 1) < 1 ||
  1202. ctx->buffer.buf[ctx->cur] != ' '
  1203. ) goto L0000;
  1204. ctx->cur++;
  1205. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_height, &chunk->thunks, NULL)) goto L0000;
  1206. if (
  1207. pcc_refill_buffer(ctx, 1) < 1 ||
  1208. ctx->buffer.buf[ctx->cur] != ' '
  1209. ) goto L0000;
  1210. ctx->cur++;
  1211. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_label, &chunk->thunks, NULL)) goto L0000;
  1212. if (
  1213. pcc_refill_buffer(ctx, 1) < 1 ||
  1214. ctx->buffer.buf[ctx->cur] != ' '
  1215. ) goto L0000;
  1216. ctx->cur++;
  1217. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_style, &chunk->thunks, NULL)) goto L0000;
  1218. if (
  1219. pcc_refill_buffer(ctx, 1) < 1 ||
  1220. ctx->buffer.buf[ctx->cur] != ' '
  1221. ) goto L0000;
  1222. ctx->cur++;
  1223. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_shape, &chunk->thunks, NULL)) goto L0000;
  1224. if (
  1225. pcc_refill_buffer(ctx, 1) < 1 ||
  1226. ctx->buffer.buf[ctx->cur] != ' '
  1227. ) goto L0000;
  1228. ctx->cur++;
  1229. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_color, &chunk->thunks, NULL)) goto L0000;
  1230. if (
  1231. pcc_refill_buffer(ctx, 1) < 1 ||
  1232. ctx->buffer.buf[ctx->cur] != ' '
  1233. ) goto L0000;
  1234. ctx->cur++;
  1235. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_fillcolor, &chunk->thunks, NULL)) goto L0000;
  1236. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1237. {
  1238. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_nodes_0, 0, 0);
  1239. thunk->data.leaf.capt0.range.start = chunk->pos;
  1240. thunk->data.leaf.capt0.range.end = ctx->cur;
  1241. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  1242. }
  1243. ctx->level--;
  1244. PCC_DEBUG(PCC_DBG_MATCH, "nodes", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1245. return chunk;
  1246. L0000:;
  1247. ctx->level--;
  1248. PCC_DEBUG(PCC_DBG_NOMATCH, "nodes", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1249. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1250. return NULL;
  1251. }
  1252. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_name(gvplain_context_t *ctx) {
  1253. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1254. chunk->pos = ctx->cur;
  1255. PCC_DEBUG(PCC_DBG_EVALUATE, "node_name", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1256. ctx->level++;
  1257. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1258. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1259. {
  1260. const size_t p = ctx->cur;
  1261. const size_t n = chunk->thunks.len;
  1262. if (
  1263. pcc_refill_buffer(ctx, 1) < 1 ||
  1264. ctx->buffer.buf[ctx->cur] != '\"'
  1265. ) goto L0002;
  1266. ctx->cur++;
  1267. {
  1268. int i;
  1269. for (i = 0;; i++) {
  1270. const size_t p = ctx->cur;
  1271. const size_t n = chunk->thunks.len;
  1272. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_name_char, &chunk->thunks, NULL)) goto L0003;
  1273. if (ctx->cur == p) break;
  1274. continue;
  1275. L0003:;
  1276. ctx->cur = p;
  1277. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1278. break;
  1279. }
  1280. }
  1281. if (
  1282. pcc_refill_buffer(ctx, 1) < 1 ||
  1283. ctx->buffer.buf[ctx->cur] != '\"'
  1284. ) goto L0002;
  1285. ctx->cur++;
  1286. goto L0001;
  1287. L0002:;
  1288. ctx->cur = p;
  1289. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1290. {
  1291. int i;
  1292. for (i = 0;; i++) {
  1293. const size_t p = ctx->cur;
  1294. const size_t n = chunk->thunks.len;
  1295. {
  1296. const size_t p = ctx->cur;
  1297. const size_t n = chunk->thunks.len;
  1298. if (
  1299. pcc_refill_buffer(ctx, 1) < 1 ||
  1300. ctx->buffer.buf[ctx->cur] != ' '
  1301. ) goto L0006;
  1302. ctx->cur++;
  1303. ctx->cur = p;
  1304. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1305. goto L0005;
  1306. L0006:;
  1307. ctx->cur = p;
  1308. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1309. }
  1310. {
  1311. int u;
  1312. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1313. if (n == 0) goto L0005;
  1314. ctx->cur += n;
  1315. }
  1316. if (ctx->cur == p) break;
  1317. continue;
  1318. L0005:;
  1319. ctx->cur = p;
  1320. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1321. break;
  1322. }
  1323. }
  1324. L0001:;
  1325. }
  1326. ctx->level--;
  1327. PCC_DEBUG(PCC_DBG_MATCH, "node_name", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1328. return chunk;
  1329. }
  1330. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_name_char(gvplain_context_t *ctx) {
  1331. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1332. chunk->pos = ctx->cur;
  1333. PCC_DEBUG(PCC_DBG_EVALUATE, "node_name_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1334. ctx->level++;
  1335. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1336. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1337. {
  1338. const size_t p = ctx->cur;
  1339. const size_t n = chunk->thunks.len;
  1340. if (
  1341. pcc_refill_buffer(ctx, 1) < 1 ||
  1342. ctx->buffer.buf[ctx->cur] != '\\'
  1343. ) goto L0002;
  1344. ctx->cur++;
  1345. if (
  1346. pcc_refill_buffer(ctx, 1) < 1 ||
  1347. ctx->buffer.buf[ctx->cur] != '\"'
  1348. ) goto L0002;
  1349. ctx->cur++;
  1350. goto L0001;
  1351. L0002:;
  1352. ctx->cur = p;
  1353. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1354. if (
  1355. pcc_refill_buffer(ctx, 1) < 1 ||
  1356. ctx->buffer.buf[ctx->cur] != '\\'
  1357. ) goto L0003;
  1358. ctx->cur++;
  1359. if (
  1360. pcc_refill_buffer(ctx, 1) < 1 ||
  1361. ctx->buffer.buf[ctx->cur] != '\\'
  1362. ) goto L0003;
  1363. ctx->cur++;
  1364. goto L0001;
  1365. L0003:;
  1366. ctx->cur = p;
  1367. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1368. if (
  1369. pcc_refill_buffer(ctx, 1) < 1 ||
  1370. ctx->buffer.buf[ctx->cur] != '\\'
  1371. ) goto L0004;
  1372. ctx->cur++;
  1373. if (
  1374. pcc_refill_buffer(ctx, 1) < 1 ||
  1375. ctx->buffer.buf[ctx->cur] != 'b'
  1376. ) goto L0004;
  1377. ctx->cur++;
  1378. goto L0001;
  1379. L0004:;
  1380. ctx->cur = p;
  1381. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1382. if (
  1383. pcc_refill_buffer(ctx, 1) < 1 ||
  1384. ctx->buffer.buf[ctx->cur] != '\\'
  1385. ) goto L0005;
  1386. ctx->cur++;
  1387. if (
  1388. pcc_refill_buffer(ctx, 1) < 1 ||
  1389. ctx->buffer.buf[ctx->cur] != 'f'
  1390. ) goto L0005;
  1391. ctx->cur++;
  1392. goto L0001;
  1393. L0005:;
  1394. ctx->cur = p;
  1395. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1396. if (
  1397. pcc_refill_buffer(ctx, 1) < 1 ||
  1398. ctx->buffer.buf[ctx->cur] != '\\'
  1399. ) goto L0006;
  1400. ctx->cur++;
  1401. if (
  1402. pcc_refill_buffer(ctx, 1) < 1 ||
  1403. ctx->buffer.buf[ctx->cur] != 'n'
  1404. ) goto L0006;
  1405. ctx->cur++;
  1406. goto L0001;
  1407. L0006:;
  1408. ctx->cur = p;
  1409. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1410. if (
  1411. pcc_refill_buffer(ctx, 1) < 1 ||
  1412. ctx->buffer.buf[ctx->cur] != '\\'
  1413. ) goto L0007;
  1414. ctx->cur++;
  1415. if (
  1416. pcc_refill_buffer(ctx, 1) < 1 ||
  1417. ctx->buffer.buf[ctx->cur] != 'r'
  1418. ) goto L0007;
  1419. ctx->cur++;
  1420. goto L0001;
  1421. L0007:;
  1422. ctx->cur = p;
  1423. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1424. if (
  1425. pcc_refill_buffer(ctx, 1) < 1 ||
  1426. ctx->buffer.buf[ctx->cur] != '\\'
  1427. ) goto L0008;
  1428. ctx->cur++;
  1429. if (
  1430. pcc_refill_buffer(ctx, 1) < 1 ||
  1431. ctx->buffer.buf[ctx->cur] != 't'
  1432. ) goto L0008;
  1433. ctx->cur++;
  1434. goto L0001;
  1435. L0008:;
  1436. ctx->cur = p;
  1437. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1438. {
  1439. const size_t p = ctx->cur;
  1440. const size_t n = chunk->thunks.len;
  1441. if (
  1442. pcc_refill_buffer(ctx, 1) < 1 ||
  1443. ctx->buffer.buf[ctx->cur] != '\"'
  1444. ) goto L0010;
  1445. ctx->cur++;
  1446. ctx->cur = p;
  1447. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1448. goto L0009;
  1449. L0010:;
  1450. ctx->cur = p;
  1451. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1452. }
  1453. {
  1454. int u;
  1455. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1456. if (n == 0) goto L0009;
  1457. ctx->cur += n;
  1458. }
  1459. goto L0001;
  1460. L0009:;
  1461. ctx->cur = p;
  1462. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1463. goto L0000;
  1464. L0001:;
  1465. }
  1466. ctx->level--;
  1467. PCC_DEBUG(PCC_DBG_MATCH, "node_name_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1468. return chunk;
  1469. L0000:;
  1470. ctx->level--;
  1471. PCC_DEBUG(PCC_DBG_NOMATCH, "node_name_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1472. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1473. return NULL;
  1474. }
  1475. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_x(gvplain_context_t *ctx) {
  1476. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1477. chunk->pos = ctx->cur;
  1478. PCC_DEBUG(PCC_DBG_EVALUATE, "node_x", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1479. ctx->level++;
  1480. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1481. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1482. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  1483. ctx->level--;
  1484. PCC_DEBUG(PCC_DBG_MATCH, "node_x", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1485. return chunk;
  1486. L0000:;
  1487. ctx->level--;
  1488. PCC_DEBUG(PCC_DBG_NOMATCH, "node_x", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1489. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1490. return NULL;
  1491. }
  1492. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_y(gvplain_context_t *ctx) {
  1493. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1494. chunk->pos = ctx->cur;
  1495. PCC_DEBUG(PCC_DBG_EVALUATE, "node_y", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1496. ctx->level++;
  1497. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1498. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1499. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  1500. ctx->level--;
  1501. PCC_DEBUG(PCC_DBG_MATCH, "node_y", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1502. return chunk;
  1503. L0000:;
  1504. ctx->level--;
  1505. PCC_DEBUG(PCC_DBG_NOMATCH, "node_y", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1506. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1507. return NULL;
  1508. }
  1509. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_width(gvplain_context_t *ctx) {
  1510. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1511. chunk->pos = ctx->cur;
  1512. PCC_DEBUG(PCC_DBG_EVALUATE, "node_width", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1513. ctx->level++;
  1514. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1515. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1516. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  1517. ctx->level--;
  1518. PCC_DEBUG(PCC_DBG_MATCH, "node_width", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1519. return chunk;
  1520. L0000:;
  1521. ctx->level--;
  1522. PCC_DEBUG(PCC_DBG_NOMATCH, "node_width", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1523. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1524. return NULL;
  1525. }
  1526. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_height(gvplain_context_t *ctx) {
  1527. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1528. chunk->pos = ctx->cur;
  1529. PCC_DEBUG(PCC_DBG_EVALUATE, "node_height", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1530. ctx->level++;
  1531. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1532. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1533. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  1534. ctx->level--;
  1535. PCC_DEBUG(PCC_DBG_MATCH, "node_height", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1536. return chunk;
  1537. L0000:;
  1538. ctx->level--;
  1539. PCC_DEBUG(PCC_DBG_NOMATCH, "node_height", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1540. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1541. return NULL;
  1542. }
  1543. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_label(gvplain_context_t *ctx) {
  1544. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1545. chunk->pos = ctx->cur;
  1546. PCC_DEBUG(PCC_DBG_EVALUATE, "node_label", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1547. ctx->level++;
  1548. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1549. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1550. {
  1551. const size_t p = ctx->cur;
  1552. const size_t n = chunk->thunks.len;
  1553. if (
  1554. pcc_refill_buffer(ctx, 1) < 1 ||
  1555. ctx->buffer.buf[ctx->cur] != '\"'
  1556. ) goto L0002;
  1557. ctx->cur++;
  1558. {
  1559. int i;
  1560. for (i = 0;; i++) {
  1561. const size_t p = ctx->cur;
  1562. const size_t n = chunk->thunks.len;
  1563. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_node_char, &chunk->thunks, NULL)) goto L0003;
  1564. if (ctx->cur == p) break;
  1565. continue;
  1566. L0003:;
  1567. ctx->cur = p;
  1568. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1569. break;
  1570. }
  1571. }
  1572. if (
  1573. pcc_refill_buffer(ctx, 1) < 1 ||
  1574. ctx->buffer.buf[ctx->cur] != '\"'
  1575. ) goto L0002;
  1576. ctx->cur++;
  1577. goto L0001;
  1578. L0002:;
  1579. ctx->cur = p;
  1580. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1581. {
  1582. int i;
  1583. for (i = 0;; i++) {
  1584. const size_t p = ctx->cur;
  1585. const size_t n = chunk->thunks.len;
  1586. {
  1587. const size_t p = ctx->cur;
  1588. const size_t n = chunk->thunks.len;
  1589. if (
  1590. pcc_refill_buffer(ctx, 1) < 1 ||
  1591. ctx->buffer.buf[ctx->cur] != ' '
  1592. ) goto L0006;
  1593. ctx->cur++;
  1594. ctx->cur = p;
  1595. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1596. goto L0005;
  1597. L0006:;
  1598. ctx->cur = p;
  1599. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1600. }
  1601. {
  1602. int u;
  1603. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1604. if (n == 0) goto L0005;
  1605. ctx->cur += n;
  1606. }
  1607. if (ctx->cur == p) break;
  1608. continue;
  1609. L0005:;
  1610. ctx->cur = p;
  1611. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1612. break;
  1613. }
  1614. }
  1615. L0001:;
  1616. }
  1617. ctx->level--;
  1618. PCC_DEBUG(PCC_DBG_MATCH, "node_label", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1619. return chunk;
  1620. }
  1621. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_char(gvplain_context_t *ctx) {
  1622. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1623. chunk->pos = ctx->cur;
  1624. PCC_DEBUG(PCC_DBG_EVALUATE, "node_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1625. ctx->level++;
  1626. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1627. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1628. {
  1629. const size_t p = ctx->cur;
  1630. const size_t n = chunk->thunks.len;
  1631. if (
  1632. pcc_refill_buffer(ctx, 1) < 1 ||
  1633. ctx->buffer.buf[ctx->cur] != '\\'
  1634. ) goto L0002;
  1635. ctx->cur++;
  1636. if (
  1637. pcc_refill_buffer(ctx, 1) < 1 ||
  1638. ctx->buffer.buf[ctx->cur] != '\"'
  1639. ) goto L0002;
  1640. ctx->cur++;
  1641. goto L0001;
  1642. L0002:;
  1643. ctx->cur = p;
  1644. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1645. if (
  1646. pcc_refill_buffer(ctx, 1) < 1 ||
  1647. ctx->buffer.buf[ctx->cur] != '\\'
  1648. ) goto L0003;
  1649. ctx->cur++;
  1650. if (
  1651. pcc_refill_buffer(ctx, 1) < 1 ||
  1652. ctx->buffer.buf[ctx->cur] != '\\'
  1653. ) goto L0003;
  1654. ctx->cur++;
  1655. goto L0001;
  1656. L0003:;
  1657. ctx->cur = p;
  1658. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1659. if (
  1660. pcc_refill_buffer(ctx, 1) < 1 ||
  1661. ctx->buffer.buf[ctx->cur] != '\\'
  1662. ) goto L0004;
  1663. ctx->cur++;
  1664. if (
  1665. pcc_refill_buffer(ctx, 1) < 1 ||
  1666. ctx->buffer.buf[ctx->cur] != 'b'
  1667. ) goto L0004;
  1668. ctx->cur++;
  1669. goto L0001;
  1670. L0004:;
  1671. ctx->cur = p;
  1672. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1673. if (
  1674. pcc_refill_buffer(ctx, 1) < 1 ||
  1675. ctx->buffer.buf[ctx->cur] != '\\'
  1676. ) goto L0005;
  1677. ctx->cur++;
  1678. if (
  1679. pcc_refill_buffer(ctx, 1) < 1 ||
  1680. ctx->buffer.buf[ctx->cur] != 'f'
  1681. ) goto L0005;
  1682. ctx->cur++;
  1683. goto L0001;
  1684. L0005:;
  1685. ctx->cur = p;
  1686. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1687. if (
  1688. pcc_refill_buffer(ctx, 1) < 1 ||
  1689. ctx->buffer.buf[ctx->cur] != '\\'
  1690. ) goto L0006;
  1691. ctx->cur++;
  1692. if (
  1693. pcc_refill_buffer(ctx, 1) < 1 ||
  1694. ctx->buffer.buf[ctx->cur] != 'n'
  1695. ) goto L0006;
  1696. ctx->cur++;
  1697. goto L0001;
  1698. L0006:;
  1699. ctx->cur = p;
  1700. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1701. if (
  1702. pcc_refill_buffer(ctx, 1) < 1 ||
  1703. ctx->buffer.buf[ctx->cur] != '\\'
  1704. ) goto L0007;
  1705. ctx->cur++;
  1706. if (
  1707. pcc_refill_buffer(ctx, 1) < 1 ||
  1708. ctx->buffer.buf[ctx->cur] != 'r'
  1709. ) goto L0007;
  1710. ctx->cur++;
  1711. goto L0001;
  1712. L0007:;
  1713. ctx->cur = p;
  1714. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1715. if (
  1716. pcc_refill_buffer(ctx, 1) < 1 ||
  1717. ctx->buffer.buf[ctx->cur] != '\\'
  1718. ) goto L0008;
  1719. ctx->cur++;
  1720. if (
  1721. pcc_refill_buffer(ctx, 1) < 1 ||
  1722. ctx->buffer.buf[ctx->cur] != 't'
  1723. ) goto L0008;
  1724. ctx->cur++;
  1725. goto L0001;
  1726. L0008:;
  1727. ctx->cur = p;
  1728. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1729. {
  1730. const size_t p = ctx->cur;
  1731. const size_t n = chunk->thunks.len;
  1732. if (
  1733. pcc_refill_buffer(ctx, 1) < 1 ||
  1734. ctx->buffer.buf[ctx->cur] != '\"'
  1735. ) goto L0010;
  1736. ctx->cur++;
  1737. ctx->cur = p;
  1738. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1739. goto L0009;
  1740. L0010:;
  1741. ctx->cur = p;
  1742. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1743. }
  1744. {
  1745. int u;
  1746. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1747. if (n == 0) goto L0009;
  1748. ctx->cur += n;
  1749. }
  1750. goto L0001;
  1751. L0009:;
  1752. ctx->cur = p;
  1753. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1754. goto L0000;
  1755. L0001:;
  1756. }
  1757. ctx->level--;
  1758. PCC_DEBUG(PCC_DBG_MATCH, "node_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1759. return chunk;
  1760. L0000:;
  1761. ctx->level--;
  1762. PCC_DEBUG(PCC_DBG_NOMATCH, "node_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1763. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1764. return NULL;
  1765. }
  1766. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_style(gvplain_context_t *ctx) {
  1767. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1768. chunk->pos = ctx->cur;
  1769. PCC_DEBUG(PCC_DBG_EVALUATE, "node_style", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1770. ctx->level++;
  1771. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1772. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1773. {
  1774. int i;
  1775. for (i = 0;; i++) {
  1776. const size_t p = ctx->cur;
  1777. const size_t n = chunk->thunks.len;
  1778. {
  1779. const size_t p = ctx->cur;
  1780. const size_t n = chunk->thunks.len;
  1781. if (
  1782. pcc_refill_buffer(ctx, 1) < 1 ||
  1783. ctx->buffer.buf[ctx->cur] != ' '
  1784. ) goto L0002;
  1785. ctx->cur++;
  1786. ctx->cur = p;
  1787. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1788. goto L0001;
  1789. L0002:;
  1790. ctx->cur = p;
  1791. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1792. }
  1793. {
  1794. int u;
  1795. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1796. if (n == 0) goto L0001;
  1797. ctx->cur += n;
  1798. }
  1799. if (ctx->cur == p) break;
  1800. continue;
  1801. L0001:;
  1802. ctx->cur = p;
  1803. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1804. break;
  1805. }
  1806. }
  1807. ctx->level--;
  1808. PCC_DEBUG(PCC_DBG_MATCH, "node_style", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1809. return chunk;
  1810. }
  1811. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_shape(gvplain_context_t *ctx) {
  1812. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1813. chunk->pos = ctx->cur;
  1814. PCC_DEBUG(PCC_DBG_EVALUATE, "node_shape", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1815. ctx->level++;
  1816. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1817. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1818. {
  1819. int i;
  1820. for (i = 0;; i++) {
  1821. const size_t p = ctx->cur;
  1822. const size_t n = chunk->thunks.len;
  1823. {
  1824. const size_t p = ctx->cur;
  1825. const size_t n = chunk->thunks.len;
  1826. if (
  1827. pcc_refill_buffer(ctx, 1) < 1 ||
  1828. ctx->buffer.buf[ctx->cur] != ' '
  1829. ) goto L0002;
  1830. ctx->cur++;
  1831. ctx->cur = p;
  1832. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1833. goto L0001;
  1834. L0002:;
  1835. ctx->cur = p;
  1836. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1837. }
  1838. {
  1839. int u;
  1840. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1841. if (n == 0) goto L0001;
  1842. ctx->cur += n;
  1843. }
  1844. if (ctx->cur == p) break;
  1845. continue;
  1846. L0001:;
  1847. ctx->cur = p;
  1848. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1849. break;
  1850. }
  1851. }
  1852. ctx->level--;
  1853. PCC_DEBUG(PCC_DBG_MATCH, "node_shape", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1854. return chunk;
  1855. }
  1856. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_color(gvplain_context_t *ctx) {
  1857. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1858. chunk->pos = ctx->cur;
  1859. PCC_DEBUG(PCC_DBG_EVALUATE, "node_color", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1860. ctx->level++;
  1861. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1862. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1863. {
  1864. int i;
  1865. for (i = 0;; i++) {
  1866. const size_t p = ctx->cur;
  1867. const size_t n = chunk->thunks.len;
  1868. {
  1869. const size_t p = ctx->cur;
  1870. const size_t n = chunk->thunks.len;
  1871. if (
  1872. pcc_refill_buffer(ctx, 1) < 1 ||
  1873. ctx->buffer.buf[ctx->cur] != ' '
  1874. ) goto L0002;
  1875. ctx->cur++;
  1876. ctx->cur = p;
  1877. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1878. goto L0001;
  1879. L0002:;
  1880. ctx->cur = p;
  1881. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1882. }
  1883. {
  1884. int u;
  1885. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1886. if (n == 0) goto L0001;
  1887. ctx->cur += n;
  1888. }
  1889. if (ctx->cur == p) break;
  1890. continue;
  1891. L0001:;
  1892. ctx->cur = p;
  1893. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1894. break;
  1895. }
  1896. }
  1897. ctx->level--;
  1898. PCC_DEBUG(PCC_DBG_MATCH, "node_color", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1899. return chunk;
  1900. }
  1901. static pcc_thunk_chunk_t *pcc_evaluate_rule_node_fillcolor(gvplain_context_t *ctx) {
  1902. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1903. chunk->pos = ctx->cur;
  1904. PCC_DEBUG(PCC_DBG_EVALUATE, "node_fillcolor", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1905. ctx->level++;
  1906. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1907. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1908. {
  1909. int i;
  1910. for (i = 0;; i++) {
  1911. const size_t p = ctx->cur;
  1912. const size_t n = chunk->thunks.len;
  1913. {
  1914. const size_t p = ctx->cur;
  1915. const size_t n = chunk->thunks.len;
  1916. {
  1917. int u;
  1918. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1919. if (n == 0) goto L0002;
  1920. if (!(
  1921. u == 0x00000a
  1922. )) goto L0002;
  1923. ctx->cur += n;
  1924. }
  1925. ctx->cur = p;
  1926. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1927. goto L0001;
  1928. L0002:;
  1929. ctx->cur = p;
  1930. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1931. }
  1932. {
  1933. int u;
  1934. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  1935. if (n == 0) goto L0001;
  1936. ctx->cur += n;
  1937. }
  1938. if (ctx->cur == p) break;
  1939. continue;
  1940. L0001:;
  1941. ctx->cur = p;
  1942. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1943. break;
  1944. }
  1945. }
  1946. ctx->level--;
  1947. PCC_DEBUG(PCC_DBG_MATCH, "node_fillcolor", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1948. return chunk;
  1949. }
  1950. static pcc_thunk_chunk_t *pcc_evaluate_rule_edges(gvplain_context_t *ctx) {
  1951. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1952. chunk->pos = ctx->cur;
  1953. PCC_DEBUG(PCC_DBG_EVALUATE, "edges", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1954. ctx->level++;
  1955. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1956. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1957. {
  1958. const size_t p = ctx->cur;
  1959. const size_t n = chunk->thunks.len;
  1960. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edges_el, &chunk->thunks, NULL)) goto L0002;
  1961. goto L0001;
  1962. L0002:;
  1963. ctx->cur = p;
  1964. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1965. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edges_wl, &chunk->thunks, NULL)) goto L0003;
  1966. goto L0001;
  1967. L0003:;
  1968. ctx->cur = p;
  1969. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1970. goto L0000;
  1971. L0001:;
  1972. }
  1973. ctx->level--;
  1974. PCC_DEBUG(PCC_DBG_MATCH, "edges", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1975. return chunk;
  1976. L0000:;
  1977. ctx->level--;
  1978. PCC_DEBUG(PCC_DBG_NOMATCH, "edges", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1979. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1980. return NULL;
  1981. }
  1982. static pcc_thunk_chunk_t *pcc_evaluate_rule_edges_el(gvplain_context_t *ctx) {
  1983. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1984. chunk->pos = ctx->cur;
  1985. PCC_DEBUG(PCC_DBG_EVALUATE, "edges_el", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1986. ctx->level++;
  1987. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1988. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1989. if (
  1990. pcc_refill_buffer(ctx, 4) < 4 ||
  1991. (ctx->buffer.buf + ctx->cur)[0] != 'e' ||
  1992. (ctx->buffer.buf + ctx->cur)[1] != 'd' ||
  1993. (ctx->buffer.buf + ctx->cur)[2] != 'g' ||
  1994. (ctx->buffer.buf + ctx->cur)[3] != 'e'
  1995. ) goto L0000;
  1996. ctx->cur += 4;
  1997. if (
  1998. pcc_refill_buffer(ctx, 1) < 1 ||
  1999. ctx->buffer.buf[ctx->cur] != ' '
  2000. ) goto L0000;
  2001. ctx->cur++;
  2002. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_tail, &chunk->thunks, NULL)) goto L0000;
  2003. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2004. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_head, &chunk->thunks, NULL)) goto L0000;
  2005. if (
  2006. pcc_refill_buffer(ctx, 1) < 1 ||
  2007. ctx->buffer.buf[ctx->cur] != ' '
  2008. ) goto L0000;
  2009. ctx->cur++;
  2010. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_n, &chunk->thunks, NULL)) goto L0000;
  2011. if (
  2012. pcc_refill_buffer(ctx, 1) < 1 ||
  2013. ctx->buffer.buf[ctx->cur] != ' '
  2014. ) goto L0000;
  2015. ctx->cur++;
  2016. {
  2017. const size_t p0 = ctx->cur;
  2018. const size_t n0 = chunk->thunks.len;
  2019. int i;
  2020. for (i = 0;; i++) {
  2021. const size_t p = ctx->cur;
  2022. const size_t n = chunk->thunks.len;
  2023. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_pair, &chunk->thunks, NULL)) goto L0001;
  2024. if (ctx->cur == p) break;
  2025. continue;
  2026. L0001:;
  2027. ctx->cur = p;
  2028. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2029. break;
  2030. }
  2031. if (i < 1) {
  2032. ctx->cur = p0;
  2033. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  2034. goto L0000;
  2035. }
  2036. }
  2037. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_label, &chunk->thunks, NULL)) goto L0000;
  2038. if (
  2039. pcc_refill_buffer(ctx, 1) < 1 ||
  2040. ctx->buffer.buf[ctx->cur] != ' '
  2041. ) goto L0000;
  2042. ctx->cur++;
  2043. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_xl, &chunk->thunks, NULL)) goto L0000;
  2044. if (
  2045. pcc_refill_buffer(ctx, 1) < 1 ||
  2046. ctx->buffer.buf[ctx->cur] != ' '
  2047. ) goto L0000;
  2048. ctx->cur++;
  2049. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_yl, &chunk->thunks, NULL)) goto L0000;
  2050. if (
  2051. pcc_refill_buffer(ctx, 1) < 1 ||
  2052. ctx->buffer.buf[ctx->cur] != ' '
  2053. ) goto L0000;
  2054. ctx->cur++;
  2055. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_style, &chunk->thunks, NULL)) goto L0000;
  2056. if (
  2057. pcc_refill_buffer(ctx, 1) < 1 ||
  2058. ctx->buffer.buf[ctx->cur] != ' '
  2059. ) goto L0000;
  2060. ctx->cur++;
  2061. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_color, &chunk->thunks, NULL)) goto L0000;
  2062. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2063. {
  2064. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_edges_el_0, 0, 0);
  2065. thunk->data.leaf.capt0.range.start = chunk->pos;
  2066. thunk->data.leaf.capt0.range.end = ctx->cur;
  2067. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2068. }
  2069. ctx->level--;
  2070. PCC_DEBUG(PCC_DBG_MATCH, "edges_el", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2071. return chunk;
  2072. L0000:;
  2073. ctx->level--;
  2074. PCC_DEBUG(PCC_DBG_NOMATCH, "edges_el", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2075. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2076. return NULL;
  2077. }
  2078. static pcc_thunk_chunk_t *pcc_evaluate_rule_edges_wl(gvplain_context_t *ctx) {
  2079. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2080. chunk->pos = ctx->cur;
  2081. PCC_DEBUG(PCC_DBG_EVALUATE, "edges_wl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2082. ctx->level++;
  2083. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2084. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2085. if (
  2086. pcc_refill_buffer(ctx, 4) < 4 ||
  2087. (ctx->buffer.buf + ctx->cur)[0] != 'e' ||
  2088. (ctx->buffer.buf + ctx->cur)[1] != 'd' ||
  2089. (ctx->buffer.buf + ctx->cur)[2] != 'g' ||
  2090. (ctx->buffer.buf + ctx->cur)[3] != 'e'
  2091. ) goto L0000;
  2092. ctx->cur += 4;
  2093. if (
  2094. pcc_refill_buffer(ctx, 1) < 1 ||
  2095. ctx->buffer.buf[ctx->cur] != ' '
  2096. ) goto L0000;
  2097. ctx->cur++;
  2098. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_tail, &chunk->thunks, NULL)) goto L0000;
  2099. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2100. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_head, &chunk->thunks, NULL)) goto L0000;
  2101. if (
  2102. pcc_refill_buffer(ctx, 1) < 1 ||
  2103. ctx->buffer.buf[ctx->cur] != ' '
  2104. ) goto L0000;
  2105. ctx->cur++;
  2106. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_n, &chunk->thunks, NULL)) goto L0000;
  2107. if (
  2108. pcc_refill_buffer(ctx, 1) < 1 ||
  2109. ctx->buffer.buf[ctx->cur] != ' '
  2110. ) goto L0000;
  2111. ctx->cur++;
  2112. {
  2113. const size_t p0 = ctx->cur;
  2114. const size_t n0 = chunk->thunks.len;
  2115. int i;
  2116. for (i = 0;; i++) {
  2117. const size_t p = ctx->cur;
  2118. const size_t n = chunk->thunks.len;
  2119. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_pair, &chunk->thunks, NULL)) goto L0001;
  2120. if (ctx->cur == p) break;
  2121. continue;
  2122. L0001:;
  2123. ctx->cur = p;
  2124. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2125. break;
  2126. }
  2127. if (i < 1) {
  2128. ctx->cur = p0;
  2129. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  2130. goto L0000;
  2131. }
  2132. }
  2133. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_style, &chunk->thunks, NULL)) goto L0000;
  2134. if (
  2135. pcc_refill_buffer(ctx, 1) < 1 ||
  2136. ctx->buffer.buf[ctx->cur] != ' '
  2137. ) goto L0000;
  2138. ctx->cur++;
  2139. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_color, &chunk->thunks, NULL)) goto L0000;
  2140. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2141. {
  2142. pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_edges_wl_0, 0, 0);
  2143. thunk->data.leaf.capt0.range.start = chunk->pos;
  2144. thunk->data.leaf.capt0.range.end = ctx->cur;
  2145. pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
  2146. }
  2147. ctx->level--;
  2148. PCC_DEBUG(PCC_DBG_MATCH, "edges_wl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2149. return chunk;
  2150. L0000:;
  2151. ctx->level--;
  2152. PCC_DEBUG(PCC_DBG_NOMATCH, "edges_wl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2153. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2154. return NULL;
  2155. }
  2156. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_tail(gvplain_context_t *ctx) {
  2157. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2158. chunk->pos = ctx->cur;
  2159. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_tail", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2160. ctx->level++;
  2161. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2162. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2163. {
  2164. const size_t p = ctx->cur;
  2165. const size_t n = chunk->thunks.len;
  2166. if (
  2167. pcc_refill_buffer(ctx, 1) < 1 ||
  2168. ctx->buffer.buf[ctx->cur] != '\"'
  2169. ) goto L0002;
  2170. ctx->cur++;
  2171. {
  2172. int i;
  2173. for (i = 0;; i++) {
  2174. const size_t p = ctx->cur;
  2175. const size_t n = chunk->thunks.len;
  2176. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_tail_char, &chunk->thunks, NULL)) goto L0003;
  2177. if (ctx->cur == p) break;
  2178. continue;
  2179. L0003:;
  2180. ctx->cur = p;
  2181. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2182. break;
  2183. }
  2184. }
  2185. if (
  2186. pcc_refill_buffer(ctx, 1) < 1 ||
  2187. ctx->buffer.buf[ctx->cur] != '\"'
  2188. ) goto L0002;
  2189. ctx->cur++;
  2190. goto L0001;
  2191. L0002:;
  2192. ctx->cur = p;
  2193. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2194. {
  2195. int i;
  2196. for (i = 0;; i++) {
  2197. const size_t p = ctx->cur;
  2198. const size_t n = chunk->thunks.len;
  2199. {
  2200. const size_t p = ctx->cur;
  2201. const size_t n = chunk->thunks.len;
  2202. if (
  2203. pcc_refill_buffer(ctx, 1) < 1 ||
  2204. ctx->buffer.buf[ctx->cur] != ' '
  2205. ) goto L0006;
  2206. ctx->cur++;
  2207. ctx->cur = p;
  2208. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2209. goto L0005;
  2210. L0006:;
  2211. ctx->cur = p;
  2212. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2213. }
  2214. {
  2215. int u;
  2216. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2217. if (n == 0) goto L0005;
  2218. ctx->cur += n;
  2219. }
  2220. if (ctx->cur == p) break;
  2221. continue;
  2222. L0005:;
  2223. ctx->cur = p;
  2224. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2225. break;
  2226. }
  2227. }
  2228. L0001:;
  2229. }
  2230. ctx->level--;
  2231. PCC_DEBUG(PCC_DBG_MATCH, "edge_tail", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2232. return chunk;
  2233. }
  2234. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_tail_char(gvplain_context_t *ctx) {
  2235. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2236. chunk->pos = ctx->cur;
  2237. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_tail_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2238. ctx->level++;
  2239. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2240. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2241. {
  2242. const size_t p = ctx->cur;
  2243. const size_t n = chunk->thunks.len;
  2244. if (
  2245. pcc_refill_buffer(ctx, 1) < 1 ||
  2246. ctx->buffer.buf[ctx->cur] != '\\'
  2247. ) goto L0002;
  2248. ctx->cur++;
  2249. if (
  2250. pcc_refill_buffer(ctx, 1) < 1 ||
  2251. ctx->buffer.buf[ctx->cur] != '\"'
  2252. ) goto L0002;
  2253. ctx->cur++;
  2254. goto L0001;
  2255. L0002:;
  2256. ctx->cur = p;
  2257. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2258. if (
  2259. pcc_refill_buffer(ctx, 1) < 1 ||
  2260. ctx->buffer.buf[ctx->cur] != '\\'
  2261. ) goto L0003;
  2262. ctx->cur++;
  2263. if (
  2264. pcc_refill_buffer(ctx, 1) < 1 ||
  2265. ctx->buffer.buf[ctx->cur] != '\\'
  2266. ) goto L0003;
  2267. ctx->cur++;
  2268. goto L0001;
  2269. L0003:;
  2270. ctx->cur = p;
  2271. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2272. if (
  2273. pcc_refill_buffer(ctx, 1) < 1 ||
  2274. ctx->buffer.buf[ctx->cur] != '\\'
  2275. ) goto L0004;
  2276. ctx->cur++;
  2277. if (
  2278. pcc_refill_buffer(ctx, 1) < 1 ||
  2279. ctx->buffer.buf[ctx->cur] != 'b'
  2280. ) goto L0004;
  2281. ctx->cur++;
  2282. goto L0001;
  2283. L0004:;
  2284. ctx->cur = p;
  2285. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2286. if (
  2287. pcc_refill_buffer(ctx, 1) < 1 ||
  2288. ctx->buffer.buf[ctx->cur] != '\\'
  2289. ) goto L0005;
  2290. ctx->cur++;
  2291. if (
  2292. pcc_refill_buffer(ctx, 1) < 1 ||
  2293. ctx->buffer.buf[ctx->cur] != 'f'
  2294. ) goto L0005;
  2295. ctx->cur++;
  2296. goto L0001;
  2297. L0005:;
  2298. ctx->cur = p;
  2299. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2300. if (
  2301. pcc_refill_buffer(ctx, 1) < 1 ||
  2302. ctx->buffer.buf[ctx->cur] != '\\'
  2303. ) goto L0006;
  2304. ctx->cur++;
  2305. if (
  2306. pcc_refill_buffer(ctx, 1) < 1 ||
  2307. ctx->buffer.buf[ctx->cur] != 'n'
  2308. ) goto L0006;
  2309. ctx->cur++;
  2310. goto L0001;
  2311. L0006:;
  2312. ctx->cur = p;
  2313. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2314. if (
  2315. pcc_refill_buffer(ctx, 1) < 1 ||
  2316. ctx->buffer.buf[ctx->cur] != '\\'
  2317. ) goto L0007;
  2318. ctx->cur++;
  2319. if (
  2320. pcc_refill_buffer(ctx, 1) < 1 ||
  2321. ctx->buffer.buf[ctx->cur] != 'r'
  2322. ) goto L0007;
  2323. ctx->cur++;
  2324. goto L0001;
  2325. L0007:;
  2326. ctx->cur = p;
  2327. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2328. if (
  2329. pcc_refill_buffer(ctx, 1) < 1 ||
  2330. ctx->buffer.buf[ctx->cur] != '\\'
  2331. ) goto L0008;
  2332. ctx->cur++;
  2333. if (
  2334. pcc_refill_buffer(ctx, 1) < 1 ||
  2335. ctx->buffer.buf[ctx->cur] != 't'
  2336. ) goto L0008;
  2337. ctx->cur++;
  2338. goto L0001;
  2339. L0008:;
  2340. ctx->cur = p;
  2341. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2342. {
  2343. const size_t p = ctx->cur;
  2344. const size_t n = chunk->thunks.len;
  2345. if (
  2346. pcc_refill_buffer(ctx, 1) < 1 ||
  2347. ctx->buffer.buf[ctx->cur] != '\"'
  2348. ) goto L0010;
  2349. ctx->cur++;
  2350. ctx->cur = p;
  2351. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2352. goto L0009;
  2353. L0010:;
  2354. ctx->cur = p;
  2355. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2356. }
  2357. {
  2358. int u;
  2359. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2360. if (n == 0) goto L0009;
  2361. ctx->cur += n;
  2362. }
  2363. goto L0001;
  2364. L0009:;
  2365. ctx->cur = p;
  2366. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2367. goto L0000;
  2368. L0001:;
  2369. }
  2370. ctx->level--;
  2371. PCC_DEBUG(PCC_DBG_MATCH, "edge_tail_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2372. return chunk;
  2373. L0000:;
  2374. ctx->level--;
  2375. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_tail_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2376. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2377. return NULL;
  2378. }
  2379. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_head(gvplain_context_t *ctx) {
  2380. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2381. chunk->pos = ctx->cur;
  2382. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_head", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2383. ctx->level++;
  2384. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2385. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2386. {
  2387. const size_t p = ctx->cur;
  2388. const size_t n = chunk->thunks.len;
  2389. if (
  2390. pcc_refill_buffer(ctx, 1) < 1 ||
  2391. ctx->buffer.buf[ctx->cur] != '\"'
  2392. ) goto L0002;
  2393. ctx->cur++;
  2394. {
  2395. int i;
  2396. for (i = 0;; i++) {
  2397. const size_t p = ctx->cur;
  2398. const size_t n = chunk->thunks.len;
  2399. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_head_char, &chunk->thunks, NULL)) goto L0003;
  2400. if (ctx->cur == p) break;
  2401. continue;
  2402. L0003:;
  2403. ctx->cur = p;
  2404. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2405. break;
  2406. }
  2407. }
  2408. if (
  2409. pcc_refill_buffer(ctx, 1) < 1 ||
  2410. ctx->buffer.buf[ctx->cur] != '\"'
  2411. ) goto L0002;
  2412. ctx->cur++;
  2413. goto L0001;
  2414. L0002:;
  2415. ctx->cur = p;
  2416. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2417. {
  2418. int i;
  2419. for (i = 0;; i++) {
  2420. const size_t p = ctx->cur;
  2421. const size_t n = chunk->thunks.len;
  2422. {
  2423. const size_t p = ctx->cur;
  2424. const size_t n = chunk->thunks.len;
  2425. if (
  2426. pcc_refill_buffer(ctx, 1) < 1 ||
  2427. ctx->buffer.buf[ctx->cur] != ' '
  2428. ) goto L0006;
  2429. ctx->cur++;
  2430. ctx->cur = p;
  2431. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2432. goto L0005;
  2433. L0006:;
  2434. ctx->cur = p;
  2435. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2436. }
  2437. {
  2438. int u;
  2439. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2440. if (n == 0) goto L0005;
  2441. ctx->cur += n;
  2442. }
  2443. if (ctx->cur == p) break;
  2444. continue;
  2445. L0005:;
  2446. ctx->cur = p;
  2447. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2448. break;
  2449. }
  2450. }
  2451. L0001:;
  2452. }
  2453. ctx->level--;
  2454. PCC_DEBUG(PCC_DBG_MATCH, "edge_head", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2455. return chunk;
  2456. }
  2457. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_head_char(gvplain_context_t *ctx) {
  2458. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2459. chunk->pos = ctx->cur;
  2460. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_head_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2461. ctx->level++;
  2462. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2463. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2464. {
  2465. const size_t p = ctx->cur;
  2466. const size_t n = chunk->thunks.len;
  2467. if (
  2468. pcc_refill_buffer(ctx, 1) < 1 ||
  2469. ctx->buffer.buf[ctx->cur] != '\\'
  2470. ) goto L0002;
  2471. ctx->cur++;
  2472. if (
  2473. pcc_refill_buffer(ctx, 1) < 1 ||
  2474. ctx->buffer.buf[ctx->cur] != '\"'
  2475. ) goto L0002;
  2476. ctx->cur++;
  2477. goto L0001;
  2478. L0002:;
  2479. ctx->cur = p;
  2480. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2481. if (
  2482. pcc_refill_buffer(ctx, 1) < 1 ||
  2483. ctx->buffer.buf[ctx->cur] != '\\'
  2484. ) goto L0003;
  2485. ctx->cur++;
  2486. if (
  2487. pcc_refill_buffer(ctx, 1) < 1 ||
  2488. ctx->buffer.buf[ctx->cur] != '\\'
  2489. ) goto L0003;
  2490. ctx->cur++;
  2491. goto L0001;
  2492. L0003:;
  2493. ctx->cur = p;
  2494. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2495. if (
  2496. pcc_refill_buffer(ctx, 1) < 1 ||
  2497. ctx->buffer.buf[ctx->cur] != '\\'
  2498. ) goto L0004;
  2499. ctx->cur++;
  2500. if (
  2501. pcc_refill_buffer(ctx, 1) < 1 ||
  2502. ctx->buffer.buf[ctx->cur] != 'b'
  2503. ) goto L0004;
  2504. ctx->cur++;
  2505. goto L0001;
  2506. L0004:;
  2507. ctx->cur = p;
  2508. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2509. if (
  2510. pcc_refill_buffer(ctx, 1) < 1 ||
  2511. ctx->buffer.buf[ctx->cur] != '\\'
  2512. ) goto L0005;
  2513. ctx->cur++;
  2514. if (
  2515. pcc_refill_buffer(ctx, 1) < 1 ||
  2516. ctx->buffer.buf[ctx->cur] != 'f'
  2517. ) goto L0005;
  2518. ctx->cur++;
  2519. goto L0001;
  2520. L0005:;
  2521. ctx->cur = p;
  2522. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2523. if (
  2524. pcc_refill_buffer(ctx, 1) < 1 ||
  2525. ctx->buffer.buf[ctx->cur] != '\\'
  2526. ) goto L0006;
  2527. ctx->cur++;
  2528. if (
  2529. pcc_refill_buffer(ctx, 1) < 1 ||
  2530. ctx->buffer.buf[ctx->cur] != 'n'
  2531. ) goto L0006;
  2532. ctx->cur++;
  2533. goto L0001;
  2534. L0006:;
  2535. ctx->cur = p;
  2536. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2537. if (
  2538. pcc_refill_buffer(ctx, 1) < 1 ||
  2539. ctx->buffer.buf[ctx->cur] != '\\'
  2540. ) goto L0007;
  2541. ctx->cur++;
  2542. if (
  2543. pcc_refill_buffer(ctx, 1) < 1 ||
  2544. ctx->buffer.buf[ctx->cur] != 'r'
  2545. ) goto L0007;
  2546. ctx->cur++;
  2547. goto L0001;
  2548. L0007:;
  2549. ctx->cur = p;
  2550. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2551. if (
  2552. pcc_refill_buffer(ctx, 1) < 1 ||
  2553. ctx->buffer.buf[ctx->cur] != '\\'
  2554. ) goto L0008;
  2555. ctx->cur++;
  2556. if (
  2557. pcc_refill_buffer(ctx, 1) < 1 ||
  2558. ctx->buffer.buf[ctx->cur] != 't'
  2559. ) goto L0008;
  2560. ctx->cur++;
  2561. goto L0001;
  2562. L0008:;
  2563. ctx->cur = p;
  2564. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2565. {
  2566. const size_t p = ctx->cur;
  2567. const size_t n = chunk->thunks.len;
  2568. if (
  2569. pcc_refill_buffer(ctx, 1) < 1 ||
  2570. ctx->buffer.buf[ctx->cur] != '\"'
  2571. ) goto L0010;
  2572. ctx->cur++;
  2573. ctx->cur = p;
  2574. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2575. goto L0009;
  2576. L0010:;
  2577. ctx->cur = p;
  2578. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2579. }
  2580. {
  2581. int u;
  2582. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2583. if (n == 0) goto L0009;
  2584. ctx->cur += n;
  2585. }
  2586. goto L0001;
  2587. L0009:;
  2588. ctx->cur = p;
  2589. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2590. goto L0000;
  2591. L0001:;
  2592. }
  2593. ctx->level--;
  2594. PCC_DEBUG(PCC_DBG_MATCH, "edge_head_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2595. return chunk;
  2596. L0000:;
  2597. ctx->level--;
  2598. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_head_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2599. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2600. return NULL;
  2601. }
  2602. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_pair(gvplain_context_t *ctx) {
  2603. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2604. chunk->pos = ctx->cur;
  2605. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_pair", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2606. ctx->level++;
  2607. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2608. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2609. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_x, &chunk->thunks, NULL)) goto L0000;
  2610. if (
  2611. pcc_refill_buffer(ctx, 1) < 1 ||
  2612. ctx->buffer.buf[ctx->cur] != ' '
  2613. ) goto L0000;
  2614. ctx->cur++;
  2615. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_y, &chunk->thunks, NULL)) goto L0000;
  2616. if (
  2617. pcc_refill_buffer(ctx, 1) < 1 ||
  2618. ctx->buffer.buf[ctx->cur] != ' '
  2619. ) goto L0000;
  2620. ctx->cur++;
  2621. ctx->level--;
  2622. PCC_DEBUG(PCC_DBG_MATCH, "edge_pair", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2623. return chunk;
  2624. L0000:;
  2625. ctx->level--;
  2626. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_pair", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2627. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2628. return NULL;
  2629. }
  2630. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_n(gvplain_context_t *ctx) {
  2631. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2632. chunk->pos = ctx->cur;
  2633. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_n", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2634. ctx->level++;
  2635. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2636. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2637. {
  2638. int i;
  2639. for (i = 0;; i++) {
  2640. const size_t p = ctx->cur;
  2641. const size_t n = chunk->thunks.len;
  2642. {
  2643. const size_t p = ctx->cur;
  2644. const size_t n = chunk->thunks.len;
  2645. if (
  2646. pcc_refill_buffer(ctx, 1) < 1 ||
  2647. ctx->buffer.buf[ctx->cur] != ' '
  2648. ) goto L0002;
  2649. ctx->cur++;
  2650. ctx->cur = p;
  2651. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2652. goto L0001;
  2653. L0002:;
  2654. ctx->cur = p;
  2655. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2656. }
  2657. {
  2658. int u;
  2659. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2660. if (n == 0) goto L0001;
  2661. ctx->cur += n;
  2662. }
  2663. if (ctx->cur == p) break;
  2664. continue;
  2665. L0001:;
  2666. ctx->cur = p;
  2667. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2668. break;
  2669. }
  2670. }
  2671. ctx->level--;
  2672. PCC_DEBUG(PCC_DBG_MATCH, "edge_n", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2673. return chunk;
  2674. }
  2675. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_x(gvplain_context_t *ctx) {
  2676. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2677. chunk->pos = ctx->cur;
  2678. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_x", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2679. ctx->level++;
  2680. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2681. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2682. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  2683. ctx->level--;
  2684. PCC_DEBUG(PCC_DBG_MATCH, "edge_x", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2685. return chunk;
  2686. L0000:;
  2687. ctx->level--;
  2688. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_x", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2689. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2690. return NULL;
  2691. }
  2692. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_y(gvplain_context_t *ctx) {
  2693. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2694. chunk->pos = ctx->cur;
  2695. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_y", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2696. ctx->level++;
  2697. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2698. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2699. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  2700. ctx->level--;
  2701. PCC_DEBUG(PCC_DBG_MATCH, "edge_y", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2702. return chunk;
  2703. L0000:;
  2704. ctx->level--;
  2705. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_y", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2706. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2707. return NULL;
  2708. }
  2709. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_style(gvplain_context_t *ctx) {
  2710. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2711. chunk->pos = ctx->cur;
  2712. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_style", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2713. ctx->level++;
  2714. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2715. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2716. {
  2717. int i;
  2718. for (i = 0;; i++) {
  2719. const size_t p = ctx->cur;
  2720. const size_t n = chunk->thunks.len;
  2721. {
  2722. const size_t p = ctx->cur;
  2723. const size_t n = chunk->thunks.len;
  2724. if (
  2725. pcc_refill_buffer(ctx, 1) < 1 ||
  2726. ctx->buffer.buf[ctx->cur] != ' '
  2727. ) goto L0002;
  2728. ctx->cur++;
  2729. ctx->cur = p;
  2730. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2731. goto L0001;
  2732. L0002:;
  2733. ctx->cur = p;
  2734. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2735. }
  2736. {
  2737. int u;
  2738. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2739. if (n == 0) goto L0001;
  2740. ctx->cur += n;
  2741. }
  2742. if (ctx->cur == p) break;
  2743. continue;
  2744. L0001:;
  2745. ctx->cur = p;
  2746. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2747. break;
  2748. }
  2749. }
  2750. ctx->level--;
  2751. PCC_DEBUG(PCC_DBG_MATCH, "edge_style", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2752. return chunk;
  2753. }
  2754. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_color(gvplain_context_t *ctx) {
  2755. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2756. chunk->pos = ctx->cur;
  2757. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_color", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2758. ctx->level++;
  2759. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2760. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2761. {
  2762. int i;
  2763. for (i = 0;; i++) {
  2764. const size_t p = ctx->cur;
  2765. const size_t n = chunk->thunks.len;
  2766. {
  2767. const size_t p = ctx->cur;
  2768. const size_t n = chunk->thunks.len;
  2769. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_eol, &chunk->thunks, NULL)) goto L0002;
  2770. ctx->cur = p;
  2771. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2772. goto L0001;
  2773. L0002:;
  2774. ctx->cur = p;
  2775. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2776. }
  2777. {
  2778. int u;
  2779. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2780. if (n == 0) goto L0001;
  2781. ctx->cur += n;
  2782. }
  2783. if (ctx->cur == p) break;
  2784. continue;
  2785. L0001:;
  2786. ctx->cur = p;
  2787. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2788. break;
  2789. }
  2790. }
  2791. ctx->level--;
  2792. PCC_DEBUG(PCC_DBG_MATCH, "edge_color", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2793. return chunk;
  2794. }
  2795. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_label(gvplain_context_t *ctx) {
  2796. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2797. chunk->pos = ctx->cur;
  2798. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_label", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2799. ctx->level++;
  2800. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2801. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2802. {
  2803. const size_t p = ctx->cur;
  2804. const size_t n = chunk->thunks.len;
  2805. if (
  2806. pcc_refill_buffer(ctx, 1) < 1 ||
  2807. ctx->buffer.buf[ctx->cur] != '\"'
  2808. ) goto L0002;
  2809. ctx->cur++;
  2810. {
  2811. int i;
  2812. for (i = 0;; i++) {
  2813. const size_t p = ctx->cur;
  2814. const size_t n = chunk->thunks.len;
  2815. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_edge_char, &chunk->thunks, NULL)) goto L0003;
  2816. if (ctx->cur == p) break;
  2817. continue;
  2818. L0003:;
  2819. ctx->cur = p;
  2820. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2821. break;
  2822. }
  2823. }
  2824. if (
  2825. pcc_refill_buffer(ctx, 1) < 1 ||
  2826. ctx->buffer.buf[ctx->cur] != '\"'
  2827. ) goto L0002;
  2828. ctx->cur++;
  2829. goto L0001;
  2830. L0002:;
  2831. ctx->cur = p;
  2832. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2833. {
  2834. int i;
  2835. for (i = 0;; i++) {
  2836. const size_t p = ctx->cur;
  2837. const size_t n = chunk->thunks.len;
  2838. {
  2839. const size_t p = ctx->cur;
  2840. const size_t n = chunk->thunks.len;
  2841. if (
  2842. pcc_refill_buffer(ctx, 1) < 1 ||
  2843. ctx->buffer.buf[ctx->cur] != ' '
  2844. ) goto L0006;
  2845. ctx->cur++;
  2846. ctx->cur = p;
  2847. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2848. goto L0005;
  2849. L0006:;
  2850. ctx->cur = p;
  2851. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2852. }
  2853. {
  2854. int u;
  2855. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2856. if (n == 0) goto L0005;
  2857. ctx->cur += n;
  2858. }
  2859. if (ctx->cur == p) break;
  2860. continue;
  2861. L0005:;
  2862. ctx->cur = p;
  2863. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2864. break;
  2865. }
  2866. }
  2867. L0001:;
  2868. }
  2869. ctx->level--;
  2870. PCC_DEBUG(PCC_DBG_MATCH, "edge_label", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2871. return chunk;
  2872. }
  2873. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_char(gvplain_context_t *ctx) {
  2874. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2875. chunk->pos = ctx->cur;
  2876. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2877. ctx->level++;
  2878. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2879. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2880. {
  2881. const size_t p = ctx->cur;
  2882. const size_t n = chunk->thunks.len;
  2883. if (
  2884. pcc_refill_buffer(ctx, 1) < 1 ||
  2885. ctx->buffer.buf[ctx->cur] != '\\'
  2886. ) goto L0002;
  2887. ctx->cur++;
  2888. if (
  2889. pcc_refill_buffer(ctx, 1) < 1 ||
  2890. ctx->buffer.buf[ctx->cur] != '\"'
  2891. ) goto L0002;
  2892. ctx->cur++;
  2893. goto L0001;
  2894. L0002:;
  2895. ctx->cur = p;
  2896. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2897. if (
  2898. pcc_refill_buffer(ctx, 1) < 1 ||
  2899. ctx->buffer.buf[ctx->cur] != '\\'
  2900. ) goto L0003;
  2901. ctx->cur++;
  2902. if (
  2903. pcc_refill_buffer(ctx, 1) < 1 ||
  2904. ctx->buffer.buf[ctx->cur] != '\\'
  2905. ) goto L0003;
  2906. ctx->cur++;
  2907. goto L0001;
  2908. L0003:;
  2909. ctx->cur = p;
  2910. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2911. if (
  2912. pcc_refill_buffer(ctx, 1) < 1 ||
  2913. ctx->buffer.buf[ctx->cur] != '\\'
  2914. ) goto L0004;
  2915. ctx->cur++;
  2916. if (
  2917. pcc_refill_buffer(ctx, 1) < 1 ||
  2918. ctx->buffer.buf[ctx->cur] != 'b'
  2919. ) goto L0004;
  2920. ctx->cur++;
  2921. goto L0001;
  2922. L0004:;
  2923. ctx->cur = p;
  2924. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2925. if (
  2926. pcc_refill_buffer(ctx, 1) < 1 ||
  2927. ctx->buffer.buf[ctx->cur] != '\\'
  2928. ) goto L0005;
  2929. ctx->cur++;
  2930. if (
  2931. pcc_refill_buffer(ctx, 1) < 1 ||
  2932. ctx->buffer.buf[ctx->cur] != 'f'
  2933. ) goto L0005;
  2934. ctx->cur++;
  2935. goto L0001;
  2936. L0005:;
  2937. ctx->cur = p;
  2938. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2939. if (
  2940. pcc_refill_buffer(ctx, 1) < 1 ||
  2941. ctx->buffer.buf[ctx->cur] != '\\'
  2942. ) goto L0006;
  2943. ctx->cur++;
  2944. if (
  2945. pcc_refill_buffer(ctx, 1) < 1 ||
  2946. ctx->buffer.buf[ctx->cur] != 'n'
  2947. ) goto L0006;
  2948. ctx->cur++;
  2949. goto L0001;
  2950. L0006:;
  2951. ctx->cur = p;
  2952. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2953. if (
  2954. pcc_refill_buffer(ctx, 1) < 1 ||
  2955. ctx->buffer.buf[ctx->cur] != '\\'
  2956. ) goto L0007;
  2957. ctx->cur++;
  2958. if (
  2959. pcc_refill_buffer(ctx, 1) < 1 ||
  2960. ctx->buffer.buf[ctx->cur] != 'r'
  2961. ) goto L0007;
  2962. ctx->cur++;
  2963. goto L0001;
  2964. L0007:;
  2965. ctx->cur = p;
  2966. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2967. if (
  2968. pcc_refill_buffer(ctx, 1) < 1 ||
  2969. ctx->buffer.buf[ctx->cur] != '\\'
  2970. ) goto L0008;
  2971. ctx->cur++;
  2972. if (
  2973. pcc_refill_buffer(ctx, 1) < 1 ||
  2974. ctx->buffer.buf[ctx->cur] != 't'
  2975. ) goto L0008;
  2976. ctx->cur++;
  2977. goto L0001;
  2978. L0008:;
  2979. ctx->cur = p;
  2980. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2981. {
  2982. const size_t p = ctx->cur;
  2983. const size_t n = chunk->thunks.len;
  2984. if (
  2985. pcc_refill_buffer(ctx, 1) < 1 ||
  2986. ctx->buffer.buf[ctx->cur] != '\"'
  2987. ) goto L0010;
  2988. ctx->cur++;
  2989. ctx->cur = p;
  2990. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2991. goto L0009;
  2992. L0010:;
  2993. ctx->cur = p;
  2994. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2995. }
  2996. {
  2997. int u;
  2998. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  2999. if (n == 0) goto L0009;
  3000. ctx->cur += n;
  3001. }
  3002. goto L0001;
  3003. L0009:;
  3004. ctx->cur = p;
  3005. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3006. goto L0000;
  3007. L0001:;
  3008. }
  3009. ctx->level--;
  3010. PCC_DEBUG(PCC_DBG_MATCH, "edge_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3011. return chunk;
  3012. L0000:;
  3013. ctx->level--;
  3014. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_char", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3015. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3016. return NULL;
  3017. }
  3018. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_xl(gvplain_context_t *ctx) {
  3019. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3020. chunk->pos = ctx->cur;
  3021. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_xl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3022. ctx->level++;
  3023. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3024. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3025. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  3026. ctx->level--;
  3027. PCC_DEBUG(PCC_DBG_MATCH, "edge_xl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3028. return chunk;
  3029. L0000:;
  3030. ctx->level--;
  3031. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_xl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3032. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3033. return NULL;
  3034. }
  3035. static pcc_thunk_chunk_t *pcc_evaluate_rule_edge_yl(gvplain_context_t *ctx) {
  3036. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3037. chunk->pos = ctx->cur;
  3038. PCC_DEBUG(PCC_DBG_EVALUATE, "edge_yl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3039. ctx->level++;
  3040. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3041. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3042. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_fpnum, &chunk->thunks, NULL)) goto L0000;
  3043. ctx->level--;
  3044. PCC_DEBUG(PCC_DBG_MATCH, "edge_yl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3045. return chunk;
  3046. L0000:;
  3047. ctx->level--;
  3048. PCC_DEBUG(PCC_DBG_NOMATCH, "edge_yl", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3049. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3050. return NULL;
  3051. }
  3052. static pcc_thunk_chunk_t *pcc_evaluate_rule_linestop(gvplain_context_t *ctx) {
  3053. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3054. chunk->pos = ctx->cur;
  3055. PCC_DEBUG(PCC_DBG_EVALUATE, "linestop", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3056. ctx->level++;
  3057. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3058. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3059. if (
  3060. pcc_refill_buffer(ctx, 4) < 4 ||
  3061. (ctx->buffer.buf + ctx->cur)[0] != 's' ||
  3062. (ctx->buffer.buf + ctx->cur)[1] != 't' ||
  3063. (ctx->buffer.buf + ctx->cur)[2] != 'o' ||
  3064. (ctx->buffer.buf + ctx->cur)[3] != 'p'
  3065. ) goto L0000;
  3066. ctx->cur += 4;
  3067. ctx->level--;
  3068. PCC_DEBUG(PCC_DBG_MATCH, "linestop", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3069. return chunk;
  3070. L0000:;
  3071. ctx->level--;
  3072. PCC_DEBUG(PCC_DBG_NOMATCH, "linestop", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3073. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3074. return NULL;
  3075. }
  3076. static pcc_thunk_chunk_t *pcc_evaluate_rule_fpnum(gvplain_context_t *ctx) {
  3077. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3078. chunk->pos = ctx->cur;
  3079. PCC_DEBUG(PCC_DBG_EVALUATE, "fpnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3080. ctx->level++;
  3081. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3082. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3083. {
  3084. const size_t p0 = ctx->cur;
  3085. const size_t n0 = chunk->thunks.len;
  3086. int i;
  3087. for (i = 0;; i++) {
  3088. const size_t p = ctx->cur;
  3089. const size_t n = chunk->thunks.len;
  3090. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_digit, &chunk->thunks, NULL)) goto L0001;
  3091. if (ctx->cur == p) break;
  3092. continue;
  3093. L0001:;
  3094. ctx->cur = p;
  3095. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3096. break;
  3097. }
  3098. if (i < 1) {
  3099. ctx->cur = p0;
  3100. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  3101. goto L0000;
  3102. }
  3103. }
  3104. {
  3105. const size_t p = ctx->cur;
  3106. const size_t n = chunk->thunks.len;
  3107. if (
  3108. pcc_refill_buffer(ctx, 1) < 1 ||
  3109. ctx->buffer.buf[ctx->cur] != '.'
  3110. ) goto L0002;
  3111. ctx->cur++;
  3112. {
  3113. int i;
  3114. for (i = 0;; i++) {
  3115. const size_t p = ctx->cur;
  3116. const size_t n = chunk->thunks.len;
  3117. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_digit, &chunk->thunks, NULL)) goto L0003;
  3118. if (ctx->cur == p) break;
  3119. continue;
  3120. L0003:;
  3121. ctx->cur = p;
  3122. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3123. break;
  3124. }
  3125. }
  3126. goto L0004;
  3127. L0002:;
  3128. ctx->cur = p;
  3129. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3130. L0004:;
  3131. }
  3132. ctx->level--;
  3133. PCC_DEBUG(PCC_DBG_MATCH, "fpnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3134. return chunk;
  3135. L0000:;
  3136. ctx->level--;
  3137. PCC_DEBUG(PCC_DBG_NOMATCH, "fpnum", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3138. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3139. return NULL;
  3140. }
  3141. static pcc_thunk_chunk_t *pcc_evaluate_rule_digit(gvplain_context_t *ctx) {
  3142. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3143. chunk->pos = ctx->cur;
  3144. PCC_DEBUG(PCC_DBG_EVALUATE, "digit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3145. ctx->level++;
  3146. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3147. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3148. {
  3149. int u;
  3150. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3151. if (n == 0) goto L0000;
  3152. if (!(
  3153. (u >= 0x000030 && u <= 0x000039)
  3154. )) goto L0000;
  3155. ctx->cur += n;
  3156. }
  3157. ctx->level--;
  3158. PCC_DEBUG(PCC_DBG_MATCH, "digit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3159. return chunk;
  3160. L0000:;
  3161. ctx->level--;
  3162. PCC_DEBUG(PCC_DBG_NOMATCH, "digit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3163. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3164. return NULL;
  3165. }
  3166. static pcc_thunk_chunk_t *pcc_evaluate_rule_eol(gvplain_context_t *ctx) {
  3167. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3168. chunk->pos = ctx->cur;
  3169. PCC_DEBUG(PCC_DBG_EVALUATE, "eol", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3170. ctx->level++;
  3171. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3172. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3173. {
  3174. int u;
  3175. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3176. if (n == 0) goto L0000;
  3177. if (!(
  3178. u == 0x00000a
  3179. )) goto L0000;
  3180. ctx->cur += n;
  3181. }
  3182. ctx->level--;
  3183. PCC_DEBUG(PCC_DBG_MATCH, "eol", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3184. return chunk;
  3185. L0000:;
  3186. ctx->level--;
  3187. PCC_DEBUG(PCC_DBG_NOMATCH, "eol", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3188. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3189. return NULL;
  3190. }
  3191. static pcc_thunk_chunk_t *pcc_evaluate_rule__(gvplain_context_t *ctx) {
  3192. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3193. chunk->pos = ctx->cur;
  3194. PCC_DEBUG(PCC_DBG_EVALUATE, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3195. ctx->level++;
  3196. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3197. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3198. {
  3199. int i;
  3200. for (i = 0;; i++) {
  3201. const size_t p = ctx->cur;
  3202. const size_t n = chunk->thunks.len;
  3203. {
  3204. int u;
  3205. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3206. if (n == 0) goto L0001;
  3207. if (!(
  3208. u == 0x000020 ||
  3209. u == 0x000009 ||
  3210. u == 0x00000a ||
  3211. u == 0x00000d
  3212. )) goto L0001;
  3213. ctx->cur += n;
  3214. }
  3215. if (ctx->cur == p) break;
  3216. continue;
  3217. L0001:;
  3218. ctx->cur = p;
  3219. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3220. break;
  3221. }
  3222. }
  3223. ctx->level--;
  3224. PCC_DEBUG(PCC_DBG_MATCH, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3225. return chunk;
  3226. }
  3227. gvplain_context_t *gvplain_create(void *auxil) {
  3228. return pcc_context__create(auxil);
  3229. }
  3230. int gvplain_parse(gvplain_context_t *ctx, int *ret) {
  3231. pcc_thunk_array_t thunks;
  3232. pcc_thunk_array__init(ctx->auxil, &thunks, PCC_ARRAYSIZE);
  3233. if (pcc_apply_rule(ctx, pcc_evaluate_rule_gvplain, &thunks, ret))
  3234. pcc_do_action(ctx, &thunks, ret);
  3235. else
  3236. PCC_ERROR(ctx->auxil);
  3237. pcc_commit_buffer(ctx);
  3238. pcc_thunk_array__term(ctx->auxil, &thunks);
  3239. return pcc_refill_buffer(ctx, 1) >= 1;
  3240. }
  3241. void gvplain_destroy(gvplain_context_t *ctx) {
  3242. pcc_context__destroy(ctx);
  3243. }
  3244. int main() {
  3245. gvplain_context_t *ctx=gvplain_create(NULL);
  3246. while (gvplain_parse(ctx, NULL)){;}
  3247. gvplain_destroy(ctx);
  3248. return 0;
  3249. }