Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
Functions
parser.c File Reference

The SABNF parser. More...

#include "./lib.h"
#include "./parserp.h"
#include "./operators.h"
#include "./tracep.h"
#include "./statsp.h"
#include "./backref.h"
#include "./backrefu.h"
#include "./backrefp.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Functions

void * vpParserCtor (exception *spException, void *vpParserInit)
 The parser's constructor for file initialization data. More...
 
void * vpParserAllocCtor (exception *spException, void *vpParserInit, abool bAllocateTables)
 The parser constructor. More...
 
void vParserDtor (void *vpCtx)
 Clears the parser component's context and frees all heap memory associated with this parser. More...
 
void vParserParse (void *vpCtx, parser_config *spConfig, parser_state *spState)
 Parse an input string of alphabet characters. More...
 
void vParserSetRuleCallback (void *vpCtx, aint uiRuleId, parser_callback pfnCallback)
 Set a call back function for a specific rule. More...
 
void vParserSetUdtCallback (void *vpCtx, aint uiUdtId, parser_callback pfnCallback)
 Set a call back function for a specific UDT. More...
 
abool bParserValidate (void *vpCtx)
 Validate the context pointer of a parser. More...
 
aint uiParserRuleLookup (void *vpCtx, const char *cpRuleName)
 Find the rule index corresponding to a rule name. More...
 
const char * cpParserRuleName (void *vpCtx, aint uiRuleIndex)
 Find the rule name from the corresponding index. More...
 
const char * cpParserUdtName (void *vpCtx, aint uiUdtIndex)
 Find the UDT name corresponding to a UDT index. More...
 

Detailed Description

The SABNF parser.

Definition in file parser.c.

Function Documentation

◆ bParserValidate()

abool bParserValidate ( void *  vpCtx)

Validate the context pointer of a parser.

Parameters
vpCtxPointer to a supposedly valid parser context previously returned from vpParserCtor() or vpApiOutputParser().
Returns
True if the context pointer is valid, false otherwise.

Definition at line 422 of file parser.c.

◆ cpParserRuleName()

const char* cpParserRuleName ( void *  vpCtx,
aint  uiRuleIndex 
)

Find the rule name from the corresponding index.

A rule's index is the 0-based order in which it appears in the SABNF grammar. Used in many places instead of the name to identify a rule. The parser's start rule (parser_config) would be a prime example.

Parameters
vpCtxPointer to a valid parser context previously returned from vpParserCtor() or vpApiOutputParser(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
uiRuleIndxIndex (order of appearance in the SABNF grammar) of the rule name to look up
Returns
Pointer to the rule name if successful. NULL if the index is out of range.

Definition at line 469 of file parser.c.

◆ cpParserUdtName()

const char* cpParserUdtName ( void *  vpCtx,
aint  uiUdtIndex 
)

Find the UDT name corresponding to a UDT index.

A UDT's index is the 0-based order in which it appears in the SABNF grammar. Used in some places instead of the name to identify a UDT. vParserSetUdtCallback() would be an example.

Parameters
vpCtxPointer to a valid parser context previously returned from vpParserCtor() or vpApiOutputParser(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
uiUdtIndexIndex of the UDT to look up.
Returns
Pointer to the UDT name if successful. NULL if the index is out of range.

Definition at line 491 of file parser.c.

◆ uiParserRuleLookup()

aint uiParserRuleLookup ( void *  vpCtx,
const char *  cpRuleName 
)

Find the rule index corresponding to a rule name.

A rule's index is the 0-based order in which it appears in the SABNF grammar. Used in many places instead of the name to identify a rule. The parser's start rule (parser_config) would be a prime example.

Parameters
vpCtxPointer to a valid parser context previously returned from vpParserCtor() or vpApiOutputParser(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
cpRuleNameName of the rule to look up. Case insensitive.
Returns
The rule index if successful. APG_UNDEFINED if the name does not appear in the SABNF grammar.

Definition at line 440 of file parser.c.

◆ vParserDtor()

void vParserDtor ( void *  vpCtx)

Clears the parser component's context and frees all heap memory associated with this parser.

Parameters
vpCtxa parser context pointer previously returned from vpParserCtor() or vpApiOutputParser(). NULL is silently ignored. However, non-NULL values must be valid parser context pointers.

Definition at line 245 of file parser.c.

◆ vParserParse()

void vParserParse ( void *  vpCtx,
parser_config spConfig,
parser_state spState 
)

Parse an input string of alphabet characters.

Parameters
vpCtxPointer to a valid parser context previously returned from vpParserCtor() or vpApiOutputParser(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
spConfigPointer to the configuration defining the input string and other parsing parameters. See parser_config.
spStatePointer to a parser state structure. See parser_state.
Returns
The parser state is returned in the caller's state structure, spState.

Definition at line 268 of file parser.c.

◆ vParserSetRuleCallback()

void vParserSetRuleCallback ( void *  vpCtx,
aint  uiRuleId,
parser_callback  pfnCallback 
)

Set a call back function for a specific rule.

Parameters
vpCtxPointer to a valid parser context previously returned from vpParserCtor() or vpApiOutputParser(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
uiRuleIdThe index of the rule to set the call back function for.
pfnCallbackPointer to the call back function.

Definition at line 386 of file parser.c.

◆ vParserSetUdtCallback()

void vParserSetUdtCallback ( void *  vpCtx,
aint  uiUdtId,
parser_callback  pfnCallback 
)

Set a call back function for a specific UDT.

Note that the parser, vParserParse(), checks on initialization that all UDTs in the SABNF grammar have call back functions set.

Parameters
vpCtxPointer to a valid parser context previously returned from vpParserCtor() or vpApiOutputParser(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
uiUdtIdThe index of the UDT to set the call back function for.
pfnCallbackPointer to the call back function.

Definition at line 407 of file parser.c.

◆ vpParserAllocCtor()

void* vpParserAllocCtor ( exception spException,
void *  vpParserInit,
abool  bAllocateTables 
)

The parser constructor.

The generator can generate the parser's initialization data in one of two ways.

  • With vApiOutput() the data is in an C-language code file, "namespace.c". When constructing a parser from the file data, no further memory allocations for it are necessary.
  • With vpApiOutputParser() the data is in the API object's context and must be copied to the parser's context to separate it completely from the API. That is, the parser's context must remain complete and valid even if the API context is destroyed. This function has a switch to chose between the two.
Parameters
spExceptionPointer to a valid exception structure initialized with vExCtor() or XCTOR(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
vpParserInitPointer to the initialization data.
bAllocateTablesIf true, memory is allocated to copy the initialization data into the parser'scontext. If false, no memory allocation and copying is done.
Returns
Pointer to a parser context. Exceptions thrown on errors.

Definition at line 88 of file parser.c.

◆ vpParserCtor()

void* vpParserCtor ( exception spException,
void *  vpParserInit 
)

The parser's constructor for file initialization data.

This function is used to construct a parser from grammar file, "namespace.c", generated by vApiOutput().

Parameters
spExceptionPointer to a valid exception structure initialized with vExCtor() or XCTOR(). If not valid, the application will silently exit with a BAD_CONTEXT exit code.
vpParserInit- Pointer to the initialization data in the generated "namespace.c" file.
Returns
Pointer to a parser context. Exceptions thrown on errors.

Definition at line 67 of file parser.c.

APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.