==> include/mesh/toml.h <==1/* @ajax/mesh-toml: the value syntax of `program.toml` (mesh-host manifest.rs):
2 * integers (decimal or 0x hex, `_` separators), negative integers, floats
3 * (with a '.'), "strings" (no escapes), true/false, and one-line lists of
4 * strings; `#` comments outside strings. Errors read exactly as the Rust's. */
5#ifndef MESH_TOML_H
6#define MESH_TOML_H
7
8#include "mesh/text.h"
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13
14typedef enum { MESH_TOML_INT, MESH_TOML_NEG, MESH_TOML_FLOAT, MESH_TOML_STR, MESH_TOML_BOOL, MESH_TOML_LIST } mesh_toml_kind;
15
16typedef struct {
17 mesh_toml_kind kind;
18 uint32_t n; /* INT, NEG (the magnitude) */
19 double f; /* FLOAT */
20 char *s; /* STR */
21 bool b; /* BOOL */
22 char **items; /* LIST */
23 size_t nitems;
24} mesh_toml_val;
25
26/* Rust's `int`: `_` removed, then "0x" hex or decimal u32 (an optional '+'). */
27bool mesh_toml_int(const char *s, size_t n, uint32_t *out);
28/* "a:b", both `int`s after trimming. */
29bool mesh_toml_pair(const char *s, size_t n, uint32_t *a, uint32_t *b);
30/* One value (the text after '='). False with *err ("unterminated string",
31 * "bad value \"x\"", ...). */
32bool mesh_toml_value(const char *v, size_t n, mesh_toml_val *out, char **err);
33/* The length of line without a `#` comment that is not inside a string. */
34size_t mesh_toml_strip_comment(const char *line, size_t n);
35/* Rust's `{:?}` of the value: Int(5), Neg(3), Float(2.0), Str("x"), Bool(true), List(["a", "b"]). */
36void mesh_toml_val_debug(mesh_text *t, const mesh_toml_val *v);
37char *mesh_toml_val_debug_str(const mesh_toml_val *v);
38void mesh_toml_val_free(mesh_toml_val *v);
39
40#endif