APG
… an ABNF Parser Generator
|
Header file for the apgex object. More...
#include "../api/api.h"
Go to the source code of this file.
Data Structures | |
struct | apgex_phrase |
The representation of a matched phrase. More... | |
struct | apgex_rule |
Information about each rule or UDT in the SABNF pattern. More... | |
struct | apgex_result |
The phrase matching results. More... | |
struct | apgex_properties |
Detailed information about the apgex object after vApgexPattern() has been called. More... | |
Typedefs | |
typedef apg_phrase(* | pfn_replace) (apgex_result *spResult, apgex_properties *spProperties, void *vpUser) |
Prototype for the replacement function used by sApgexReplaceFunc(). More... | |
Functions | |
void | vApgexBkrCheck (exception *spEx) |
Back referencing check. More... | |
Construction and Destruction | |
void * | vpApgexCtor (exception *spEx) |
The phrase-matching engine object constructor. More... | |
void | vApgexDtor (void *vpCtx) |
The phrase-matching engine object destructor. More... | |
Pattern Definition | |
void | vApgexPattern (void *vpCtx, const char *cpPattern, const char *cpFlags) |
Prepare a phrase-matching parser for the given pattern. More... | |
void | vApgexPatternFile (void *vpCtx, const char *cpFileName, const char *cpFlags) |
Reads the SABNF grammar defining the pattern from a file. More... | |
void | vApgexPatternParser (void *vpCtx, void *vpParser, const char *cpFlags) |
Define the SABNF pattern with a user-created parser. More... | |
Pattern Matching Configuration | |
void | vApgexEnableRules (void *vpCtx, const char *cpNames, abool bEnable) |
Enable or disable specified rule and/or UDT names for phrase capture. More... | |
void | vApgexDefineUDT (void *vpCtx, const char *cpName, parser_callback pfnUdt) |
Define the callback function for a User-Defined Terminal (UDT). More... | |
void | vApgexSetLastIndex (void *vpCtx, aint uiLastIndex) |
Sets the index of the character in the source where the pattern-match search is to begin. More... | |
Pattern Matching | |
apgex_result | sApgexExec (void *vpCtx, apg_phrase *spSource) |
Attempt a pattern match on the source array of APG alphabet characters. More... | |
apg_phrase | sApgexReplace (void *vpCtx, apg_phrase *spSource, apg_phrase *spReplacement) |
Replace the matched phrase with a specified phrase. More... | |
apg_phrase | sApgexReplaceFunc (void *vpCtx, apg_phrase *spSource, pfn_replace pfnFunc, void *vpUser) |
Replace the matched phrase with a user-generated phrase. More... | |
apg_phrase * | spApgexSplit (void *vpCtx, apg_phrase *spSource, aint uiLimit, aint *uipCount) |
Split a phrase into an array of sub-phrases. More... | |
abool | bApgexTest (void *vpCtx, apg_phrase *spSource) |
Report only success or failure on a pattern match. More... | |
apgex_properties | sApgexProperties (void *vpCtx) |
Get a copy of the object's properties. More... | |
void * | vpApgexGetAst (void *vpCtx) |
Get a pointer to the AST object's context. More... | |
void * | vpApgexGetTrace (void *vpCtx) |
Get a pointer to the trace object's context. More... | |
void * | vpApgexGetParser (void *vpCtx) |
Get a pointer to the parser object's context. More... | |
Display Helpers | |
void | vApgexDisplayResult (void *vpCtx, apgex_result *spResult, const char *cpFileName) |
Display the complete results from a pattern match. More... | |
void | vApgexDisplayPhrase (void *vpCtx, apgex_phrase *spPhrase, const char *cpFileName) |
Display the object's properties. More... | |
void | vApgexDisplayProperties (void *vpCtx, apgex_properties *spProperties, const char *cpFileName) |
Display the object's properties. More... | |
void | vApgexDisplayPatternErrors (void *vpCtx, const char *cpFileName) |
Header file for the apgex object.
Definition in file apgex.h.
pfn_replace |
Prototype for the replacement function used by sApgexReplaceFunc().
spResult | Pointer to a pattern-matching result - same as return from sApgexExec(). |
spProperties | Pointer to a pattern-matching properties - same as returned from sApgexProperties(). |
vpUser | Pointer to user-supplied data. Same user-supplied data passed to sApgexReplaceFunc(). |
abool bApgexTest | ( | void * | vpCtx, |
apg_phrase * | spSource | ||
) |
Report only success or failure on a pattern match.
Similar to sApgexExec() in default mode, except that only success or failure is reported. The matched phrase is not returned.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spSource | Pointer to the source or input string as an APG phrase. |
apgex_result sApgexExec | ( | void * | vpCtx, |
apg_phrase * | spSource | ||
) |
Attempt a pattern match on the source array of APG alphabet characters.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spSource | Pointer to the source or input string as an APG phrase. |
spResult
element in the result structure will be NULL if no match was found. apgex_properties sApgexProperties | ( | void * | vpCtx | ) |
Get a copy of the object's properties.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
apg_phrase sApgexReplace | ( | void * | vpCtx, |
apg_phrase * | spSource, | ||
apg_phrase * | spReplacement | ||
) |
Replace the matched phrase with a specified phrase.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spSource | Pointer to the source as a apg_phrase. |
spReplacement | Pointer to the replacement phrase. In default mode, only the first matched phrase is replaced. In global or sticky mode, all possible matched phrases in those respective modes are replaced. The search begins at uiLastIndex which is always set to zero on return. The replacement phrase may have some special characters for dynamic replacement possibilities.
|
apg_phrase sApgexReplaceFunc | ( | void * | vpCtx, |
apg_phrase * | spSource, | ||
pfn_replace | pfnFunc, | ||
void * | vpUser | ||
) |
Replace the matched phrase with a user-generated phrase.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spSource | Pointer to the source as a apg_phrase. |
pfnFunc | Pointer to the replacement function. See pfn_replace for the function prototype. The returned phrase from this function will be used as the replacement for the matched phrase. In default mode, only the first matched phrase is replaced. In global or sticky mode, all possible matched phrases in those respective modes are replaced. The search begins at uiLastIndex which is always set to zero on return. |
vpUser | Pointer to user-supplied data. This pointer will be passed to the above function, pfnFunc. |
apg_phrase* spApgexSplit | ( | void * | vpCtx, |
apg_phrase * | spSource, | ||
aint | uiLimit, | ||
aint * | uipCount | ||
) |
Split a phrase into an array of sub-phrases.
This function is modeled after the JavaScript function str.split([separator[, limit]]) when using a regular expression. The source phrase is searched for pattern matches.
Also,
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spSource | A pointer to the source to search for pattern matches. May not be NULL. If it is empty (uiLength = 0) the return will be a single empty phrase. |
uiLimit | Places a limit on the number of pattern matches to find. If uiLimit = 0, all matches will be found. That is, uiLimit = 0 is shorthand for uiLimit = APG_MAX_AINT. |
uipCount | The number of sub-phrases in the returned array. |
void vApgexBkrCheck | ( | exception * | spEx | ) |
Back referencing check.
The back referencing macro APG_BKR must be defined when compiling the apgex object. If not, a macro is defined in apg.h which calls this function, whose only purpose is to throw an exception reminding the user do define the macro.
spEx | Pointer to a valid exception structure. If not valid application will silently exit with a BAD_CONTEXT exit code. |
void vApgexDefineUDT | ( | void * | vpCtx, |
const char * | cpName, | ||
parser_callback | pfnUdt | ||
) |
Define the callback function for a User-Defined Terminal (UDT).
If there are any UDTs in the SABNF pattern grammar, each one of them must have a user-written callback function to do its pattern matching work. This function will define a callback function to the apgex object for a single UDT. This function must be called for each UDT appearing in the SABNF pattern grammar.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
cpName | Name of the UDT. |
pfnUdt | The callback function for this UDT. |
void vApgexDisplayPatternErrors | ( | void * | vpCtx, |
const char * | cpFileName | ||
) |
void vApgexDisplayPhrase | ( | void * | vpCtx, |
apgex_phrase * | spPhrase, | ||
const char * | cpFileName | ||
) |
Display the object's properties.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spPhrase | Pointer to the apgex_phrase to display. This would be a one of the members of an apgex_result or apgex_rule. |
cpFileName | The name of the file to write the display to. If NULL, stdout is used. If non-NULL any directories in the pathname must exist. |
void vApgexDisplayProperties | ( | void * | vpCtx, |
apgex_properties * | spProperties, | ||
const char * | cpFileName | ||
) |
Display the object's properties.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spProperties | Pointer to the properties to display. This would be a pointer to the return value of sApgexProperties(). |
cpFileName | The name of the file to write the display to. If NULL, stdout is used. If non-NULL any directories in the pathname must exist. |
void vApgexDisplayResult | ( | void * | vpCtx, |
apgex_result * | spResult, | ||
const char * | cpFileName | ||
) |
Display the complete results from a pattern match.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
spResult | Pointer to the pattern matched result, the return from sApgexExec(); |
cpFileName | The file to display the output to. If NULL, stdout is used. |
void vApgexDtor | ( | void * | vpCtx | ) |
The phrase-matching engine object destructor.
Frees all memory allocated to the apgex
object and for good measure zeros it out as insurance against reuse by a stale pointer.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). Silently ignores a NULL pointer, but exits the application with BAD_CONTEXT exit code if the pointer is non-NULL and not a valid apgex object context pointer. |
void vApgexEnableRules | ( | void * | vpCtx, |
const char * | cpNames, | ||
abool | bEnable | ||
) |
Enable or disable specified rule and/or UDT names for phrase capture.
By default, all rules and UDTs are disabled. The result, which is equal to the start rule, is always captured, independent of these selections. However, the start rule, like all other rules, is captured independently and only if it is enabled here. Note that UDTs, if any, must always be defined with vApgexDefineUDT() prior to any matching function call. Disabling them simply means that matched phrases are not saved. They still must be defined for the parse to be performed.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
cpNames | The name or names of the rules/UDTs to enable or disable. All names are case insensitive. May not be NULL or empty.
|
bEnable | If true, the named rules/UDTS are enabled, meaning that their phrase will be captured. If false, the rules/UDTS will be disabled, meaning that their respective phrases will not be captured |
void vApgexPattern | ( | void * | vpCtx, |
const char * | cpPattern, | ||
const char * | cpFlags | ||
) |
Prepare a phrase-matching parser for the given pattern.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
cpPattern | The complete SABNF grammar to define the strings to be matched. Must be a complete grammar including line end characters (\n, \r\n or \r) after each line including the last. |
cpFlags | A string of flags that control the pattern-matching behavior. The flag characters may appear in any order and may appear multiple times. If "g" and "y" are both present, the first appearing will be honored.
|
†By default, uiLastIndex
begins at 0. However, it can be set to any valid value prior to the phrase matching attempt with a call to vApgexSetLastIndex()
void vApgexPatternFile | ( | void * | vpCtx, |
const char * | cpFileName, | ||
const char * | cpFlags | ||
) |
Reads the SABNF grammar defining the pattern from a file.
Same as vApgexPattern() except the pattern grammar is read from a file.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
cpFileName | Name of the file with the SABNF grammar. |
cpFlags | A string of flags. See vApgexPattern(). |
void vApgexPatternParser | ( | void * | vpCtx, |
void * | vpParser, | ||
const char * | cpFlags | ||
) |
Define the SABNF pattern with a user-created parser.
The SABNF pattern is implicitly defined by a user-supplied parser. This parser is independent of the apgex
context and it's destructor is never called, even by vApgexDtor(). The supplied parser may or may not have been created with the same memory object, vpMem. It is the user's responsibility to have a properly defined catch block
to handle any exceptions thrown from the supplied parser. In this case, the apgex
properties will have an empty string for the unknown pattern.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
vpParser | Pointer to a valid SABNF parser context. |
cpFlags | A string of flags. See vApgexPattern(). |
void vApgexSetLastIndex | ( | void * | vpCtx, |
aint | uiLastIndex | ||
) |
Sets the index of the character in the source where the pattern-match search is to begin.
uiLastIndex governs the starting point of the search in the next call to any of the pattern-matching functions. It is initialized to 0 by default. It's value on consecutive calls to a pattern-matching function are normally governed by the mode (default, global, sticky) rules. This function can be used prior to any pattern-matching call to override the default behavior.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
uiLastIndex | The source character index where the pattern match is to begin. Must be lest than the source length or an exception will be thrown. |
void* vpApgexCtor | ( | exception * | spEx | ) |
The phrase-matching engine object constructor.
spEx | Pointer to a valid exception structure initialized with XCTOR(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
void* vpApgexGetAst | ( | void * | vpCtx | ) |
Get a pointer to the AST object's context.
This function can be called after any of the phrase-matching functions.
The AST object will reflect the results of the last successful phrase match. If the last phrase match was unsuccessful the pointer is valid but the AST will have no records. Be sure to understand the meaning of the flags used and the result of the phrase-matching function called.
Following a successful phrase match, the AST object will have records for all rules and UDTs in the pattern but all call back functions will be NULL. Use vAstSetRuleCallback() and vAstSetUdtCallback() to set the translation functions specific to the application prior to translation with vAstTranslate().
See sApgexProperties() for alternate access to this pointer.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
void* vpApgexGetParser | ( | void * | vpCtx | ) |
Get a pointer to the parser object's context.
This function can be called after any of the pattern-defining functions.
See sApgexProperties() for alternate access to this pointer.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
void* vpApgexGetTrace | ( | void * | vpCtx | ) |
Get a pointer to the trace object's context.
This function can be called after any of the pattern-defining functions.
The trace context pointer can be used to configure the trace prior to any of the phrase-matching functions.
See sApgexProperties() for alternate access to this pointer.
vpCtx | A pointer to a valid apgex object context returned from vpApgexCtor(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |