Parse struct definitions. Support scalar types(int, long, float,
double, sstr_t), arrays, structs.
More...
#include <stddef.h>
#include "utils/diag.h"
#include "utils/hash_map.h"
#include "utils/sstr.h"
Go to the source code of this file.
|
|
#define | FIELD_TYPE_INT 0 |
| |
|
#define | FIELD_TYPE_LONG 1 |
| |
|
#define | FIELD_TYPE_FLOAT 2 |
| |
|
#define | FIELD_TYPE_DOUBLE 3 |
| |
|
#define | FIELD_TYPE_SSTR 4 |
| |
|
#define | FIELD_TYPE_ENUM 5 |
| |
|
#define | FIELD_TYPE_STRUCT 6 |
| |
|
#define | FIELD_TYPE_BOOL 7 |
| |
|
#define | FIELD_TYPE_MAP 8 |
| |
|
#define | FIELD_TYPE_INT8 9 |
| |
|
#define | FIELD_TYPE_INT16 10 |
| |
|
#define | FIELD_TYPE_INT32 11 |
| |
|
#define | FIELD_TYPE_INT64 12 |
| |
|
#define | FIELD_TYPE_UINT8 13 |
| |
|
#define | FIELD_TYPE_UINT16 14 |
| |
|
#define | FIELD_TYPE_UINT32 15 |
| |
|
#define | FIELD_TYPE_UINT64 16 |
| |
|
#define | FIELD_TYPE_ONEOF 17 |
| |
|
#define | TYPE_NAME_INT "int" |
| |
|
#define | TYPE_NAME_BOOL "bool" |
| |
|
#define | TYPE_NAME_SSTR "sstr_t" |
| |
|
#define | TYPE_NAME_LONG "long" |
| |
|
#define | TYPE_NAME_FLOAT "float" |
| |
|
#define | TYPE_NAME_DOUBLE "double" |
| |
|
#define | TYPE_NAME_INT8 "int8_t" |
| |
|
#define | TYPE_NAME_INT16 "int16_t" |
| |
|
#define | TYPE_NAME_INT32 "int32_t" |
| |
|
#define | TYPE_NAME_INT64 "int64_t" |
| |
|
#define | TYPE_NAME_UINT8 "uint8_t" |
| |
|
#define | TYPE_NAME_UINT16 "uint16_t" |
| |
|
#define | TYPE_NAME_UINT32 "uint32_t" |
| |
|
#define | TYPE_NAME_UINT64 "uint64_t" |
| |
|
#define | STRUCT_MAP_BUCKET_SIZE 4096 |
| | We use a hash map to store parsed structs, and use the struct name as the key. This is the size of the hash map's bucket.
|
| |
|
#define | TOKEN_LEFT_BRACE '{' |
| |
|
#define | TOKEN_RIGHT_BRACE '}' |
| |
|
#define | TOKEN_LEFT_BRACKET '[' |
| |
|
#define | TOKEN_RIGHT_BRACKET ']' |
| |
|
#define | TOKEN_SEMICOLON ';' |
| |
|
#define | TOKEN_COMMA ',' |
| |
|
#define | TOKEN_SHARPE '#' |
| |
|
#define | TOKEN_AT '@' |
| |
|
#define | TOKEN_EQUAL '=' |
| |
|
#define | TOKEN_STRING 4 |
| |
|
#define | TOKEN_IDENTIFY 1 |
| |
|
#define | TOKEN_INTEGER 2 |
| |
|
#define | TOKEN_FLOAT 3 |
| |
|
#define | TOKEN_EOF 0 |
| |
|
#define | TOKEN_ERROR -1 |
| |
Parse struct definitions. Support scalar types(int, long, float,
double, sstr_t), arrays, structs.
◆ struct_parser_free()
free a struct_parser instance.
- Parameters
-
| parser | struct struct_parser* |
◆ struct_parser_new()
create and init a struct_parser instance.
- Returns
- struct struct_parser* if success, NULL otherwise.
◆ struct_parser_parse()
parse a struct definition file, and store the parsed structs in struct_parser.
- Parameters
-
| parser | context of parser. |
| content | content of the file. |
- Returns
- int 0 if success, -1 otherwise.
◆ struct_parser_validate()
Validate parsed schema for semantic errors.
Checks for: undefined type references, duplicate field names, duplicate enum values, and C keyword usage.
- Parameters
-
| parser | Parser with populated struct_map and enum_map. |
- Returns
- 0 if no errors, -1 if validation errors found.
◆ struct_parser_validate_to()
| int struct_parser_validate_to |
( |
struct struct_parser * |
parser, |
|
|
FILE * |
out |
|
) |
| |
Validate parsed schema and optionally print diagnostics.
- Parameters
-
| parser | Parser with populated struct_map, enum_map, and oneof_map. |
| out | Destination stream for diagnostics, or NULL to suppress printing. |
- Returns
- 0 if no errors, -1 if validation errors found.