das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
toml.h
Go to the documentation of this file.
1/* Copyright (c) 2024-2026, CK Tan.
2 * https://github.com/cktan/tomlc17/blob/main/LICENSE
3 */
4
5/* das2C: generated by buildfiles/import_toml.sh, do not edit. From
6 * tomlc17 commit 85000d0836ce6089065b4241220e1e6f4aec2310
7 * Public names carry the dastoml_ and DASTOML_ prefixes and the entry points
8 * carry DAS_API, see the script for why. */
9
19#ifndef DASTOMLC17_H
20#define DASTOMLC17_H
21
22// A crude way to determine version. Manually changed.
23#define DASTOMLC17_RELEASE_AFTER "260618"
24
25/*
26 * USAGE:
27 *
28 * 1. Call dastoml_parse(), dastoml_parse_file(), or dastoml_parse_file_ex()
29 * 2. Check result.ok
30 * 3. Use dastoml_get() or dastoml_seek() to query and traverse the
31 * result.toptab
32 * 4. Call dastoml_free() to release resources.
33 *
34 */
35
36#include <stdbool.h>
37#include <stdint.h>
38#include <stdio.h>
39
40#include <das3/defs.h> /* das2C: DAS_API */
41
42#ifdef __cplusplus
43#define DASTOML_EXTERN extern "C"
44#else
45#define DASTOML_EXTERN extern
46#endif
47
65
72typedef struct dastoml_datum_t dastoml_datum_t;
75 uint32_t flag;
76 int lineno;
77 int colno;
78 const char *source;
80 union {
81 const char *s;
82 struct {
83 const char *ptr;
84 int len;
85 } str;
86 int64_t int64;
87 double fp64;
88 bool boolean;
89 struct {
90 int16_t year, month, day;
91 int16_t hour, minute, second;
92 int32_t usec;
93 int16_t tz;
94 } ts;
95 struct {
96 int32_t size;
98 } arr;
99 struct {
100 int32_t size;
101 const char **key;
102 int *len;
104 } tab;
105 } u;
106};
107
114#define DASTOML_FLAG_INLINED \
115 1
116#define DASTOML_FLAG_STDEXPR 2
117#define DASTOML_FLAG_EXPLICIT 4
129
138DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse(const char *src, int len);
139
150DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_named(const char *src, int len,
151 const char *name);
152
164DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_file(FILE *fp);
165
178DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_file_named(FILE *fp, const char *name);
179
188DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_file_ex(const char *fname);
189
195DASTOML_EXTERN DAS_API void dastoml_free(dastoml_result_t result);
196
205DASTOML_EXTERN DAS_API dastoml_datum_t dastoml_get(dastoml_datum_t table, const char *key);
206
215DASTOML_EXTERN DAS_API dastoml_datum_t dastoml_seek(dastoml_datum_t table,
216 const char *multipart_key);
217
223static inline dastoml_datum_t dastoml_table_find(dastoml_datum_t table,
224 const char *key) {
225 return dastoml_get(table, key);
226}
227
251DASTOML_EXTERN DAS_API dastoml_result_t dastoml_merge(const dastoml_result_t *r1,
252 const dastoml_result_t *r2);
253
264DASTOML_EXTERN DAS_API bool dastoml_equiv(const dastoml_result_t *r1, const dastoml_result_t *r2);
265
273 void *(*mem_realloc)(void *ptr,
274 size_t size);
276 void (*mem_free)(void *ptr);
277};
278
287DASTOML_EXTERN DAS_API dastoml_option_t dastoml_default_option(void);
288
296DASTOML_EXTERN DAS_API void dastoml_set_option(dastoml_option_t opt);
297
298#endif // DASTOMLC17_H
Minimal definitions for das2 utilities that can safely be run without calling das_init().
Represents a single piece of TOML data.
Definition toml.h:73
int * len
Array of key lengths.
Definition toml.h:102
const char * ptr
NUL terminated string pointer.
Definition toml.h:83
double fp64
64-bit floating point value
Definition toml.h:87
int colno
1-based source column number, 0 if synthesized
Definition toml.h:77
int64_t int64
64-bit integer value
Definition toml.h:86
int lineno
1-based source line number, 0 if synthesized
Definition toml.h:76
bool boolean
Boolean value.
Definition toml.h:88
uint32_t flag
Internal flag, do not use.
Definition toml.h:75
int16_t tz
Timezone offset in minutes.
Definition toml.h:93
dastoml_type_t type
Type of the datum.
Definition toml.h:74
const char * s
Shorthand for str.ptr.
Definition toml.h:81
dastoml_datum_t * value
Array of values corresponding to keys.
Definition toml.h:103
int16_t year
< Date and time components
Definition toml.h:90
const char * source
Source name (e.g.
Definition toml.h:78
dastoml_datum_t * elem
Array of elements.
Definition toml.h:97
const char ** key
Array of keys.
Definition toml.h:101
int32_t size
< Array data
Definition toml.h:96
int len
Length of the string excluding the terminating NUL.
Definition toml.h:84
Global options for the TOML parser.
Definition toml.h:270
void(* mem_free)(void *ptr)
Custom free function.
Definition toml.h:276
bool check_utf8
If true, check if all characters are valid UTF-8.
Definition toml.h:271
Result of a TOML parsing operation.
Definition toml.h:123
bool ok
True if parsing was successful.
Definition toml.h:124
char errmsg[200]
Error message (valid if ok is false)
Definition toml.h:126
void * __internal
Internal state, do not use.
Definition toml.h:127
dastoml_datum_t toptab
The top-level table (valid if ok is true)
Definition toml.h:125
DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_file_ex(const char *fname)
Parse a TOML document from a file path.
DASTOML_EXTERN DAS_API dastoml_datum_t dastoml_seek(dastoml_datum_t table, const char *multipart_key)
Locate a value using a multipart-key (e.g., "a.b.c").
DASTOML_EXTERN DAS_API void dastoml_set_option(dastoml_option_t opt)
Set the global parser options.
dastoml_type_t
Enumeration of TOML data types.
Definition toml.h:51
@ DASTOML_BOOLEAN
Boolean type.
Definition toml.h:56
@ DASTOML_STRING
String type.
Definition toml.h:53
@ DASTOML_DATETIMETZ
Offset datetime type.
Definition toml.h:60
@ DASTOML_TABLE
Table type.
Definition toml.h:62
@ DASTOML_TIME
Local time type.
Definition toml.h:58
@ DASTOML_ARRAY
Array type.
Definition toml.h:61
@ DASTOML_INT64
64-bit integer type
Definition toml.h:54
@ DASTOML_DATETIME
Local datetime type.
Definition toml.h:59
@ DASTOML_UNKNOWN
Unknown or invalid type.
Definition toml.h:52
@ DASTOML_DATE
Local date type.
Definition toml.h:57
@ DASTOML_FP64
64-bit floating point type
Definition toml.h:55
DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse(const char *src, int len)
Parse a TOML document from a string.
DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_file(FILE *fp)
Parse a TOML document from a file pointer.
DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_named(const char *src, int len, const char *name)
Parse a TOML document, tagging every datum with a source name.
DASTOML_EXTERN DAS_API dastoml_option_t dastoml_default_option(void)
Get the default parser options.
DASTOML_EXTERN DAS_API void dastoml_free(dastoml_result_t result)
Release resources allocated for a TOML result.
DASTOML_EXTERN DAS_API bool dastoml_equiv(const dastoml_result_t *r1, const dastoml_result_t *r2)
Compare two TOML results for equality.
DASTOML_EXTERN DAS_API dastoml_datum_t dastoml_get(dastoml_datum_t table, const char *key)
Find a value for a specific key in a TOML table.
DASTOML_EXTERN DAS_API dastoml_result_t dastoml_parse_file_named(FILE *fp, const char *name)
Parse a TOML document from a file pointer, tagging datums with a name.
DASTOML_EXTERN DAS_API dastoml_result_t dastoml_merge(const dastoml_result_t *r1, const dastoml_result_t *r2)
Merge two TOML results.