APG
… an ABNF Parser Generator
|
Public header file for the APG API suite of functions. More...
Go to the source code of this file.
Data Structures | |
struct | api_attr |
The recursive attributes of a single SABNF grammra rule. More... | |
struct | pppt_size |
Size information for the **P**artially-**P**redictive **P**arsing **T**ables (PPPT) data. More... | |
Functions | |
Construction/Destruction | |
void * | vpApiCtor (exception *spEx) |
Construct an API component context (object). More... | |
void | vApiDtor (void *vpCtx) |
The API component destructor. More... | |
abool | bApiValidate (void *vpCtx) |
Validates an API context pointer. More... | |
void * | vpApiGetErrorLog (void *vpCtx) |
Get the internal message log. More... | |
Input - Getting the Grammar Source | |
This suite of functions is concerned with the input SABNF grammar file. Facilities are available for files, strings, clearing for a new grammar and display of the input grammar. | |
void | vApiInClear (void *vpCtx) |
Clears the input and related memory. More... | |
const char * | cpApiInFile (void *vpCtx, const char *cpFileName) |
Reads an SABNF grammar byte stream from a file. More... | |
const char * | cpApiInString (void *vpCtx, const char *cpString) |
Reads an SABNF grammar byte stream from a string. More... | |
void | vApiInValidate (void *vpCtx, abool bStrict) |
Scans the input SABNF grammar for invalid characters and line ends. More... | |
void | vApiInToAscii (void *vpCtx, const char *cpFileName) |
Display the input lines with line numbers and character offsets. More... | |
void | vApiInToHtml (void *vpCtx, const char *cpFileName, const char *cpTitle) |
Display the input lines with line numbers and character offsets. More... | |
Syntax Analysis of the Grammar | |
The syntax is validated and if valid an Abstract Syntax Tree (AST)is generated. | |
void | vApiSyntax (void *vpCtx, abool bStrict) |
Parse the SABNF grammar to validate that the grammar structure is valid. More... | |
Semantic Analysis of the Grammar | |
The AST from the syntax phase is translated into specific opcode. That is, for each node in the syntax tree, the grammar-specific information necessary to execute the node operations are generated. | |
void | vApiOpcodes (void *vpCtx) |
Parse the SABNF grammar and translate its AST into opcodes for all the rules. More... | |
void | vApiOpcodesToAscii (void *vpCtx, const char *cpFileName) |
Display all opcodes in human-readable format. More... | |
void | vApiRulesToAscii (void *vpCtx, const char *cpMode, const char *cpFileName) |
Display rules and UDTs in human-readable format in ASCII format. More... | |
void | vApiRulesToHtml (void *vpCtx, const char *cpFileName) |
Display the grammar rules in human-readable, HTML format. More... | |
The Rule Attributes | |
Evaluate the rule attributes (e.g. left recursive, cyclic) to identify any fatal aspects or attributes of the grammar. | |
abool | bApiAttrs (void *vpCtx) |
Computes the grammar's attributes. More... | |
void | vApiAttrsToAscii (void *vpCtx, const char *cpMode, const char *cpFileName) |
Display all rule attributes. More... | |
void | vApiAttrsErrorsToAscii (void *vpCtx, const char *cpMode, const char *cpFileName) |
Display all rule attributes with errors. More... | |
Evaluate the Partially-Predictive Parsing Tables (PPPT) | |
PPPT maps can significantly reduce the number of node visits necessary for a traversal of the parse tree. The PPPT maps are generated here. | |
void | vApiPppt (void *vpCtx, char **cppProtectedRules, aint uiProtectedRules) |
Compute the Partially-Predictive Parsing Tables. More... | |
void | vApiPpptSize (void *vpCtx, pppt_size *spSize) |
Compute the size of the PPPT maps and the number of bytes for the entire table. More... | |
One-Step Generation | |
Composite functions which will perform all steps of generation with a single function call.
| |
void | vApiFile (void *vpCtx, const char *cpFileName, abool bStrict, abool bPppt) |
Quicky way to generate a parser from a grammar file. More... | |
void | vApiString (void *vpCtx, const char *cpString, abool bStrict, abool bPppt) |
Quicky way to generate a parser from a grammar string. More... | |
Parser Generation | |
Generator output can be in two forms. A pair of grammar files can be generated from which a parser can be constructed. Or a parser object, completely independent of the API, can be generated. | |
void | vApiOutput (void *vpCtx, const char *cpOutput) |
Generate a source and header file that can be used to construct a parser for the specified SABNF grammar. More... | |
void * | vpApiOutputParser (void *vpCtx) |
Generate a parser object directly from the specified SABNF grammar. More... | |
Public header file for the APG API suite of functions.
The command line parser generator, apg, is built from an Application Programming Interface (API) object. This object is available for custom applications to use as well. It's primary documentation is here and in api.c but it has a lot of code which is spread over a number of files in the api directory. Refer to them here:
Definition in file api.h.
abool bApiAttrs | ( | void * | vpCtx | ) |
Computes the grammar's attributes.
For each rule in the SABNF grammar the rule attributes are:
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
uipCount | - Pointer to an integer. Set to the number (count) of attributes. This will always be the number of rules in the grammar. May be NULL if no count is wanted. |
Definition at line 79 of file attributes.c.
abool bApiValidate | ( | void * | vpCtx | ) |
Validates an API context pointer.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
const char* cpApiInFile | ( | void * | vpCtx, |
const char * | cpFileName | ||
) |
Reads an SABNF grammar byte stream from a file.
May be called multiple times. Successive calls will append data to the previous grammar result. May be mixed with calls to cpApiInString().
[in] | vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
[in] | cpFileName | - Name of the file to read. |
const char* cpApiInString | ( | void * | vpCtx, |
const char * | cpString | ||
) |
Reads an SABNF grammar byte stream from a string.
May be called multiple times. Successive calls will append data to the previous SABNF grammar result. May be mixed with calls to cpApiInFile().
[in] | vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
[in] | cpString | - Pointer to the string to read. |
void vApiAttrsErrorsToAscii | ( | void * | vpCtx, |
const char * | cpMode, | ||
const char * | cpFileName | ||
) |
Display all rule attributes with errors.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpMode | (note: the first character (case-insensitive) of the following options is all that is needed)
|
cpFileName | - Name of the file to display on. Any directories in the path name must exist. If NULL, stdout is used. |
Definition at line 268 of file attributes.c.
void vApiAttrsToAscii | ( | void * | vpCtx, |
const char * | cpMode, | ||
const char * | cpFileName | ||
) |
Display all rule attributes.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpMode | (note: the first character (case-insensitive) of the following options is all that is needed)
|
cpFileName | - Name of the file to display on. Any directories in the path name must exist. If NULL, stdout is used. |
Definition at line 220 of file attributes.c.
void vApiDtor | ( | void * | vpCtx | ) |
The API component destructor.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
Quicky way to generate a parser from a grammar file.
Calls all of the intermediate steps in one function. Input is limited to a single file.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpFileName | - Name of the grammar file. |
bStrict | If true, only strictly ABNF (RFC 5234 & RFC7405) grammars allowed. |
bPppt | If true, Partially-Predictive Parsing Tables (PPPTs) are generated. Note that in this single, collective call to generate a parser there is no opportunity to protect any rules from PPPT replacement. If any rules need protecting it will be necessary to do the full sequence of API calls. |
void vApiInClear | ( | void * | vpCtx | ) |
Clears the input and related memory.
The user must call this to clear any previous input grammar before reusing the API object for another job.
[in] | vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
void vApiInToAscii | ( | void * | vpCtx, |
const char * | cpFileName | ||
) |
Display the input lines with line numbers and character offsets.
Writes the input grammar in ASCII format to a file.
[in] | vpCtx | - pointer to an API context previously returned from vpApiCtor(). |
[in] | cpFileName | - Name of the file to write the result to. If NULL, stdout is used. |
void vApiInToHtml | ( | void * | vpCtx, |
const char * | cpFileName, | ||
const char * | cpTitle | ||
) |
Display the input lines with line numbers and character offsets.
Writes the input grammar as an HTML page to a file.
[in] | vpCtx | - pointer to an API context previously returned from vpApiCtor(). |
[in] | cpFileName | - name of the file to write the result to. |
[in] | cpTitle | - HTML title. If NULL, a default page title is used. |
void vApiInValidate | ( | void * | vpCtx, |
abool | bStrict | ||
) |
Scans the input SABNF grammar for invalid characters and line ends.
Constructs a lines
object for dealing with finding and handling lines.
[in] | vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
[in] | bStrict | - If true, validate as strict ABNF. If APG_TRUE, validate as strict ABNF (RFC5234 & RFC7405). Otherwise, validate as SABNF. |
void vApiOpcodes | ( | void * | vpCtx | ) |
Parse the SABNF grammar and translate its AST into opcodes for all the rules.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
Definition at line 64 of file semantics.c.
void vApiOpcodesToAscii | ( | void * | vpCtx, |
const char * | cpFileName | ||
) |
Display all opcodes in human-readable format.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpFileName | - Name of the file to display on. Any directories in the path name must exist. If NULL, stdout is used. |
void vApiOutput | ( | void * | vpCtx, |
const char * | cpOutput | ||
) |
Generate a source and header file that can be used to construct a parser for the specified SABNF grammar.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpOutput | The root of the file name to use for the generated source and header files. Any extension will be stripped and replaces with .h for the header file and .c for the source file. The name may be relative or absolute. Any directories in the pathname must exist. |
void vApiPppt | ( | void * | vpCtx, |
char ** | cppProtectedRules, | ||
aint | uiProtectedRules | ||
) |
Compute the Partially-Predictive Parsing Tables.
vpCtx | Context pointer previously returned from vpApiCtor(). |
cppProtectedRules | An array of string pointers pointing to the rule names to protect. Protection means that the rule is generated, even if the PPPT would have been deterministic prior to calling the rule. May be NULL, in which case no rules are protected. |
uiProtectedRules | The number of protected rules. May be 0, in which case no rules are protected. |
void vApiPpptSize | ( | void * | vpCtx, |
pppt_size * | spSize | ||
) |
Compute the size of the PPPT maps and the number of bytes for the entire table.
This function may be called after vApiOpcodes() and before vApiPppt() to determine if the application has sufficient memory to handle the PPPTs. vApiOpcodes() is where the PPPT sizes are computed. The tables are not allocated until vApiPppt().
vpCtx | Context pointer previously returned from vpApiCtor(). |
spSize | Pointer to a pppt_size structure to receive the size information. |
void vApiRulesToAscii | ( | void * | vpCtx, |
const char * | cpMode, | ||
const char * | cpFileName | ||
) |
Display rules and UDTs in human-readable format in ASCII format.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpMode | (note: the first character (case-insensitive) of the following options is all that is needed)
|
cpFileName | - Name of the file to display on. Any directories in the path name must exist. If NULL, stdout is used. |
void vApiRulesToHtml | ( | void * | vpCtx, |
const char * | cpFileName | ||
) |
Display the grammar rules in human-readable, HTML format.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpFileName | - Name of the file to display on. Any directories in the path name must exist. If NULL, stdout is used. |
Quicky way to generate a parser from a grammar string.
Calls all of the intermediate steps in one function. Input is limited to a single file.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
cpString | - Pointer to a string which contains the entire grammar. |
bStrict | If true, only strictly ABNF (RFC 5234 & RFC7405) grammars allowed. |
bPppt | If true, Partially-Predictive Parsing Tables (PPPTs) are generated. Note that in this single, collective call to generate a parser there is no opportunity to protect any rules from PPPT replacement. If any rules need protecting it will be necessary to do the full sequence of API calls. |
void vApiSyntax | ( | void * | vpCtx, |
abool | bStrict | ||
) |
Parse the SABNF grammar to validate that the grammar structure is valid.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
bStrict | If true, only strict RFC 5234 syntax is allowed. If false, full SABNF syntax is allowed. |
void* vpApiCtor | ( | exception * | spEx | ) |
Construct an API component context (object).
spEx | Pointer to a valid exception object. See XCTOR(). If invalid, the application will silently exit with a BAD_CONTEXT exit code. |
void* vpApiGetErrorLog | ( | void * | vpCtx | ) |
Get the internal message log.
User may want to display or otherwise use the list of messages.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |
void* vpApiOutputParser | ( | void * | vpCtx | ) |
Generate a parser object directly from the specified SABNF grammar.
The generated parser has its own memory object and is independent of the parent API object other than sharing the same exception object. That is, throw exceptions will land in the API catch block. But the API and the generated parser must each call their respective destructors to prevent memory leaks.
vpCtx | - Pointer to an API context previously returned from vpApiCtor(). |