aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/template.c45
-rw-r--r--tests/test_template.c7
2 files changed, 40 insertions, 12 deletions
diff --git a/src/template.c b/src/template.c
index f945b7e..51c9a77 100644
--- a/src/template.c
+++ b/src/template.c
@@ -72,23 +72,44 @@ mpc_parser_t *parser_init() {
mpc_parser_t *Var = mpc_new("var");
mpc_parser_t *Block_Open = mpc_new("block_open");
mpc_parser_t *Block_Close = mpc_new("block_close");
+ mpc_parser_t *Comment = mpc_new("comment");
+ mpc_parser_t *Comment_Open = mpc_new("comment_open");
+ mpc_parser_t *Comment_Close = mpc_new("comment_close");
mpc_parser_t *For = mpc_new("for");
mpc_parser_t *Body = mpc_new("body");
mpc_parser_t *Content = mpc_new("content");
mpc_parser_t *Template = mpc_new("template");
mpca_lang(MPCA_LANG_WHITESPACE_SENSITIVE,
- " symbol : /[a-zA-Z_.]+/ ;"
- " var_open : /\{{2} ?/ ;"
- " var_close : / ?}{2}/ ;"
- " var : <var_open> <symbol> <var_close> ;"
- " block_open: /\{\% ?/ ;"
- " block_close: / ?\%}/ ;"
- " for : <block_open> \"for \" <symbol> \" in \" <symbol> <block_close> <body> <block_open> \"endfor\" <block_close> ;"
- " text : /[^{][^{%]*/ ;"
- " content : <var> | <for> | <text>;"
- " body : <content>* ;"
- " template : /^/ <body> /$/ ;",
- Symbol, Symbols, Var_Open, Var_Close, Var, Block_Open, Block_Close, For, Text, Content, Body, Template, NULL);
+ " symbol : /[a-zA-Z_.]+/ ;"
+ " var_open : /\{{2} ?/ ;"
+ " var_close : / ?}{2}/ ;"
+ " var : <var_open> <symbol> <var_close> ;"
+ " block_open: /\{\% ?/ ;"
+ " block_close: / ?\%}/ ;"
+ " comment_open : \"{#\" ;"
+ " comment_close : \"#}\" ;"
+ " comment : <comment_open> /[^#][^#}]*/ <comment_close> ;"
+ " for : <block_open> \"for \" <symbol> \" in \" <symbol> <block_close> <body> <block_open> \"endfor\" <block_close> ;"
+ " text : /[^{][^{%]*/ ;"
+ " content : <var> | <for> | <text> | <comment>;"
+ " body : <content>* ;"
+ " template : /^/ <body> /$/ ;",
+ Symbol,
+ Symbols,
+ Var_Open,
+ Var_Close,
+ Var,
+ Block_Open,
+ Block_Close,
+ Comment_Open,
+ Comment_Close,
+ Comment,
+ For,
+ Text,
+ Content,
+ Body,
+ Template,
+ NULL);
return Template;
}
diff --git a/tests/test_template.c b/tests/test_template.c
index ac78677..d9f74ac 100644
--- a/tests/test_template.c
+++ b/tests/test_template.c
@@ -61,4 +61,11 @@ TEST(var_dot_notation) {
free(output);
}
+TEST(comments) {
+ char *input = "Hello {# comment here #} world.";
+ char *output = template(input, NULL);
+ assert_str(output, "Hello world.");
+ free(output);
+}
+
END_TESTS