Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
syntax-callbacks.c
Go to the documentation of this file.
1 /* *************************************************************************************
2  Copyright (c) 2021, Lowell D. Thomas
3  All rights reserved.
4 
5  This file is part of APG Version 7.0.
6  APG Version 7.0 may be used under the terms of the BSD 2-Clause License.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 * *************************************************************************************/
34 #include "./api.h"
35 #include "./apip.h"
36 #include "../library/parserp.h"
37 #include "./syntax.h"
38 #include "sabnf-grammar.h"
39 
40 // find the line number
41 // push an error message on the log stack
42 // if can't find the line, note error and abort
43 static void vSynPushError(callback_data* spCallbackData, aint uiCharIndex, char* cpMsg) {
44  syntax_data* spData = (syntax_data*) spCallbackData->vpUserData;
45  spData->uiErrorsFound++;
46  vLineError(spData->spApi, uiCharIndex, "syntax", cpMsg);
47  const char* cpLogMsg = cpMsgsFirst(spData->spApi->vpLog);
48  const char* cpPrev = cpMsg;
49  while(cpLogMsg){
50  cpPrev = cpLogMsg;
51  cpLogMsg = cpMsgsNext(spData->spApi->vpLog);
52  }
53  char caBuf[1024];
54  snprintf(caBuf, 1024, "error found at character index: %"PRIuMAX"\n%s",
55  (luint)uiCharIndex, cpPrev);
56  XTHROW(spData->spApi->spException, caBuf);
57 }
58 
59 static void vFile(callback_data* spData) {
60  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
61  if (spData->uiParserState == ID_ACTIVE) {
62  spUserData->uiRulesFound = 0;
63  spUserData->uiErrorsFound = 0;
64  spUserData->spTopAlt = (alt_data*) vpVecPush(spUserData->vpAltStack, NULL);
65  memset((void*) spUserData->spTopAlt, 0, sizeof(*spUserData->spTopAlt));
66  } else if (spData->uiParserState == ID_MATCH) {
67  if(!spUserData->uiRulesFound){
68  vSynPushError(spData, spData->uiParserOffset, "no rules found - grammar must have at least one rule");
69  }
70  } else {
71  vSynPushError(spData, spData->uiParserOffset, "NOMATCH found for file - should never happen");
72  }
73 }
74 static void vRule(callback_data* spData) {
75  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
76  if (spData->uiParserState == ID_ACTIVE) {
77  spUserData->uiRuleError = 0;
78  } else if (spData->uiParserState == ID_MATCH) {
79  spUserData->uiRulesFound++;
80  }
81 }
82 static void vRuleError(callback_data* spData) {
83  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
84  if (spData->uiParserState == ID_MATCH) {
85  spUserData->uiRuleError++;
86  vSynPushError(spData, spData->uiParserOffset, "malformed rule found");
87  }
88 }
89 static void vRuleNameError(callback_data* spData) {
90  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
91  if (spData->uiParserState == ID_MATCH) {
92  spUserData->uiRuleError++;
93  vSynPushError(spData, spData->uiParserOffset, "malformed rule name");
94  }
95 }
96 static void vDefinedAsError(callback_data* spData) {
97  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
98  if (spData->uiParserState == ID_MATCH) {
99  spUserData->uiRuleError++;
100  vSynPushError(spData, spData->uiParserOffset, "malformed \"defined as\", must be \"=\" or \"=/\"");
101  }
102 }
103 static void vAndOp(callback_data* spData) {
104  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
105  if (spData->uiParserState == ID_MATCH) {
106  if (spUserData->bStrict) {
107  spUserData->uiRuleError++;
108  vSynPushError(spData, spData->uiParserOffset, "AND operator (&) found and strict ABNF specified");
109  }
110  }
111 }
112 static void vNotOp(callback_data* spData) {
113  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
114  if (spData->uiParserState == ID_MATCH) {
115  if (spUserData->bStrict) {
116  spUserData->uiRuleError++;
117  vSynPushError(spData, spData->uiParserOffset, "NOT operator (!) found and strict ABNF specified");
118  }
119  }
120 }
121 static void vBkaOp(callback_data* spData) {
122  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
123  if (spData->uiParserState == ID_MATCH) {
124  if (spUserData->bStrict) {
125  spUserData->uiRuleError++;
126  vSynPushError(spData, spData->uiParserOffset,
127  "positive look behind operator (&&) found and strict ABNF specified");
128  }
129  }
130 }
131 static void vBknOp(callback_data* spData) {
132  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
133  if (spData->uiParserState == ID_MATCH) {
134  if (spUserData->bStrict) {
135  spUserData->uiRuleError++;
136  vSynPushError(spData, spData->uiParserOffset,
137  "negative look behind operator (!!) found and strict ABNF specified");
138  }
139  }
140 }
141 static void vAbgOp(callback_data* spData) {
142  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
143  if (spData->uiParserState == ID_MATCH) {
144  if (spUserData->bStrict) {
145  spUserData->uiRuleError++;
146  vSynPushError(spData, spData->uiParserOffset,
147  "begin of line anchor operator (%^) found and strict ABNF specified");
148  }
149  }
150 }
151 static void vAenOp(callback_data* spData) {
152  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
153  if (spData->uiParserState == ID_MATCH) {
154  if (spUserData->bStrict) {
155  spUserData->uiRuleError++;
156  vSynPushError(spData, spData->uiParserOffset,
157  "end of line anchor operator (%$) found and strict ABNF specified");
158  }
159  }
160 }
161 static void vBkrOp(callback_data* spData) {
162  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
163  if (spData->uiParserState == ID_MATCH) {
164  if (spUserData->bStrict) {
165  spUserData->uiRuleError++;
166  vSynPushError(spData, spData->uiParserOffset,
167  "back reference operator (\\rulename or \\udtname) found and strict ABNF specified");
168  }
169  }
170 }
171 static void vUdtOp(callback_data* spData) {
172  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
173  if (spData->uiParserState == ID_MATCH) {
174  if (spUserData->bStrict) {
175  spUserData->uiRuleError++;
176  vSynPushError(spData, spData->uiParserOffset,
177  "user-defined terminal operator (u_name or e_name) found and strict ABNF specified");
178  }
179  }
180 }
181 static void vTlsOpen(callback_data* spData) {
182  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
183  if (spData->uiParserState == ID_MATCH) {
184  spUserData->spTopAlt->uiTlsOpen = spData->uiParserOffset;
185  }
186 }
187 static void vTlsString(callback_data* spData) {
188  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
189  if (spData->uiParserState == ID_MATCH) {
190  if (spUserData->spTopAlt->uiStringTab) {
191  spUserData->uiRuleError++;
192  vSynPushError(spData, spData->uiParserOffset,
193  "tab (\\t or 0x09) not allowed in case-insensitive literal string (see RFC 5234, char-val)");
194  spUserData->spTopAlt->uiStringTab = APG_FALSE;
195  }
196  }
197 }
198 static void vStringTab(callback_data* spData) {
199  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
200  if (spData->uiParserState == ID_MATCH) {
201  spUserData->spTopAlt->uiStringTab = APG_TRUE;
202  }
203 }
204 static void vTlsClose(callback_data* spData) {
205  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
206  if (spData->uiParserState == ID_MATCH) {
207  spUserData->spTopAlt->uiTlsOpen = APG_FALSE;
208  } else if (spData->uiParserState == ID_NOMATCH) {
209  spUserData->uiRuleError++;
210  vSynPushError(spData, spData->uiParserOffset,
211  "expected open case-insensitive literal string closure not found");
212  }
213 }
214 static void vClsOpen(callback_data* spData) {
215  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
216  if (spData->uiParserState == ID_MATCH) {
217  spUserData->spTopAlt->uiClsOpen = spData->uiParserOffset;
218  if (spUserData->bStrict) {
219  spUserData->uiRuleError++;
220  vSynPushError(spData, spData->uiParserOffset,
221  "case-sensitive literal string ('') found and strict ABNF specified");
222  }
223  }
224 }
225 static void vClsString(callback_data* spData) {
226  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
227  if (spData->uiParserState == ID_MATCH) {
228  if (spUserData->spTopAlt->uiStringTab) {
229  spUserData->uiRuleError++;
230  vSynPushError(spData, spData->uiParserOffset,
231  "tab (\\t or 0x09) not allowed in case-sensitive literal string (see RFC 5234, char-val)");
232  spUserData->spTopAlt->uiStringTab = APG_FALSE;
233  }
234  }
235 }
236 static void vClsClose(callback_data* spData) {
237  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
238  if (spData->uiParserState == ID_MATCH) {
239  spUserData->spTopAlt->uiClsOpen = APG_FALSE;
240  } else if (spData->uiParserState == ID_NOMATCH) {
241  spUserData->uiRuleError++;
242  vSynPushError(spData, spData->uiParserOffset, "expected open case-sensitive literal string closure not found");
243  }
244 }
245 static void vProseValOpen(callback_data* spData) {
246  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
247  if (spData->uiParserState == ID_MATCH) {
248  spUserData->spTopAlt->uiProseValOpen = spData->uiParserOffset;
249  vSynPushError(spData, spData->uiParserOffset,
250  "prose-val found. Defined in RFC 5234 but cannot be parsed.)");
251  }
252 }
253 static void vProseValString(callback_data* spData) {
254  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
255  if (spData->uiParserState == ID_MATCH) {
256  if (spUserData->spTopAlt->uiStringTab) {
257  spUserData->uiRuleError++;
258  vSynPushError(spData, spData->uiParserOffset,
259  "tab (\\t or 0x09) not allowed in prose value (see RFC 5234, prose-val)");
260  spUserData->spTopAlt->uiStringTab = APG_FALSE;
261  }
262  }
263 }
264 static void vProseValClose(callback_data* spData) {
265  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
266  if (spData->uiParserState == ID_MATCH) {
267  spUserData->spTopAlt->uiProseValOpen = APG_FALSE;
268  } else if (spData->uiParserState == ID_NOMATCH) {
269  spUserData->uiRuleError++;
270  vSynPushError(spData, spData->uiParserOffset, "expected open prose value closure not found");
271  }
272 }
273 static void vGroupOpen(callback_data* spData) {
274  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
275  if (spData->uiParserState == ID_MATCH) {
276  spUserData->spTopAlt = (alt_data*) vpVecPush(spUserData->vpAltStack, NULL);
277  memset((void*) spUserData->spTopAlt, 0, sizeof(*spUserData->spTopAlt));
278  spUserData->spTopAlt->uiGroupOpen = spData->uiParserOffset;
279  }
280 }
281 static void vGroupClose(callback_data* spData) {
282  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
283  if (spData->uiParserState == ID_NOMATCH) {
284  vSynPushError(spData, spData->uiParserOffset, "open group closure expected but not found");
285  vpVecPop(spUserData->vpAltStack);
286  spUserData->spTopAlt = vpVecFirst(spUserData->vpAltStack);
287  spUserData->uiRuleError++;
288  } else if (spData->uiParserState == ID_MATCH) {
289  vpVecPop(spUserData->vpAltStack);
290  spUserData->spTopAlt = vpVecFirst(spUserData->vpAltStack);
291  }
292 }
293 static void vOptionOpen(callback_data* spData) {
294  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
295  spUserData->spTopAlt = (alt_data*) vpVecPush(spUserData->vpAltStack, NULL);
296  memset((void*) spUserData->spTopAlt, 0, sizeof(*spUserData->spTopAlt));
297  spUserData->spTopAlt->uiOptionOpen = spData->uiParserOffset;
298 }
299 static void vOptionClose(callback_data* spData) {
300  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
301  if (spData->uiParserState == ID_NOMATCH) {
302  vSynPushError(spData, spData->uiParserOffset, "open option closure expected but not found");
303  vpVecPop(spUserData->vpAltStack);
304  spUserData->spTopAlt = vpVecFirst(spUserData->vpAltStack);
305  spUserData->uiRuleError++;
306  } else if (spData->uiParserState == ID_MATCH) {
307  vpVecPop(spUserData->vpAltStack);
308  spUserData->spTopAlt = vpVecFirst(spUserData->vpAltStack);
309  }
310 }
311 static void vBasicElementError(callback_data* spData) {
312  syntax_data* spUserData = (syntax_data*) spData->vpUserData;
313  if (spData->uiParserState == ID_MATCH) {
314  if (!spUserData->uiRuleError++) {
315  vSynPushError(spData, spData->uiParserOffset, "malformed element found");
316  }
317  }
318 }
319 static void vLineEndError(callback_data* spData) {
320  if (spData->uiParserState == ID_MATCH) {
321  vSynPushError(spData, spData->uiParserOffset, "malformed element found");
322  vSynPushError(spData, spData->uiParserOffset,
323  "line end expected not found, possibly some extraneous after alternation and before line end");
324  }
325 }
329 void vSabnfGrammarRuleCallbacks(void* vpParserCtx) {
330  aint ui;
332  cb[SABNF_GRAMMAR_ABGOP] = vAbgOp;
333  cb[SABNF_GRAMMAR_AENOP] = vAenOp;
334  cb[SABNF_GRAMMAR_ALPHANUM] = NULL;
335  cb[SABNF_GRAMMAR_ALTERNATION] = NULL;
336  cb[SABNF_GRAMMAR_ALTOP] = NULL;
337  cb[SABNF_GRAMMAR_ANDOP] = vAndOp;
338  cb[SABNF_GRAMMAR_BASICELEMENT] = NULL;
339  cb[SABNF_GRAMMAR_BASICELEMENTERR] = vBasicElementError;
340  cb[SABNF_GRAMMAR_BIN] = NULL;
341  cb[SABNF_GRAMMAR_BKAOP] = vBkaOp;
342  cb[SABNF_GRAMMAR_BKNOP] = vBknOp;
343  cb[SABNF_GRAMMAR_BKR_NAME] = NULL;
344  cb[SABNF_GRAMMAR_BKRMODIFIER] = NULL;
345  cb[SABNF_GRAMMAR_BKROP] = vBkrOp;
346  cb[SABNF_GRAMMAR_BLANKLINE] = NULL;
347  cb[SABNF_GRAMMAR_BMAX] = NULL;
348  cb[SABNF_GRAMMAR_BMIN] = NULL;
349  cb[SABNF_GRAMMAR_BNUM] = NULL;
350  cb[SABNF_GRAMMAR_BSTRING] = NULL;
351  cb[SABNF_GRAMMAR_CATOP] = NULL;
352  cb[SABNF_GRAMMAR_CI] = NULL;
353  cb[SABNF_GRAMMAR_CLSCLOSE] = vClsClose;
354  cb[SABNF_GRAMMAR_CLSOP] = NULL;
355  cb[SABNF_GRAMMAR_CLSOPEN] = vClsOpen;
356  cb[SABNF_GRAMMAR_CLSSTRING] = vClsString;
357  cb[SABNF_GRAMMAR_COMMENT] = NULL;
358  cb[SABNF_GRAMMAR_CONCATENATION] = NULL;
359  cb[SABNF_GRAMMAR_CS] = NULL;
360  cb[SABNF_GRAMMAR_DEC] = NULL;
361  cb[SABNF_GRAMMAR_DEFINED] = NULL;
362  cb[SABNF_GRAMMAR_DEFINEDAS] = NULL;
363  cb[SABNF_GRAMMAR_DEFINEDASERROR] = vDefinedAsError;
364  cb[SABNF_GRAMMAR_DEFINEDASTEST] = NULL;
365  cb[SABNF_GRAMMAR_DMAX] = NULL;
366  cb[SABNF_GRAMMAR_DMIN] = NULL;
367  cb[SABNF_GRAMMAR_DNUM] = NULL;
368  cb[SABNF_GRAMMAR_DSTRING] = NULL;
369  cb[SABNF_GRAMMAR_ENAME] = NULL;
370  cb[SABNF_GRAMMAR_FILE] = vFile;
371  cb[SABNF_GRAMMAR_GROUP] = NULL;
372  cb[SABNF_GRAMMAR_GROUPCLOSE] = vGroupClose;
373  cb[SABNF_GRAMMAR_GROUPERROR] = NULL;
374  cb[SABNF_GRAMMAR_GROUPOPEN] = vGroupOpen;
375  cb[SABNF_GRAMMAR_HEX] = NULL;
376  cb[SABNF_GRAMMAR_INCALT] = NULL;
377  cb[SABNF_GRAMMAR_LINECONTINUE] = NULL;
378  cb[SABNF_GRAMMAR_LINEEND] = NULL;
379  cb[SABNF_GRAMMAR_LINEENDERROR] = vLineEndError;
380  cb[SABNF_GRAMMAR_MODIFIER] = NULL;
381  cb[SABNF_GRAMMAR_NOTOP] = vNotOp;
382  cb[SABNF_GRAMMAR_OPTION] = NULL;
383  cb[SABNF_GRAMMAR_OPTIONCLOSE] = vOptionClose;
384  cb[SABNF_GRAMMAR_OPTIONERROR] = NULL;
385  cb[SABNF_GRAMMAR_OPTIONOPEN] = vOptionOpen;
386  cb[SABNF_GRAMMAR_OWSP] = NULL;
387  cb[SABNF_GRAMMAR_PM] = NULL;
388  cb[SABNF_GRAMMAR_PREDICATE] = NULL;
389  cb[SABNF_GRAMMAR_PROSVAL] = NULL;
390  cb[SABNF_GRAMMAR_PROSVALCLOSE] = vProseValClose;
391  cb[SABNF_GRAMMAR_PROSVALOPEN] = vProseValOpen;
392  cb[SABNF_GRAMMAR_PROSVALSTRING] = vProseValString;
393  cb[SABNF_GRAMMAR_REP_MAX] = NULL;
394  cb[SABNF_GRAMMAR_REP_MIN] = NULL;
395  cb[SABNF_GRAMMAR_REP_MIN_MAX] = NULL;
396  cb[SABNF_GRAMMAR_REP_NUM] = NULL;
397  cb[SABNF_GRAMMAR_REPETITION] = NULL;
398  cb[SABNF_GRAMMAR_REPOP] = NULL;
399  cb[SABNF_GRAMMAR_RNAME] = NULL;
400  cb[SABNF_GRAMMAR_RNMOP] = NULL;
401  cb[SABNF_GRAMMAR_RULE] = vRule;
402  cb[SABNF_GRAMMAR_RULEERROR] = vRuleError;
403  cb[SABNF_GRAMMAR_RULELOOKUP] = NULL;
404  cb[SABNF_GRAMMAR_RULENAME] = NULL;
405  cb[SABNF_GRAMMAR_RULENAMEERROR] = vRuleNameError;
406  cb[SABNF_GRAMMAR_RULENAMETEST] = NULL;
407  cb[SABNF_GRAMMAR_SPACE] = NULL;
408  cb[SABNF_GRAMMAR_STRINGTAB] = vStringTab;
409  cb[SABNF_GRAMMAR_TBSOP] = NULL;
410  cb[SABNF_GRAMMAR_TLSCASE] = NULL;
411  cb[SABNF_GRAMMAR_TLSCLOSE] = vTlsClose;
412  cb[SABNF_GRAMMAR_TLSOP] = NULL;
413  cb[SABNF_GRAMMAR_TLSOPEN] = vTlsOpen;
414  cb[SABNF_GRAMMAR_TLSSTRING] = vTlsString;
415  cb[SABNF_GRAMMAR_TRGOP] = NULL;
416  cb[SABNF_GRAMMAR_UDT_EMPTY] = NULL;
417  cb[SABNF_GRAMMAR_UDT_NON_EMPTY] = NULL;
418  cb[SABNF_GRAMMAR_UDTOP] = vUdtOp;
419  cb[SABNF_GRAMMAR_UM] = NULL;
420  cb[SABNF_GRAMMAR_UNAME] = NULL;
421  cb[SABNF_GRAMMAR_WSP] = NULL;
422  cb[SABNF_GRAMMAR_XMAX] = NULL;
423  cb[SABNF_GRAMMAR_XMIN] = NULL;
424  cb[SABNF_GRAMMAR_XNUM] = NULL;
425  cb[SABNF_GRAMMAR_XSTRING] = NULL;
426  for (ui = 0; ui < (aint) RULE_COUNT_SABNF_GRAMMAR; ui += 1) {
427  vParserSetRuleCallback(vpParserCtx, ui, cb[ui]);
428  }
429 }
syntax_data
The syntax data that gets passed to the syntax parser's callback functions.
Definition: syntax.h:44
SABNF_GRAMMAR_TLSCASE
#define SABNF_GRAMMAR_TLSCASE
Definition: sabnf-grammar.h:117
SABNF_GRAMMAR_TLSCLOSE
#define SABNF_GRAMMAR_TLSCLOSE
Definition: sabnf-grammar.h:118
SABNF_GRAMMAR_RULE
#define SABNF_GRAMMAR_RULE
Definition: sabnf-grammar.h:108
SABNF_GRAMMAR_REP_NUM
#define SABNF_GRAMMAR_REP_NUM
Definition: sabnf-grammar.h:103
syntax_data::spApi
api * spApi
Pointer to the parent API object context.
Definition: syntax.h:45
SABNF_GRAMMAR_NOTOP
#define SABNF_GRAMMAR_NOTOP
Definition: sabnf-grammar.h:88
alt_data::uiStringTab
aint uiStringTab
Definition: apip.h:48
SABNF_GRAMMAR_RULENAMEERROR
#define SABNF_GRAMMAR_RULENAMEERROR
Definition: sabnf-grammar.h:112
SABNF_GRAMMAR_COMMENT
#define SABNF_GRAMMAR_COMMENT
Definition: sabnf-grammar.h:64
api::vpLog
void * vpLog
A msglog context for error reporting.
Definition: apip.h:179
SABNF_GRAMMAR_GROUPERROR
#define SABNF_GRAMMAR_GROUPERROR
Definition: sabnf-grammar.h:80
callback_data::uiParserOffset
aint uiParserOffset
[read only] Offset from acpString to the first character to match
Definition: parser.h:160
SABNF_GRAMMAR_UDTOP
#define SABNF_GRAMMAR_UDTOP
Definition: sabnf-grammar.h:125
SABNF_GRAMMAR_XSTRING
#define SABNF_GRAMMAR_XSTRING
Definition: sabnf-grammar.h:132
SABNF_GRAMMAR_TLSOPEN
#define SABNF_GRAMMAR_TLSOPEN
Definition: sabnf-grammar.h:120
callback_data::uiParserState
aint uiParserState
[read only] ID_ACTIVE if the parser is going down the tree. ID_MATCH or ID_NOMATCH if coming up the t...
Definition: parser.h:158
syntax_data::uiRulesFound
aint uiRulesFound
True if rules have been found in the grammar.
Definition: syntax.h:50
SABNF_GRAMMAR_OPTIONERROR
#define SABNF_GRAMMAR_OPTIONERROR
Definition: sabnf-grammar.h:91
SABNF_GRAMMAR_ALPHANUM
#define SABNF_GRAMMAR_ALPHANUM
Definition: sabnf-grammar.h:41
SABNF_GRAMMAR_REPETITION
#define SABNF_GRAMMAR_REPETITION
Definition: sabnf-grammar.h:104
SABNF_GRAMMAR_WSP
#define SABNF_GRAMMAR_WSP
Definition: sabnf-grammar.h:128
syntax_data::vpAltStack
void * vpAltStack
A stack vector to manage open ALT operators.
Definition: syntax.h:47
SABNF_GRAMMAR_DEC
#define SABNF_GRAMMAR_DEC
Definition: sabnf-grammar.h:67
apip.h
Private header file for the APG API suite of functions.
SABNF_GRAMMAR_DEFINEDASERROR
#define SABNF_GRAMMAR_DEFINEDASERROR
Definition: sabnf-grammar.h:70
SABNF_GRAMMAR_OPTIONCLOSE
#define SABNF_GRAMMAR_OPTIONCLOSE
Definition: sabnf-grammar.h:90
vParserSetRuleCallback
void vParserSetRuleCallback(void *vpCtx, aint uiRuleId, parser_callback pfnCallback)
Set a call back function for a specific rule.
Definition: parser.c:386
SABNF_GRAMMAR_INCALT
#define SABNF_GRAMMAR_INCALT
Definition: sabnf-grammar.h:83
SABNF_GRAMMAR_GROUP
#define SABNF_GRAMMAR_GROUP
Definition: sabnf-grammar.h:78
SABNF_GRAMMAR_CLSOP
#define SABNF_GRAMMAR_CLSOP
Definition: sabnf-grammar.h:61
alt_data
Used by syntax.c but needed here for constructor/destructor.
Definition: apip.h:40
SABNF_GRAMMAR_HEX
#define SABNF_GRAMMAR_HEX
Definition: sabnf-grammar.h:82
alt_data::uiTlsOpen
aint uiTlsOpen
Definition: apip.h:45
SABNF_GRAMMAR_ALTOP
#define SABNF_GRAMMAR_ALTOP
Definition: sabnf-grammar.h:43
SABNF_GRAMMAR_GROUPCLOSE
#define SABNF_GRAMMAR_GROUPCLOSE
Definition: sabnf-grammar.h:79
SABNF_GRAMMAR_DMIN
#define SABNF_GRAMMAR_DMIN
Definition: sabnf-grammar.h:73
SABNF_GRAMMAR_RULENAMETEST
#define SABNF_GRAMMAR_RULENAMETEST
Definition: sabnf-grammar.h:113
XTHROW
#define XTHROW(ctx, msg)
Exception throw macro.
Definition: exception.h:67
parser_callback
void(* parser_callback)(callback_data *spData)
User-written callback function prototype.
Definition: parser.h:178
vpVecPop
void * vpVecPop(void *vpCtx)
Pops one element from the end of the array.
Definition: vector.c:250
syntax_data::spTopAlt
alt_data * spTopAlt
Pointer to the top of the ALT stack.
Definition: syntax.h:48
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
SABNF_GRAMMAR_BKROP
#define SABNF_GRAMMAR_BKROP
Definition: sabnf-grammar.h:52
sabnf-grammar.h
SABNF_GRAMMAR_OPTIONOPEN
#define SABNF_GRAMMAR_OPTIONOPEN
Definition: sabnf-grammar.h:92
SABNF_GRAMMAR_BASICELEMENT
#define SABNF_GRAMMAR_BASICELEMENT
Definition: sabnf-grammar.h:45
SABNF_GRAMMAR_UNAME
#define SABNF_GRAMMAR_UNAME
Definition: sabnf-grammar.h:127
SABNF_GRAMMAR_SPACE
#define SABNF_GRAMMAR_SPACE
Definition: sabnf-grammar.h:114
SABNF_GRAMMAR_REPOP
#define SABNF_GRAMMAR_REPOP
Definition: sabnf-grammar.h:105
syntax_data::uiErrorsFound
aint uiErrorsFound
True if any errors in the grammar have been found.
Definition: syntax.h:51
SABNF_GRAMMAR_BMAX
#define SABNF_GRAMMAR_BMAX
Definition: sabnf-grammar.h:54
SABNF_GRAMMAR_CLSCLOSE
#define SABNF_GRAMMAR_CLSCLOSE
Definition: sabnf-grammar.h:60
SABNF_GRAMMAR_CI
#define SABNF_GRAMMAR_CI
Definition: sabnf-grammar.h:59
SABNF_GRAMMAR_STRINGTAB
#define SABNF_GRAMMAR_STRINGTAB
Definition: sabnf-grammar.h:115
SABNF_GRAMMAR_DEFINEDAS
#define SABNF_GRAMMAR_DEFINEDAS
Definition: sabnf-grammar.h:69
SABNF_GRAMMAR_RULENAME
#define SABNF_GRAMMAR_RULENAME
Definition: sabnf-grammar.h:111
ID_ACTIVE
#define ID_ACTIVE
indicates active parser state, parser has just entered the node and is moving down the parse tree
Definition: parser.h:72
SABNF_GRAMMAR_DSTRING
#define SABNF_GRAMMAR_DSTRING
Definition: sabnf-grammar.h:75
SABNF_GRAMMAR_PM
#define SABNF_GRAMMAR_PM
Definition: sabnf-grammar.h:94
SABNF_GRAMMAR_BKNOP
#define SABNF_GRAMMAR_BKNOP
Definition: sabnf-grammar.h:49
alt_data::uiGroupOpen
aint uiGroupOpen
Definition: apip.h:41
ID_MATCH
#define ID_MATCH
indicates a matched phrase parser state on return from parse tree below this node
Definition: parser.h:73
luint
uintmax_t luint
luint is used to cast integers suitable for the %"PRIuMAX" printf format.
Definition: apg.h:133
SABNF_GRAMMAR_UM
#define SABNF_GRAMMAR_UM
Definition: sabnf-grammar.h:126
SABNF_GRAMMAR_BKRMODIFIER
#define SABNF_GRAMMAR_BKRMODIFIER
Definition: sabnf-grammar.h:51
cpMsgsFirst
const char * cpMsgsFirst(void *vpCtx)
Get a pointer to the first logged message, if any.
Definition: msglog.c:164
callback_data
The data struct passed to each callback function.
Definition: parser.h:134
cpMsgsNext
const char * cpMsgsNext(void *vpCtx)
Get a pointer to the next logged message, if any.
Definition: msglog.c:185
RULE_COUNT_SABNF_GRAMMAR
#define RULE_COUNT_SABNF_GRAMMAR
Definition: sabnf-grammar.h:133
SABNF_GRAMMAR_CONCATENATION
#define SABNF_GRAMMAR_CONCATENATION
Definition: sabnf-grammar.h:65
SABNF_GRAMMAR_BNUM
#define SABNF_GRAMMAR_BNUM
Definition: sabnf-grammar.h:56
SABNF_GRAMMAR_TLSSTRING
#define SABNF_GRAMMAR_TLSSTRING
Definition: sabnf-grammar.h:121
SABNF_GRAMMAR_PROSVALSTRING
#define SABNF_GRAMMAR_PROSVALSTRING
Definition: sabnf-grammar.h:99
SABNF_GRAMMAR_GROUPOPEN
#define SABNF_GRAMMAR_GROUPOPEN
Definition: sabnf-grammar.h:81
vpVecFirst
void * vpVecFirst(void *vpCtx)
Get the first element one the vector. The vector is not altered.
Definition: vector.c:326
SABNF_GRAMMAR_MODIFIER
#define SABNF_GRAMMAR_MODIFIER
Definition: sabnf-grammar.h:87
SABNF_GRAMMAR_ABGOP
#define SABNF_GRAMMAR_ABGOP
Definition: sabnf-grammar.h:39
SABNF_GRAMMAR_RULELOOKUP
#define SABNF_GRAMMAR_RULELOOKUP
Definition: sabnf-grammar.h:110
SABNF_GRAMMAR_LINEENDERROR
#define SABNF_GRAMMAR_LINEENDERROR
Definition: sabnf-grammar.h:86
SABNF_GRAMMAR_DMAX
#define SABNF_GRAMMAR_DMAX
Definition: sabnf-grammar.h:72
SABNF_GRAMMAR_LINEEND
#define SABNF_GRAMMAR_LINEEND
Definition: sabnf-grammar.h:85
SABNF_GRAMMAR_LINECONTINUE
#define SABNF_GRAMMAR_LINECONTINUE
Definition: sabnf-grammar.h:84
SABNF_GRAMMAR_BASICELEMENTERR
#define SABNF_GRAMMAR_BASICELEMENTERR
Definition: sabnf-grammar.h:46
vSabnfGrammarRuleCallbacks
void vSabnfGrammarRuleCallbacks(void *vpParserCtx)
Set the parser's rule callback functions for the syntax phase.
Definition: syntax-callbacks.c:329
callback_data::vpUserData
void * vpUserData
[input/output] User-defined data passed to to the parser in parser_config.
Definition: parser.h:136
SABNF_GRAMMAR_TLSOP
#define SABNF_GRAMMAR_TLSOP
Definition: sabnf-grammar.h:119
APG_TRUE
#define APG_TRUE
Definition: apg.h:291
SABNF_GRAMMAR_PROSVALOPEN
#define SABNF_GRAMMAR_PROSVALOPEN
Definition: sabnf-grammar.h:98
SABNF_GRAMMAR_CLSOPEN
#define SABNF_GRAMMAR_CLSOPEN
Definition: sabnf-grammar.h:62
syntax.h
Header file for the syntax phase functions.
SABNF_GRAMMAR_CS
#define SABNF_GRAMMAR_CS
Definition: sabnf-grammar.h:66
SABNF_GRAMMAR_UDT_NON_EMPTY
#define SABNF_GRAMMAR_UDT_NON_EMPTY
Definition: sabnf-grammar.h:124
SABNF_GRAMMAR_BSTRING
#define SABNF_GRAMMAR_BSTRING
Definition: sabnf-grammar.h:57
SABNF_GRAMMAR_OPTION
#define SABNF_GRAMMAR_OPTION
Definition: sabnf-grammar.h:89
SABNF_GRAMMAR_TRGOP
#define SABNF_GRAMMAR_TRGOP
Definition: sabnf-grammar.h:122
SABNF_GRAMMAR_FILE
#define SABNF_GRAMMAR_FILE
Definition: sabnf-grammar.h:77
SABNF_GRAMMAR_RULEERROR
#define SABNF_GRAMMAR_RULEERROR
Definition: sabnf-grammar.h:109
SABNF_GRAMMAR_DNUM
#define SABNF_GRAMMAR_DNUM
Definition: sabnf-grammar.h:74
SABNF_GRAMMAR_XMIN
#define SABNF_GRAMMAR_XMIN
Definition: sabnf-grammar.h:130
SABNF_GRAMMAR_CATOP
#define SABNF_GRAMMAR_CATOP
Definition: sabnf-grammar.h:58
alt_data::uiClsOpen
aint uiClsOpen
Definition: apip.h:46
SABNF_GRAMMAR_REP_MAX
#define SABNF_GRAMMAR_REP_MAX
Definition: sabnf-grammar.h:100
SABNF_GRAMMAR_ALTERNATION
#define SABNF_GRAMMAR_ALTERNATION
Definition: sabnf-grammar.h:42
SABNF_GRAMMAR_BIN
#define SABNF_GRAMMAR_BIN
Definition: sabnf-grammar.h:47
SABNF_GRAMMAR_BKAOP
#define SABNF_GRAMMAR_BKAOP
Definition: sabnf-grammar.h:48
ID_NOMATCH
#define ID_NOMATCH
indicates that no phrase was matched on return from parse tree below this node
Definition: parser.h:74
SABNF_GRAMMAR_PREDICATE
#define SABNF_GRAMMAR_PREDICATE
Definition: sabnf-grammar.h:95
SABNF_GRAMMAR_BKR_NAME
#define SABNF_GRAMMAR_BKR_NAME
Definition: sabnf-grammar.h:50
syntax_data::uiRuleError
aint uiRuleError
True if an error has been found in the rule definition/.
Definition: syntax.h:49
syntax_data::bStrict
abool bStrict
True if the grammar is to be treated as strict RFC5234 ABNF. No superset operators allowed.
Definition: syntax.h:46
SABNF_GRAMMAR_REP_MIN
#define SABNF_GRAMMAR_REP_MIN
Definition: sabnf-grammar.h:101
alt_data::uiOptionOpen
aint uiOptionOpen
Definition: apip.h:43
SABNF_GRAMMAR_ANDOP
#define SABNF_GRAMMAR_ANDOP
Definition: sabnf-grammar.h:44
SABNF_GRAMMAR_XNUM
#define SABNF_GRAMMAR_XNUM
Definition: sabnf-grammar.h:131
SABNF_GRAMMAR_OWSP
#define SABNF_GRAMMAR_OWSP
Definition: sabnf-grammar.h:93
alt_data::uiProseValOpen
aint uiProseValOpen
Definition: apip.h:47
api::spException
exception * spException
Definition: apip.h:125
SABNF_GRAMMAR_RNMOP
#define SABNF_GRAMMAR_RNMOP
Definition: sabnf-grammar.h:107
SABNF_GRAMMAR_BMIN
#define SABNF_GRAMMAR_BMIN
Definition: sabnf-grammar.h:55
SABNF_GRAMMAR_DEFINEDASTEST
#define SABNF_GRAMMAR_DEFINEDASTEST
Definition: sabnf-grammar.h:71
vLineError
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...
Definition: input.c:383
SABNF_GRAMMAR_TBSOP
#define SABNF_GRAMMAR_TBSOP
Definition: sabnf-grammar.h:116
SABNF_GRAMMAR_PROSVAL
#define SABNF_GRAMMAR_PROSVAL
Definition: sabnf-grammar.h:96
SABNF_GRAMMAR_XMAX
#define SABNF_GRAMMAR_XMAX
Definition: sabnf-grammar.h:129
SABNF_GRAMMAR_ENAME
#define SABNF_GRAMMAR_ENAME
Definition: sabnf-grammar.h:76
SABNF_GRAMMAR_RNAME
#define SABNF_GRAMMAR_RNAME
Definition: sabnf-grammar.h:106
vpVecPush
void * vpVecPush(void *vpCtx, void *vpElement)
Adds one element to the end of the array.
Definition: vector.c:193
SABNF_GRAMMAR_BLANKLINE
#define SABNF_GRAMMAR_BLANKLINE
Definition: sabnf-grammar.h:53
SABNF_GRAMMAR_CLSSTRING
#define SABNF_GRAMMAR_CLSSTRING
Definition: sabnf-grammar.h:63
SABNF_GRAMMAR_PROSVALCLOSE
#define SABNF_GRAMMAR_PROSVALCLOSE
Definition: sabnf-grammar.h:97
SABNF_GRAMMAR_DEFINED
#define SABNF_GRAMMAR_DEFINED
Definition: sabnf-grammar.h:68
SABNF_GRAMMAR_AENOP
#define SABNF_GRAMMAR_AENOP
Definition: sabnf-grammar.h:40
api.h
Public header file for the APG API suite of functions.
SABNF_GRAMMAR_REP_MIN_MAX
#define SABNF_GRAMMAR_REP_MIN_MAX
Definition: sabnf-grammar.h:102
APG_FALSE
#define APG_FALSE
Definition: apg.h:292
SABNF_GRAMMAR_UDT_EMPTY
#define SABNF_GRAMMAR_UDT_EMPTY
Definition: sabnf-grammar.h:123
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.