diff options
| -rw-r--r-- | src/blogc/debug.c | 46 | ||||
| -rw-r--r-- | src/blogc/debug.h | 2 | ||||
| -rw-r--r-- | src/blogc/main.c | 2 | ||||
| -rw-r--r-- | src/blogc/renderer.c | 112 | ||||
| -rw-r--r-- | src/blogc/template-parser.c | 120 | ||||
| -rw-r--r-- | src/blogc/template-parser.h | 43 | ||||
| -rw-r--r-- | tests/blogc/check_loader.c | 2 | ||||
| -rw-r--r-- | tests/blogc/check_renderer.c | 48 | ||||
| -rw-r--r-- | tests/blogc/check_template_parser.c | 730 | 
9 files changed, 554 insertions, 551 deletions
diff --git a/src/blogc/debug.c b/src/blogc/debug.c index 7219c0c..afb2fe3 100644 --- a/src/blogc/debug.c +++ b/src/blogc/debug.c @@ -14,7 +14,7 @@  static const char* -get_operator(blogc_template_stmt_operator_t op) +get_operator(blogc_template_operator_t op)  {      if (op & BLOGC_TEMPLATE_OP_NEQ)          return "!="; @@ -34,45 +34,45 @@ get_operator(blogc_template_stmt_operator_t op)  void -blogc_debug_template(bc_slist_t *stmts) +blogc_debug_template(bc_slist_t *ast)  { -    for (bc_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { -        blogc_template_stmt_t *data = tmp->data; +    for (bc_slist_t *tmp = ast; tmp != NULL; tmp = tmp->next) { +        blogc_template_node_t *data = tmp->data;          fprintf(stderr, "DEBUG: <TEMPLATE ");          switch (data->type) { -            case BLOGC_TEMPLATE_IFDEF_STMT: -                fprintf(stderr, "IFDEF: %s", data->value); +            case BLOGC_TEMPLATE_NODE_IFDEF: +                fprintf(stderr, "IFDEF: %s", data->data[0]);                  break; -            case BLOGC_TEMPLATE_IFNDEF_STMT: -                fprintf(stderr, "IFNDEF: %s", data->value); +            case BLOGC_TEMPLATE_NODE_IFNDEF: +                fprintf(stderr, "IFNDEF: %s", data->data[0]);                  break; -            case BLOGC_TEMPLATE_IF_STMT: -                fprintf(stderr, "IF: %s %s %s", data->value, -                    get_operator(data->op), data->value2); +            case BLOGC_TEMPLATE_NODE_IF: +                fprintf(stderr, "IF: %s %s %s", data->data[0], +                    get_operator(data->op), data->data[1]);                  break; -            case BLOGC_TEMPLATE_ELSE_STMT: +            case BLOGC_TEMPLATE_NODE_ELSE:                  fprintf(stderr, "ELSE");                  break; -            case BLOGC_TEMPLATE_ENDIF_STMT: +            case BLOGC_TEMPLATE_NODE_ENDIF:                  fprintf(stderr, "ENDIF");                  break; -            case BLOGC_TEMPLATE_FOREACH_STMT: -                fprintf(stderr, "FOREACH: %s", data->value); +            case BLOGC_TEMPLATE_NODE_FOREACH: +                fprintf(stderr, "FOREACH: %s", data->data[0]);                  break; -            case BLOGC_TEMPLATE_ENDFOREACH_STMT: +            case BLOGC_TEMPLATE_NODE_ENDFOREACH:                  fprintf(stderr, "ENDFOREACH");                  break; -            case BLOGC_TEMPLATE_BLOCK_STMT: -                fprintf(stderr, "BLOCK: %s", data->value); +            case BLOGC_TEMPLATE_NODE_BLOCK: +                fprintf(stderr, "BLOCK: %s", data->data[0]);                  break; -            case BLOGC_TEMPLATE_ENDBLOCK_STMT: +            case BLOGC_TEMPLATE_NODE_ENDBLOCK:                  fprintf(stderr, "ENDBLOCK");                  break; -            case BLOGC_TEMPLATE_VARIABLE_STMT: -                fprintf(stderr, "VARIABLE: %s", data->value); +            case BLOGC_TEMPLATE_NODE_VARIABLE: +                fprintf(stderr, "VARIABLE: %s", data->data[0]);                  break; -            case BLOGC_TEMPLATE_CONTENT_STMT: -                fprintf(stderr, "CONTENT: `%s`", data->value); +            case BLOGC_TEMPLATE_NODE_CONTENT: +                fprintf(stderr, "CONTENT: `%s`", data->data[0]);                  break;          }          fprintf(stderr, ">\n"); diff --git a/src/blogc/debug.h b/src/blogc/debug.h index e47d840..c7c1fbe 100644 --- a/src/blogc/debug.h +++ b/src/blogc/debug.h @@ -11,6 +11,6 @@  #include "../common/utils.h" -void blogc_debug_template(bc_slist_t *stmts); +void blogc_debug_template(bc_slist_t *ast);  #endif /* ___DEBUG_H */ diff --git a/src/blogc/main.c b/src/blogc/main.c index df9a401..d72091e 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -346,7 +346,7 @@ main(int argc, char **argv)  cleanup4:      free(out);  cleanup3: -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);  cleanup2:      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      bc_error_free(err); diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c index cee9ef9..a49e87d 100644 --- a/src/blogc/renderer.c +++ b/src/blogc/renderer.c @@ -191,53 +191,53 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list      bc_slist_t *tmp = tmpl;      while (tmp != NULL) { -        blogc_template_stmt_t *stmt = tmp->data; +        blogc_template_node_t *node = tmp->data; -        switch (stmt->type) { +        switch (node->type) { -            case BLOGC_TEMPLATE_CONTENT_STMT: -                if (stmt->value != NULL) -                    bc_string_append(str, stmt->value); +            case BLOGC_TEMPLATE_NODE_CONTENT: +                if (node->data[0] != NULL) +                    bc_string_append(str, node->data[0]);                  break; -            case BLOGC_TEMPLATE_BLOCK_STMT: +            case BLOGC_TEMPLATE_NODE_BLOCK:                  inside_block = true;                  if_count = 0; -                if (0 == strcmp("entry", stmt->value)) { +                if (0 == strcmp("entry", node->data[0])) {                      if (listing) {                          // we can just skip anything and walk until the next                          // 'endblock' -                        while (stmt->type != BLOGC_TEMPLATE_ENDBLOCK_STMT) { +                        while (node->type != BLOGC_TEMPLATE_NODE_ENDBLOCK) {                              tmp = tmp->next; -                            stmt = tmp->data; +                            node = tmp->data;                          }                          break;                      }                      current_source = sources;                      tmp_source = current_source->data;                  } -                else if ((0 == strcmp("listing", stmt->value)) || -                         (0 == strcmp("listing_once", stmt->value))) { +                else if ((0 == strcmp("listing", node->data[0])) || +                         (0 == strcmp("listing_once", node->data[0]))) {                      if (!listing) {                          // we can just skip anything and walk until the next                          // 'endblock' -                        while (stmt->type != BLOGC_TEMPLATE_ENDBLOCK_STMT) { +                        while (node->type != BLOGC_TEMPLATE_NODE_ENDBLOCK) {                              tmp = tmp->next; -                            stmt = tmp->data; +                            node = tmp->data;                          }                          break;                      }                  } -                if (0 == strcmp("listing", stmt->value)) { +                if (0 == strcmp("listing", node->data[0])) {                      if (sources == NULL) {                          // we can just skip anything and walk until the next                          // 'endblock' -                        while (stmt->type != BLOGC_TEMPLATE_ENDBLOCK_STMT) { +                        while (node->type != BLOGC_TEMPLATE_NODE_ENDBLOCK) {                              tmp = tmp->next; -                            stmt = tmp->data; +                            node = tmp->data;                          }                          break;                      } @@ -249,9 +249,9 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                  }                  break; -            case BLOGC_TEMPLATE_VARIABLE_STMT: -                if (stmt->value != NULL) { -                    config_value = blogc_format_variable(stmt->value, +            case BLOGC_TEMPLATE_NODE_VARIABLE: +                if (node->data[0] != NULL) { +                    config_value = blogc_format_variable(node->data[0],                          config, inside_block ? tmp_source : NULL, foreach_var);                      if (config_value != NULL) {                          bc_string_append(str, config_value); @@ -262,7 +262,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                  }                  break; -            case BLOGC_TEMPLATE_ENDBLOCK_STMT: +            case BLOGC_TEMPLATE_NODE_ENDBLOCK:                  inside_block = false;                  if (listing_start != NULL && current_source != NULL) {                      current_source = current_source->next; @@ -275,32 +275,32 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                  }                  break; -            case BLOGC_TEMPLATE_IFNDEF_STMT: +            case BLOGC_TEMPLATE_NODE_IFNDEF:                  if_not = true; -            case BLOGC_TEMPLATE_IF_STMT: -            case BLOGC_TEMPLATE_IFDEF_STMT: +            case BLOGC_TEMPLATE_NODE_IF: +            case BLOGC_TEMPLATE_NODE_IFDEF:                  if_count = 0;                  defined = NULL; -                if (stmt->value != NULL) -                    defined = blogc_format_variable(stmt->value, config, +                if (node->data[0] != NULL) +                    defined = blogc_format_variable(node->data[0], config,                          inside_block ? tmp_source : NULL, foreach_var);                  evaluate = false; -                if (stmt->op != 0) { +                if (node->op != 0) {                      // Strings that start with a '"' are actually strings, the                      // others are meant to be looked up as a second variable                      // check.                      char *defined2 = NULL; -                    if (stmt->value2 != NULL) { -                        if ((strlen(stmt->value2) >= 2) && -                            (stmt->value2[0] == '"') && -                            (stmt->value2[strlen(stmt->value2) - 1] == '"')) +                    if (node->data[1] != NULL) { +                        if ((strlen(node->data[1]) >= 2) && +                            (node->data[1][0] == '"') && +                            (node->data[1][strlen(node->data[1]) - 1] == '"'))                          { -                            defined2 = bc_strndup(stmt->value2 + 1, -                                strlen(stmt->value2) - 2); +                            defined2 = bc_strndup(node->data[1] + 1, +                                strlen(node->data[1]) - 2);                          }                          else { -                            defined2 = blogc_format_variable(stmt->value2, +                            defined2 = blogc_format_variable(node->data[1],                                  config, inside_block ? tmp_source : NULL,                                  foreach_var);                          } @@ -308,13 +308,13 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                      if (defined != NULL && defined2 != NULL) {                          cmp = strcmp(defined, defined2); -                        if (cmp != 0 && stmt->op & BLOGC_TEMPLATE_OP_NEQ) +                        if (cmp != 0 && node->op & BLOGC_TEMPLATE_OP_NEQ)                              evaluate = true; -                        else if (cmp == 0 && stmt->op & BLOGC_TEMPLATE_OP_EQ) +                        else if (cmp == 0 && node->op & BLOGC_TEMPLATE_OP_EQ)                              evaluate = true; -                        else if (cmp < 0 && stmt->op & BLOGC_TEMPLATE_OP_LT) +                        else if (cmp < 0 && node->op & BLOGC_TEMPLATE_OP_LT)                              evaluate = true; -                        else if (cmp > 0 && stmt->op & BLOGC_TEMPLATE_OP_GT) +                        else if (cmp > 0 && node->op & BLOGC_TEMPLATE_OP_GT)                              evaluate = true;                      } @@ -333,15 +333,15 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                      // skip as well.                      while (1) {                          tmp = tmp->next; -                        stmt = tmp->data; -                        if ((stmt->type == BLOGC_TEMPLATE_IF_STMT) || -                            (stmt->type == BLOGC_TEMPLATE_IFDEF_STMT) || -                            (stmt->type == BLOGC_TEMPLATE_IFNDEF_STMT)) +                        node = tmp->data; +                        if ((node->type == BLOGC_TEMPLATE_NODE_IF) || +                            (node->type == BLOGC_TEMPLATE_NODE_IFDEF) || +                            (node->type == BLOGC_TEMPLATE_NODE_IFNDEF))                          {                              if_count++;                              continue;                          } -                        if ((stmt->type == BLOGC_TEMPLATE_ELSE_STMT) && +                        if ((node->type == BLOGC_TEMPLATE_NODE_ELSE) &&                              (if_count == 0))                          {                              // this is somewhat complex. only an else statement @@ -352,7 +352,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                              valid_else = true;                              break;                          } -                        if (stmt->type == BLOGC_TEMPLATE_ENDIF_STMT) { +                        if (node->type == BLOGC_TEMPLATE_NODE_ENDIF) {                              if (if_count > 0) {                                  if_count--;                                  continue; @@ -369,7 +369,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                  if_not = false;                  break; -            case BLOGC_TEMPLATE_ELSE_STMT: +            case BLOGC_TEMPLATE_NODE_ELSE:                  if_count = 0;                  if (!valid_else) { @@ -378,17 +378,17 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                      // skip as well.                      while (1) {                          tmp = tmp->next; -                        stmt = tmp->data; -                        if ((stmt->type == BLOGC_TEMPLATE_IF_STMT) || -                            (stmt->type == BLOGC_TEMPLATE_IFDEF_STMT) || -                            (stmt->type == BLOGC_TEMPLATE_IFNDEF_STMT)) +                        node = tmp->data; +                        if ((node->type == BLOGC_TEMPLATE_NODE_IF) || +                            (node->type == BLOGC_TEMPLATE_NODE_IFDEF) || +                            (node->type == BLOGC_TEMPLATE_NODE_IFNDEF))                          {                              if_count++;                              continue;                          }                          // no need to handle else statements here, because every                          // if should have an endif. -                        if (stmt->type == BLOGC_TEMPLATE_ENDIF_STMT) { +                        if (node->type == BLOGC_TEMPLATE_NODE_ENDIF) {                              if (if_count > 0) {                                  if_count--;                                  continue; @@ -400,7 +400,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                  valid_else = false;                  break; -            case BLOGC_TEMPLATE_ENDIF_STMT: +            case BLOGC_TEMPLATE_NODE_ENDIF:                  // any endif statement should invalidate valid_else, to avoid                  // propagation to outter conditionals.                  valid_else = false; @@ -408,10 +408,10 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                      if_count--;                  break; -            case BLOGC_TEMPLATE_FOREACH_STMT: +            case BLOGC_TEMPLATE_NODE_FOREACH:                  if (foreach_var_start == NULL) { -                    if (stmt->value != NULL) -                        foreach_var_start = blogc_split_list_variable(stmt->value, +                    if (node->data[0] != NULL) +                        foreach_var_start = blogc_split_list_variable(node->data[0],                              config, inside_block ? tmp_source : NULL);                      if (foreach_var_start != NULL) { @@ -422,9 +422,9 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                          // we can just skip anything and walk until the next                          // 'endforeach' -                        while (stmt->type != BLOGC_TEMPLATE_ENDFOREACH_STMT) { +                        while (node->type != BLOGC_TEMPLATE_NODE_ENDFOREACH) {                              tmp = tmp->next; -                            stmt = tmp->data; +                            node = tmp->data;                          }                          break;                      } @@ -436,7 +436,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list                  }                  break; -            case BLOGC_TEMPLATE_ENDFOREACH_STMT: +            case BLOGC_TEMPLATE_NODE_ENDFOREACH:                  if (foreach_start != NULL && foreach_var != NULL) {                      foreach_var = foreach_var->next;                      if (foreach_var != NULL) { diff --git a/src/blogc/template-parser.c b/src/blogc/template-parser.c index 6308095..4d2cb3c 100644 --- a/src/blogc/template-parser.c +++ b/src/blogc/template-parser.c @@ -55,7 +55,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)      size_t start2 = 0;      size_t end2 = 0; -    blogc_template_stmt_operator_t tmp_op = 0; +    blogc_template_operator_t tmp_op = 0;      unsigned int if_count = 0;      unsigned int block_if_count = 0; @@ -63,8 +63,8 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)      bool foreach_open = false;      bool block_foreach_open = false; -    bc_slist_t *stmts = NULL; -    blogc_template_stmt_t *stmt = NULL; +    bc_slist_t *ast = NULL; +    blogc_template_node_t *node = NULL;      /*       * this is a reference to the content of previous node in the singly-linked @@ -75,14 +75,14 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)       * - template parser never walk backwards, then the list itself does not       *   need to know its previous node.       */ -    blogc_template_stmt_t *previous = NULL; +    blogc_template_node_t *previous = NULL;      bool lstrip_next = false;      char *tmp = NULL;      char *block_type = NULL;      blogc_template_parser_state_t state = TEMPLATE_START; -    blogc_template_stmt_type_t type = BLOGC_TEMPLATE_CONTENT_STMT; +    blogc_template_node_type_t type = BLOGC_TEMPLATE_NODE_CONTENT;      bool block_open = false; @@ -94,23 +94,23 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)              case TEMPLATE_START:                  if (last) { -                    stmt = bc_malloc(sizeof(blogc_template_stmt_t)); -                    stmt->type = type; +                    node = bc_malloc(sizeof(blogc_template_node_t)); +                    node->type = type;                      if (lstrip_next) {                          tmp = bc_strndup(src + start, src_len - start); -                        stmt->value = bc_strdup(bc_str_lstrip(tmp)); +                        node->data[0] = bc_strdup(bc_str_lstrip(tmp));                          free(tmp);                          tmp = NULL;                          lstrip_next = false;                      }                      else { -                        stmt->value = bc_strndup(src + start, src_len - start); +                        node->data[0] = bc_strndup(src + start, src_len - start);                      } -                    stmt->op = 0; -                    stmt->value2 = NULL; -                    stmts = bc_slist_append(stmts, stmt); -                    previous = stmt; -                    stmt = NULL; +                    node->op = 0; +                    node->data[1] = NULL; +                    ast = bc_slist_append(ast, node); +                    previous = node; +                    node = NULL;                  }                  if (c == '{') {                      end = current; @@ -125,23 +125,23 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                      else                          state = TEMPLATE_VARIABLE_START;                      if (end > start) { -                        stmt = bc_malloc(sizeof(blogc_template_stmt_t)); -                        stmt->type = type; +                        node = bc_malloc(sizeof(blogc_template_node_t)); +                        node->type = type;                          if (lstrip_next) {                              tmp = bc_strndup(src + start, end - start); -                            stmt->value = bc_strdup(bc_str_lstrip(tmp)); +                            node->data[0] = bc_strdup(bc_str_lstrip(tmp));                              free(tmp);                              tmp = NULL;                              lstrip_next = false;                          }                          else { -                            stmt->value = bc_strndup(src + start, end - start); +                            node->data[0] = bc_strndup(src + start, end - start);                          } -                        stmt->op = 0; -                        stmt->value2 = NULL; -                        stmts = bc_slist_append(stmts, stmt); -                        previous = stmt; -                        stmt = NULL; +                        node->op = 0; +                        node->data[1] = NULL; +                        ast = bc_slist_append(ast, node); +                        previous = node; +                        node = NULL;                      }                      break;                  } @@ -151,9 +151,9 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)              case TEMPLATE_BLOCK_START_WHITESPACE_CLEANER:                  if (c == '-') {                      if ((previous != NULL) && -                        (previous->type == BLOGC_TEMPLATE_CONTENT_STMT)) +                        (previous->type == BLOGC_TEMPLATE_NODE_CONTENT))                      { -                        previous->value = bc_str_rstrip(previous->value);  // does not need copy +                        previous->data[0] = bc_str_rstrip(previous->data[0]);  // does not need copy                      }                      state = TEMPLATE_BLOCK_START;                      break; @@ -189,7 +189,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                      {                          if (!block_open) {                              state = TEMPLATE_BLOCK_BLOCK_TYPE_START; -                            type = BLOGC_TEMPLATE_BLOCK_STMT; +                            type = BLOGC_TEMPLATE_NODE_BLOCK;                              start = current;                              block_if_count = if_count;                              block_foreach_open = foreach_open; @@ -217,7 +217,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                                  break;                              }                              state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; -                            type = BLOGC_TEMPLATE_ENDBLOCK_STMT; +                            type = BLOGC_TEMPLATE_NODE_ENDBLOCK;                              block_open = false;                              break;                          } @@ -230,7 +230,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                          (0 == strncmp("ifdef", src + start, 5)))                      {                          state = TEMPLATE_BLOCK_IF_START; -                        type = BLOGC_TEMPLATE_IFDEF_STMT; +                        type = BLOGC_TEMPLATE_NODE_IFDEF;                          start = current;                          if_count++;                          else_open = false; @@ -240,7 +240,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                          (0 == strncmp("ifndef", src + start, 6)))                      {                          state = TEMPLATE_BLOCK_IF_START; -                        type = BLOGC_TEMPLATE_IFNDEF_STMT; +                        type = BLOGC_TEMPLATE_NODE_IFNDEF;                          start = current;                          if_count++;                          else_open = false; @@ -250,7 +250,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                          (0 == strncmp("if", src + start, 2)))                      {                          state = TEMPLATE_BLOCK_IF_START; -                        type = BLOGC_TEMPLATE_IF_STMT; +                        type = BLOGC_TEMPLATE_NODE_IF;                          start = current;                          if_count++;                          else_open = false; @@ -264,7 +264,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                          {                              if (!else_open) {                                  state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; -                                type = BLOGC_TEMPLATE_ELSE_STMT; +                                type = BLOGC_TEMPLATE_NODE_ELSE;                                  else_open = true;                                  break;                              } @@ -287,7 +287,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                              (!block_open && if_count > 0))                          {                              state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; -                            type = BLOGC_TEMPLATE_ENDIF_STMT; +                            type = BLOGC_TEMPLATE_NODE_ENDIF;                              if_count--;                              else_open = false;                              break; @@ -303,7 +303,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                      {                          if (!foreach_open) {                              state = TEMPLATE_BLOCK_FOREACH_START; -                            type = BLOGC_TEMPLATE_FOREACH_STMT; +                            type = BLOGC_TEMPLATE_NODE_FOREACH;                              start = current;                              foreach_open = true;                              break; @@ -320,7 +320,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                              (!block_open && foreach_open))                          {                              state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; -                            type = BLOGC_TEMPLATE_ENDFOREACH_STMT; +                            type = BLOGC_TEMPLATE_NODE_ENDFOREACH;                              foreach_open = false;                              break;                          } @@ -404,7 +404,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                      break;                  if (c == ' ') {                      end = current; -                    if (type == BLOGC_TEMPLATE_IF_STMT) +                    if (type == BLOGC_TEMPLATE_NODE_IF)                          state = TEMPLATE_BLOCK_IF_OPERATOR_START;                      else                          state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; @@ -528,7 +528,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                      break;                  if (c >= 'A' && c <= 'Z') {                      state = TEMPLATE_VARIABLE; -                    type = BLOGC_TEMPLATE_VARIABLE_STMT; +                    type = BLOGC_TEMPLATE_NODE_VARIABLE;                      start = current;                      break;                  } @@ -600,25 +600,25 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)                          op_start = 0;                          op_end = 0;                      } -                    stmt = bc_malloc(sizeof(blogc_template_stmt_t)); -                    stmt->type = type; -                    stmt->value = NULL; -                    stmt->op = tmp_op; -                    stmt->value2 = NULL; +                    node = bc_malloc(sizeof(blogc_template_node_t)); +                    node->type = type; +                    node->op = tmp_op; +                    node->data[0] = NULL; +                    node->data[1] = NULL;                      if (end > start) -                        stmt->value = bc_strndup(src + start, end - start); +                        node->data[0] = bc_strndup(src + start, end - start);                      if (end2 > start2) { -                        stmt->value2 = bc_strndup(src + start2, end2 - start2); +                        node->data[1] = bc_strndup(src + start2, end2 - start2);                          start2 = 0;                          end2 = 0;                      } -                    if (type == BLOGC_TEMPLATE_BLOCK_STMT) -                        block_type = stmt->value; -                    stmts = bc_slist_append(stmts, stmt); -                    previous = stmt; -                    stmt = NULL; +                    if (type == BLOGC_TEMPLATE_NODE_BLOCK) +                        block_type = node->data[0]; +                    ast = bc_slist_append(ast, node); +                    previous = node; +                    node = NULL;                      state = TEMPLATE_START; -                    type = BLOGC_TEMPLATE_CONTENT_STMT; +                    type = BLOGC_TEMPLATE_NODE_CONTENT;                      start = current + 1;                      break;                  } @@ -652,28 +652,28 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)      }      if (*err != NULL) { -        if (stmt != NULL) { -            free(stmt->value); -            free(stmt); +        if (node != NULL) { +            free(node->data[0]); +            free(node);          } -        blogc_template_free_stmts(stmts); +        blogc_template_free_ast(ast);          return NULL;      } -    return stmts; +    return ast;  }  void -blogc_template_free_stmts(bc_slist_t *stmts) +blogc_template_free_ast(bc_slist_t *ast)  { -    for (bc_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { -        blogc_template_stmt_t *data = tmp->data; +    for (bc_slist_t *tmp = ast; tmp != NULL; tmp = tmp->next) { +        blogc_template_node_t *data = tmp->data;          if (data == NULL)              continue; -        free(data->value); -        free(data->value2); +        free(data->data[0]); +        free(data->data[1]);          free(data);      } -    bc_slist_free(stmts); +    bc_slist_free(ast);  } 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 */ diff --git a/tests/blogc/check_loader.c b/tests/blogc/check_loader.c index ec82af1..504b296 100644 --- a/tests/blogc/check_loader.c +++ b/tests/blogc/check_loader.c @@ -75,7 +75,7 @@ test_template_parse_from_file(void **state)      assert_null(err);      assert_non_null(l);      assert_int_equal(bc_slist_length(l), 2); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);  } diff --git a/tests/blogc/check_renderer.c b/tests/blogc/check_renderer.c index 327a42b..b0fbb94 100644 --- a/tests/blogc/check_renderer.c +++ b/tests/blogc/check_renderer.c @@ -101,7 +101,7 @@ test_render_entry(void **state)          "LOL4\n"          "lol foo haha lol bar haha lol baz haha \n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -150,7 +150,7 @@ test_render_listing(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -181,7 +181,7 @@ test_render_listing_empty(void **state)          "fuuu\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      free(out);  } @@ -209,7 +209,7 @@ test_render_ifdef(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -240,7 +240,7 @@ test_render_ifdef2(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -273,7 +273,7 @@ test_render_ifdef3(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -309,7 +309,7 @@ test_render_ifdef4(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -343,7 +343,7 @@ test_render_ifdef5(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -375,7 +375,7 @@ test_render_ifdef6(void **state)          "lol\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -413,7 +413,7 @@ test_render_ifdef7(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -448,7 +448,7 @@ test_render_ifndef(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -485,7 +485,7 @@ test_render_if_eq(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -522,7 +522,7 @@ test_render_if_neq(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -559,7 +559,7 @@ test_render_if_lt(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -596,7 +596,7 @@ test_render_if_gt(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -637,7 +637,7 @@ test_render_if_lt_eq(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -678,7 +678,7 @@ test_render_if_gt_eq(void **state)          "\n"          "\n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -702,7 +702,7 @@ test_render_foreach(void **state)          "\n"          " foo  bar  baz \n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -727,7 +727,7 @@ test_render_foreach_if(void **state)          "\n"          "   bar   \n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -753,7 +753,7 @@ test_render_foreach_if_else(void **state)          "\n"          "foo yay baz \n"          "\n"); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -787,7 +787,7 @@ test_render_outside_block(void **state)          "\n"          "lol\n");      bc_trie_free(c); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -826,7 +826,7 @@ test_render_prefer_local_variable(void **state)          "\n"          "\n");      bc_trie_free(c); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -858,7 +858,7 @@ test_render_respect_variable_scope(void **state)          "asd\n"          "\n");      bc_trie_free(c); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } @@ -889,7 +889,7 @@ test_render_ifcount_bug(void **state)          "\n"          "\n");      bc_trie_free(c); -    blogc_template_free_stmts(l); +    blogc_template_free_ast(l);      bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);      free(out);  } diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c index afc42f2..a6d9034 100644 --- a/tests/blogc/check_template_parser.c +++ b/tests/blogc/check_template_parser.c @@ -17,27 +17,27 @@  static void -blogc_assert_template_stmt(bc_slist_t *l, const char *value, -    const blogc_template_stmt_type_t type) +blogc_assert_template_node(bc_slist_t *l, const char *data, +    const blogc_template_node_type_t type)  { -    blogc_template_stmt_t *stmt = l->data; -    if (value == NULL) -        assert_null(stmt->value); +    blogc_template_node_t *node = l->data; +    if (data == NULL) +        assert_null(node->data[0]);      else -        assert_string_equal(stmt->value, value); -    assert_int_equal(stmt->type, type); +        assert_string_equal(node->data[0], data); +    assert_int_equal(node->type, type);  }  static void -blogc_assert_template_if_stmt(bc_slist_t *l, const char *variable, -    blogc_template_stmt_operator_t operator, const char *operand) +blogc_assert_template_if_node(bc_slist_t *l, const char *variable, +    blogc_template_operator_t operator, const char *operand)  { -    blogc_template_stmt_t *stmt = l->data; -    assert_string_equal(stmt->value, variable); -    assert_int_equal(stmt->op, operator); -    assert_string_equal(stmt->value2, operand); -    assert_int_equal(stmt->type, BLOGC_TEMPLATE_IF_STMT); +    blogc_template_node_t *node = l->data; +    assert_string_equal(node->data[0], variable); +    assert_int_equal(node->op, operator); +    assert_string_equal(node->data[1], operand); +    assert_int_equal(node->type, BLOGC_TEMPLATE_NODE_IF);  } @@ -60,68 +60,68 @@ test_template_parse(void **state)          "{%- foreach BOLA %}hahaha{% endforeach %}\n"          "{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_null(err); -    assert_non_null(stmts); -    blogc_assert_template_stmt(stmts, "Test", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next, "entry", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(stmts->next->next, "", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next, "CHUNDA", -        BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next, "\nbola\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    bc_slist_t *tmp = stmts->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); -    blogc_assert_template_stmt(tmp->next, "\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); +    assert_non_null(ast); +    blogc_assert_template_node(ast, "Test", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next, "entry", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(ast->next->next, "", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next, "CHUNDA", +        BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(ast->next->next->next->next, "\nbola\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(ast->next->next->next->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    bc_slist_t *tmp = ast->next->next->next->next->next->next->next; +    blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_IFNDEF); +    blogc_assert_template_node(tmp->next, "\nbolao", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT);      tmp = tmp->next->next->next->next; -    blogc_assert_template_stmt(tmp, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, "listing", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "BOLA", -        BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -        "listing_once", BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "asd", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, -        "", BLOGC_TEMPLATE_CONTENT_STMT); +    blogc_assert_template_node(tmp, NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next, "\n", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, "listing", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next->next, "BOLA", +        BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, +        "listing_once", BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "asd", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next->next, +        "", BLOGC_TEMPLATE_NODE_CONTENT);      tmp = tmp->next->next->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); -    blogc_assert_template_stmt(tmp->next, "hahaha", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, NULL, -        BLOGC_TEMPLATE_ENDFOREACH_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_if_stmt(tmp->next->next->next->next, "BOLA", +    blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_FOREACH); +    blogc_assert_template_node(tmp->next, "hahaha", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDFOREACH); +    blogc_assert_template_node(tmp->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_if_node(tmp->next->next->next->next, "BOLA",          BLOGC_TEMPLATE_OP_EQ, "\"1\\\"0\""); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, "aee", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ELSE_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "fffuuuuuuu", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDIF_STMT); +    blogc_assert_template_node(tmp->next->next->next->next->next, "aee", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ELSE); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "fffuuuuuuu", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDIF);      assert_null(tmp->next->next->next->next->next->next->next->next->next); -    blogc_template_free_stmts(stmts); +    blogc_template_free_ast(ast);  } @@ -144,68 +144,68 @@ test_template_parse_crlf(void **state)          "{%- foreach BOLA %}hahaha{% endforeach %}\r\n"          "{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_null(err); -    assert_non_null(stmts); -    blogc_assert_template_stmt(stmts, "Test", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next, "entry", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(stmts->next->next, "", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next, "CHUNDA", -        BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next, "\r\nbola\r\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\r\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    bc_slist_t *tmp = stmts->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); -    blogc_assert_template_stmt(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "\r\n", -        BLOGC_TEMPLATE_CONTENT_STMT); +    assert_non_null(ast); +    blogc_assert_template_node(ast, "Test", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next, "entry", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(ast->next->next, "", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next, "CHUNDA", +        BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(ast->next->next->next->next, "\r\nbola\r\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(ast->next->next->next->next->next->next, "\r\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    bc_slist_t *tmp = ast->next->next->next->next->next->next->next; +    blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_IFNDEF); +    blogc_assert_template_node(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next, "\r\n", +        BLOGC_TEMPLATE_NODE_CONTENT);      tmp = tmp->next->next->next->next; -    blogc_assert_template_stmt(tmp, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next, "\r\n", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, "listing", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "BOLA", -        BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, "\r\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -        "listing_once", BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "asd", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, -        "", BLOGC_TEMPLATE_CONTENT_STMT); +    blogc_assert_template_node(tmp, NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next, "\r\n", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, "listing", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next->next, "BOLA", +        BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next, "\r\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, +        "listing_once", BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "asd", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next->next, +        "", BLOGC_TEMPLATE_NODE_CONTENT);      tmp = tmp->next->next->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); -    blogc_assert_template_stmt(tmp->next, "hahaha", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, NULL, -        BLOGC_TEMPLATE_ENDFOREACH_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "\r\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_if_stmt(tmp->next->next->next->next, "BOLA", +    blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_FOREACH); +    blogc_assert_template_node(tmp->next, "hahaha", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDFOREACH); +    blogc_assert_template_node(tmp->next->next->next, "\r\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_if_node(tmp->next->next->next->next, "BOLA",          BLOGC_TEMPLATE_OP_EQ, "\"1\\\"0\""); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, "aee", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ELSE_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "fffuuuuuuu", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDIF_STMT); +    blogc_assert_template_node(tmp->next->next->next->next->next, "aee", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ELSE); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "fffuuuuuuu", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDIF);      assert_null(tmp->next->next->next->next->next->next->next->next->next); -    blogc_template_free_stmts(stmts); +    blogc_template_free_ast(ast);  } @@ -236,105 +236,105 @@ test_template_parse_html(void **state)          "    </body>\n"          "</html>\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_null(err); -    assert_non_null(stmts); -    blogc_assert_template_stmt(stmts, "<html>\n    <head>\n        ", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next, "entry", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(stmts->next->next, -        "\n        <title>My cool blog >> ", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next, "TITLE", -        BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next, -        "</title>\n        ", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next->next, -        "\n        ", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next->next->next, -        "listing_once", BLOGC_TEMPLATE_BLOCK_STMT); -    bc_slist_t *tmp = stmts->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, +    assert_non_null(ast); +    blogc_assert_template_node(ast, "<html>\n    <head>\n        ", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next, "entry", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(ast->next->next, +        "\n        <title>My cool blog >> ", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next, "TITLE", +        BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(ast->next->next->next->next, +        "</title>\n        ", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(ast->next->next->next->next->next->next, +        "\n        ", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next->next->next->next, +        "listing_once", BLOGC_TEMPLATE_NODE_BLOCK); +    bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next; +    blogc_assert_template_node(tmp,          "\n        <title>My cool blog - Main page</title>\n        ", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next, +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next, NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next->next,          "\n    </head>\n    <body>\n        <h1>My cool blog</h1>\n        ", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "entry", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, -        "\n        <h2>", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, -        "TITLE", BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -        "</h2>\n        ", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "DATE", BLOGC_TEMPLATE_IFDEF_STMT); +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next, "entry", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next->next->next, +        "\n        <h2>", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next, +        "TITLE", BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, +        "</h2>\n        ", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "DATE", BLOGC_TEMPLATE_NODE_IFDEF);      tmp = tmp->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, "<h4>Published in: ", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next, "DATE", BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next->next, "</h4>", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, "\n        <pre>", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, -        "CONTENT", BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -        "</pre>\n        ", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); +    blogc_assert_template_node(tmp, "<h4>Published in: ", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next, "DATE", BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next->next, "</h4>", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next->next, "\n        <pre>", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next, +        "CONTENT", BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, +        "</pre>\n        ", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK);      tmp = tmp->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, "\n        ", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next, "listing_once", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next, "<ul>", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, "\n        ", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, -        "listing", BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -        "<p><a href=\"", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "FILENAME", BLOGC_TEMPLATE_VARIABLE_STMT); +    blogc_assert_template_node(tmp, "\n        ", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next, "listing_once", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next, "<ul>", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next->next->next->next, "\n        ", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next, +        "listing", BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, +        "<p><a href=\"", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "FILENAME", BLOGC_TEMPLATE_NODE_VARIABLE);      tmp = tmp->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, ".html\">", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next, "TITLE", -        BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next->next, "</a>", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "DATE", -        BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, " - ", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, "DATE", -        BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -        NULL, BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "</p>", BLOGC_TEMPLATE_CONTENT_STMT); +    blogc_assert_template_node(tmp, ".html\">", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next, "TITLE", +        BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next->next, "</a>", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next, "DATE", +        BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(tmp->next->next->next->next, " - ", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next, "DATE", +        BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, +        NULL, BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "</p>", BLOGC_TEMPLATE_NODE_CONTENT);      tmp = tmp->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next, "\n        ", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, "listing_once", -        BLOGC_TEMPLATE_BLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "</ul>", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDBLOCK_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, -        "\n    </body>\n</html>\n", BLOGC_TEMPLATE_CONTENT_STMT); +    blogc_assert_template_node(tmp, NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next, "\n        ", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, "listing_once", +        BLOGC_TEMPLATE_NODE_BLOCK); +    blogc_assert_template_node(tmp->next->next->next, "</ul>", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDBLOCK); +    blogc_assert_template_node(tmp->next->next->next->next->next, +        "\n    </body>\n</html>\n", BLOGC_TEMPLATE_NODE_CONTENT);      assert_null(tmp->next->next->next->next->next->next); -    blogc_template_free_stmts(stmts); +    blogc_template_free_ast(ast);  } @@ -346,29 +346,29 @@ test_template_parse_ifdef_and_var_outside_block(void **state)          "{{ BOLA }}\n"          "{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_null(err); -    assert_non_null(stmts); -    blogc_assert_template_stmt(stmts, "GUDA", BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(stmts->next, "bola", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(stmts->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next, "BOLA", -        BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next->next, -        "CHUNDA", BLOGC_TEMPLATE_IFNDEF_STMT); -    bc_slist_t *tmp = stmts->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, "CHUNDA", BLOGC_TEMPLATE_VARIABLE_STMT); -    blogc_assert_template_stmt(tmp->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); +    assert_non_null(ast); +    blogc_assert_template_node(ast, "GUDA", BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(ast->next, "bola", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(ast->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next, "BOLA", +        BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(ast->next->next->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next->next->next, +        "CHUNDA", BLOGC_TEMPLATE_NODE_IFNDEF); +    bc_slist_t *tmp = ast->next->next->next->next->next->next->next; +    blogc_assert_template_node(tmp, "CHUNDA", BLOGC_TEMPLATE_NODE_VARIABLE); +    blogc_assert_template_node(tmp->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT);      assert_null(tmp->next->next->next); -    blogc_template_free_stmts(stmts); +    blogc_template_free_ast(ast);  } @@ -393,50 +393,50 @@ test_template_parse_nested_else(void **state)          "{% endif %}\n"          "{% endif %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_null(err); -    assert_non_null(stmts); -    blogc_assert_template_stmt(stmts, "GUDA", BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(stmts->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next, "BOLA", BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(stmts->next->next->next, "\nasd\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ELSE_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next->next, -        "CHUNDA", BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(stmts->next->next->next->next->next->next->next, -        "\nqwe\n", BLOGC_TEMPLATE_CONTENT_STMT); -    bc_slist_t *tmp = stmts->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, NULL, BLOGC_TEMPLATE_ELSE_STMT); -    blogc_assert_template_stmt(tmp->next, "\nrty\n", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -        "LOL", BLOGC_TEMPLATE_IFDEF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next, -        "\nzxc\n", BLOGC_TEMPLATE_CONTENT_STMT); +    assert_non_null(ast); +    blogc_assert_template_node(ast, "GUDA", BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(ast->next, "\n", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next, "BOLA", BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(ast->next->next->next, "\nasd\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ELSE); +    blogc_assert_template_node(ast->next->next->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(ast->next->next->next->next->next->next, +        "CHUNDA", BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(ast->next->next->next->next->next->next->next, +        "\nqwe\n", BLOGC_TEMPLATE_NODE_CONTENT); +    bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next; +    blogc_assert_template_node(tmp, NULL, BLOGC_TEMPLATE_NODE_ELSE); +    blogc_assert_template_node(tmp->next, "\nrty\n", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next->next->next, +        "LOL", BLOGC_TEMPLATE_NODE_IFDEF); +    blogc_assert_template_node(tmp->next->next->next->next->next->next->next, +        "\nzxc\n", BLOGC_TEMPLATE_NODE_CONTENT);      tmp = tmp->next->next->next->next->next->next->next->next; -    blogc_assert_template_stmt(tmp, NULL, BLOGC_TEMPLATE_ELSE_STMT); -    blogc_assert_template_stmt(tmp->next, "\nbnm\n", BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next, NULL, -        BLOGC_TEMPLATE_ENDIF_STMT); -    blogc_assert_template_stmt(tmp->next->next->next->next->next, "\n", -        BLOGC_TEMPLATE_CONTENT_STMT); +    blogc_assert_template_node(tmp, NULL, BLOGC_TEMPLATE_NODE_ELSE); +    blogc_assert_template_node(tmp->next, "\nbnm\n", BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT); +    blogc_assert_template_node(tmp->next->next->next->next, NULL, +        BLOGC_TEMPLATE_NODE_ENDIF); +    blogc_assert_template_node(tmp->next->next->next->next->next, "\n", +        BLOGC_TEMPLATE_NODE_CONTENT);      assert_null(tmp->next->next->next->next->next->next); -    blogc_template_free_stmts(stmts); +    blogc_template_free_ast(ast);  } @@ -445,9 +445,9 @@ test_template_parse_invalid_block_start(void **state)  {      const char *a = "{% ASD %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement syntax. Must begin with lowercase letter.\n" @@ -455,9 +455,9 @@ test_template_parse_invalid_block_start(void **state)      bc_error_free(err);      a = "{%-- block entry %}\n";      err = NULL; -    stmts = blogc_template_parse(a, strlen(a), &err); +    ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" @@ -465,9 +465,9 @@ test_template_parse_invalid_block_start(void **state)      bc_error_free(err);      a = "{% block entry --%}\n";      err = NULL; -    stmts = blogc_template_parse(a, strlen(a), &err); +    ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" @@ -483,9 +483,9 @@ test_template_parse_invalid_block_nested(void **state)          "{% block entry %}\n"          "{% block listing %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Blocks can't be nested.\n" @@ -501,9 +501,9 @@ test_template_parse_invalid_foreach_nested(void **state)          "{% foreach A %}\n"          "{% foreach B %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'foreach' statements can't be nested.\n" @@ -517,9 +517,9 @@ test_template_parse_invalid_block_not_open(void **state)  {      const char *a = "{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'endblock' statement without an open 'block' statement.\n" @@ -533,9 +533,9 @@ test_template_parse_invalid_endif_not_open(void **state)  {      const char *a = "{% block listing %}{% endif %}{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n" @@ -550,9 +550,9 @@ test_template_parse_invalid_endif_not_open_inside_block(void **state)  {      const char *a = "{% ifdef BOLA %}{% block listing %}{% endif %}{% endblock %}";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n" @@ -567,9 +567,9 @@ test_template_parse_invalid_else_not_open_inside_block(void **state)  {      const char *a = "{% ifdef BOLA %}{% block listing %}{% else %}{% endif %}{% endblock %}";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n" @@ -584,9 +584,9 @@ test_template_parse_invalid_endforeach_not_open(void **state)  {      const char *a = "{% endforeach %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'endforeach' statement without an open 'foreach' statement.\n" @@ -601,9 +601,9 @@ test_template_parse_invalid_endforeach_not_open_inside_block(void **state)      const char *a = "{% foreach TAGS %}{% block entry %}{% endforeach %}"          "{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'endforeach' statement without an open 'foreach' statement.\n" @@ -619,9 +619,9 @@ test_template_parse_invalid_endforeach_not_open_inside_block2(void **state)      const char *a = "{% block entry %}{% foreach TAGS %}"          "{% endforeach %}{% endforeach %}{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'endforeach' statement without an open 'foreach' statement.\n" @@ -637,9 +637,9 @@ test_template_parse_invalid_endforeach_not_closed_inside_block(void **state)      const char *a = "{% block entry %}{% foreach TAGS %}{% endblock %}"          "{% endforeach %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "An open 'foreach' statement was not closed inside a 'entry' block!"); @@ -653,9 +653,9 @@ test_template_parse_invalid_endforeach_not_closed_inside_block2(void **state)      const char *a = "{% block entry %}{% foreach TAGS %}{% endforeach %}"          "{% foreach TAGS %}{% endblock %}{% endforeach %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "An open 'foreach' statement was not closed inside a 'entry' block!"); @@ -668,9 +668,9 @@ test_template_parse_invalid_block_name(void **state)  {      const char *a = "{% chunda %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement type: Allowed types are: 'block', 'endblock', 'if', " @@ -685,9 +685,9 @@ test_template_parse_invalid_block_type_start(void **state)  {      const char *a = "{% block ENTRY %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid block syntax. Must begin with lowercase letter.\n" @@ -701,9 +701,9 @@ test_template_parse_invalid_block_type(void **state)  {      const char *a = "{% block chunda %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n" @@ -717,9 +717,9 @@ test_template_parse_invalid_ifdef_start(void **state)  {      const char *a = "{% block entry %}{% ifdef guda %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid variable name. Must begin with uppercase letter.\n" @@ -734,9 +734,9 @@ test_template_parse_invalid_foreach_start(void **state)  {      const char *a = "{% block entry %}{% foreach guda %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid foreach variable name. Must begin with uppercase letter.\n" @@ -751,9 +751,9 @@ test_template_parse_invalid_ifdef_variable(void **state)  {      const char *a = "{% block entry %}{% ifdef BoLA %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid variable name. Must be uppercase letter, number or '_'.\n" @@ -768,9 +768,9 @@ test_template_parse_invalid_ifdef_variable2(void **state)  {      const char *a = "{% block entry %}{% ifdef 0123 %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid variable name. Must begin with uppercase letter.\n" @@ -785,9 +785,9 @@ test_template_parse_invalid_foreach_variable(void **state)  {      const char *a = "{% block entry %}{% foreach BoLA %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n" @@ -802,9 +802,9 @@ test_template_parse_invalid_foreach_variable2(void **state)  {      const char *a = "{% block entry %}{% foreach 0123 %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid foreach variable name. Must begin with uppercase letter.\n" @@ -819,9 +819,9 @@ test_template_parse_invalid_if_operator(void **state)  {      const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n" @@ -836,9 +836,9 @@ test_template_parse_invalid_if_operand(void **state)  {      const char *a = "{% block entry %}{% if BOLA == asd %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid 'if' operand. Must be double-quoted static string or variable.\n" @@ -853,9 +853,9 @@ test_template_parse_invalid_if_operand2(void **state)  {      const char *a = "{% block entry %}{% if BOLA == \"asd %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Found an open double-quoted string.\n" @@ -870,9 +870,9 @@ test_template_parse_invalid_if_operand3(void **state)  {      const char *a = "{% block entry %}{% if BOLA == 0123 %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid 'if' operand. Must be double-quoted static string or variable.\n" @@ -887,9 +887,9 @@ test_template_parse_invalid_else1(void **state)  {      const char *a = "{% else %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n" @@ -903,9 +903,9 @@ test_template_parse_invalid_else2(void **state)  {      const char *a = "{% if BOLA == \"123\" %}{% if GUDA == \"1\" %}{% else %}{% else %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' " @@ -927,9 +927,9 @@ test_template_parse_invalid_else3(void **state)          "{% else %}\n"          "{% else %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' " @@ -943,9 +943,9 @@ test_template_parse_invalid_block_end(void **state)  {      const char *a = "{% block entry }}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement syntax. Must end with '%}'.\n" @@ -959,9 +959,9 @@ test_template_parse_invalid_variable_name(void **state)  {      const char *a = "{% block entry %}{{ bola }}{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid variable name. Must begin with uppercase letter.\n" @@ -976,9 +976,9 @@ test_template_parse_invalid_variable_name2(void **state)  {      const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid variable name. Must be uppercase letter, number or '_'.\n" @@ -993,9 +993,9 @@ test_template_parse_invalid_variable_name3(void **state)  {      const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid variable name. Must begin with uppercase letter.\n" @@ -1010,9 +1010,9 @@ test_template_parse_invalid_variable_end(void **state)  {      const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement syntax. Must end with '}}'.\n" @@ -1027,9 +1027,9 @@ test_template_parse_invalid_close(void **state)  {      const char *a = "{% block entry %%\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement syntax. Must end with '}'.\n" @@ -1043,9 +1043,9 @@ test_template_parse_invalid_close2(void **state)  {      const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "Invalid statement syntax. Must end with '}'.\n" @@ -1060,9 +1060,9 @@ test_template_parse_invalid_endif_not_closed(void **state)  {      const char *a = "{% block entry %}{% endblock %}{% ifdef BOLA %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg, "1 open 'if', 'ifdef' and/or 'ifndef' statements "          "were not closed!"); @@ -1075,9 +1075,9 @@ test_template_parse_invalid_endif_not_closed_inside_block(void **state)  {      const char *a = "{% block listing %}{% ifdef BOLA %}{% endblock %}{% endif %}";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside " @@ -1091,9 +1091,9 @@ test_template_parse_invalid_else_not_closed_inside_block(void **state)  {      const char *a = "{% block listing %}{% ifdef BOLA %}{% else %}{% endblock %}{% endif %}";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg,          "1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside " @@ -1107,9 +1107,9 @@ test_template_parse_invalid_block_not_closed(void **state)  {      const char *a = "{% block entry %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg, "An open block was not closed!");      bc_error_free(err); @@ -1121,9 +1121,9 @@ test_template_parse_invalid_foreach_not_closed(void **state)  {      const char *a = "{% foreach ASD %}\n";      bc_error_t *err = NULL; -    bc_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); +    bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);      assert_non_null(err); -    assert_null(stmts); +    assert_null(ast);      assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);      assert_string_equal(err->msg, "An open 'foreach' statement was not closed!");      bc_error_free(err);  | 
