Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
Data Structures | Typedefs | Functions
ast.h File Reference

Public header file for the AST functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_record
 Format of an AST record. More...
 
struct  ast_info
 All the information a user needs to write a custom AST translator. More...
 
struct  ast_data
 Input data to the AST callback functions. More...
 

Typedefs

typedef aint(* ast_callback) (ast_data *spData)
 The prototype for AST translation callback functions. More...
 

Functions

void * vpAstCtor (void *vpParserCtx)
 The AST object constructor. More...
 
void vAstDtor (void *vpCtx)
 
void vAstTranslate (void *vpCtx, void *vpUserData)
 Do a depth-first traversal of the AST with user-defined callback functions to translate the AST records. More...
 
void vAstInfo (void *vpCtx, ast_info *spInfo)
 Retrieve basic information about the AST object. More...
 
void vAstSetRuleCallback (void *vpCtx, aint uiRuleIndex, ast_callback pfnCallback)
 Define a callback function for a single rule on the AST. More...
 
void vAstSetUdtCallback (void *vpCtx, aint uiUdtIndex, ast_callback pfnCallback)
 Define a callback function for a single UDT on the AST. More...
 
void vAstClear (void *vpCtx)
 Clear the AST records for reuse of the AST object. More...
 
abool bAstValidate (void *vpCtx)
 Validate an AST context pointer. More...
 

Detailed Description

Public header file for the AST functions.

Definition in file ast.h.

Typedef Documentation

◆ ast_callback

ast_callback

The prototype for AST translation callback functions.

Parameters
spDataPointer to the callback data passed to the callback function.
Returns
One of:
  • ID_AST_OK normal return
  • ID_AST_SKIP skip traversal of the remaining branch below this node

Definition at line 91 of file ast.h.

Function Documentation

◆ bAstValidate()

abool bAstValidate ( void *  vpCtx)

Validate an AST context pointer.

Parameters
vpCtxPointer to a possible AST context returned by vpAstCtor().
Returns
True if the pointer is valid, false otherwise.

Definition at line 104 of file ast.c.

◆ vAstClear()

void vAstClear ( void *  vpCtx)

Clear the AST records for reuse of the AST object.

Parameters
vpCtxPointer to an AST context returned from vpAstCtor(); Silently ignored if NULL. However, if non-NULL it must be a valid AST context pointer or the application will exit with BAD_CONTEXT.

Definition at line 118 of file ast.c.

◆ vAstDtor()

void vAstDtor ( void *  vpCtx)

Definition at line 81 of file ast.c.

◆ vAstInfo()

void vAstInfo ( void *  vpCtx,
ast_info spInfo 
)

Retrieve basic information about the AST object.

Parameters
vpCtxPointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code;
spInfoPointer to the user's info struct to receive the information.

Definition at line 137 of file ast.c.

◆ vAstSetRuleCallback()

void vAstSetRuleCallback ( void *  vpCtx,
aint  uiRuleIndex,
ast_callback  pfnCallback 
)

Define a callback function for a single rule on the AST.

NOTE: There is an important difference between the role of the call back functions during parsing and translation. See this note for a discussion of this important distinction.

Parameters
vpCtxPointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code;
uiRuleIndexThe index of the rule to attach this callback function to.
pfnCallbackPointer to the callback function. Must match the ast_callback prototype.

Definition at line 243 of file ast.c.

◆ vAstSetUdtCallback()

void vAstSetUdtCallback ( void *  vpCtx,
aint  uiUdtIndex,
ast_callback  pfnCallback 
)

Define a callback function for a single UDT on the AST.

NOTE: There is an important difference between the role of the call back functions during parsing and translation. See this note for a discussion of this important distinction.

Parameters
vpCtxPointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code;
uiUdtIndexThe index of the UDT to attach this callback function to.
pfnCallbackPointer to the callback function. Must match the ast_callback prototype.

Definition at line 266 of file ast.c.

◆ vAstTranslate()

void vAstTranslate ( void *  vpCtx,
void *  vpUserData 
)

Do a depth-first traversal of the AST with user-defined callback functions to translate the AST records.

NOTE: There is an important difference between the role of the call back functions during parsing and translation. See this note for a discussion of this important distinction.

Parameters
vpCtxPointer to a valid AST context returned by vpAstCtor(). If invalid, the application will silently exit with a BAD_CONTEXT exit code;
vpUserDataPointer to optional user data. This pointer is passed to the user's callback functions for any purpose the application requires for the translation. May be NULL.

Definition at line 165 of file ast.c.

◆ vpAstCtor()

void* vpAstCtor ( void *  vpParserCtx)

The AST object constructor.

This object is a "sub-object" of the parser. The parser will keep a pointer to and use this object to generate the AST records. Note that there is no associated destructor. This object is destroyed by its parent parser object's destructor, vParserDtor().

Parameters
vpParserCtxPointer to a valid parser context returned from vpParserCtor(); If invalid, the application will silently exit with a BAD_CONTEXT exit code;
Returns
Returns a pointer to the object context. Throws an exception on any errors.

Definition at line 51 of file ast.c.

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