From 5205db347cb9f56187c2ad5e767281a7a4016533 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 27 Apr 2015 00:10:26 -0300 Subject: added global variable support --- src/template-parser.c | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) (limited to 'src/template-parser.c') diff --git a/src/template-parser.c b/src/template-parser.c index 69402cf..a91182f 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -143,36 +143,22 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) break; } else if (0 == strncmp("if", src + start, current - start)) { - if (block_state == BLOCK_ENTRY || block_state == BLOCK_LISTING) { - state = TEMPLATE_BLOCK_IF_START; - type = BLOGC_TEMPLATE_IF_STMT; - start = current; - if_count++; - break; - } - *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, - src, src_len, current, - "'if' statements only allowed inside 'entry' and " - "'listing' blocks."); + state = TEMPLATE_BLOCK_IF_START; + type = BLOGC_TEMPLATE_IF_STMT; + start = current; + if_count++; break; } else if (0 == strncmp("endif", src + start, current - start)) { - if (block_state == BLOCK_ENTRY || block_state == BLOCK_LISTING) { - if (if_count > 0) { - state = TEMPLATE_BLOCK_END; - type = BLOGC_TEMPLATE_ENDIF_STMT; - if_count--; - break; - } - *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, - src, src_len, current, - "'endif' statement without an open 'if' statement."); + if (if_count > 0) { + state = TEMPLATE_BLOCK_END; + type = BLOGC_TEMPLATE_ENDIF_STMT; + if_count--; break; } *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, src_len, current, - "'endif' statements only allowed inside 'entry' " - "and 'listing' blocks."); + "'endif' statement without an open 'if' statement."); break; } } @@ -250,7 +236,6 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) break; if (c == ' ') { if (0 == strncmp("not", src + start, current - start)) { - block_state = BLOCK_ENTRY; end = current; state = TEMPLATE_BLOCK_IF_START; type = BLOGC_TEMPLATE_IF_NOT_STMT; @@ -293,16 +278,9 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) if (c == ' ') break; if (c >= 'A' && c <= 'Z') { - if (block_state == BLOCK_ENTRY || block_state == BLOCK_LISTING) { - state = TEMPLATE_VARIABLE; - type = BLOGC_TEMPLATE_VARIABLE_STMT; - start = current; - break; - } - *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, - src, src_len, current, - "Variable statements only allowed inside 'entry' and " - "'listing' blocks."); + state = TEMPLATE_VARIABLE; + type = BLOGC_TEMPLATE_VARIABLE_STMT; + start = current; break; } *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, -- cgit v1.2.3-18-g5258