APG
… an ABNF Parser Generator
|
The SABNF parser's public header file. More...
Go to the source code of this file.
Data Structures | |
struct | callback_data |
The data struct passed to each callback function. More... | |
struct | parser_state |
The parser's final state. More... | |
struct | parser_config |
Defines the input string and other configuration parameters for the parser,. More... | |
Macros | |
ABNF Opcode Identifiers | |
These are the unique identifiers of the original 7 ABNF opcodes. | |
#define | ID_ALT 1 |
alternation More... | |
#define | ID_CAT 2 |
concatenation More... | |
#define | ID_REP 3 |
repetition More... | |
#define | ID_RNM 4 |
rule name More... | |
#define | ID_TRG 5 |
terminal range More... | |
#define | ID_TBS 6 |
terminal binary string More... | |
#define | ID_TLS 7 |
terminal literal string More... | |
SABNF Superset Opcode Identifiers | |
These are the unique identifiers of the additional opcodes of the superset SABNF. | |
#define | ID_UDT 8 |
user-defined terminal More... | |
#define | ID_AND 9 |
positive look ahead More... | |
#define | ID_NOT 10 |
negative look ahead More... | |
#define | ID_BKR 11 |
back reference to a previously matched rule or UDT name More... | |
#define | ID_BKA 12 |
positive look behind More... | |
#define | ID_BKN 13 |
negative look behind More... | |
#define | ID_ABG 14 |
anchor - beginning of string More... | |
#define | ID_AEN 15 |
anchor - end of string More... | |
#define | ID_GEN 19 |
general opcode (not SABNF). Serves to locate the ID in any opcode structure and must be larger than all other opcode IDs. One or more arrays may be created of size ID_GEN and data for all other opcodes must fit in the array. More... | |
Parser State Indentifiers | |
These four identifiers are used to indicate the parser state for any node operation in the parse tree. | |
#define | ID_ACTIVE 20 |
indicates active parser state, parser has just entered the node and is moving down the parse tree More... | |
#define | ID_MATCH 21 |
indicates a matched phrase parser state on return from parse tree below this node More... | |
#define | ID_NOMATCH 22 |
indicates that no phrase was matched on return from parse tree below this node More... | |
#define | ID_EMPTY 23 |
indicates a matched empty phrase parser state on return from parse tree below this node More... | |
PPPT Map Values | |
These are the four possible values for a single character in a Partially-Predictive Parsing Table map. | |
#define | ID_PPPT_NOMATCH 0 |
deterministic NOMATCH – there is no chance of a phrase match with this leading character More... | |
#define | ID_PPPT_MATCH 1 |
deterministic MATCH – this character constitutes a single character phrase match of length 1 More... | |
#define | ID_PPPT_EMPTY 2 |
deterministic EMTPY – this is an empty string match, the parse succeeds but the phrase length is 0 More... | |
#define | ID_PPPT_ACTIVE 3 |
non-deterministic – it is not possible to determine a match or not based on this character – the parser will have to do a full, normal parse to find out More... | |
Asymetric Syntax Tree (AST) States and Return Codes | |
These identifiers are used for the traversal direction and return codes in AST call back functions. | |
#define | ID_AST_PRE 30 |
indicates pre-node-traversal AST callback state (down the tree) More... | |
#define | ID_AST_POST 31 |
indicates post-node-traversal AST callback state (up the tree) More... | |
#define | ID_AST_OK 32 |
normal AST callback function return More... | |
#define | ID_AST_SKIP 33 |
on return from AST callback, skip all nodes below (ignored on return from ID_AST_POST state) More... | |
Attribute Rule Types | |
These identifiers indicate the attribute classifications of the grammar's rules. | |
#define | ID_ATTR_N 40 |
rule is non-recursive - never refers to itself More... | |
#define | ID_ATTR_R 41 |
rule is recursive - refers to itself, directly or indirectly, one or more times More... | |
#define | ID_ATTR_MR 42 |
rule is one of a mutually-recursive group (each rule in the group refers to itself and all others) More... | |
Look Ahead and Look Behind (Look Around) Indicators | |
The parser behaves somewhat differently when in a look around state. That is, whether or not there is a look around opcode (AND(&), NOT(!), BKA(&&) or BKN(!!)) in the branch of the parse tree, | |
#define | ID_LOOKAROUND_NONE 50 |
the parser presently is not in look around mode More... | |
#define | ID_LOOKAROUND_AHEAD 51 |
the parser presently is in look ahead mode More... | |
#define | ID_LOOKAROUND_BEHIND 52 |
the parser presently is in look behind mode More... | |
Back Reference Mode and Case Indicators | |
Identifies the case sensitivity and back reference mode of the back reference operator. Back referencing can be either case-sensitive or insensitive and can be either universal- or parent-mode. | |
#define | ID_BKR_MODE_U 60 |
the back reference is universal mode More... | |
#define | ID_BKR_MODE_P 61 |
the back reference is parent mode More... | |
#define | ID_BKR_CASE_S 62 |
the back reference is case sensitive More... | |
#define | ID_BKR_CASE_I 63 |
the back reference is case insensitive More... | |
Typedefs | |
typedef void(* | parser_callback) (callback_data *spData) |
User-written callback function prototype. More... | |
Functions | |
void * | vpParserCtor (exception *spException, void *vpParserInit) |
The parser's constructor for file initialization data. More... | |
void | vParserDtor (void *vpCtx) |
Clears the parser component's context and frees all heap memory associated with this parser. More... | |
abool | bParserValidate (void *vpCtx) |
Validate the context pointer of a parser. More... | |
void | vParserParse (void *vpCtx, parser_config *spConfig, parser_state *spState) |
Parse an input string of alphabet characters. More... | |
aint | uiParserRuleLookup (void *vpCtx, const char *cpRuleName) |
Find the rule index corresponding to a rule name. More... | |
aint | uiParserUdtLookup (void *vpCtx, const char *cpUdtName) |
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... | |
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... | |
The SABNF parser's public header file.
Defines only the macros, structures, typedefs, and function prototypes needed by the user of the parser.
Definition in file parser.h.
#define ID_ACTIVE 20 |
#define ID_AST_POST 31 |
#define ID_AST_PRE 30 |
#define ID_AST_SKIP 33 |
#define ID_ATTR_MR 42 |
#define ID_ATTR_N 40 |
#define ID_ATTR_R 41 |
#define ID_BKR 11 |
#define ID_BKR_CASE_I 63 |
#define ID_BKR_CASE_S 62 |
#define ID_BKR_MODE_U 60 |
#define ID_EMPTY 23 |
#define ID_GEN 19 |
#define ID_LOOKAROUND_AHEAD 51 |
#define ID_LOOKAROUND_BEHIND 52 |
#define ID_LOOKAROUND_NONE 50 |
#define ID_MATCH 21 |
#define ID_NOMATCH 22 |
#define ID_PPPT_ACTIVE 3 |
#define ID_PPPT_EMPTY 2 |
#define ID_PPPT_MATCH 1 |
#define ID_PPPT_NOMATCH 0 |
parser_callback |
User-written callback function prototype.
spData | Callback data supplied by the parser. See callback_data for restrictions. |
abool bParserValidate | ( | void * | vpCtx | ) |
Validate the context pointer of a parser.
vpCtx | Pointer to a supposedly valid parser context previously returned from vpParserCtor() or vpApiOutputParser(). |
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.
vpCtx | Pointer 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. |
uiRuleIndx | Index (order of appearance in the SABNF grammar) of the rule name to look up |
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.
vpCtx | Pointer 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. |
uiUdtIndex | Index of the UDT to look up. |
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.
vpCtx | Pointer 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. |
cpRuleName | Name of the rule to look up. Case insensitive. |
aint uiParserUdtLookup | ( | void * | vpCtx, |
const char * | cpUdtName | ||
) |
void vParserDtor | ( | void * | vpCtx | ) |
Clears the parser component's context and frees all heap memory associated with this parser.
vpCtx | a parser context pointer previously returned from vpParserCtor() or vpApiOutputParser(). NULL is silently ignored. However, non-NULL values must be valid parser context pointers. |
void vParserParse | ( | void * | vpCtx, |
parser_config * | spConfig, | ||
parser_state * | spState | ||
) |
Parse an input string of alphabet characters.
vpCtx | Pointer 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. |
spConfig | Pointer to the configuration defining the input string and other parsing parameters. See parser_config. |
spState | Pointer to a parser state structure. See parser_state. |
void vParserSetRuleCallback | ( | void * | vpCtx, |
aint | uiRuleId, | ||
parser_callback | pfnCallback | ||
) |
Set a call back function for a specific rule.
vpCtx | Pointer 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. |
uiRuleId | The index of the rule to set the call back function for. |
pfnCallback | Pointer to the call back function. |
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.
vpCtx | Pointer 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. |
uiUdtId | The index of the UDT to set the call back function for. |
pfnCallback | Pointer to the call back function. |
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().
spException | Pointer 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. |