Macro in stdx_tml.h

X_TML_VERSION_MAJOR

#define X_TML_VERSION_MAJOR 2
Macro in stdx_tml.h

X_TML_VERSION_MINOR

#define X_TML_VERSION_MINOR 1
Macro in stdx_tml.h

X_TML_VERSION_PATCH

#define X_TML_VERSION_PATCH 0
Struct in stdx_tml.h

TMLString

typedef struct TMLString{
  char const *data;
  u32 size;
}TMLString;
Enum in stdx_tml.h

TMLValueType

typedef enum TMLValueType{
  TML_VALUE_BOOL,
  TML_VALUE_I64,
  TML_VALUE_F64,
  TML_VALUE_STRING,
  TML_VALUE_ARRAY_I64,
  TML_VALUE_ARRAY_F64,
  TML_VALUE_ARRAY_STRING
}TMLValueType;
Struct in stdx_tml.h

TMLArray

typedef struct TMLArray{
  u32 first;
  u32 count;
}TMLArray;
Struct in stdx_tml.h

TMLI64Slice

typedef struct TMLI64Slice{
  i64 const *data;
  u32 count;
}TMLI64Slice;
Struct in stdx_tml.h

TMLF64Slice

typedef struct TMLF64Slice{
  f64 const *data;
  u32 count;
}TMLF64Slice;
Struct in stdx_tml.h

TMLStringSlice

typedef struct TMLStringSlice{
  TMLString const *data;
  u32 count;
}TMLStringSlice;
Struct in stdx_tml.h

TMLDocument

typedef struct TMLDocument{
  void *memory;
  u64 memory_size;
  TMLNode *nodes;
  TMLEntry *entries;
  char *string_data;
  i64 *array_i64;
  f64 *array_f64;
  TMLString *array_string;
  u32 node_count;
  u32 entry_count;
  u32 string_size;
  u32 array_i64_count;
  u32 array_f64_count;
  u32 array_string_count;
  u32 first_root_node;
  u32 last_root_node;
  u32 root_node_count;
}TMLDocument;
Struct in stdx_tml.h

TMLParseResult

typedef struct TMLParseResult{
  int ok;
  char error[256];
  u32 line;
  u32 column;
  TMLDocument *document;
}TMLParseResult;
Function in stdx_tml.h

tml_document_free

Release all memory associated with a parsed TML document.

X_TML_API void tml_document_free(TMLDocument *doc);

Parameters

TMLDocument *doc
Pointer to the document returned by tml_parse(). The document and all associated internal memory become invalid after this call.
Function in stdx_tml.h

tml_parse

Parse a TML document from a UTF-8 source string.

X_TML_API TMLParseResult tml_parse(char const *source);

Parameters

char const *source
Null-terminated source text.

Returns

Parse result structure. On success: - result.ok is non-zero - result.document contains the parsed immutable document On failure: - result.ok is 0 - result.error contains a human-readable error message - result.line and result.column identify the error location The returned document must be released with: tml_document_free()

Function in stdx_tml.h

tml_node_at

Retrieve a node by global node index.

X_TML_API TMLNode const * tml_node_at(
 TMLDocument const *doc,
 u32 index
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
u32 index
Zero-based global node index.

Returns

Pointer to the node, or NULL if the index is invalid. Nodes are stored sequentially in document order.

Function in stdx_tml.h

tml_entry_at

Retrieve an entry by global entry index.

X_TML_API TMLEntry const * tml_entry_at(
 TMLDocument const *doc,
 u32 index
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
u32 index
Zero-based global entry index.

Returns

Pointer to the entry, or NULL if the index is invalid. Entries are stored sequentially in document order.

Function in stdx_tml.h

tml_root_node_at

Retrieve a root node by index.

X_TML_API TMLNode const * tml_root_node_at(
 TMLDocument const *doc,
 u32 index
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
u32 index
Zero-based root node index.

Returns

Pointer to the root node, or NULL if the index is invalid.

Function in stdx_tml.h

tml_node_child_at

Retrieve a direct child node by index.

X_TML_API TMLNode const * tml_node_child_at(
 TMLDocument const *doc,
 TMLNode const *node,
 u32 index
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
u32 index
Zero-based child node index.

Returns

Pointer to the child node, or NULL if the index is invalid. Child indices are stable and include both named and anonymous nodes.

Function in stdx_tml.h

tml_node_entry_at

Retrieve a direct entry from a node by index.

X_TML_API TMLEntry const * tml_node_entry_at(
 TMLDocument const *doc,
 TMLNode const *node,
 u32 index
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
u32 index
Zero-based entry index.

Returns

Pointer to the entry, or NULL if the index is invalid.

Function in stdx_tml.h

tml_node_find_child

Find a direct child node by name.

X_TML_API TMLNode const * tml_node_find_child(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Child node name.

Returns

Pointer to the matching child node, or NULL if no child matches.

Function in stdx_tml.h

tml_node_find_entry

Find a direct entry by name.

X_TML_API TMLEntry const * tml_node_find_entry(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Entry name.

Returns

Pointer to the matching entry, or NULL if no entry matches.

Function in stdx_tml.h

tml_entry_get_bool

Retrieve a boolean value from an entry.

X_TML_API int tml_entry_get_bool(
 TMLEntry const *entry,
 u8 *out_value
);

Parameters

TMLEntry const *entry
Pointer to the entry.
u8 *out_value
Output boolean value.

Returns

Non-zero on success, 0 if the entry is NULL or not a boolean.

Function in stdx_tml.h

tml_entry_get_i64

Retrieve a signed 64-bit integer value from an entry.

X_TML_API int tml_entry_get_i64(
 TMLEntry const *entry,
 i64 *out_value
);

Parameters

TMLEntry const *entry
Pointer to the entry.
i64 *out_value
Output integer value.

Returns

Non-zero on success, 0 if the entry is NULL or not an integer.

Function in stdx_tml.h

tml_entry_get_f64

Retrieve a double-precision floating point value from an entry.

X_TML_API int tml_entry_get_f64(
 TMLEntry const *entry,
 f64 *out_value
);

Parameters

TMLEntry const *entry
Pointer to the entry.
f64 *out_value
Output floating point value.

Returns

Non-zero on success, 0 if the entry is NULL or not a float.

Function in stdx_tml.h

tml_entry_get_string

Retrieve a string value from an entry.

X_TML_API int tml_entry_get_string(
 TMLEntry const *entry,
 TMLString *out_value
);

Parameters

TMLEntry const *entry
Pointer to the entry.
TMLString *out_value
Output string view.

Returns

Non-zero on success, 0 if the entry is NULL or not a string.

Function in stdx_tml.h

tml_entry_get_i64_array

Retrieve an i64 array slice from an entry.

X_TML_API int tml_entry_get_i64_array(
 TMLDocument const *doc,
 TMLEntry const *entry,
 TMLI64Slice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLEntry const *entry
Pointer to the entry.
TMLI64Slice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the entry is NULL or not an i64 array.

Function in stdx_tml.h

tml_entry_get_f64_array

Retrieve an f64 array slice from an entry.

X_TML_API int tml_entry_get_f64_array(
 TMLDocument const *doc,
 TMLEntry const *entry,
 TMLF64Slice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLEntry const *entry
Pointer to the entry.
TMLF64Slice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the entry is NULL or not an f64 array.

Function in stdx_tml.h

tml_entry_get_string_array

Retrieve a string array slice from an entry.

X_TML_API int tml_entry_get_string_array(
 TMLDocument const *doc,
 TMLEntry const *entry,
 TMLStringSlice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLEntry const *entry
Pointer to the entry.
TMLStringSlice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the entry is NULL or not a string array.

Function in stdx_tml.h

tml_node_get_bool

Retrieve a boolean entry value from a node by name.

X_TML_API int tml_node_get_bool(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name,
 u8 *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Name of the entry.
u8 *out_value
Output boolean value.

Returns

Non-zero on success, 0 if the entry does not exist or is not a boolean.

Function in stdx_tml.h

tml_node_get_i64

Retrieve a signed 64-bit integer entry value from a node by name.

X_TML_API int tml_node_get_i64(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name,
 i64 *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Name of the entry.
i64 *out_value
Output integer value.

Returns

Non-zero on success, 0 if the entry does not exist or is not an integer.

Function in stdx_tml.h

tml_node_get_f64

Retrieve a double-precision floating point entry value from a node by name.

X_TML_API int tml_node_get_f64(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name,
 f64 *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Name of the entry.
f64 *out_value
Output floating point value.

Returns

Non-zero on success, 0 if the entry does not exist or is not a float.

Function in stdx_tml.h

tml_node_get_string

Retrieve a string entry value from a node by name.

X_TML_API int tml_node_get_string(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name,
 TMLString *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Name of the entry.
TMLString *out_value
Output string view.

Returns

Non-zero on success, 0 if the entry does not exist or is not a string.

Function in stdx_tml.h

tml_node_get_i64_array

Retrieve an i64 array entry from a node by name.

X_TML_API int tml_node_get_i64_array(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name,
 TMLI64Slice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Name of the entry.
TMLI64Slice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the entry does not exist or is not an i64 array.

Function in stdx_tml.h

tml_node_get_f64_array

Retrieve an f64 array entry from a node by name.

X_TML_API int tml_node_get_f64_array(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name,
 TMLF64Slice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Name of the entry.
TMLF64Slice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the entry does not exist or is not an f64 array.

Function in stdx_tml.h

tml_node_get_string_array

Retrieve a string array entry from a node by name.

X_TML_API int tml_node_get_string_array(
 TMLDocument const *doc,
 TMLNode const *node,
 char const *name,
 TMLStringSlice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
TMLNode const *node
Pointer to the parent node.
char const *name
Name of the entry.
TMLStringSlice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the entry does not exist or is not a string array.

Function in stdx_tml.h

tml_path_find_node

Find a node using a dot path.

X_TML_API TMLNode const * tml_path_find_node(
 TMLDocument const *doc,
 char const *path
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated node path.

Returns

Pointer to the matching node, or NULL if the path does not resolve. Path segments may refer to: - named child nodes - child node indices Example: scene.objects.1

Function in stdx_tml.h

tml_path_find_entry

Find an entry using a dot path.

X_TML_API TMLEntry const * tml_path_find_entry(
 TMLDocument const *doc,
 char const *path
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.

Returns

Pointer to the matching entry, or NULL if the path does not resolve. The final path segment must refer to an entry name. Example: scene.objects.1.position

Function in stdx_tml.h

tml_path_get_bool

Retrieve a boolean value using a dot path.

X_TML_API int tml_path_get_bool(
 TMLDocument const *doc,
 char const *path,
 u8 *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.
u8 *out_value
Output boolean value.

Returns

Non-zero on success, 0 if the path does not resolve or the value is not a boolean.

Function in stdx_tml.h

tml_path_get_i64

Retrieve a signed 64-bit integer value using a dot path.

X_TML_API int tml_path_get_i64(
 TMLDocument const *doc,
 char const *path,
 i64 *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.
i64 *out_value
Output integer value.

Returns

Non-zero on success, 0 if the path does not resolve or the value is not an integer.

Function in stdx_tml.h

tml_path_get_f64

Retrieve a double-precision floating point value using a dot path.

X_TML_API int tml_path_get_f64(
 TMLDocument const *doc,
 char const *path,
 f64 *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.
f64 *out_value
Output floating point value.

Returns

Non-zero on success, 0 if the path does not resolve or the value is not a float.

Function in stdx_tml.h

tml_path_get_string

Retrieve a string value using a dot path.

X_TML_API int tml_path_get_string(
 TMLDocument const *doc,
 char const *path,
 TMLString *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.
TMLString *out_value
Output string view.

Returns

Non-zero on success, 0 if the path does not resolve or the value is not a string.

Function in stdx_tml.h

tml_path_get_i64_array

Retrieve an i64 array using a dot path.

X_TML_API int tml_path_get_i64_array(
 TMLDocument const *doc,
 char const *path,
 TMLI64Slice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.
TMLI64Slice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the path does not resolve or the value is not an i64 array.

Function in stdx_tml.h

tml_path_get_f64_array

Retrieve an f64 array using a dot path.

X_TML_API int tml_path_get_f64_array(
 TMLDocument const *doc,
 char const *path,
 TMLF64Slice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.
TMLF64Slice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the path does not resolve or the value is not an f64 array.

Function in stdx_tml.h

tml_path_get_string_array

Retrieve a string array using a dot path.

X_TML_API int tml_path_get_string_array(
 TMLDocument const *doc,
 char const *path,
 TMLStringSlice *out_value
);

Parameters

TMLDocument const *doc
Pointer to the parsed document.
char const *path
Dot-separated entry path.
TMLStringSlice *out_value
Output array slice.

Returns

Non-zero on success, 0 if the path does not resolve or the value is not a string array.

Macro in stdx_tml.h

X_TML_ALLOC

Internal macro for allocating memory. To override how this header allocates memory, define this macro with a different implementation before including this header.

#define X_TML_ALLOC(sz) calloc(1, sz)

Parameters

sz
The size of memory to alloc.
Macro in stdx_tml.h

X_TML_FREE

Internal macro for freeing memory. To override how this header frees memory, define this macro with a different implementation before including this header.

#define X_TML_FREE(p) free(p)

Parameters

p
The address of memory region to free.
Macro in stdx_tml.h

TML_INVALID_INDEX

#define TML_INVALID_INDEX((uint32_t)0xFFFFFFFFu)
Struct in stdx_tml.h

TMLStats

typedef struct TMLStats{
  u32 node_count;
  u32 entry_count;
  u32 string_size;
  u32 array_i64_count;
  u32 array_f64_count;
  u32 array_string_count;
}TMLStats;
Enum in stdx_tml.h

TMLParseMode

typedef enum TMLParseMode{
  TML_PARSE_COUNT,
  TML_PARSE_WRITE
}TMLParseMode;
Struct in stdx_tml.h

TMLScope

typedef struct TMLScope{
  u32 node;
  u32 indent;
}TMLScope;
Struct in stdx_tml.h

TMLParser

typedef struct TMLParser{
  char const *source;
  char const *cursor;
  char const *line_start;
  u32 line;
  u32 indent_unit;
  TMLParseMode mode;
  TMLStats stats;
  TMLDocument *doc;
  u32 node_cursor;
  u32 entry_cursor;
  u32 string_cursor;
  u32 array_i64_cursor;
  u32 array_f64_cursor;
  u32 array_string_cursor;
  TMLScope scopes[256];
  u32 scope_count;
  char error[256];
  u32 error_line;
  u32 error_column;
}TMLParser;
Enum in stdx_tml.h

TMLScalarKind

typedef enum TMLScalarKind{
  TML_SCALAR_BOOL,
  TML_SCALAR_I64,
  TML_SCALAR_F64,
  TML_SCALAR_STRING
}TMLScalarKind;