diff options
author | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-12 21:45:18 +0100 |
---|---|---|
committer | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-12 21:45:18 +0100 |
commit | c9a5143b2aa9b92d1fbff4c804f058cf0e84f953 (patch) | |
tree | a4e58d559670f3a5ed1cd75634e7050791707328 | |
parent | 2d1d7bd16100eb9d702ef67897b2f62a972d6426 (diff) | |
download | unja-c9a5143b2aa9b92d1fbff4c804f058cf0e84f953.tar.gz unja-c9a5143b2aa9b92d1fbff4c804f058cf0e84f953.zip |
add support for comments
-rw-r--r-- | src/template.c | 45 | ||||
-rw-r--r-- | tests/test_template.c | 7 |
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 |