aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2023-01-26 22:39:41 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2023-01-26 22:39:41 +0300
commit49c2589427e0f81bea68ccba1a95c6890e10538d (patch)
tree0633bc052552831b3860d1d4816bbee7b85d6313 /include
parent4665a620775da64ec7280762979a9fc6fa37c0bc (diff)
downloadroscha-master.tar.gz
roscha-master.zip
Fix break tag parsing and code formatHEADmaster
auto-formatted the code with clang-format.
Diffstat (limited to 'include')
-rw-r--r--include/ast.h67
-rw-r--r--include/hmap.h14
-rw-r--r--include/lexer.h2
-rw-r--r--include/object.h9
-rw-r--r--include/token.h8
5 files changed, 53 insertions, 47 deletions
diff --git a/include/ast.h b/include/ast.h
index fe722bf..acbc108 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -42,12 +42,12 @@ struct ident {
struct integer {
struct token token;
- int64_t value;
+ int64_t value;
};
struct boolean {
struct token token;
- bool value;
+ bool value;
};
struct string {
@@ -56,21 +56,21 @@ struct string {
};
struct prefix {
- struct token token;
- struct slice operator;
+ struct token token;
+ struct slice operator;
struct expression *right;
};
struct infix {
- struct token token;
- struct slice operator;
+ struct token token;
+ struct slice operator;
struct expression *left;
struct expression *right;
};
/* Either a map key (map.k) or an array/vector index (arr[i]) */
struct indexkey {
- struct token token;
+ struct token token;
struct expression *left;
struct expression *key;
};
@@ -78,13 +78,13 @@ struct indexkey {
struct expression {
enum expression_type type;
union {
- struct token token;
- struct ident ident;
- struct integer integer;
- struct boolean boolean;
- struct string string;
- struct prefix prefix;
- struct infix infix;
+ struct token token;
+ struct ident ident;
+ struct integer integer;
+ struct boolean boolean;
+ struct string string;
+ struct prefix prefix;
+ struct infix infix;
struct indexkey indexkey;
};
};
@@ -94,44 +94,44 @@ struct branch {
struct token token;
/* if condition is null it means it is an else branch */
struct expression *condition;
- struct vector *subblocks;
+ struct vector *subblocks;
/* elif or else */
struct branch *next;
};
/* start of if, elif, else */
struct cond {
- struct token token;
+ struct token token;
struct branch *root;
};
/* for loop */
struct loop {
- struct token token;
- struct ident item;
+ struct token token;
+ struct ident item;
struct expression *seq;
- struct vector *subblocks;
+ struct vector *subblocks;
};
/* template block {% block ... %} */
struct tblock {
- struct token token;
- struct ident name;
+ struct token token;
+ struct ident name;
struct vector *subblocks;
};
/* {% extends ... %} */
struct parent {
- struct token token;
+ struct token token;
struct string *name;
};
/* {% ... %} blocks */
struct tag {
- union{
- struct token token;
- struct cond cond;
- struct loop loop;
+ union {
+ struct token token;
+ struct cond cond;
+ struct loop loop;
struct tblock tblock;
struct parent parent;
};
@@ -140,7 +140,7 @@ struct tag {
/* {{ ... }} blocks */
struct variable {
- struct token token;
+ struct token token;
struct expression *expression;
};
@@ -151,21 +151,22 @@ struct content {
/*
* The template is divided into blocks or chunks which are either plain text
- * content, {% %} tags or {{ }} variables. Not to be confused with
+ * content, {% %} tags or {{ }} variables. Not to be confused with
* {% block ... %} tags.
*/
struct block {
union {
- struct token token;
- struct content content;
- struct tag tag;
+ struct token token;
+ struct content content;
+ struct tag tag;
struct variable variable;
};
enum block_type type;
};
/* Root of the AST */
-struct template {
+struct template
+{
/*
* The name of the template, might be a file name; used to identifiy the
* template in error messages. Will be free'd by template_destroy function
@@ -179,7 +180,7 @@ struct template {
char *source;
/*
* struct that holds references to {% block ... %} tags, for easier/faster
- * access to said blocks.
+ * access to said blocks.
*/
struct hmap *tblocks;
/*
diff --git a/include/hmap.h b/include/hmap.h
index fa24982..7735c53 100644
--- a/include/hmap.h
+++ b/include/hmap.h
@@ -12,9 +12,9 @@
typedef void (hmap_cb)(const struct slice *key, void *value);
struct hmap {
- struct hnode **buckets;
- size_t cap;
- size_t size;
+ struct hnode **buckets;
+ size_t cap;
+ size_t size;
};
struct hmap_iter;
@@ -24,9 +24,9 @@ struct hmap *hmap_new_with_cap(size_t cap);
#define hmap_new() hmap_new_with_cap(HASHMAP_CAP)
-/*
+/*
* Inserts a key-value pair into the map. Returns NULL if map did not have key,
- * old value if it did.
+ * old value if it did.
*/
void *hmap_sets(struct hmap *hm, struct slice key, void *value);
@@ -39,7 +39,7 @@ void *hmap_gets(struct hmap *hm, const struct slice *key);
/* Same as hmap_gets but pass a C string instead */
void *hmap_get(struct hmap *hm, const char *key);
-/*
+/*
* Removes a key from the map, returning the value at the key if the key was
* previously in the map.
*/
@@ -56,7 +56,7 @@ struct hmap_iter *hmap_iter_new(struct hmap *);
/* Get the next key, value */
bool hmap_iter_next(struct hmap_iter *iter, const struct slice **key,
- void **value);
+ void **value);
#define hmap_iter_foreach(it, k, v) while (hmap_iter_next(it, k, v))
diff --git a/include/lexer.h b/include/lexer.h
index 8491c5a..97809df 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -16,7 +16,7 @@ struct lexer {
/* The current slice of the input string that will be tokenized */
struct slice word;
/* The current character belongs to content and should not be tokenized */
- bool in_content;
+ bool in_content;
size_t line;
size_t column;
};
diff --git a/include/object.h b/include/object.h
index 71fc969..2325b15 100644
--- a/include/object.h
+++ b/include/object.h
@@ -58,7 +58,7 @@ struct roscha_object {
sds roscha_object_string(const struct roscha_object *, sds str);
/* Return the textual representation of the type */
-inline const char *roscha_type_print(enum roscha_type);
+const char *roscha_type_print(enum roscha_type);
/* Create a new roscha object based on its type */
struct roscha_object *roscha_object_new_int(int64_t val);
@@ -77,7 +77,12 @@ struct roscha_object *roscha_object_new_hmap(struct hmap *);
)(v)
/* Increment reference count of object */
-void roscha_object_ref(struct roscha_object *);
+static inline void
+roscha_object_ref(struct roscha_object *obj)
+{
+ obj->refcount++;
+}
+
/* Decrement reference count of object */
void roscha_object_unref(struct roscha_object *);
diff --git a/include/token.h b/include/token.h
index edff1d2..6c5eb5e 100644
--- a/include/token.h
+++ b/include/token.h
@@ -61,9 +61,9 @@ enum token_type {
/* A token in our template */
struct token {
enum token_type type;
- struct slice literal;
- size_t line;
- size_t column;
+ struct slice literal;
+ size_t line;
+ size_t column;
};
/* Intialize our keywords hashmap */
@@ -73,7 +73,7 @@ void token_init_keywords(void);
enum token_type token_lookup_ident(const struct slice *ident);
/* Return a C string with the token type name */
-inline const char *token_type_print(enum token_type);
+const char *token_type_print(enum token_type);
/* Concatenate this token to a sds string */
sds token_string(struct token *, sds str);