Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
|
Go to the documentation of this file.
36 #include "../library/parserp.h"
43 static void vSynPushError(
callback_data* spCallbackData,
aint uiCharIndex,
char* cpMsg) {
48 const char* cpPrev = cpMsg;
54 snprintf(caBuf, 1024,
"error found at character index: %"PRIuMAX
"\n%s",
55 (
luint)uiCharIndex, cpPrev);
68 vSynPushError(spData, spData->
uiParserOffset,
"no rules found - grammar must have at least one rule");
71 vSynPushError(spData, spData->
uiParserOffset,
"NOMATCH found for file - should never happen");
86 vSynPushError(spData, spData->
uiParserOffset,
"malformed rule found");
93 vSynPushError(spData, spData->
uiParserOffset,
"malformed rule name");
100 vSynPushError(spData, spData->
uiParserOffset,
"malformed \"defined as\", must be \"=\" or \"=/\"");
108 vSynPushError(spData, spData->
uiParserOffset,
"AND operator (&) found and strict ABNF specified");
117 vSynPushError(spData, spData->
uiParserOffset,
"NOT operator (!) found and strict ABNF specified");
127 "positive look behind operator (&&) found and strict ABNF specified");
137 "negative look behind operator (!!) found and strict ABNF specified");
147 "begin of line anchor operator (%^) found and strict ABNF specified");
157 "end of line anchor operator (%$) found and strict ABNF specified");
167 "back reference operator (\\rulename or \\udtname) found and strict ABNF specified");
177 "user-defined terminal operator (u_name or e_name) found and strict ABNF specified");
193 "tab (\\t or 0x09) not allowed in case-insensitive literal string (see RFC 5234, char-val)");
211 "expected open case-insensitive literal string closure not found");
221 "case-sensitive literal string ('') found and strict ABNF specified");
231 "tab (\\t or 0x09) not allowed in case-sensitive literal string (see RFC 5234, char-val)");
242 vSynPushError(spData, spData->
uiParserOffset,
"expected open case-sensitive literal string closure not found");
250 "prose-val found. Defined in RFC 5234 but cannot be parsed.)");
259 "tab (\\t or 0x09) not allowed in prose value (see RFC 5234, prose-val)");
270 vSynPushError(spData, spData->
uiParserOffset,
"expected open prose value closure not found");
284 vSynPushError(spData, spData->
uiParserOffset,
"open group closure expected but not found");
302 vSynPushError(spData, spData->
uiParserOffset,
"open option closure expected but not found");
315 vSynPushError(spData, spData->
uiParserOffset,
"malformed element found");
321 vSynPushError(spData, spData->
uiParserOffset,
"malformed element found");
323 "line end expected not found, possibly some extraneous after alternation and before line end");
The syntax data that gets passed to the syntax parser's callback functions.
#define SABNF_GRAMMAR_TLSCASE
#define SABNF_GRAMMAR_TLSCLOSE
#define SABNF_GRAMMAR_RULE
#define SABNF_GRAMMAR_REP_NUM
api * spApi
Pointer to the parent API object context.
#define SABNF_GRAMMAR_NOTOP
#define SABNF_GRAMMAR_RULENAMEERROR
#define SABNF_GRAMMAR_COMMENT
void * vpLog
A msglog context for error reporting.
#define SABNF_GRAMMAR_GROUPERROR
aint uiParserOffset
[read only] Offset from acpString to the first character to match
#define SABNF_GRAMMAR_UDTOP
#define SABNF_GRAMMAR_XSTRING
#define SABNF_GRAMMAR_TLSOPEN
aint uiParserState
[read only] ID_ACTIVE if the parser is going down the tree. ID_MATCH or ID_NOMATCH if coming up the t...
aint uiRulesFound
True if rules have been found in the grammar.
#define SABNF_GRAMMAR_OPTIONERROR
#define SABNF_GRAMMAR_ALPHANUM
#define SABNF_GRAMMAR_REPETITION
#define SABNF_GRAMMAR_WSP
void * vpAltStack
A stack vector to manage open ALT operators.
#define SABNF_GRAMMAR_DEC
Private header file for the APG API suite of functions.
#define SABNF_GRAMMAR_DEFINEDASERROR
#define SABNF_GRAMMAR_OPTIONCLOSE
void vParserSetRuleCallback(void *vpCtx, aint uiRuleId, parser_callback pfnCallback)
Set a call back function for a specific rule.
#define SABNF_GRAMMAR_INCALT
#define SABNF_GRAMMAR_GROUP
#define SABNF_GRAMMAR_CLSOP
Used by syntax.c but needed here for constructor/destructor.
#define SABNF_GRAMMAR_HEX
#define SABNF_GRAMMAR_ALTOP
#define SABNF_GRAMMAR_GROUPCLOSE
#define SABNF_GRAMMAR_DMIN
#define SABNF_GRAMMAR_RULENAMETEST
#define XTHROW(ctx, msg)
Exception throw macro.
void(* parser_callback)(callback_data *spData)
User-written callback function prototype.
void * vpVecPop(void *vpCtx)
Pops one element from the end of the array.
alt_data * spTopAlt
Pointer to the top of the ALT stack.
uint_fast32_t aint
The APG parser's unsigned integer type.
#define SABNF_GRAMMAR_BKROP
#define SABNF_GRAMMAR_OPTIONOPEN
#define SABNF_GRAMMAR_BASICELEMENT
#define SABNF_GRAMMAR_UNAME
#define SABNF_GRAMMAR_SPACE
#define SABNF_GRAMMAR_REPOP
aint uiErrorsFound
True if any errors in the grammar have been found.
#define SABNF_GRAMMAR_BMAX
#define SABNF_GRAMMAR_CLSCLOSE
#define SABNF_GRAMMAR_STRINGTAB
#define SABNF_GRAMMAR_DEFINEDAS
#define SABNF_GRAMMAR_RULENAME
#define ID_ACTIVE
indicates active parser state, parser has just entered the node and is moving down the parse tree
#define SABNF_GRAMMAR_DSTRING
#define SABNF_GRAMMAR_BKNOP
#define ID_MATCH
indicates a matched phrase parser state on return from parse tree below this node
uintmax_t luint
luint is used to cast integers suitable for the %"PRIuMAX" printf format.
#define SABNF_GRAMMAR_BKRMODIFIER
const char * cpMsgsFirst(void *vpCtx)
Get a pointer to the first logged message, if any.
The data struct passed to each callback function.
const char * cpMsgsNext(void *vpCtx)
Get a pointer to the next logged message, if any.
#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 SABNF_GRAMMAR_MODIFIER
#define SABNF_GRAMMAR_ABGOP
#define SABNF_GRAMMAR_RULELOOKUP
#define SABNF_GRAMMAR_LINEENDERROR
#define SABNF_GRAMMAR_DMAX
#define SABNF_GRAMMAR_LINEEND
#define SABNF_GRAMMAR_LINECONTINUE
#define SABNF_GRAMMAR_BASICELEMENTERR
void vSabnfGrammarRuleCallbacks(void *vpParserCtx)
Set the parser's rule callback functions for the syntax phase.
void * vpUserData
[input/output] User-defined data passed to to the parser in parser_config.
#define SABNF_GRAMMAR_TLSOP
#define SABNF_GRAMMAR_PROSVALOPEN
#define SABNF_GRAMMAR_CLSOPEN
Header file for the syntax phase functions.
#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 SABNF_GRAMMAR_REP_MAX
#define SABNF_GRAMMAR_ALTERNATION
#define SABNF_GRAMMAR_BIN
#define SABNF_GRAMMAR_BKAOP
#define ID_NOMATCH
indicates that no phrase was matched on return from parse tree below this node
#define SABNF_GRAMMAR_PREDICATE
#define SABNF_GRAMMAR_BKR_NAME
aint uiRuleError
True if an error has been found in the rule definition/.
abool bStrict
True if the grammar is to be treated as strict RFC5234 ABNF. No superset operators allowed.
#define SABNF_GRAMMAR_REP_MIN
#define SABNF_GRAMMAR_ANDOP
#define SABNF_GRAMMAR_XNUM
#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
void * vpVecPush(void *vpCtx, void *vpElement)
Adds one element to the end of the array.
#define SABNF_GRAMMAR_BLANKLINE
#define SABNF_GRAMMAR_CLSSTRING
#define SABNF_GRAMMAR_PROSVALCLOSE
#define SABNF_GRAMMAR_DEFINED
#define SABNF_GRAMMAR_AENOP
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.