json-gen-c  0.1.5
json-gen-c generate C code for json manipulation
struct_parse.c File Reference

parse struct definition file. More...

#include "struct/struct_parse.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils/diag.h"
#include "utils/compat.h"
#include "utils/hash_map.h"
#include "utils/io.h"
#include "utils/sstr.h"
#include "utils/error_codes.h"
Include dependency graph for struct_parse.c:

Classes

struct  validate_ctx
 

Macros

#define PERROR(parser, fmt, ...)
 

Enumerations

enum  top_level_item_kind {
  TOP_LEVEL_ITEM_INVALID = 0 , TOP_LEVEL_ITEM_INCLUDE , TOP_LEVEL_ITEM_STRUCT , TOP_LEVEL_ITEM_ENUM ,
  TOP_LEVEL_ITEM_ONEOF
}
 

Functions

struct struct_parserstruct_parser_new ()
 create and init a struct_parser instance.
 
void struct_parser_free (struct struct_parser *parser)
 free a struct_parser instance.
 
int struct_parser_parse (struct struct_parser *parser, sstr_t content)
 parse a struct definition file, and store the parsed structs in struct_parser.
 
int struct_parser_validate_to (struct struct_parser *parser, FILE *out)
 Validate parsed schema and optionally print diagnostics.
 
int struct_parser_validate (struct struct_parser *parser)
 Validate parsed schema for semantic errors.
 

Detailed Description

parse struct definition file.

Macro Definition Documentation

◆ PERROR

#define PERROR (   parser,
  fmt,
  ... 
)
Value:
diag_emit(parser->diag, DIAG_ERROR, parser->pos.line, parser->pos.col, \
fmt, ##__VA_ARGS__)

Function Documentation

◆ struct_parser_free()

void struct_parser_free ( struct struct_parser parser)

free a struct_parser instance.

Parameters
parserstruct struct_parser*

◆ struct_parser_new()

struct struct_parser * struct_parser_new ( )

create and init a struct_parser instance.

Returns
struct struct_parser* if success, NULL otherwise.

◆ struct_parser_parse()

int struct_parser_parse ( struct struct_parser parser,
sstr_t  content 
)

parse a struct definition file, and store the parsed structs in struct_parser.

Parameters
parsercontext of parser.
contentcontent of the file.
Returns
int 0 if success, -1 otherwise.

◆ struct_parser_validate()

int struct_parser_validate ( struct struct_parser parser)

Validate parsed schema for semantic errors.

Checks for: undefined type references, duplicate field names, duplicate enum values, and C keyword usage.

Parameters
parserParser 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
parserParser with populated struct_map, enum_map, and oneof_map.
outDestination stream for diagnostics, or NULL to suppress printing.
Returns
0 if no errors, -1 if validation errors found.