aboutsummaryrefslogtreecommitdiff
path: root/include/roscha.h
blob: 82a206248086c4554dafe1fc7a6d9cb44e50d8da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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