Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
43 static const void* s_vpMagicNumber = (
void*)
"API";
45 static void vRulesFooter(FILE *spOut);
46 static void vRulesHeader(FILE *spOut);
47 static int iCompRules(
const void *vpL,
const void *vpR);
48 static int iCompUdts(
const void *vpL,
const void *vpR);
61 memset((
void*) spCtx, 0,
sizeof(
api));
63 spCtx->spException = spEx;
69 spCtx->vpVecInput =
vpVecCtor(spCtx->vpMem, (
aint)
sizeof(
char), 5120);
70 spCtx->vpVecTempChars =
vpVecCtor(spCtx->vpMem, (
aint)
sizeof(
char), 1024);
72 spCtx->cpInput = (
char*)
vpVecPush(spCtx->vpVecInput, &cZero);
73 spCtx->uiInputLength = 0;
75 spCtx->vpValidate = s_vpMagicNumber;
88 void *vpMem = spCtx->
vpMem;
92 memset(vpCtx, 0,
sizeof(
api));
105 if(vpCtx && ((
api*)vpCtx)->vpValidate == s_vpMagicNumber){
118 api *spApi = (
api*) vpCtx;
119 if (vpCtx && (spApi->
vpValidate == s_vpMagicNumber)) {
133 api *spApi = (
api*) vpCtx;
134 if (!vpCtx || (spApi->
vpValidate != s_vpMagicNumber)) {
137 FILE *spOut = stdout;
141 "cannot display rule dependencies without attributes (bApiAttrs())");
144 spOut = fopen(cpFileName,
"wb");
147 snprintf(caBuf, 126,
"cannot output open file name %s for writing", cpFileName);
156 aint ui, uj, uiCount;
163 for (ui = 0; ui < uiRuleCount; ui++, spAttr++) {
164 fprintf(spOut,
"rulesData[%"PRIuMAX
"] = {\n", (
luint) ui);
165 fprintf(spOut,
"name: \"%s\",\n", spAttr->
cpRuleName);
167 fprintf(spOut,
"to: [");
169 for (uj = 0; uj < uiRuleCount; uj++) {
171 saRules[uiCount] = spRules[uj];
176 qsort(saRules, uiCount,
sizeof(
api_rule), iCompRules);
178 for (uj = 0; uj < uiCount; uj++) {
180 fprintf(spOut,
"\"%s\"", saRules[uj].cpName);
183 fprintf(spOut,
", \"%s\"", saRules[uj].cpName);
187 fprintf(spOut,
"],\n");
188 fprintf(spOut,
"by: [");
190 for (uj = 0; uj < uiRuleCount; uj++) {
192 saRules[uiCount] = spRules[uj];
197 qsort(saRules, uiCount,
sizeof(
api_rule), iCompRules);
199 for (uj = 0; uj < uiCount; uj++) {
201 fprintf(spOut,
"\"%s\"", saRules[uj].cpName);
204 fprintf(spOut,
", \"%s\"", saRules[uj].cpName);
208 fprintf(spOut,
"]};\n");
213 for (ui = 0; ui < uiUdtCount; ui++, spUdt++) {
214 fprintf(spOut,
"udtsData[%"PRIuMAX
"] = {\n", (
luint) ui);
215 fprintf(spOut,
"name: \"%s\",\n", spUdt->
cpName);
216 fprintf(spOut,
"index: %"PRIuMAX
",\n", (
luint) spUdt->
uiIndex);
217 fprintf(spOut,
"by: [");
220 for (uj = 0; uj < uiRuleCount; uj++, spAttr++) {
222 saRules[uiCount] = spRules[uj];
227 qsort(saRules, uiCount,
sizeof(
api_rule), iCompRules);
229 for (uj = 0; uj < uiCount; uj++) {
231 fprintf(spOut,
"\"%s\"", saRules[uj].cpName);
234 fprintf(spOut,
", \"%s\"", saRules[uj].cpName);
239 fprintf(spOut,
"]};\n");
258 api *spApi = (
api*) vpCtx;
259 if (!vpCtx || (spApi->
vpValidate != s_vpMagicNumber)) {
262 FILE *spOut = stdout;
265 "cannot display rules until semantic phase is complete (bApiOpcodes())");
274 spOut = fopen(cpFileName,
"wb");
277 snprintf(caBuf, 126,
"cannot open file name %s for writing", cpFileName);
282 if (*cpMode ==
'a' || *cpMode ==
'A') {
286 for (ui = 0; ui < uiRuleCount; ui++) {
287 saRules[ui] = spApi->
spRules[ui];
290 qsort((
void*) saRules, (
size_t) uiRuleCount,
sizeof(
api_rule), iCompRules);
291 fprintf(spOut,
"RULES BY ALPHABET\n");
293 fprintf(spOut,
"RULES BY INDEX\n");
295 fprintf(spOut,
" index | rule name\n");
296 fprintf(spOut,
"-------|----------\n");
297 for (ui = 0; ui < uiRuleCount; ui++) {
298 fprintf(spOut,
"%6"PRIuMAX
" | %s\n", (
luint) saRules[ui].uiIndex, saRules[ui].cpName);
301 fprintf(spOut,
"\n");
302 for (ui = 0; ui < uiUdtCount; ui++) {
303 saUdts[ui] = spApi->
spUdts[ui];
306 qsort((
void*) saUdts, (
size_t) uiUdtCount,
sizeof(
api_udt), iCompUdts);
307 fprintf(spOut,
"UDTS BY ALPHABET\n");
309 fprintf(spOut,
"UDTS BY INDEX\n");
311 fprintf(spOut,
"index | UDT name\n");
312 fprintf(spOut,
"------|----------\n");
313 for (ui = 0; ui < uiUdtCount; ui++) {
314 fprintf(spOut,
"%6"PRIuMAX
"| %s\n", (
luint) saUdts[ui].uiIndex, saUdts[ui].cpName);
317 fprintf(spOut,
"\n");
318 if (spOut != stdout) {
329 api *spApi = (
api*) vpCtx;
330 if (!vpCtx || (spApi->
vpValidate != s_vpMagicNumber)) {
335 "cannot display opcodes until semantic phase is complete (bApiOpcodes())");
337 FILE *spOut = stdout;
339 spOut = fopen(cpFileName,
"wb");
342 snprintf(caBuf, 126,
"cannot open file name %s for writing", cpFileName);
352 fprintf(spOut,
"OPCODES\n");
354 for (ui = 0; ui < uiRuleCount; ui++) {
356 fprintf(spOut,
"rule: %"PRIuMAX
": %s\n", (
luint) ui, spRule->
cpName);
357 for (uj = 0; uj < spRule->
uiOpCount; uj++, uk++) {
359 switch (spOp->
uiId) {
361 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
362 fprintf(spOut,
"ALT: ");
372 fprintf(spOut,
"\n");
375 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
376 fprintf(spOut,
"CAT: ");
386 fprintf(spOut,
"\n");
389 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
390 fprintf(spOut,
"REP: ");
391 fprintf(spOut,
"min: %"PRIuMAX
": ", spOp->
luiMin);
393 fprintf(spOut,
"max: infinity");
395 fprintf(spOut,
"max: %"PRIuMAX
"", spOp->
luiMax);
397 fprintf(spOut,
"\n");
400 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
401 fprintf(spOut,
"RNM: ");
403 fprintf(spOut,
"\n");
406 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
407 fprintf(spOut,
"TBS: ");
409 fprintf(spOut,
"\'");
411 if (*luipBeg >= 32 && *luipBeg <= 126) {
412 fprintf(spOut,
"%c", (
char) *luipBeg);
414 fprintf(spOut,
"0x%.2"PRIXMAX
"", *luipBeg);
417 fprintf(spOut,
"\'");
418 fprintf(spOut,
"\n");
421 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
422 fprintf(spOut,
"TLS: ");
423 fprintf(spOut,
"\"");
426 fprintf(spOut,
"%c", (
char) *luipBeg);
428 fprintf(spOut,
"\"");
429 fprintf(spOut,
"\n");
432 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
433 fprintf(spOut,
"TRG: ");
434 fprintf(spOut,
"min: %"PRIuMAX
": ", spOp->
luiMin);
435 fprintf(spOut,
"max: %"PRIuMAX
"", spOp->
luiMax);
436 fprintf(spOut,
"\n");
439 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
440 fprintf(spOut,
"UDT: ");
442 fprintf(spOut,
"\n");
445 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
446 fprintf(spOut,
"AND: ");
447 fprintf(spOut,
"\n");
450 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
451 fprintf(spOut,
"NOT: ");
452 fprintf(spOut,
"\n");
455 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
456 fprintf(spOut,
"BKA: ");
457 fprintf(spOut,
"\n");
460 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
461 fprintf(spOut,
"BKN: ");
462 fprintf(spOut,
"\n");
465 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
466 fprintf(spOut,
"BKR: ");
468 fprintf(spOut,
"\\%%i");
470 fprintf(spOut,
"\\%%s");
473 fprintf(spOut,
"%%u");
475 fprintf(spOut,
"%%p");
478 if (uiIndex < spApi->uiRuleCount) {
484 fprintf(spOut,
"\n");
487 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
488 fprintf(spOut,
"ABG: ");
489 fprintf(spOut,
"\n");
492 fprintf(spOut,
"%"PRIuMAX
": ", (
luint) uk);
493 fprintf(spOut,
"AEN: ");
494 fprintf(spOut,
"\n");
498 fprintf(spOut,
"\n");
518 api *spApi = (
api*) vpCtx;
519 if (!vpCtx || (spApi->
vpValidate != s_vpMagicNumber)) {
545 api *spApi = (
api*) vpCtx;
546 if (!vpCtx || (spApi->
vpValidate != s_vpMagicNumber)) {
568 cpTitle =
"APG generated HTML";
570 fprintf(spFile,
"<!DOCTYPE html>\n");
571 fprintf(spFile,
"<html lang=\"en\">\n");
572 fprintf(spFile,
"<meta charset=\"utf-8\">\n");
573 fprintf(spFile,
"<title>\n");
574 fprintf(spFile,
"%s", cpTitle);
575 fprintf(spFile,
"</title>\n<style>\n");
576 fprintf(spFile,
"body{font-family: monospace; font-size: 1em;}\n");
577 fprintf(spFile,
"kbd{font-weight: bold; font-style: italic; color: red;}\n");
578 fprintf(spFile,
"var{color: #8A2BE2;}\n");
579 fprintf(spFile,
"th{text-align: left;}\n");
580 fprintf(spFile,
"</style>\n");
581 fprintf(spFile,
"<body>\n");
591 fprintf(spFile,
"</body>\n");
592 fprintf(spFile,
"</html>\n");
596 static void vRulesHeader(FILE *spOut) {
597 fprintf(spOut,
"<!DOCTYPE html>\n");
598 fprintf(spOut,
"<!-- LICENSE:\n");
599 fprintf(spOut,
"-->\n");
600 fprintf(spOut,
"<html>\n");
601 fprintf(spOut,
" <head>\n");
602 fprintf(spOut,
" <title>Rule Dependencies</title>\n");
603 fprintf(spOut,
" <meta charset=\"UTF-8\">\n");
604 fprintf(spOut,
" <meta name=\"viewport\" sContent=\"width=device-width, initial-scale=1.0\">\n");
605 fprintf(spOut,
" <style>\n");
606 fprintf(spOut,
" td{\n");
607 fprintf(spOut,
" vertical-align: top;\n");
608 fprintf(spOut,
" }\n");
609 fprintf(spOut,
" caption{\n");
610 fprintf(spOut,
" text-align: left;\n");
611 fprintf(spOut,
" }\n");
612 fprintf(spOut,
" ul{\n");
613 fprintf(spOut,
" margin: 0;\n");
614 fprintf(spOut,
" list-style: none;\n");
615 fprintf(spOut,
" padding-left: 5px;\n");
616 fprintf(spOut,
" }\n");
617 fprintf(spOut,
" li{\n");
618 fprintf(spOut,
" font-size: .8em;\n");
619 fprintf(spOut,
" }\n");
620 fprintf(spOut,
" .bold{\n");
621 fprintf(spOut,
" font-weight: bold;\n");
622 fprintf(spOut,
" }\n");
623 fprintf(spOut,
" .tableButton, .closeButton{\n");
624 fprintf(spOut,
" background-color:#ffffff;\n");
625 fprintf(spOut,
" -moz-border-radius:28px;\n");
626 fprintf(spOut,
" -webkit-border-radius:28px;\n");
627 fprintf(spOut,
" border-radius:28px;\n");
628 fprintf(spOut,
" border:1px solid #000000;\n");
629 fprintf(spOut,
" cursor:pointer;\n");
630 fprintf(spOut,
" color:#000000;\n");
631 fprintf(spOut,
" font-family:Arial;\n");
632 fprintf(spOut,
" font-size:12px;\n");
633 fprintf(spOut,
" font-weight:bold;\n");
634 fprintf(spOut,
" padding:1px 18px;\n");
635 fprintf(spOut,
" text-decoration:none;\n");
636 fprintf(spOut,
" outline: none;\n");
637 fprintf(spOut,
" }\n");
638 fprintf(spOut,
" .tableButton:hover, .closeButton:hover {\n");
639 fprintf(spOut,
" background-color:lightgray;\n");
640 fprintf(spOut,
" }\n");
641 fprintf(spOut,
" .closeButton{\n");
642 fprintf(spOut,
" margin: 8px 0px;\n");
643 fprintf(spOut,
" }\n");
644 fprintf(spOut,
" </style>\n");
645 fprintf(spOut,
" </head>\n");
646 fprintf(spOut,
" <body>\n");
647 fprintf(spOut,
" <div id=\"rulesTable\"></div>\n");
648 fprintf(spOut,
" <div id=\"udtsTable\"></div>\n");
649 fprintf(spOut,
" <script>\n");
650 fprintf(spOut,
" var ASC = 0;\n");
651 fprintf(spOut,
" var DESC = 1;\n");
652 fprintf(spOut,
" var rulesNameToggle = ASC;\n");
653 fprintf(spOut,
" var rulesIndexToggle = DESC;\n");
654 fprintf(spOut,
" var udtsNameToggle = ASC;\n");
655 fprintf(spOut,
" var udtsIndexToggle = DESC;\n");
656 fprintf(spOut,
" var rulesData = [];\n");
657 fprintf(spOut,
" var udtsData = [];\n");
658 fprintf(spOut,
" function toggle(id) {\n");
659 fprintf(spOut,
" var x = document.getElementById(id);\n");
660 fprintf(spOut,
" if (x.style.display === \"none\") {\n");
661 fprintf(spOut,
" x.style.display = \"block\";\n");
662 fprintf(spOut,
" } else {\n");
663 fprintf(spOut,
" x.style.display = \"none\";\n");
664 fprintf(spOut,
" }\n");
665 fprintf(spOut,
" }\n");
666 fprintf(spOut,
" function closeAllRules() {\n");
667 fprintf(spOut,
" for (var i = 0; i < rulesData.length; i++) {\n");
668 fprintf(spOut,
" x = document.getElementById(\"to\" + i);\n");
669 fprintf(spOut,
" if (x) {\n");
670 fprintf(spOut,
" x.style.display = \"none\";\n");
671 fprintf(spOut,
" }\n");
672 fprintf(spOut,
" x = document.getElementById(\"by\" + i);\n");
673 fprintf(spOut,
" if (x) {\n");
674 fprintf(spOut,
" x.style.display = \"none\";\n");
675 fprintf(spOut,
" }\n");
676 fprintf(spOut,
" }\n");
677 fprintf(spOut,
" }\n");
678 fprintf(spOut,
" function closeAllUdts() {\n");
679 fprintf(spOut,
" for (var i = 0; i < udtsData.length; i++) {\n");
680 fprintf(spOut,
" x = document.getElementById(\"udt\" + i);\n");
681 fprintf(spOut,
" if (x) {\n");
682 fprintf(spOut,
" x.style.display = \"none\";\n");
683 fprintf(spOut,
" }\n");
684 fprintf(spOut,
" }\n");
685 fprintf(spOut,
" }\n");
686 fprintf(spOut,
" function nameSortAscending(l, r) {\n");
687 fprintf(spOut,
" var li = l.name.toUpperCase();\n");
688 fprintf(spOut,
" var ri = r.name.toUpperCase();\n");
689 fprintf(spOut,
" var ret = 0;\n");
690 fprintf(spOut,
" if (li > ri) {\n");
691 fprintf(spOut,
" ret = 1;\n");
692 fprintf(spOut,
" } else if (li < ri) {\n");
693 fprintf(spOut,
" ret = -1;\n");
694 fprintf(spOut,
" }\n");
695 fprintf(spOut,
" return ret;\n");
696 fprintf(spOut,
" }\n");
697 fprintf(spOut,
" function nameSortDescending(l, r) {\n");
698 fprintf(spOut,
" return -1 * nameSortAscending(l, r);\n");
699 fprintf(spOut,
" }\n");
700 fprintf(spOut,
" function tableSort(data, col) {\n");
701 fprintf(spOut,
" if (data === \"rules\") {\n");
702 fprintf(spOut,
" if (col === \"index\") {\n");
703 fprintf(spOut,
" if (rulesIndexToggle === ASC) {\n");
704 fprintf(spOut,
" rulesData.sort((l,r)=>(l.index - r.index));\n");
705 fprintf(spOut,
" rulesIndexToggle = DESC;\n");
706 fprintf(spOut,
" } else if (rulesIndexToggle === DESC) {\n");
707 fprintf(spOut,
" rulesData.sort((l,r)=>(r.index - l.index));\n");
708 fprintf(spOut,
" rulesIndexToggle = ASC;\n");
709 fprintf(spOut,
" }\n");
710 fprintf(spOut,
" } else if (col === \"name\") {\n");
711 fprintf(spOut,
" if (rulesNameToggle === ASC) {\n");
712 fprintf(spOut,
" rulesData.sort(nameSortAscending);\n");
713 fprintf(spOut,
" rulesNameToggle = DESC;\n");
714 fprintf(spOut,
" } else if (rulesNameToggle === DESC) {\n");
715 fprintf(spOut,
" rulesData.sort(nameSortDescending);\n");
716 fprintf(spOut,
" rulesNameToggle = ASC;\n");
717 fprintf(spOut,
" }\n");
718 fprintf(spOut,
" }\n");
719 fprintf(spOut,
" rulesGen();\n");
720 fprintf(spOut,
" } else if (data === \"udts\") {\n");
721 fprintf(spOut,
" if (col === \"index\") {\n");
722 fprintf(spOut,
" if (udtsIndexToggle === ASC) {\n");
723 fprintf(spOut,
" udtsData.sort((l,r)=>(l.index - r.index));\n");
724 fprintf(spOut,
" udtsIndexToggle = DESC;\n");
725 fprintf(spOut,
" } else if (udtsIndexToggle === DESC) {\n");
726 fprintf(spOut,
" udtsData.sort((l,r)=>(r.index - l.index));\n");
727 fprintf(spOut,
" udtsIndexToggle = ASC;\n");
728 fprintf(spOut,
" }\n");
729 fprintf(spOut,
" } else if (col === \"name\") {\n");
730 fprintf(spOut,
" if (udtsNameToggle === ASC) {\n");
731 fprintf(spOut,
" udtsData.sort(nameSortAscending);\n");
732 fprintf(spOut,
" udtsNameToggle = DESC;\n");
733 fprintf(spOut,
" } else if (udtsNameToggle === DESC) {\n");
734 fprintf(spOut,
" udtsData.sort(nameSortDescending);\n");
735 fprintf(spOut,
" udtsNameToggle = ASC;\n");
736 fprintf(spOut,
" }\n");
737 fprintf(spOut,
" }\n");
738 fprintf(spOut,
" udtsGen();\n");
739 fprintf(spOut,
" }\n");
740 fprintf(spOut,
" }\n");
741 fprintf(spOut,
" function rulesGen() {\n");
742 fprintf(spOut,
" var html = \"\";\n");
743 fprintf(spOut,
" html += '<table id=\"rulesTable\">';\n");
744 fprintf(spOut,
" html += '<caption><strong>Rule Dependencies</strong><br>';\n");
746 " html += '<button class=\"closeButton\" onclick=\"closeAllRules()\">close all rules</button>';\n");
747 fprintf(spOut,
" html += '<caption/>';\n");
749 " html += '<tr><td class=\"tableButton\" onclick=\"tableSort(\\'rules\\', \\'index\\')\">index</td>';\n");
751 " html += '<td class=\"tableButton\" onclick=\"tableSort(\\'rules\\', \\'name\\')\">name</td>';\n");
752 fprintf(spOut,
" html += '<td class=\"bold\">dependencies</td></tr>';\n");
753 fprintf(spOut,
" for (var i = 0; i < rulesData.length; i++) {\n");
754 fprintf(spOut,
" var data = rulesData[i];\n");
755 fprintf(spOut,
" html += \"<tr><td>\" + data.index + \"</td><td>\" + data.name + \"</td>\";\n");
756 fprintf(spOut,
" if (data.to.length > 0) {\n");
757 fprintf(spOut,
" var to = \"to\" + i;\n");
759 " html += '<td><button class=\"tableButton\" onclick=\"toggle(\\'' + to + '\\')\">refers to</button><br>';\n");
760 fprintf(spOut,
" html += '<ul id=\"' + to + '\">';\n");
761 fprintf(spOut,
" for (var j = 0; j < data.to.length; j++) {\n");
762 fprintf(spOut,
" html += \"<li>\" + data.to[j] + \"</li>\";\n");
763 fprintf(spOut,
" }\n");
764 fprintf(spOut,
" html += '</ul>';\n");
765 fprintf(spOut,
" html += \"</td></tr>\";\n");
766 fprintf(spOut,
" } else {\n");
767 fprintf(spOut,
" html += \"<td><i>no referals</i></td></tr>\";\n");
768 fprintf(spOut,
" }\n");
769 fprintf(spOut,
" if (data.by.length > 0) {\n");
770 fprintf(spOut,
" var by = \"by\" + i;\n");
772 " html += '<tr><td></td><td></td><td><button class=\"tableButton\" onclick=\"toggle(\\'' + by + '\\')\">referenced by</button><br>';\n");
773 fprintf(spOut,
" html += '<ul id=\"' + by + '\">';\n");
774 fprintf(spOut,
" for (var j = 0; j < data.by.length; j++) {\n");
775 fprintf(spOut,
" html += \"<li>\" + data.by[j] + \"</li>\";\n");
776 fprintf(spOut,
" }\n");
777 fprintf(spOut,
" html += '</ul>';\n");
778 fprintf(spOut,
" html += \"</td><tr>\";\n");
779 fprintf(spOut,
" } else {\n");
780 fprintf(spOut,
" html += \"<tr><td></td><td></td><td><i>not referenced</i></td></tr>\";\n");
781 fprintf(spOut,
" }\n");
782 fprintf(spOut,
" }\n");
783 fprintf(spOut,
" html += '</table>';\n");
784 fprintf(spOut,
" var d = document.getElementById(\"rulesTable\");\n");
785 fprintf(spOut,
" d.innerHTML = html;\n");
786 fprintf(spOut,
" closeAllRules();\n");
787 fprintf(spOut,
" }\n");
788 fprintf(spOut,
" function udtsGen() {\n");
789 fprintf(spOut,
" if (udtsData.length > 0) {\n");
790 fprintf(spOut,
" var html = \"\";\n");
791 fprintf(spOut,
" html += \"<p></p>\";\n");
792 fprintf(spOut,
" html += '<table id=\"rulesTable\">';\n");
793 fprintf(spOut,
" html += '<caption><strong>UDT Dependencies</strong><br>';\n");
795 " html += '<button class=\"closeButton\" onclick=\"closeAllUdts()\">close all UDTS</button>';\n");
796 fprintf(spOut,
" html += '<caption/>';\n");
798 " html += '<tr><td class=\"tableButton\" onclick=\"tableSort(\\'udts\\', \\'index\\')\">index</td>';\n");
800 " html += '<td class=\"tableButton\" onclick=\"tableSort(\\'udts\\', \\'name\\')\">name</td>';\n");
801 fprintf(spOut,
" html += '<td class=\"bold\">dependencies</td><tr>';\n");
802 fprintf(spOut,
" for (var i = 0; i < udtsData.length; i++) {\n");
803 fprintf(spOut,
" var data = udtsData[i];\n");
804 fprintf(spOut,
" html += \"<tr><td>\" + data.index + \"</td><td>\" + data.name + \"</td>\";\n");
805 fprintf(spOut,
" if (data.by.length > 0) {\n");
806 fprintf(spOut,
" var by = \"udt\" + i;\n");
808 " html += '<td><button class=\"tableButton\" onclick=\"toggle(\\'' + by + '\\')\">referenced by</button><br>';\n");
809 fprintf(spOut,
" html += '<ul id=\"' + by + '\">';\n");
810 fprintf(spOut,
" for (var j = 0; j < data.by.length; j++) {\n");
811 fprintf(spOut,
" html += \"<li>\" + data.by[j] + \"</li>\";\n");
812 fprintf(spOut,
" }\n");
813 fprintf(spOut,
" html += '</ul>';\n");
814 fprintf(spOut,
" html += \"</td><tr>\";\n");
815 fprintf(spOut,
" } else {\n");
816 fprintf(spOut,
" html += \"<td><i>not referenced</i></td></tr>\";\n");
817 fprintf(spOut,
" }\n");
818 fprintf(spOut,
" }\n");
819 fprintf(spOut,
" html += '</table>';\n");
820 fprintf(spOut,
" var d = document.getElementById(\"udtsTable\");\n");
821 fprintf(spOut,
" d.innerHTML = html;\n");
822 fprintf(spOut,
" closeAllUdts();\n");
823 fprintf(spOut,
" }\n");
824 fprintf(spOut,
" }\n");
825 fprintf(spOut,
" function setup() {\n");
826 fprintf(spOut,
" if (rulesData.length > 0) {\n");
827 fprintf(spOut,
" rulesGen();\n");
828 fprintf(spOut,
" }\n");
829 fprintf(spOut,
" if (udtsData.length > 0) {\n");
830 fprintf(spOut,
" udtsGen();\n");
831 fprintf(spOut,
" }\n");
832 fprintf(spOut,
" }\n");
833 fprintf(spOut,
" window.onload = setup;\n");
835 static void vRulesFooter(FILE *spOut) {
836 fprintf(spOut,
"</script>\n");
837 fprintf(spOut,
"</body>\n");
838 fprintf(spOut,
"</html>\n");
840 static int iCompRules(
const void *vpL,
const void *vpR) {
845 static int iCompUdts(
const void *vpL,
const void *vpR) {
abool * bpRefersToUdt
a list of all the UDTs that this rule refers to
aint uiUdtCount
The number of UDTs referenced in the SABNF grammar.
abool bApiValidate(void *vpCtx)
Validates an API context pointer.
#define ID_BKR_CASE_I
the back reference is case insensitive
void vHtmlHeader(FILE *spFile, const char *cpTitle)
Prints an HTML header to an open file.
api_rule * spRules
Points to an array of rule structures.
abool * bpIsReferencedBy
a list of all the rules that refer to this rule
luint luiMax
maximum value for REP and TRG opcodes
void vMemDtor(void *vpCtx)
Destroys a Memory component. Frees all memory allocated.
api_op * spOpcodes
Pointer to the array of opcodes for the SANF grammar.
void vApiInClear(void *vpCtx)
Clears the input and related memory.
aint uiAcharLength
number of characters in TLS/TBS strings
The API will construct an attributes object. This is the attribute object's context.
void * vpLog
A msglog context for error reporting.
Working attribute information about a each rule.
void * vpApiCtor(exception *spEx)
Construct an API component context (object).
#define ID_ALT
alternation
#define ID_BKR
back reference to a previously matched rule or UDT name
#define ID_UDT
user-defined terminal
void vApiInValidate(void *vpCtx, abool bStrict)
Scans the input SABNF grammar for invalid characters and line ends.
API information about each rule.
Private header file for the APG API suite of functions.
void vExContext()
Handles bad context pointers.
aint uiChildCount
number of children for this ALT or CAT operator
void vApiOpcodes(void *vpCtx)
Parse the SABNF grammar and translate its AST into opcodes for all the rules.
uint_fast8_t achar
achar is the type for the parser's alphabet characters.
void * vpAttrsCtx
context handle to the attributes object
void vApiDtor(void *vpCtx)
The API component destructor.
void * vpApiGetErrorLog(void *vpCtx)
Get the internal message log.
Used by syntax.c but needed here for constructor/destructor.
#define ID_NOT
negative look ahead
#define ID_AND
positive look ahead
luint * luipAchar
pointer to the first character in the achar table for this TLS/TBS operator
#define XTHROW(ctx, msg)
Exception throw macro.
luint luiMin
minimum value for REP and TRG opcodes
api_udt * spUdts
Points to an array of UDT structures, if one or more UDTs are referenced in the SABNF grammar.
aint uiRuleCount
The number of rules in the SABNF grammar and in the array.
uint_fast32_t aint
The APG parser's unsigned integer type.
void vApiFile(void *vpCtx, const char *cpFileName, abool bStrict, abool bPppt)
Quicky way to generate a parser from a grammar file.
void * vpMsgsCtor(exception *spEx)
The Message Log constructor.
#define ID_CAT
concatenation
aint uiMode
ID_BKR_MODE_U of ID_BKR_MODE_P for BKR.
void * vpMemAlloc(void *vpCtx, aint uiBytes)
Allocates memory.
void vHtmlFooter(FILE *spFile)
Prints an HTML footer to an open file.
void vApiSyntax(void *vpCtx, abool bStrict)
Parse the SABNF grammar to validate that the grammar structure is valid.
void * vpVecCtor(void *vpMem, aint uiElementSize, aint uiInitialAlloc)
The vector object constructor.
#define ID_TRG
terminal range
char * cpName
pointer to null-terminated string in the string table
void * vpLines
Context pointer to a lines object.
A structure to describe the type and location of a caught exception.
aint uiCase
ID_BKR_CASE_S or ID_BKR_CASE_I for BKR.
aint uiIndex
index of this referenced rule or UDT
void vMsgsDtor(void *vpCtx)
The object destructor.
uintmax_t luint
luint is used to cast integers suitable for the %"PRIuMAX" printf format.
void vApiRulesToAscii(void *vpCtx, const char *cpMode, const char *cpFileName)
Display rules and UDTs in human-readable format in ASCII format.
abool bExValidate(exception *spException)
Test an exception structure for validity.
char * cpRuleName
the rule name for these attributes
API information about each opcode.
abool bApiAttrs(void *vpCtx)
Computes the grammar's attributes.
API information about each UDT.
#define ID_BKA
positive look behind
void * vpMemCtor(exception *spException)
Construct a memory component.
Header file for the attributes functions.
abool bAttributesComputed
APG_TRUE if attributes have been computed (even is there are attribute errors), APG_FALSE otherwise.
const void * vpValidate
the "magic number" to indicate that this is a valid context
const char * cpApiInFile(void *vpCtx, const char *cpFileName)
Reads an SABNF grammar byte stream from a file.
abool * bpRefersTo
a list of all the rules that this rule refers to
aint uiId
type of opcode, ID_ALT, etc.
#define ID_TLS
terminal literal string
const char * cpApiInString(void *vpCtx, const char *cpString)
Reads an SABNF grammar byte stream from a string.
void vLinesDtor(void *vpCtx)
The lines object destructor.
void vParserDtor(void *vpCtx)
Clears the parser component's context and frees all heap memory associated with this parser.
void vApiOpcodesToAscii(void *vpCtx, const char *cpFileName)
Display all opcodes in human-readable format.
#define ID_BKN
negative look behind
uint8_t abool
abool is the APG bool type.
char * cpName
pointer to null-terminated string in the string table
aint uiRuleIndex
the index of the rule for these attributes
aint uiIndex
index of this UDT in the UDT list
aint uiBkrIndex
if BKR, this is the index to the rule or UDT that is being back referenced
void * vpParser
context handle to the SABNF grammar parser object
void * vpMem
Pointer to the memory context used for all memory allocations and exceptions thrown.
void vApiRulesToHtml(void *vpCtx, const char *cpFileName)
Display the grammar rules in human-readable, HTML format.
aint * uipChildIndex
pointer to the first child index of this ALT or CAT operator
api_attr_w * spAttrs
An array of private attribute structures used in their construction.
#define ID_ABG
anchor - beginning of string
abool bSemanticsValid
APG_TRUE if the the input semantics are valid. That is, the opcodes for the parser have been generate...
#define ID_BKR_MODE_U
the back reference is universal mode
void vApiString(void *vpCtx, const char *cpString, abool bStrict, abool bPppt)
Quicky way to generate a parser from a grammar string.
#define ID_TBS
terminal binary string
void * vpVecPush(void *vpCtx, void *vpElement)
Adds one element to the end of the array.
aint uiOpCount
the number of opcodes in this rule
#define ID_AEN
anchor - end of string
void vApiPppt(void *vpCtx, char **cppProtectedRules, aint uiProtectedRules)
Compute the Partially-Predictive Parsing Tables.
Public header file for the APG API suite of functions.
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.