Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
ast.h
Go to the documentation of this file.
1 /* *************************************************************************************
2  Copyright (c) 2021, Lowell D. Thomas
3  All rights reserved.
4 
5  This file is part of APG Version 7.0.
6  APG Version 7.0 may be used under the terms of the BSD 2-Clause License.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 * *************************************************************************************/
30 #ifndef LIB_AST_H_
31 #define LIB_AST_H_
32 
35 #ifdef APG_AST
36 
42 typedef struct{
43  const char* cpName;
52 } ast_record;
53 
57 typedef struct{
58  const achar* acpString;
64 } ast_info;
65 
69 typedef struct{
70  const achar* acpString;
75  const char* cpName;
80  void* vpUserData;
81 } ast_data;
82 
91 typedef aint (*ast_callback)(ast_data* spData);
92 
93 void* vpAstCtor(void* vpParserCtx);
94 void vAstDtor(void* vpCtx);
95 void vAstTranslate(void* vpCtx, void* vpUserData);
96 void vAstInfo(void* vpCtx, ast_info* spInfo);
97 void vAstSetRuleCallback(void* vpCtx, aint uiRuleIndex, ast_callback pfnCallback);
98 void vAstSetUdtCallback(void* vpCtx, aint uiUdtIndex, ast_callback pfnCallback);
99 void vAstClear(void* vpCtx);
100 abool bAstValidate(void* vpCtx);
101 
102 #endif /* APG_AST */
103 #endif /* LIB_AST_H_ */
vAstInfo
void vAstInfo(void *vpCtx, ast_info *spInfo)
Retrieve basic information about the AST object.
Definition: ast.c:137
ast_record::uiThatRecord
aint uiThatRecord
The matching record number. That is, if uiThisRecord the number of the record that opens the rule,...
Definition: ast.h:46
bAstValidate
abool bAstValidate(void *vpCtx)
Validate an AST context pointer.
Definition: ast.c:104
ast_data::uiPhraseOffset
aint uiPhraseOffset
Definition: ast.h:72
ast_info::acpString
const achar * acpString
The parsed input string.
Definition: ast.h:58
ast_info::uiRuleCount
aint uiRuleCount
The number of rules.
Definition: ast.h:60
ast_info::uiStringLength
aint uiStringLength
The number of characters in the input string.
Definition: ast.h:62
ast_data::uiStringLength
aint uiStringLength
Definition: ast.h:71
ast_record::uiPhraseLength
aint uiPhraseLength
The number of characters in the matched phrase.
Definition: ast.h:49
ast_info::uiUdtCount
aint uiUdtCount
The number of UDTs.
Definition: ast.h:61
ast_data::spException
exception * spException
Use but don't alter. Use to throw exceptions to the AST catch block.
Definition: ast.h:78
ast_data
Input data to the AST callback functions.
Definition: ast.h:69
achar
uint_fast8_t achar
achar is the type for the parser's alphabet characters.
Definition: apg.h:91
ast_data::cpName
const char * cpName
Name of the rule or UDT.
Definition: ast.h:75
ast_record::cpName
const char * cpName
Name of the rule or UDT of this record.
Definition: ast.h:43
ast_data::uiPhraseLength
aint uiPhraseLength
Definition: ast.h:73
ast_data::uiIndex
aint uiIndex
Index of the rule or UDT.
Definition: ast.h:76
ast_record
Format of an AST record.
Definition: ast.h:42
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
vAstDtor
void vAstDtor(void *vpCtx)
Definition: ast.c:81
ast_record::bIsUdt
abool bIsUdt
True if this record is for a UDT.
Definition: ast.h:51
vAstTranslate
void vAstTranslate(void *vpCtx, void *vpUserData)
Do a depth-first traversal of the AST with user-defined callback functions to translate the AST recor...
Definition: ast.c:165
ast_data::uiState
aint uiState
Definition: ast.h:74
ast_info
All the information a user needs to write a custom AST translator.
Definition: ast.h:57
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
ast_callback
aint(* ast_callback)(ast_data *spData)
The prototype for AST translation callback functions.
Definition: ast.h:91
vAstSetUdtCallback
void vAstSetUdtCallback(void *vpCtx, aint uiUdtIndex, ast_callback pfnCallback)
Define a callback function for a single UDT on the AST.
Definition: ast.c:266
ast_info::uiRecordCount
aint uiRecordCount
The number of records (two for each node of the AST, one down traversal, one up.)
Definition: ast.h:63
ast_record::uiState
aint uiState
ID_AST_PRE if the current record opens the rule, ID_AST_POST if the current record closes the rule.
Definition: ast.h:50
ast_record::uiThisRecord
aint uiThisRecord
The record number.
Definition: ast.h:45
ast_data::acpString
const achar * acpString
Definition: ast.h:70
ast_info::spRecords
ast_record * spRecords
The list of records in the order of a depth-first traversal of the AST.
Definition: ast.h:59
ast_data::bIsUdt
abool bIsUdt
True if this record is for a UDT. False if it is for a rule.
Definition: ast.h:77
vAstSetRuleCallback
void vAstSetRuleCallback(void *vpCtx, aint uiRuleIndex, ast_callback pfnCallback)
Define a callback function for a single rule on the AST.
Definition: ast.c:243
ast_data::vpUserData
void * vpUserData
Definition: ast.h:80
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
ast_record::uiPhraseOffset
aint uiPhraseOffset
The offset into the input string to the first character of the matched phrase.
Definition: ast.h:48
ast_record::uiIndex
aint uiIndex
Index of the rule or UDT of this record.
Definition: ast.h:44
vAstClear
void vAstClear(void *vpCtx)
Clear the AST records for reuse of the AST object.
Definition: ast.c:118
vpAstCtor
void * vpAstCtor(void *vpParserCtx)
The AST object constructor.
Definition: ast.c:51
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.