diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-06-22 00:49:24 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-06-22 00:49:24 +0200 |
commit | b3c7c4633cdd0dedf3e329251fc7a6728bc041b5 (patch) | |
tree | 7a9e5ec0eb9209c5832685410356fbb774d2d39f /src/template-parser.c | |
parent | 469731a89ab1e1b98b0498914bbe5016e8282b23 (diff) | |
download | blogc-b3c7c4633cdd0dedf3e329251fc7a6728bc041b5.tar.gz blogc-b3c7c4633cdd0dedf3e329251fc7a6728bc041b5.tar.bz2 blogc-b3c7c4633cdd0dedf3e329251fc7a6728bc041b5.zip |
template-parser: added some ast debug
Diffstat (limited to 'src/template-parser.c')
-rw-r--r-- | src/template-parser.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/template-parser.c b/src/template-parser.c index 525f5f5..1582c17 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -11,6 +11,7 @@ #endif /* HAVE_CONFIG_H */ #include <stdbool.h> +#include <stdio.h> #include <string.h> #include "template-parser.h" @@ -634,3 +635,67 @@ blogc_template_free_stmts(sb_slist_t *stmts) } sb_slist_free(stmts); } + + +static const char* +get_operator(blogc_template_stmt_operator_t op) +{ + if (op & BLOGC_TEMPLATE_OP_NEQ) + return "!="; + if (op & BLOGC_TEMPLATE_OP_EQ) { + if (op & BLOGC_TEMPLATE_OP_LT) + return "<="; + else if (op & BLOGC_TEMPLATE_OP_GT) + return ">="; + return "=="; + } + if (op & BLOGC_TEMPLATE_OP_LT) + return "<"; + else if (op & BLOGC_TEMPLATE_OP_GT) + return ">"; + return ""; +} + + +void +blogc_template_debug(sb_slist_t *stmts) +{ + for (sb_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { + blogc_template_stmt_t *data = tmp->data; + fprintf(stderr, "DEBUG: <TEMPLATE "); + switch (data->type) { + case BLOGC_TEMPLATE_IFDEF_STMT: + fprintf(stderr, "IFDEF: %s", data->value); + break; + case BLOGC_TEMPLATE_IFNDEF_STMT: + fprintf(stderr, "IFNDEF: %s", data->value); + break; + case BLOGC_TEMPLATE_IF_STMT: + fprintf(stderr, "IF: %s %s %s", data->value, + get_operator(data->op), data->value2); + break; + case BLOGC_TEMPLATE_ENDIF_STMT: + fprintf(stderr, "ENDIF"); + break; + case BLOGC_TEMPLATE_FOREACH_STMT: + fprintf(stderr, "FOREACH: %s", data->value); + break; + case BLOGC_TEMPLATE_ENDFOREACH_STMT: + fprintf(stderr, "ENDFOREACH"); + break; + case BLOGC_TEMPLATE_BLOCK_STMT: + fprintf(stderr, "BLOCK: %s", data->value); + break; + case BLOGC_TEMPLATE_ENDBLOCK_STMT: + fprintf(stderr, "ENDBLOCK"); + break; + case BLOGC_TEMPLATE_VARIABLE_STMT: + fprintf(stderr, "VARIABLE: %s", data->value); + break; + case BLOGC_TEMPLATE_CONTENT_STMT: + fprintf(stderr, "CONTENT: `%s`", data->value); + break; + } + fprintf(stderr, ">\n"); + } +} |