Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
jsonp.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 * *************************************************************************************/
33 #ifndef JSONP_H_
34 #define JSONP_H_
35 
39 #define TAB 9
40 #define LF 10
41 #define CR 13
42 #define LINE_LEN 16
43 #define LINE_LEN4 4
44 #define LINE_LEN8 8
45 #define LINE_LEN12 12
46 
55 typedef struct {
58 } string_r;
59 
68 typedef struct {
73  union{
76  };
77 } value_r;
78 
85 typedef struct {
89  void* vpVecIndexes;
90 } frame;
91 
95 typedef struct {
96  const void* vpValidate;
98  void* vpMem;
100 // const char* cpTraceOut; ///< The file name to write the internal APG parser's trace to. NULL (default) results in no trace.
103 
104  // the JSON input (a UTF-8 encoded byte string)
105  void* vpVecInput;
106  void* vpLines;
107 
108  // used and reused by the parser
109  void* vpVecChars;
110  void* vpVecAscii;
111  void* vpVecValuesr;
112  void* vpVecValues;
113  json_value* spValues;
116  void* vpVecStrings;
119  void* vpVecNumbers;
121  void* vpVecFrames;
122  void* vpVecChildPointers; //< \brief A vector of pointers to object and array children.
125  // working values during the parse
127  uint32_t uiChar;
132  // pointer lists for returning values to user
135  void* vpVecKeyList;
137 
138  // iterator helpers
140 
141  // display and writer helpers
142  FILE* spIn;
144  void* vpParser;
146  void* vpFmt;
147  void* vpVecOutput;
148  void* vpConv;
152 } json;
153 
157 typedef struct{
158  const void* vpValidate;
160  void* vpVec;
161  json_value** sppValues;
165 } json_iterator;
166 
169 void vJsonGrammarRuleCallbacks(void* vpParserCtx);
172 #define JSON_UTF16_MATCH 0
173 #define JSON_UTF16_NOMATCH 1
174 #define JSON_UTF16_BAD_HIGH 2
175 #define JSON_UTF16_BAD_LOW 3
176 aint uiUtf16_1(char* cpHex, uint32_t* uipChar);
177 aint uiUtf16_2(char* cpHex, uint32_t* uipChar);
178 uint32_t uiUtf8_2byte(char* cpBytes);
179 uint32_t uiUtf8_3byte(char* cpBytes);
180 uint32_t uiUtf8_4byte(char* cpBytes);
182 
183 #endif /* JSONP_H_ */
json::vpVecAscii
void * vpVecAscii
A scratch vector for constructing ASCII strings on the fly.
Definition: jsonp.h:110
json::vpVecIterators
void * vpVecIterators
A vector of iterator context pointers remembered for destruction.
Definition: jsonp.h:101
json
The object context. For intenrnal use only.
Definition: jsonp.h:95
json::vpVecNumbers
void * vpVecNumbers
Definition: jsonp.h:119
json_iterator
A JSON interator object context.
Definition: jsonp.h:157
string_r::uiCharsOffset
aint uiCharsOffset
The offset from the vector base of 32-bit character codes to the first character in the string.
Definition: jsonp.h:56
uiUtf16_1
aint uiUtf16_1(char *cpHex, uint32_t *uipChar)
Definition: parser-callbacks.c:74
json::spStrings
u32_phrase * spStrings
An array of absolute strings.
Definition: jsonp.h:117
json::spCurrentFrame
frame * spCurrentFrame
Points to the current stack frame.
Definition: jsonp.h:126
json::spException
exception * spException
Pointer to the exception structure for reporting errors to the application catch block.
Definition: jsonp.h:97
json::spValues
json_value * spValues
an array of absolute values.
Definition: jsonp.h:113
achar
uint_fast8_t achar
achar is the type for the parser's alphabet characters.
Definition: apg.h:91
json::vpVecChars
void * vpVecChars
A vector of string characters. 32-bit Unicode code points. All strings are in this single vector.
Definition: jsonp.h:109
uiUtf16_2
aint uiUtf16_2(char *cpHex, uint32_t *uipChar)
Definition: parser-callbacks.c:82
uiUtf8_3byte
uint32_t uiUtf8_3byte(char *cpBytes)
Definition: parser-callbacks.c:59
json::uiCurrentDepth
aint uiCurrentDepth
Used to keep track of the current tree depth for display of the tree of values.
Definition: jsonp.h:150
json::vpVecKeyList
void * vpVecKeyList
Vector of pointers to the list of valued found in a key search.
Definition: jsonp.h:135
frame
Each value is a node in the parse tree.
Definition: jsonp.h:85
frame::uiValue
aint uiValue
Index to the value represented by this frame.
Definition: jsonp.h:87
json::vpVecChildIndexes
void * vpVecChildIndexes
A vector of number objects.
Definition: jsonp.h:120
json_iterator::spJson
json * spJson
Pointer to the parent JSON object context.
Definition: jsonp.h:159
json_iterator::uiContextIndex
aint uiContextIndex
Definition: jsonp.h:164
json::vpVecChildPointers
void * vpVecChildPointers
Definition: jsonp.h:122
json::vpConv
void * vpConv
Context pointer for a conversion object.
Definition: jsonp.h:148
json::vpVecTreeList
void * vpVecTreeList
Vector of pointers to sub_tree tree. Value pointers are in the order of a depth-first traversal.
Definition: jsonp.h:133
value_r
This is the "relative" value developed during parsing.
Definition: jsonp.h:68
frame::uiNextKey
aint uiNextKey
Used to keep track of the next available key offset to be used by an object member.
Definition: jsonp.h:86
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
json::sppChildPointers
struct json_value_tag ** sppChildPointers
An array of absolute child value pointers.
Definition: jsonp.h:123
frame::vpVecIndexes
void * vpVecIndexes
Definition: jsonp.h:89
json::vpVecFrames
void * vpVecFrames
Frame stack of values to keep track of the current value in the parse tree.
Definition: jsonp.h:121
json::vpVecInput
void * vpVecInput
The UTF-8-encoded input byte stream. BOM, if any, removed.
Definition: jsonp.h:105
value_r::uiChildCount
aint uiChildCount
if uiId is JSON_ID_OBJECT or JSON_ID_ARRAY, the number of members or values.
Definition: jsonp.h:71
json::bFirstNode
abool bFirstNode
Set to true before each call to sJsonWrite() to prevent writing a key for the first node of a sub-tre...
Definition: jsonp.h:149
json_iterator::vpVec
void * vpVec
Work vector.
Definition: jsonp.h:160
json::bHasFrac
abool bHasFrac
A working value signaling presence of fractional value for a number value.
Definition: jsonp.h:129
uiUtf8_4byte
uint32_t uiUtf8_4byte(char *cpBytes)
Definition: parser-callbacks.c:66
value_r::uiNumber
aint uiNumber
Offset to a number if JSON_ID_NUMBER.
Definition: jsonp.h:75
uiUtf8_2byte
uint32_t uiUtf8_2byte(char *cpBytes)
Definition: parser-callbacks.c:53
json::uiChar
uint32_t uiChar
A working value to hold the value of a single character. Higher level rules will move it to vpVecChar...
Definition: jsonp.h:127
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
string_r
This is the "relative" string developed during parsing.
Definition: jsonp.h:55
json::uiStringCount
aint uiStringCount
The number of strings in the array.
Definition: jsonp.h:118
json::vpVecStringsr
void * vpVecStringsr
Definition: jsonp.h:115
json::vpVecChildList
void * vpVecChildList
Vector of pointers to the children of a parent value. NULL if the parent is not an object or array.
Definition: jsonp.h:134
value_r::uiKey
aint uiKey
If uiID is JSON_ID_OBJECT, offset to the key's string. Otherwise, zero and not used.
Definition: jsonp.h:70
json::vpVecValues
void * vpVecValues
A vector of relative values.
Definition: jsonp.h:112
json::uiMaxDepth
aint uiMaxDepth
The maximum tree depth of values to display.
Definition: jsonp.h:151
json::vpVecValuesr
void * vpVecValuesr
Definition: jsonp.h:111
value_r::uiChildListOffset
aint uiChildListOffset
Offset from the base of the vector of child value pointers.
Definition: jsonp.h:72
json::uiValueCount
aint uiValueCount
The number of values in the array.
Definition: jsonp.h:114
json::vpVecScratch32
void * vpVecScratch32
A vector of 32-bit integer scratch space.
Definition: jsonp.h:136
json::vpVecOutput
void * vpVecOutput
Vector of 32-bit code points for generating output of value tree to JSON-text.
Definition: jsonp.h:147
value_r::uiString
aint uiString
Offset to a string_r if JSON_ID_STRING.
Definition: jsonp.h:74
json::vpLines
void * vpLines
pointer to a lines object context
Definition: jsonp.h:106
frame::uiString
aint uiString
Offset to the string or key string for this value.
Definition: jsonp.h:88
json_iterator::uiCount
aint uiCount
The number of pointers in the list.
Definition: jsonp.h:162
json::vpVecStrings
void * vpVecStrings
A vector of relative strings.
Definition: jsonp.h:116
json_iterator::sppValues
json_value ** sppValues
List of pointers to values.
Definition: jsonp.h:161
json::acpInput
achar * acpInput
Buffer to hold the input converted from uint8_t to achar units.
Definition: jsonp.h:145
json::vpVecBuilders
void * vpVecBuilders
A vector of builder context pointers remembered for destruction.
Definition: jsonp.h:102
json_iterator::vpValidate
const void * vpValidate
Must be the "magic number" to be a valid context.
Definition: jsonp.h:158
json::vpValidate
const void * vpValidate
Must be the "magic number" to be a valid context.
Definition: jsonp.h:96
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
json::vpFmt
void * vpFmt
Pointer to a hexdump-style formatter object.
Definition: jsonp.h:146
value_r::uiId
aint uiId
The value identifier, JSON_ID_OBJECT, etc.
Definition: jsonp.h:69
json::uiWalkCount
aint uiWalkCount
An accumulator for counting sub-tree nodes and child nodes.
Definition: jsonp.h:139
json::bHasMinus
abool bHasMinus
A working value signaling a minus sign for a number value.
Definition: jsonp.h:130
u32_phrase
Defines a pointer to an array of 32-bit unsigned integers plus its length. Typically needed by Unicod...
Definition: lib.h:73
json_value_tag
The structure of a JSON value.
Definition: json.h:99
string_r::uiLength
aint uiLength
The number of characters in the string.
Definition: jsonp.h:57
json::spIn
FILE * spIn
File I/O handle for the input file. Maintained here so that it can be closed in the destructor if nec...
Definition: jsonp.h:142
json::vpParser
void * vpParser
Pointer to the parser context if exception thrown during parsing.
Definition: jsonp.h:144
spJsonIteratorCtor
json_iterator * spJsonIteratorCtor(json *spJson)
Private function for internal object use only. Never called by the application.
Definition: json.c:561
json_iterator::uiCurrent
aint uiCurrent
The current iterator value index.
Definition: jsonp.h:163
vJsonGrammarRuleCallbacks
void vJsonGrammarRuleCallbacks(void *vpParserCtx)
Definition: parser-callbacks.c:718
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.