Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
38 #include "../library/parserp.h"
42 static const char* s_cpNoTab =
"tab (\\t, 0x09) found. Not allowed in TLS strings (char-val RFC 5234).";
44 static void vSemPushError(
semantic_data* spData,
aint uiCharIndex,
const char* cpMsg) {
69 snprintf(caName, uiLen,
"%s", spData->
cpName);
70 snprintf(caBuf, iBufSize,
71 "incremental alternative rule name \"%s\" used without previous definition", caName);
109 snprintf(caName, uiLen,
"%s", spData->
cpName);
110 snprintf(caBuf, iBufSize,
"rule name \"%s\" previously defined", caName);
142 spRule->uiCurrentAlt =
uiVecLen(spRule->vpVecOps);
146 vpVecPush(spRule->vpVecAltStack, &spRule->uiCurrentAlt);
154 spRule->uiCurrentAlt = *uip;
165 spRule->uiCurrentCat =
uiVecLen(spRule->vpVecOps);
177 vpVecPush(spRule->vpVecCatStack, &spRule->uiCurrentCat);
185 spRule->uiCurrentCat = *uip;
260 snprintf(caBuf, 128,
"REP: minimum(%"PRIuMAX
") must be <= maximum (%"PRIuMAX
")",
261 spRule->spCurrentOp->luiMin, spRule->spCurrentOp->luiMax);
274 luint luiTest, luiDigit;
292 "REP: n*m: n out of range: %s", caString);
305 luint luiTest, luiDigit;
323 "REP: n*m: m out of range: %s", caString);
336 luint luiTest, luiDigit;
355 "REP: n or n*n: n out of range: %s", caString);
395 spRule->spCurrentOp =
vpVecPush(spRule->vpVecOps, &sOp);
515 "case-sensitive string may not be empty - use case-insensitive string (\"\") to represent an empty string");
538 aint uiIndex = spRule->spCurrentOp->uiStringIndex;
542 for(; ui < spRule->spCurrentOp->uiStringLength; ui++, luipChars++){
543 luiChar = *luipChars;
544 if((luiChar >= 65) && (luiChar <= 90)){
551 spRule->spCurrentOp->uiId =
ID_TBS;
585 if(spRule->spCurrentOp->luiMin > spRule->spCurrentOp->luiMax){
587 snprintf(caBuf, 128,
"TRG: minimum character (%"PRIuMAX
") must be <= maximum character (%"PRIuMAX
")",
588 spRule->spCurrentOp->luiMin, spRule->spCurrentOp->luiMax);
625 luint luiTest, luiDigit;
643 "decimal number out of range: %s", caString);
655 luint luiTest, luiDigit;
673 "binary number out of range: %s", caString);
682 if(luiChar >= 48 && luiChar <= 57){
683 luiNum = luiChar - 48;
684 }
else if(luiChar >= 65 && luiChar <= 70){
685 luiNum = luiChar - 55;
687 luiNum = luiChar - 87;
696 luint luiTest, luiDigit;
714 "hexidecimal number out of range: %s", caString);
#define SABNF_GRAMMAR_TLSCASE
#define SABNF_GRAMMAR_TLSCLOSE
#define SABNF_GRAMMAR_RULE
#define ID_BKR_CASE_I
the back reference is case insensitive
#define SABNF_GRAMMAR_REP_NUM
#define SABNF_GRAMMAR_NOTOP
#define SABNF_GRAMMAR_RULENAMEERROR
User data passed to the AST translator for use by the AST callback functions.
void vAstSetRuleCallback(void *vpCtx, aint uiRuleIndex, ast_callback pfnCallback)
Define a callback function for a single rule on the AST.
#define SABNF_GRAMMAR_COMMENT
#define SABNF_GRAMMAR_GROUPERROR
#define SABNF_GRAMMAR_UDTOP
#define SABNF_GRAMMAR_XSTRING
#define ID_AST_POST
indicates post-node-traversal AST callback state (up the tree)
#define SABNF_GRAMMAR_TLSOPEN
#define ID_ALT
alternation
#define SABNF_GRAMMAR_OPTIONERROR
#define SABNF_GRAMMAR_ALPHANUM
#define SABNF_GRAMMAR_REPETITION
#define SABNF_GRAMMAR_WSP
Header file for the semantic translation functions.
#define ID_BKR
back reference to a previously matched rule or UDT name
#define SABNF_GRAMMAR_DEC
#define ID_UDT
user-defined terminal
#define ID_AST_OK
normal AST callback function return
Private header file for the APG API suite of functions.
#define ID_AST_PRE
indicates pre-node-traversal AST callback state (down the tree)
Input data to the AST callback functions.
#define SABNF_GRAMMAR_DEFINEDASERROR
#define SABNF_GRAMMAR_OPTIONCLOSE
#define SABNF_GRAMMAR_INCALT
#define SABNF_GRAMMAR_GROUP
#define SABNF_GRAMMAR_CLSOP
#define SABNF_GRAMMAR_HEX
#define ID_NOT
negative look ahead
#define ID_AND
positive look ahead
void * vpVecAt(void *vpCtx, aint uiIndex)
Get a the indexed vector element. The vector is not altered.
#define SABNF_GRAMMAR_ALTOP
#define ID_BKR_CASE_S
the back reference is case sensitive
#define SABNF_GRAMMAR_GROUPCLOSE
#define SABNF_GRAMMAR_DMIN
#define SABNF_GRAMMAR_RULENAMETEST
#define XTHROW(ctx, msg)
Exception throw macro.
semantic_op * spCurrentOp
void * vpVecPop(void *vpCtx)
Pops one element from the end of the array.
uint_fast32_t aint
The APG parser's unsigned integer type.
void * vpVecLast(void *vpCtx)
Get the last element one the vector. The vector is not altered.
#define SABNF_GRAMMAR_BKROP
#define ID_CAT
concatenation
#define SABNF_GRAMMAR_OPTIONOPEN
#define SABNF_GRAMMAR_BASICELEMENT
#define SABNF_GRAMMAR_UNAME
aint uiVecLen(void *vpCtx)
Get the vector length. That is, the number of elements on the vector.
#define SABNF_GRAMMAR_SPACE
void * vpVecCtor(void *vpMem, aint uiElementSize, aint uiInitialAlloc)
The vector object constructor.
#define SABNF_GRAMMAR_REPOP
#define ID_TRG
terminal range
#define SABNF_GRAMMAR_BMAX
#define SABNF_GRAMMAR_CLSCLOSE
#define SABNF_GRAMMAR_STRINGTAB
#define SABNF_GRAMMAR_DEFINEDAS
aint(* ast_callback)(ast_data *spData)
The prototype for AST translation callback functions.
#define SABNF_GRAMMAR_RULENAME
#define SABNF_GRAMMAR_DSTRING
#define SABNF_GRAMMAR_BKNOP
uintmax_t luint
luint is used to cast integers suitable for the %"PRIuMAX" printf format.
#define SABNF_GRAMMAR_BKRMODIFIER
Generalized opcode for first-pass semantic processing.
#define RULE_COUNT_SABNF_GRAMMAR
#define SABNF_GRAMMAR_CONCATENATION
#define SABNF_GRAMMAR_BNUM
#define SABNF_GRAMMAR_TLSSTRING
#define SABNF_GRAMMAR_PROSVALSTRING
#define SABNF_GRAMMAR_GROUPOPEN
void * vpVecFirst(void *vpCtx)
Get the first element one the vector. The vector is not altered.
#define ID_BKA
positive look behind
#define SABNF_GRAMMAR_MODIFIER
#define SABNF_GRAMMAR_ABGOP
#define SABNF_GRAMMAR_RULELOOKUP
#define SABNF_GRAMMAR_LINEENDERROR
void vSabnfGrammarAstCallbacks(void *vpAstCtx)
Set the callback functions for the AST translation of the semantic phase parse to opcodes.
#define SABNF_GRAMMAR_DMAX
#define SABNF_GRAMMAR_LINEEND
#define SABNF_GRAMMAR_LINECONTINUE
#define SABNF_GRAMMAR_BASICELEMENTERR
semantic_rule * spCurrentRule
aint uiFindRule(semantic_rule *spRules, aint uiRuleCount, const char *cpName, aint uiNameLength)
Find the index of the named rule in the rule list.
#define SABNF_GRAMMAR_TLSOP
#define ID_TLS
terminal literal string
#define SABNF_GRAMMAR_PROSVALOPEN
#define SABNF_GRAMMAR_CLSOPEN
#define SABNF_GRAMMAR_UDT_NON_EMPTY
#define SABNF_GRAMMAR_BSTRING
#define SABNF_GRAMMAR_OPTION
#define SABNF_GRAMMAR_TRGOP
#define SABNF_GRAMMAR_FILE
#define SABNF_GRAMMAR_RULEERROR
#define SABNF_GRAMMAR_DNUM
#define SABNF_GRAMMAR_XMIN
#define SABNF_GRAMMAR_CATOP
#define ID_BKN
negative look behind
#define SABNF_GRAMMAR_REP_MAX
#define SABNF_GRAMMAR_ALTERNATION
#define SABNF_GRAMMAR_BIN
#define SABNF_GRAMMAR_BKAOP
#define SABNF_GRAMMAR_PREDICATE
#define SABNF_GRAMMAR_BKR_NAME
#define SABNF_GRAMMAR_REP_MIN
#define SABNF_GRAMMAR_ANDOP
Generalized rule for first-pass semantic processing.
#define SABNF_GRAMMAR_XNUM
#define ID_ABG
anchor - beginning of string
#define SABNF_GRAMMAR_OWSP
#define SABNF_GRAMMAR_RNMOP
#define SABNF_GRAMMAR_BMIN
#define SABNF_GRAMMAR_DEFINEDASTEST
void vLineError(api *spCtx, aint uiCharIndex, const char *cpSrc, const char *cpMsg)
Finds the grammar line associated with a character index and formats an error message to the error lo...
#define SABNF_GRAMMAR_TBSOP
#define SABNF_GRAMMAR_PROSVAL
#define SABNF_GRAMMAR_XMAX
#define SABNF_GRAMMAR_ENAME
#define SABNF_GRAMMAR_RNAME
#define ID_BKR_MODE_U
the back reference is universal mode
#define ID_TBS
terminal binary string
void * vpVecPush(void *vpCtx, void *vpElement)
Adds one element to the end of the array.
#define SABNF_GRAMMAR_BLANKLINE
#define ID_BKR_MODE_P
the back reference is parent mode
#define SABNF_GRAMMAR_CLSSTRING
#define SABNF_GRAMMAR_PROSVALCLOSE
#define SABNF_GRAMMAR_DEFINED
#define SABNF_GRAMMAR_AENOP
#define ID_AEN
anchor - end of string
Public header file for the APG API suite of functions.
#define SABNF_GRAMMAR_REP_MIN_MAX
#define SABNF_GRAMMAR_UDT_EMPTY
APG Version 7.0 is licensed under the
2-Clause BSD License,
an Open Source Initiative Approved License.