diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-02-21 18:49:24 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-02-21 16:09:40 +0100 |
commit | 4cf5dabd31c1c0bba54b36790d4068c39e2ce7d9 (patch) | |
tree | 77504e1eedf2df783ef7c962ca4d2f582f65accc /src/blogc/template-parser.h | |
parent | d6830301f215e96328fa4f9a5ad9e253830386c3 (diff) | |
download | blogc-4cf5dabd31c1c0bba54b36790d4068c39e2ce7d9.tar.gz blogc-4cf5dabd31c1c0bba54b36790d4068c39e2ce7d9.tar.bz2 blogc-4cf5dabd31c1c0bba54b36790d4068c39e2ce7d9.zip |
blogc: template parser refactoring
mostly names and data structures.
Diffstat (limited to 'src/blogc/template-parser.h')
-rw-r--r-- | src/blogc/template-parser.h | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/blogc/template-parser.h b/src/blogc/template-parser.h index 63aa404..948ec9b 100644 --- a/src/blogc/template-parser.h +++ b/src/blogc/template-parser.h @@ -14,40 +14,43 @@ #include "../common/utils.h" /* - * note: whitespace cleaners are NOT added to ast. we fix strings right during + * note: whitespace cleaners are NOT added to AST. we fix strings right during * template parsing. renderer does not need to care about it, for the sake of * simplicity. + * + * another note: technically this is not an AST, because there are no childs. */ typedef enum { - BLOGC_TEMPLATE_IFDEF_STMT = 1, - BLOGC_TEMPLATE_IFNDEF_STMT, - BLOGC_TEMPLATE_IF_STMT, - BLOGC_TEMPLATE_ELSE_STMT, - BLOGC_TEMPLATE_ENDIF_STMT, - BLOGC_TEMPLATE_FOREACH_STMT, - BLOGC_TEMPLATE_ENDFOREACH_STMT, - BLOGC_TEMPLATE_BLOCK_STMT, - BLOGC_TEMPLATE_ENDBLOCK_STMT, - BLOGC_TEMPLATE_VARIABLE_STMT, - BLOGC_TEMPLATE_CONTENT_STMT, -} blogc_template_stmt_type_t; + BLOGC_TEMPLATE_NODE_IFDEF = 1, + BLOGC_TEMPLATE_NODE_IFNDEF, + BLOGC_TEMPLATE_NODE_IF, + BLOGC_TEMPLATE_NODE_ELSE, + BLOGC_TEMPLATE_NODE_ENDIF, + BLOGC_TEMPLATE_NODE_FOREACH, + BLOGC_TEMPLATE_NODE_ENDFOREACH, + BLOGC_TEMPLATE_NODE_BLOCK, + BLOGC_TEMPLATE_NODE_ENDBLOCK, + BLOGC_TEMPLATE_NODE_VARIABLE, + BLOGC_TEMPLATE_NODE_CONTENT, +} blogc_template_node_type_t; typedef enum { BLOGC_TEMPLATE_OP_NEQ = 1 << 0, BLOGC_TEMPLATE_OP_EQ = 1 << 1, BLOGC_TEMPLATE_OP_LT = 1 << 2, BLOGC_TEMPLATE_OP_GT = 1 << 3, -} blogc_template_stmt_operator_t; +} blogc_template_operator_t; typedef struct { - blogc_template_stmt_type_t type; - char *value; - char *value2; - blogc_template_stmt_operator_t op; -} blogc_template_stmt_t; + blogc_template_node_type_t type; + blogc_template_operator_t op; + + // 2 slots to store node data. + char *data[2]; +} blogc_template_node_t; bc_slist_t* blogc_template_parse(const char *src, size_t src_len, bc_error_t **err); -void blogc_template_free_stmts(bc_slist_t *stmts); +void blogc_template_free_ast(bc_slist_t *ast); #endif /* _TEMPLATE_PARSER_H */ |