Kohi Game Engine
kson_parser.h File Reference

This file contains the parser implementation for the KSON (Kohi Storage Object Notation) file format. More...

#include "defines.h"
#include "math/math_types.h"
#include "strings/kname.h"
#include "strings/kstring_id.h"

Go to the source code of this file.

Data Structures

struct  kson_token
 
struct  kson_parser
 
struct  kson_object
 
union  kson_property_value
 
struct  kson_property
 
struct  kson_tree
 

Typedefs

typedef enum kson_token_type kson_token_type
 
typedef struct kson_token kson_token
 
typedef struct kson_parser kson_parser
 
typedef enum kson_property_type kson_property_type
 
typedef enum kson_object_type kson_object_type
 
typedef struct kson_object kson_object
 
typedef kson_object kson_array
 
typedef union kson_property_value kson_property_value
 
typedef struct kson_property kson_property
 
typedef struct kson_tree kson_tree
 

Enumerations

enum  kson_token_type {
  KSON_TOKEN_TYPE_UNKNOWN , KSON_TOKEN_TYPE_WHITESPACE , KSON_TOKEN_TYPE_COMMENT , KSON_TOKEN_TYPE_IDENTIFIER ,
  KSON_TOKEN_TYPE_OPERATOR_EQUAL , KSON_TOKEN_TYPE_OPERATOR_MINUS , KSON_TOKEN_TYPE_OPERATOR_PLUS , KSON_TOKEN_TYPE_OPERATOR_SLASH ,
  KSON_TOKEN_TYPE_OPERATOR_ASTERISK , KSON_TOKEN_TYPE_OPERATOR_DOT , KSON_TOKEN_TYPE_STRING_LITERAL , KSON_TOKEN_TYPE_NUMERIC_LITERAL ,
  KSON_TOKEN_TYPE_BOOLEAN , KSON_TOKEN_TYPE_CURLY_BRACE_OPEN , KSON_TOKEN_TYPE_CURLY_BRACE_CLOSE , KSON_TOKEN_TYPE_BRACKET_OPEN ,
  KSON_TOKEN_TYPE_BRACKET_CLOSE , KSON_TOKEN_TYPE_NEWLINE , KSON_TOKEN_TYPE_EOF
}
 
enum  kson_property_type {
  KSON_PROPERTY_TYPE_UNKNOWN , KSON_PROPERTY_TYPE_INT , KSON_PROPERTY_TYPE_FLOAT , KSON_PROPERTY_TYPE_STRING ,
  KSON_PROPERTY_TYPE_OBJECT , KSON_PROPERTY_TYPE_ARRAY , KSON_PROPERTY_TYPE_BOOLEAN
}
 
enum  kson_object_type { KSON_OBJECT_TYPE_OBJECT , KSON_OBJECT_TYPE_ARRAY }
 

Functions

KAPI const char * kson_property_type_to_string (kson_property_type type)
 Gets the given property type as a constant string. NOTE: Caller should NOT attempt to free this string. More...
 
KAPI b8 kson_parser_create (kson_parser *out_parser)
 Creates a kson parser. Note that it is generally recommended to use the kson_tree_from_string() and kson_tree_to_string() functions instead of invoking this manually, as these also handle cleanup of the parser object. More...
 
KAPI void kson_parser_destroy (kson_parser *parser)
 Destroys the provided parser. More...
 
KAPI b8 kson_parser_tokenize (kson_parser *parser, const char *source)
 Uses the given parser to tokenize the provided source string. Note that it is recommended to use the kson_tree_from_string() function instead. More...
 
KAPI b8 kson_parser_parse (kson_parser *parser, kson_tree *out_tree)
 Uses the given parser to build a kson_tree using the tokens previously parsed. This means that kson_parser_tokenize() must have been called and completed successfully for this function to work. It is recommended to use kson_tree_from_string() instead. More...
 
KAPI b8 kson_tree_from_string (const char *source, kson_tree *out_tree)
 Takes the provided source and tokenizes, then parses it in order to create a tree of kson_objects. More...
 
KAPI const char * kson_tree_to_string (kson_tree *tree)
 
KAPI void kson_object_cleanup (kson_object *obj)
 Cleans up the given kson object and its properties recursively. More...
 
KAPI void kson_tree_cleanup (kson_tree *tree)
 Performs cleanup operations on the given tree, freeing memory and resources held by it. More...
 
KAPI b8 kson_array_value_add_int (kson_array *array, i64 value)
 Adds an unnamed signed 64-bit integer value to the provided array. More...
 
KAPI b8 kson_array_value_add_float (kson_array *array, f32 value)
 Adds an unnamed floating-point value to the provided array. More...
 
KAPI b8 kson_array_value_add_boolean (kson_array *array, b8 value)
 Adds an unnamed boolean value to the provided array. More...
 
KAPI b8 kson_array_value_add_string (kson_array *array, const char *value)
 Adds an unnamed string value to the provided array. More...
 
KAPI b8 kson_array_value_add_mat4 (kson_array *array, mat4 value)
 Adds an unnamed mat4 value to the provided array. More...
 
KAPI b8 kson_array_value_add_vec4 (kson_array *array, vec4 value)
 Adds an unnamed vec4 value to the provided array. More...
 
KAPI b8 kson_array_value_add_vec3 (kson_array *array, vec3 value)
 Adds an unnamed vec3 value to the provided array. More...
 
KAPI b8 kson_array_value_add_vec2 (kson_array *array, vec2 value)
 Adds an unnamed vec2 value to the provided array. More...
 
KAPI b8 kson_array_value_add_kname_as_string (kson_array *array, kname value)
 Adds an unnamed kname value as a string to the provided array. More...
 
KAPI b8 kson_array_value_add_kstring_id_as_string (kson_array *array, kstring_id value)
 Adds an unnamed kstring_id value as a string to the provided array. More...
 
KAPI b8 kson_array_value_add_object (kson_array *array, kson_object value)
 Adds an unnamed object value to the provided array. More...
 
KAPI b8 kson_array_value_add_object_empty (kson_array *array)
 Adds an unnamed empty object value to the provided array. More...
 
KAPI b8 kson_array_value_add_array (kson_array *array, kson_array value)
 Adds an unnamed array value to the provided array. More...
 
KAPI b8 kson_array_value_add_array_empty (kson_array *array)
 Adds an unnamed empty array value to the provided array. More...
 
KAPI b8 kson_object_value_add_int (kson_object *object, const char *name, i64 value)
 Adds a named signed 64-bit integer value to the provided object. More...
 
KAPI b8 kson_object_value_add_float (kson_object *object, const char *name, f32 value)
 Adds a named floating-point value to the provided object. More...
 
KAPI b8 kson_object_value_add_boolean (kson_object *object, const char *name, b8 value)
 Adds a named boolean value to the provided object. More...
 
KAPI b8 kson_object_value_add_string (kson_object *object, const char *name, const char *value)
 Adds a named string value to the provided object. More...
 
KAPI b8 kson_object_value_add_mat4 (kson_object *object, const char *name, mat4 value)
 Adds a named mat4 value to the provided object. More...
 
KAPI b8 kson_object_value_add_vec4 (kson_object *object, const char *name, vec4 value)
 Adds a named vec4 value to the provided object. More...
 
KAPI b8 kson_object_value_add_vec3 (kson_object *object, const char *name, vec3 value)
 Adds a named vec3 value to the provided object. More...
 
KAPI b8 kson_object_value_add_vec2 (kson_object *object, const char *name, vec2 value)
 Adds a named vec2 value to the provided object. More...
 
KAPI b8 kson_object_value_add_kname_as_string (kson_object *object, const char *name, kname value)
 Adds a named kname value as a string to the provided object. More...
 
KAPI b8 kson_object_value_add_kstring_id_as_string (kson_object *object, const char *name, kstring_id value)
 Adds a named kstring_id value as a string to the provided object. More...
 
KAPI b8 kson_object_value_add_object (kson_object *object, const char *name, kson_object value)
 Adds a named object value to the provided object. More...
 
KAPI b8 kson_object_value_add_object_empty (kson_object *object, const char *name)
 Adds a named empty object value to the provided object. More...
 
KAPI b8 kson_object_value_add_array (kson_object *object, const char *name, kson_array value)
 Adds a named array value to the provided object. More...
 
KAPI b8 kson_object_value_add_array_empty (kson_object *object, const char *name)
 Adds a named empty array value to the provided object. More...
 
KAPI b8 kson_array_element_count_get (kson_array *array, u32 *out_count)
 Obtains the length of the given array. More...
 
KAPI b8 kson_array_element_type_at (kson_array *array, u32 index, kson_property_type *out_type)
 Obtains the element type at the provided index of the given array. Fails if out of range. More...
 
KAPI b8 kson_array_element_value_get_int (const kson_array *array, u32 index, i64 *out_value)
 Attempts to retrieve the array element's value at the provided index as a signed integer. Fails if out of range. or on type mismatch. More...
 
KAPI b8 kson_array_element_value_get_float (const kson_array *array, u32 index, f32 *out_value)
 Attempts to retrieve the array element's value at the provided index as a floating-point number. Fails if out of range. or on type mismatch. More...
 
KAPI b8 kson_array_element_value_get_bool (const kson_array *array, u32 index, b8 *out_value)
 Attempts to retrieve the array element's value at the provided index as a boolean. Fails if out of range. or on type mismatch. More...
 
KAPI b8 kson_array_element_value_get_string (const kson_array *array, u32 index, const char **out_value)
 Attempts to retrieve the array element's value at the provided index as a string. Fails if out of range or on type mismatch. More...
 
KAPI b8 kson_array_element_value_get_mat4 (const kson_array *array, u32 index, mat4 *out_value)
 Attempts to retrieve the array element's value at the provided index as a mat4. Fails if out of range or on type mismatch (these are stored as strings). More...
 
KAPI b8 kson_array_element_value_get_vec4 (const kson_array *array, u32 index, vec4 *out_value)
 Attempts to retrieve the array element's value at the provided index as a vec4. Fails if out of range or on type mismatch (these are stored as strings). More...
 
KAPI b8 kson_array_element_value_get_vec3 (const kson_array *array, u32 index, vec3 *out_value)
 Attempts to retrieve the array element's value at the provided index as a vec3. Fails if out of range or on type mismatch (these are stored as strings). More...
 
KAPI b8 kson_array_element_value_get_vec2 (const kson_array *array, u32 index, vec2 *out_value)
 Attempts to retrieve the array element's value at the provided index as a vec2. Fails if out of range or on type mismatch (these are stored as strings). More...
 
KAPI b8 kson_array_element_value_get_string_as_kname (const kson_array *array, u32 index, kname *out_value)
 Attempts to retrieve the array element's value at the provided index as a kname. Fails if out of range or on type mismatch. knames are always stored as strings. More...
 
KAPI b8 kson_array_element_value_get_string_as_kstring_id (const kson_array *array, u32 index, kstring_id *out_value)
 Attempts to retrieve the array element's value at the provided index as a kstring_id. Fails if out of range or on type mismatch. kstring_ids are always stored as strings. More...
 
KAPI b8 kson_array_element_value_get_object (const kson_array *array, u32 index, kson_object *out_value)
 Attempts to retrieve the array element's value at the provided index as an object. Fails if out of range. or on type mismatch. More...
 
KAPI b8 kson_array_element_value_get_array (const kson_array *array, u32 index, kson_array *out_value)
 Attempts to retrieve the array element's value at the provided index as an array. Fails if out of range. or on type mismatch. More...
 
KAPI b8 kson_object_property_type_get (const kson_object *object, const char *name, kson_property_type *out_type)
 
KAPI b8 kson_object_property_count_get (const kson_object *object, u32 *out_count)
 
KAPI b8 kson_object_property_value_type_get (const kson_object *object, const char *name, kson_property_type *out_type)
 Attempts to retrieve the given object's property value type by name. Fails if not found. More...
 
KAPI b8 kson_object_property_value_get_int (const kson_object *object, const char *name, i64 *out_value)
 Attempts to retrieve the given object's property value by name as a signed integer. Fails if not found or on type mismatch. More...
 
KAPI b8 kson_object_property_value_get_float (const kson_object *object, const char *name, f32 *out_value)
 Attempts to retrieve the given object's property value by name as a floating-point number. Fails if not found or on type mismatch. More...
 
KAPI b8 kson_object_property_value_get_bool (const kson_object *object, const char *name, b8 *out_value)
 Attempts to retrieve the given object's property value by name as a boolean. Fails if not found or on type mismatch. More...
 
KAPI b8 kson_object_property_value_get_string (const kson_object *object, const char *name, const char **out_value)
 Attempts to retrieve the given object's property value by name as a string. Fails if not found or on type mismatch. NOTE: This function always allocates new memory, so the string should be released afterward. More...
 
KAPI b8 kson_object_property_value_get_mat4 (const kson_object *object, const char *name, mat4 *out_value)
 Attempts to retrieve the given object's property value by name as a mat4. Fails if not found or on type mismatch (these are always stored as strings). More...
 
KAPI b8 kson_object_property_value_get_vec4 (const kson_object *object, const char *name, vec4 *out_value)
 Attempts to retrieve the given object's property value by name as a vec4. Fails if not found or on type mismatch (these are always stored as strings). More...
 
KAPI b8 kson_object_property_value_get_vec3 (const kson_object *object, const char *name, vec3 *out_value)
 Attempts to retrieve the given object's property value by name as a vec3. Fails if not found or on type mismatch (these are always stored as strings). More...
 
KAPI b8 kson_object_property_value_get_vec2 (const kson_object *object, const char *name, vec2 *out_value)
 Attempts to retrieve the given object's property value by name as a vec2. Fails if not found or on type mismatch (these are always stored as strings). More...
 
KAPI b8 kson_object_property_value_get_string_as_kname (const kson_object *object, const char *name, kname *out_value)
 Attempts to retrieve the given object's property value by name as a kname. Fails if not found or on type mismatch. knames are always stored as thier original text format. More...
 
KAPI b8 kson_object_property_value_get_string_as_kstring_id (const kson_object *object, const char *name, kstring_id *out_value)
 Attempts to retrieve the given object's property value by name as a kstring_id. Fails if not found or on type mismatch. kstring_ids are always stored as thier original text format. More...
 
KAPI b8 kson_object_property_value_get_object (const kson_object *object, const char *name, kson_object *out_value)
 Attempts to retrieve the a copy given object's property value by name as an object. Fails if not found or on type mismatch. More...
 
KAPI b8 kson_object_property_value_get_array (const kson_object *object, const char *name, kson_array *out_value)
 Attempts to retrieve the a copy given object's property value by name as an array. Fails if not found or on type mismatch. More...
 
KAPI kson_property kson_object_property_create (const char *name)
 
KAPI kson_property kson_array_property_create (const char *name)
 
KAPI kson_object kson_object_create (void)
 Creates and returns a new kson object. More...
 
KAPI kson_array kson_array_create (void)
 Creates and returns a new kson array. More...
 

Detailed Description

This file contains the parser implementation for the KSON (Kohi Storage Object Notation) file format.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
2.0
Date
2024-12-10

Typedef Documentation

◆ kson_array

◆ kson_object

typedef struct kson_object kson_object

◆ kson_object_type

◆ kson_parser

typedef struct kson_parser kson_parser

◆ kson_property

typedef struct kson_property kson_property

◆ kson_property_type

◆ kson_property_value

◆ kson_token

typedef struct kson_token kson_token

◆ kson_token_type

◆ kson_tree

typedef struct kson_tree kson_tree

Enumeration Type Documentation

◆ kson_object_type

Enumerator
KSON_OBJECT_TYPE_OBJECT 
KSON_OBJECT_TYPE_ARRAY 

◆ kson_property_type

Enumerator
KSON_PROPERTY_TYPE_UNKNOWN 
KSON_PROPERTY_TYPE_INT 
KSON_PROPERTY_TYPE_FLOAT 
KSON_PROPERTY_TYPE_STRING 
KSON_PROPERTY_TYPE_OBJECT 
KSON_PROPERTY_TYPE_ARRAY 
KSON_PROPERTY_TYPE_BOOLEAN 

◆ kson_token_type

Enumerator
KSON_TOKEN_TYPE_UNKNOWN 
KSON_TOKEN_TYPE_WHITESPACE 
KSON_TOKEN_TYPE_COMMENT 
KSON_TOKEN_TYPE_IDENTIFIER 
KSON_TOKEN_TYPE_OPERATOR_EQUAL 
KSON_TOKEN_TYPE_OPERATOR_MINUS 
KSON_TOKEN_TYPE_OPERATOR_PLUS 
KSON_TOKEN_TYPE_OPERATOR_SLASH 
KSON_TOKEN_TYPE_OPERATOR_ASTERISK 
KSON_TOKEN_TYPE_OPERATOR_DOT 
KSON_TOKEN_TYPE_STRING_LITERAL 
KSON_TOKEN_TYPE_NUMERIC_LITERAL 
KSON_TOKEN_TYPE_BOOLEAN 
KSON_TOKEN_TYPE_CURLY_BRACE_OPEN 
KSON_TOKEN_TYPE_CURLY_BRACE_CLOSE 
KSON_TOKEN_TYPE_BRACKET_OPEN 
KSON_TOKEN_TYPE_BRACKET_CLOSE 
KSON_TOKEN_TYPE_NEWLINE 
KSON_TOKEN_TYPE_EOF 

Function Documentation

◆ kson_array_create()

KAPI kson_array kson_array_create ( void  )

Creates and returns a new kson array.

◆ kson_array_element_count_get()

KAPI b8 kson_array_element_count_get ( kson_array array,
u32 out_count 
)

Obtains the length of the given array.

Parameters
arrayThe array to retrieve the length of.
countA pointer to hold the array element count,
Returns
True on success; otherwise false.

◆ kson_array_element_type_at()

KAPI b8 kson_array_element_type_at ( kson_array array,
u32  index,
kson_property_type out_type 
)

Obtains the element type at the provided index of the given array. Fails if out of range.

Parameters
arrayThe array to retrieve the type from.
indexThe index into the array to check the type of. Must be in range.
countA pointer to hold the array element type,
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_array()

KAPI b8 kson_array_element_value_get_array ( const kson_array array,
u32  index,
kson_array out_value 
)

Attempts to retrieve the array element's value at the provided index as an array. Fails if out of range. or on type mismatch.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_bool()

KAPI b8 kson_array_element_value_get_bool ( const kson_array array,
u32  index,
b8 out_value 
)

Attempts to retrieve the array element's value at the provided index as a boolean. Fails if out of range. or on type mismatch.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_float()

KAPI b8 kson_array_element_value_get_float ( const kson_array array,
u32  index,
f32 out_value 
)

Attempts to retrieve the array element's value at the provided index as a floating-point number. Fails if out of range. or on type mismatch.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_int()

KAPI b8 kson_array_element_value_get_int ( const kson_array array,
u32  index,
i64 out_value 
)

Attempts to retrieve the array element's value at the provided index as a signed integer. Fails if out of range. or on type mismatch.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_mat4()

KAPI b8 kson_array_element_value_get_mat4 ( const kson_array array,
u32  index,
mat4 out_value 
)

Attempts to retrieve the array element's value at the provided index as a mat4. Fails if out of range or on type mismatch (these are stored as strings).

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_object()

KAPI b8 kson_array_element_value_get_object ( const kson_array array,
u32  index,
kson_object out_value 
)

Attempts to retrieve the array element's value at the provided index as an object. Fails if out of range. or on type mismatch.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_string()

KAPI b8 kson_array_element_value_get_string ( const kson_array array,
u32  index,
const char **  out_value 
)

Attempts to retrieve the array element's value at the provided index as a string. Fails if out of range or on type mismatch.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_string_as_kname()

KAPI b8 kson_array_element_value_get_string_as_kname ( const kson_array array,
u32  index,
kname out_value 
)

Attempts to retrieve the array element's value at the provided index as a kname. Fails if out of range or on type mismatch. knames are always stored as strings.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_string_as_kstring_id()

KAPI b8 kson_array_element_value_get_string_as_kstring_id ( const kson_array array,
u32  index,
kstring_id out_value 
)

Attempts to retrieve the array element's value at the provided index as a kstring_id. Fails if out of range or on type mismatch. kstring_ids are always stored as strings.

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_vec2()

KAPI b8 kson_array_element_value_get_vec2 ( const kson_array array,
u32  index,
vec2 out_value 
)

Attempts to retrieve the array element's value at the provided index as a vec2. Fails if out of range or on type mismatch (these are stored as strings).

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_vec3()

KAPI b8 kson_array_element_value_get_vec3 ( const kson_array array,
u32  index,
vec3 out_value 
)

Attempts to retrieve the array element's value at the provided index as a vec3. Fails if out of range or on type mismatch (these are stored as strings).

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_element_value_get_vec4()

KAPI b8 kson_array_element_value_get_vec4 ( const kson_array array,
u32  index,
vec4 out_value 
)

Attempts to retrieve the array element's value at the provided index as a vec4. Fails if out of range or on type mismatch (these are stored as strings).

Parameters
arrayA constant pointer to the array to search. Required.
indexThe array index to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_array_property_create()

KAPI kson_property kson_array_property_create ( const char *  name)

Creates and returns a new property of the array type.

Parameters
nameThe name of the property. Pass 0 if later adding to an array.
Returns
The newly created array property.

◆ kson_array_value_add_array()

KAPI b8 kson_array_value_add_array ( kson_array array,
kson_array  value 
)

Adds an unnamed array value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_array_empty()

KAPI b8 kson_array_value_add_array_empty ( kson_array array)

Adds an unnamed empty array value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
Returns
True on success; otherwise false.

◆ kson_array_value_add_boolean()

KAPI b8 kson_array_value_add_boolean ( kson_array array,
b8  value 
)

Adds an unnamed boolean value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_float()

KAPI b8 kson_array_value_add_float ( kson_array array,
f32  value 
)

Adds an unnamed floating-point value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_int()

KAPI b8 kson_array_value_add_int ( kson_array array,
i64  value 
)

Adds an unnamed signed 64-bit integer value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_kname_as_string()

KAPI b8 kson_array_value_add_kname_as_string ( kson_array array,
kname  value 
)

Adds an unnamed kname value as a string to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_kstring_id_as_string()

KAPI b8 kson_array_value_add_kstring_id_as_string ( kson_array array,
kstring_id  value 
)

Adds an unnamed kstring_id value as a string to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_mat4()

KAPI b8 kson_array_value_add_mat4 ( kson_array array,
mat4  value 
)

Adds an unnamed mat4 value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_object()

KAPI b8 kson_array_value_add_object ( kson_array array,
kson_object  value 
)

Adds an unnamed object value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_object_empty()

KAPI b8 kson_array_value_add_object_empty ( kson_array array)

Adds an unnamed empty object value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
Returns
True on success; otherwise false.

◆ kson_array_value_add_string()

KAPI b8 kson_array_value_add_string ( kson_array array,
const char *  value 
)

Adds an unnamed string value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set. Required. Must not be null.
Returns
True on success; otherwise false.

◆ kson_array_value_add_vec2()

KAPI b8 kson_array_value_add_vec2 ( kson_array array,
vec2  value 
)

Adds an unnamed vec2 value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_vec3()

KAPI b8 kson_array_value_add_vec3 ( kson_array array,
vec3  value 
)

Adds an unnamed vec3 value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_array_value_add_vec4()

KAPI b8 kson_array_value_add_vec4 ( kson_array array,
vec4  value 
)

Adds an unnamed vec4 value to the provided array.

Parameters
arrayA pointer to the array to add the property to.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_cleanup()

KAPI void kson_object_cleanup ( kson_object obj)

Cleans up the given kson object and its properties recursively.

Parameters
objA pointer to the object to be cleaned up. Required.

◆ kson_object_create()

KAPI kson_object kson_object_create ( void  )

Creates and returns a new kson object.

◆ kson_object_property_count_get()

KAPI b8 kson_object_property_count_get ( const kson_object object,
u32 out_count 
)

Obtains the count of properties of the given object.

Parameters
objectThe object to retrieve the property count of.
out_countA pointer to hold the object property count,
Returns
True on success; otherwise false.

◆ kson_object_property_create()

KAPI kson_property kson_object_property_create ( const char *  name)

Creates and returns a new property of the object type.

Parameters
nameThe name of the property. Pass 0 if later adding to an array.
Returns
The newly created object property.

◆ kson_object_property_type_get()

KAPI b8 kson_object_property_type_get ( const kson_object object,
const char *  name,
kson_property_type out_type 
)

Obtains the type of the property with the given name. Fails if the name is not found.

Parameters
objectThe object to retrieve the type from.
nameThe name of the property to retrieve.
out_typeA pointer to hold the object property type,
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_array()

KAPI b8 kson_object_property_value_get_array ( const kson_object object,
const char *  name,
kson_array out_value 
)

Attempts to retrieve the a copy given object's property value by name as an array. Fails if not found or on type mismatch.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold a copy of the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_bool()

KAPI b8 kson_object_property_value_get_bool ( const kson_object object,
const char *  name,
b8 out_value 
)

Attempts to retrieve the given object's property value by name as a boolean. Fails if not found or on type mismatch.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_float()

KAPI b8 kson_object_property_value_get_float ( const kson_object object,
const char *  name,
f32 out_value 
)

Attempts to retrieve the given object's property value by name as a floating-point number. Fails if not found or on type mismatch.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_int()

KAPI b8 kson_object_property_value_get_int ( const kson_object object,
const char *  name,
i64 out_value 
)

Attempts to retrieve the given object's property value by name as a signed integer. Fails if not found or on type mismatch.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_mat4()

KAPI b8 kson_object_property_value_get_mat4 ( const kson_object object,
const char *  name,
mat4 out_value 
)

Attempts to retrieve the given object's property value by name as a mat4. Fails if not found or on type mismatch (these are always stored as strings).

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_object()

KAPI b8 kson_object_property_value_get_object ( const kson_object object,
const char *  name,
kson_object out_value 
)

Attempts to retrieve the a copy given object's property value by name as an object. Fails if not found or on type mismatch.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold a copy of the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_string()

KAPI b8 kson_object_property_value_get_string ( const kson_object object,
const char *  name,
const char **  out_value 
)

Attempts to retrieve the given object's property value by name as a string. Fails if not found or on type mismatch. NOTE: This function always allocates new memory, so the string should be released afterward.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_string_as_kname()

KAPI b8 kson_object_property_value_get_string_as_kname ( const kson_object object,
const char *  name,
kname out_value 
)

Attempts to retrieve the given object's property value by name as a kname. Fails if not found or on type mismatch. knames are always stored as thier original text format.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_string_as_kstring_id()

KAPI b8 kson_object_property_value_get_string_as_kstring_id ( const kson_object object,
const char *  name,
kstring_id out_value 
)

Attempts to retrieve the given object's property value by name as a kstring_id. Fails if not found or on type mismatch. kstring_ids are always stored as thier original text format.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_vec2()

KAPI b8 kson_object_property_value_get_vec2 ( const kson_object object,
const char *  name,
vec2 out_value 
)

Attempts to retrieve the given object's property value by name as a vec2. Fails if not found or on type mismatch (these are always stored as strings).

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_vec3()

KAPI b8 kson_object_property_value_get_vec3 ( const kson_object object,
const char *  name,
vec3 out_value 
)

Attempts to retrieve the given object's property value by name as a vec3. Fails if not found or on type mismatch (these are always stored as strings).

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_get_vec4()

KAPI b8 kson_object_property_value_get_vec4 ( const kson_object object,
const char *  name,
vec4 out_value 
)

Attempts to retrieve the given object's property value by name as a vec4. Fails if not found or on type mismatch (these are always stored as strings).

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_valueA pointer to hold the object property's value.
Returns
True on success; otherwise false.

◆ kson_object_property_value_type_get()

KAPI b8 kson_object_property_value_type_get ( const kson_object object,
const char *  name,
kson_property_type out_type 
)

Attempts to retrieve the given object's property value type by name. Fails if not found.

Parameters
objectA constant pointer to the object to search. Required.
nameThe property name to search for. Required.
out_typeA pointer to hold the object property's type.
Returns
True on success; otherwise false.

◆ kson_object_value_add_array()

KAPI b8 kson_object_value_add_array ( kson_object object,
const char *  name,
kson_array  value 
)

Adds a named array value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_array_empty()

KAPI b8 kson_object_value_add_array_empty ( kson_object object,
const char *  name 
)

Adds a named empty array value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
Returns
True on success; otherwise false.

◆ kson_object_value_add_boolean()

KAPI b8 kson_object_value_add_boolean ( kson_object object,
const char *  name,
b8  value 
)

Adds a named boolean value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_float()

KAPI b8 kson_object_value_add_float ( kson_object object,
const char *  name,
f32  value 
)

Adds a named floating-point value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_int()

KAPI b8 kson_object_value_add_int ( kson_object object,
const char *  name,
i64  value 
)

Adds a named signed 64-bit integer value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_kname_as_string()

KAPI b8 kson_object_value_add_kname_as_string ( kson_object object,
const char *  name,
kname  value 
)

Adds a named kname value as a string to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_kstring_id_as_string()

KAPI b8 kson_object_value_add_kstring_id_as_string ( kson_object object,
const char *  name,
kstring_id  value 
)

Adds a named kstring_id value as a string to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_mat4()

KAPI b8 kson_object_value_add_mat4 ( kson_object object,
const char *  name,
mat4  value 
)

Adds a named mat4 value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_object()

KAPI b8 kson_object_value_add_object ( kson_object object,
const char *  name,
kson_object  value 
)

Adds a named object value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_object_empty()

KAPI b8 kson_object_value_add_object_empty ( kson_object object,
const char *  name 
)

Adds a named empty object value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
Returns
True on success; otherwise false.

◆ kson_object_value_add_string()

KAPI b8 kson_object_value_add_string ( kson_object object,
const char *  name,
const char *  value 
)

Adds a named string value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set. Required. Must not be null.
Returns
True on success; otherwise false.

◆ kson_object_value_add_vec2()

KAPI b8 kson_object_value_add_vec2 ( kson_object object,
const char *  name,
vec2  value 
)

Adds a named vec2 value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_vec3()

KAPI b8 kson_object_value_add_vec3 ( kson_object object,
const char *  name,
vec3  value 
)

Adds a named vec3 value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_object_value_add_vec4()

KAPI b8 kson_object_value_add_vec4 ( kson_object object,
const char *  name,
vec4  value 
)

Adds a named vec4 value to the provided object.

Parameters
objectA pointer to the object to add the property to.
nameA constant pointer to the name to be used. Required.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ kson_parser_create()

KAPI b8 kson_parser_create ( kson_parser out_parser)

Creates a kson parser. Note that it is generally recommended to use the kson_tree_from_string() and kson_tree_to_string() functions instead of invoking this manually, as these also handle cleanup of the parser object.

Parameters
out_parserA pointer to hold the newly-created parser.
Returns
True on success; otherwise false.

◆ kson_parser_destroy()

KAPI void kson_parser_destroy ( kson_parser parser)

Destroys the provided parser.

Parameters
parserA pointer to the parser to be destroyed.

◆ kson_parser_parse()

KAPI b8 kson_parser_parse ( kson_parser parser,
kson_tree out_tree 
)

Uses the given parser to build a kson_tree using the tokens previously parsed. This means that kson_parser_tokenize() must have been called and completed successfully for this function to work. It is recommended to use kson_tree_from_string() instead.

Parameters
parserA pointer to the parser to use. Required. Must be a valid parser that has already had kson_parser_tokenize() called against it successfully.
out_treeA pointer to hold the generated kson_tree. Required.
Returns
True on success; otherwise false.

◆ kson_parser_tokenize()

KAPI b8 kson_parser_tokenize ( kson_parser parser,
const char *  source 
)

Uses the given parser to tokenize the provided source string. Note that it is recommended to use the kson_tree_from_string() function instead.

Parameters
parserA pointer to the parser to use. Required. Must be a valid parser.
sourceA constant pointer to the source string to tokenize.
Returns
True on success; otherwise false.

◆ kson_property_type_to_string()

KAPI const char* kson_property_type_to_string ( kson_property_type  type)

Gets the given property type as a constant string. NOTE: Caller should NOT attempt to free this string.

Parameters
typeThe KSON property type.
Returns
A constant string representation of the property type. NOTE: Caller should NOT attempt to free this string.

◆ kson_tree_cleanup()

KAPI void kson_tree_cleanup ( kson_tree tree)

Performs cleanup operations on the given tree, freeing memory and resources held by it.

Parameters
treeA pointer to the tree to cleanup. Required.

◆ kson_tree_from_string()

KAPI b8 kson_tree_from_string ( const char *  source,
kson_tree out_tree 
)

Takes the provided source and tokenizes, then parses it in order to create a tree of kson_objects.

Parameters
sourceA pointer to the source string to be tokenized and parsed. Required.
out_treeA pointer to hold the generated kson_tree. Required.
Returns
True on success; otherwise false.

◆ kson_tree_to_string()

KAPI const char* kson_tree_to_string ( kson_tree tree)

Takes the provided kson_tree and writes it to a kson-formatted string.

Parameters
treeA pointer to the kson_tree to use. Required.
Returns
A string on success; otherwise false.