diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2022-03-24 01:04:02 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2022-03-24 01:04:02 +0300 |
commit | 5d66c96a190a396a1535c89bed4e33c2a005fe8d (patch) | |
tree | 36a681d8cf226cf30f06b2764c008077d9655dc7 /include/roscha.h | |
download | roscha-5d66c96a190a396a1535c89bed4e33c2a005fe8d.tar.gz roscha-5d66c96a190a396a1535c89bed4e33c2a005fe8d.zip |
Initial commit
Basically it works, just needs some polishing and maybe a couple of
features that I could actually use.
Also probably better docs. Not sure if it will be of use to anybody
besides me.
Diffstat (limited to 'include/roscha.h')
-rw-r--r-- | include/roscha.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/roscha.h b/include/roscha.h new file mode 100644 index 0000000..82a2062 --- /dev/null +++ b/include/roscha.h @@ -0,0 +1,54 @@ +#ifndef ROSCHA_H +#define ROSCHA_H + +#include "object.h" + +/* The environment for evaluation templates */ +struct roscha_env { + /* Template variables; reference counted hmap of roscha objects */ + struct roscha_object *vars; + /* vector of sds with error messages */ + struct vector *errors; + /* internal */ + struct roscha_ *internal; +}; + +/* + * Initialize variables needed for parsing; may be used by several roscha + * parsers. + */ +void roscha_init(void); + +/* + * Free all static memory related to roscha; called when parsing/evaluation is + * no longer needed + */ +void roscha_deinit(void); + +/* Allocate a new environment */ +struct roscha_env *roscha_env_new(void); + +/* + * Parse and add a template to the environment. Returns false upon encountering + * a parsing error. + */ +bool roscha_env_add_template(struct roscha_env *, char *name, char *body); + +/* + * Load and parse templates from dir (non-recursively). All non-dir files are + * read and parsed. Returns false if an error occurred. + */ +bool roscha_env_load_dir(struct roscha_env *, const char *path); + +/* Render/evaluate the template */ +sds roscha_env_render(struct roscha_env *, const char *name); + +struct vector *roscha_env_check_errors(struct roscha_env *env); + +/* + * Free all memory associated with the environment, including parsed templates, + * and reducing reference counts of objects. + */ +void roscha_env_destroy(struct roscha_env *); + +#endif |