From 7d3782502e4a76026fd2af5f6c04bec2767df990 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Fri, 31 Jan 2025 11:48:01 -0500 Subject: [PATCH 1/2] Revert "Don't rely on std::regex::multiline which doesn't exist on msvc" This reverts commit c73b53f6bd558a5fed2fe093c3fcdc85f4425c27. --- include/minja/minja.hpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/include/minja/minja.hpp b/include/minja/minja.hpp index f0e80fd..3124f8c 100644 --- a/include/minja/minja.hpp +++ b/include/minja/minja.hpp @@ -2160,14 +2160,13 @@ class Parser { static std::regex expr_open_regex(R"(\{\{([-~])?)"); static std::regex block_open_regex(R"(^\{%([-~])?[\s\n\r]*)"); static std::regex block_keyword_tok(R"((if|else|elif|endif|for|endfor|generation|endgeneration|set|endset|block|endblock|macro|endmacro|filter|endfilter)\b)"); - static std::regex non_text_open_regex(R"(\{\{|\{%|\{#)"); + static std::regex text_regex(R"([\s\S\r\n]*?($|(?=\{\{|\{%|\{#)))", std::regex::multiline); static std::regex expr_close_regex(R"([\s\n\r]*([-~])?\}\})"); static std::regex block_close_regex(R"([\s\n\r]*([-~])?%\})"); TemplateTokenVector tokens; std::vector group; std::string text; - std::smatch match; try { while (it != end) { @@ -2294,15 +2293,10 @@ class Parser { } else { throw std::runtime_error("Unexpected block: " + keyword); } - } else if (std::regex_search(it, end, match, non_text_open_regex)) { - auto text_end = it + match.position(); - text = std::string(it, text_end); - it = text_end; + } else if (!(text = consumeToken(text_regex, SpaceHandling::Keep)).empty()) { tokens.push_back(std::make_unique(location, SpaceHandling::Keep, SpaceHandling::Keep, text)); } else { - text = std::string(it, end); - it = end; - tokens.push_back(std::make_unique(location, SpaceHandling::Keep, SpaceHandling::Keep, text)); + if (it != end) throw std::runtime_error("Unexpected character"); } } return tokens; From 8a38e27f2118cce27697e8d97c1648a8b187b4c6 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Fri, 31 Jan 2025 12:00:23 -0500 Subject: [PATCH 2/2] avoid regex::multiline and fix tests --- include/minja/minja.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/minja/minja.hpp b/include/minja/minja.hpp index 3124f8c..153fdd9 100644 --- a/include/minja/minja.hpp +++ b/include/minja/minja.hpp @@ -2160,7 +2160,7 @@ class Parser { static std::regex expr_open_regex(R"(\{\{([-~])?)"); static std::regex block_open_regex(R"(^\{%([-~])?[\s\n\r]*)"); static std::regex block_keyword_tok(R"((if|else|elif|endif|for|endfor|generation|endgeneration|set|endset|block|endblock|macro|endmacro|filter|endfilter)\b)"); - static std::regex text_regex(R"([\s\S\r\n]*?($|(?=\{\{|\{%|\{#)))", std::regex::multiline); + static std::regex text_regex(R"([\s\S\r\n]*?(?=\{[{%#]|$))"); static std::regex expr_close_regex(R"([\s\n\r]*([-~])?\}\})"); static std::regex block_close_regex(R"([\s\n\r]*([-~])?%\})");