Skip to content

Commit

Permalink
Don't rely on std::regex::multiline which doesn't exist on msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Dec 15, 2024
1 parent 396628f commit c73b53f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions include/minja/minja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2077,13 +2077,14 @@ 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|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 non_text_open_regex(R"(\{\{|\{%|\{#)");
static std::regex expr_close_regex(R"([\s\n\r]*([-~])?\}\})");
static std::regex block_close_regex(R"([\s\n\r]*([-~])?%\})");

TemplateTokenVector tokens;
std::vector<std::string> group;
std::string text;
std::smatch match;

try {
while (it != end) {
Expand Down Expand Up @@ -2204,10 +2205,15 @@ class Parser {
} else {
throw std::runtime_error("Unexpected block: " + keyword);
}
} else if (!(text = consumeToken(text_regex, SpaceHandling::Keep)).empty()) {
} 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;
tokens.push_back(nonstd_make_unique<TextTemplateToken>(location, SpaceHandling::Keep, SpaceHandling::Keep, text));
} else {
if (it != end) throw std::runtime_error("Unexpected character");
text = std::string(it, end);
it = end;
tokens.push_back(nonstd_make_unique<TextTemplateToken>(location, SpaceHandling::Keep, SpaceHandling::Keep, text));
}
}
return tokens;
Expand Down

0 comments on commit c73b53f

Please sign in to comment.