diff --git a/include/cpp2regex.h b/include/cpp2regex.h index e2a69946c..146372422 100644 --- a/include/cpp2regex.h +++ b/include/cpp2regex.h @@ -261,10 +261,10 @@ template [[nodiscard]] auto make_ #line 184 "cpp2regex.h2" // Helpers for creating wrappers of the iterators. // -template [[nodiscard]] auto make_forward_iterator(Iter const& pos) -> auto; -template [[nodiscard]] auto make_forward_iterator(std::reverse_iterator const& pos) -> auto; -template [[nodiscard]] auto make_reverse_iterator(Iter const& pos) -> auto; -template [[nodiscard]] auto make_reverse_iterator(std::reverse_iterator const& pos) -> auto; +template [[nodiscard]] auto cpp2_make_forward_iterator(Iter const& pos) -> auto; +template [[nodiscard]] auto cpp2_make_forward_iterator(std::reverse_iterator const& pos) -> auto; +template [[nodiscard]] auto cpp2_make_reverse_iterator(Iter const& pos) -> auto; +template [[nodiscard]] auto cpp2_make_reverse_iterator(std::reverse_iterator const& pos) -> auto; #line 192 "cpp2regex.h2" // End function that returns a valid match. @@ -927,13 +927,13 @@ template [[nodiscard]] auto make_ } #line 186 "cpp2regex.h2" -template [[nodiscard]] auto make_forward_iterator(Iter const& pos) -> auto { return pos; } +template [[nodiscard]] auto cpp2_make_forward_iterator(Iter const& pos) -> auto { return pos; } #line 187 "cpp2regex.h2" -template [[nodiscard]] auto make_forward_iterator(std::reverse_iterator const& pos) -> auto { return CPP2_UFCS(base)(pos); } +template [[nodiscard]] auto cpp2_make_forward_iterator(std::reverse_iterator const& pos) -> auto { return CPP2_UFCS(base)(pos); } #line 188 "cpp2regex.h2" -template [[nodiscard]] auto make_reverse_iterator(Iter const& pos) -> auto { return std::make_reverse_iterator(pos); } +template [[nodiscard]] auto cpp2_make_reverse_iterator(Iter const& pos) -> auto { return std::make_reverse_iterator(pos); } #line 189 "cpp2regex.h2" -template [[nodiscard]] auto make_reverse_iterator(std::reverse_iterator const& pos) -> auto { return pos; } +template [[nodiscard]] auto cpp2_make_reverse_iterator(std::reverse_iterator const& pos) -> auto { return pos; } #line 196 "cpp2regex.h2" [[nodiscard]] auto true_end_func::operator()(auto const& cur, auto& ctx) const& -> decltype(auto) { return ctx.pass(cur); } @@ -1153,7 +1153,7 @@ template [[nodiscard]] auto line_start_toke #line 575 "cpp2regex.h2" template [[nodiscard]] auto lookahead_token_matcher(auto const& cur, auto& ctx, auto const& func) -> bool { - auto r {func(make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func())}; + auto r {func(cpp2_make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func())}; if (!(positive)) { r.matched = !(r.matched); } @@ -1164,7 +1164,7 @@ template [[nodiscard]] auto lookahead_token_match #line 589 "cpp2regex.h2" template [[nodiscard]] auto lookbehind_token_matcher(auto const& cur, auto& ctx, auto const& func) -> bool { - auto r {func(make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func())}; + auto r {func(cpp2_make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func())}; if (!(positive)) { r.matched = !(r.matched); } diff --git a/include/cpp2regex.h2 b/include/cpp2regex.h2 index 763c5638b..6fbc03f12 100644 --- a/include/cpp2regex.h2 +++ b/include/cpp2regex.h2 @@ -183,10 +183,10 @@ make_reverse_match_context: (inout ctx: reverse_m // Helpers for creating wrappers of the iterators. // -make_forward_iterator: (pos: Iter) -> _ = pos; -make_forward_iterator: (pos: std::reverse_iterator) -> _ = pos.base(); -make_reverse_iterator: (pos: Iter) -> _ = std::make_reverse_iterator(pos); -make_reverse_iterator: (pos: std::reverse_iterator) -> _ = pos; +cpp2_make_forward_iterator: (pos: Iter) -> _ = pos; +cpp2_make_forward_iterator: (pos: std::reverse_iterator) -> _ = pos.base(); +cpp2_make_reverse_iterator: (pos: Iter) -> _ = std::make_reverse_iterator(pos); +cpp2_make_reverse_iterator: (pos: std::reverse_iterator) -> _ = pos; // End function that returns a valid match. @@ -574,7 +574,7 @@ line_start_token_matcher: (cur, inout ctx) -> bool // lookahead_token_matcher: (cur, inout ctx, func) -> bool = { - r := func(make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func()); + r := func(cpp2_make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func()); if !positive { r.matched = !r.matched; } @@ -588,7 +588,7 @@ lookahead_token_matcher: (cur, inout ctx, func) -> bool // lookbehind_token_matcher: (cur, inout ctx, func) -> bool = { - r := func(make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func()); + r := func(cpp2_make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func()); if !positive { r.matched = !r.matched; } diff --git a/regression-tests/pure2-regex_20_lookbehind.cpp2 b/regression-tests/pure2-regex_20_lookbehind.cpp2 new file mode 100644 index 000000000..75ad0ade5 --- /dev/null +++ b/regression-tests/pure2-regex_20_lookbehind.cpp2 @@ -0,0 +1,286 @@ +create_result: (resultExpr: std::string, r) -> std::string = { + result: std::string = ""; + + get_next := :(iter) -> _ = { + start := std::distance(resultExpr&$*.cbegin(), iter); + firstDollar := resultExpr&$*.find("$", start); + firstAt := resultExpr&$*.find("@", start); + + end := std::min(firstDollar, firstAt); + if end != std::string::npos { + return resultExpr&$*.cbegin() + end; + } + else { + return resultExpr&$*.cend(); + } + }; + extract_group_and_advance := :(inout iter) -> _ = { + start := iter; + + while std::isdigit(iter*) next iter++ {} + + return std::stoi(std::string(start, iter)); + }; + extract_until := :(inout iter, to: char) -> _ = { + start := iter; + + while (to != iter*) next iter++ {} // TODO: Without bracket: error: postfix unary * (dereference) cannot be immediately followed by a (, identifier, or literal - add whitespace before * here if you meant binary * (multiplication) + + return std::string(start, iter); + }; + + iter := resultExpr.begin(); + + while iter != resultExpr.end() { + next := get_next(iter); + + if next != iter { + result += std::string(iter, next); + } + if next != resultExpr.end() { + if next* == '$' { + next++; + + if next* == '&' { + next++; + result += r.group(0); + } + else if next* == '-' || next* == '+' { + is_start := next* == '-'; + next++; + if next* == '{' { + next++; // Skip { + group := extract_until(next, '}'); + next++; // Skip } + result += r.group(group); + } + else if next* == '[' { + next++; // Skip [ + group := extract_group_and_advance(next); + next++; // Skip ] + + if is_start { + result += std::to_string(r.group_start(group)); + } + else { + result += std::to_string(r.group_end(group)); + } + } + else { + // Return max group + result += r.group(r.group_number() - 1); + } + } + else if std::isdigit(next*) { + group := extract_group_and_advance(next); + result += r.group(group); + } + else { + std::cerr << "Not implemented"; + } + } + else if next* == '@' { + next++; + + if next* == '-' || next* == '+' { + i := 0; + while i < cpp2::unchecked_narrow(r.group_number()) next i++ { + pos := 0; + if next* == '-' { + pos = r.group_start(i); + } + else { + pos = r.group_end(i); + } + result += std::to_string(pos); + } + next++; + } + else { + std::cerr << "Not implemented"; + } + } + else { + std::cerr << "Not implemented."; + } + } + iter = next; + } + + return result; +} + +sanitize: (copy str: std::string) -> std::string = +{ + str = cpp2::string_util::replace_all(str, "\a", "\\a"); + str = cpp2::string_util::replace_all(str, "\f", "\\f"); + str = cpp2::string_util::replace_all(str, "\x1b", "\\e"); + str = cpp2::string_util::replace_all(str, "\n", "\\n"); + str = cpp2::string_util::replace_all(str, "\r", "\\r"); + str = cpp2::string_util::replace_all(str, "\t", "\\t"); + + return str; +} + +test: (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string, + resultExpected: std::string) = { + + warning: std::string = ""; + if regex.to_string() != regex_str { + warning = "Warning: Parsed regex does not match."; + } + + status: std::string = "OK"; + + r := regex.search(str); + + if "y" == kind || "yM" == kind || "yS" == kind || "yB" == kind { + if !r.matched { + status = "Failure: Regex should apply."; + } + else { + // Have a match check the result + + result := create_result(resultExpr, r); + + if result != resultExpected { + status = "Failure: Result is wrong. (is: (sanitize(result))$)"; + } + } + } + else if "n" == kind { + if r.matched { + status = "Failure: Regex should not apply. Result is '(r.group(0))$'"; + } + } else { + status = "Unknown kind '(kind)$'"; + } + + if !warning.empty() { + warning += " "; + } + std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl; +} + + +test_tests_20_lookbehind: @regex type = { + regex_01 := R"((?<=a)b)"; + regex_02 := R"((?<=af?)b)"; + regex_03 := R"((?<=a)b)"; + regex_04 := R"((?<=a(?:fo)?)b)"; + regex_05 := R"((?<=a)b)"; + regex_06 := R"((?<=a(?:foo)?)b)"; + regex_07 := R"((?)foo)"; + regex_50 := R"((?)foo)"; + regex_51 := R"((?<=bar>ABC)foo)"; + regex_52 := R"((?ABC)foo)"; + regex_53 := R"((?<=abcd(?<=(aaaabcd))))"; + regex_54 := R"((?=xy(?<=(aaxy))))"; + regex_55 := R"((?=xy(?<=(aaxyz?))))"; + regex_56 := R"((?<=(?=(aaxy))aa))"; + run: (this) = { + std::cout << "Running tests_20_lookbehind:"<< std::endl; + test(regex_01, "01", R"((?<=a)b)", "ab", "y", R"($&)", "b"); + test(regex_02, "02", R"((?<=af?)b)", "ab", "y", R"($&)", "b"); + test(regex_03, "03", R"((?<=a)b)", "cb", "n", R"(-)", "-"); + test(regex_04, "04", R"((?<=a(?:fo)?)b)", "cb", "n", R"(-)", "-"); + test(regex_05, "05", R"((?<=a)b)", "b", "n", R"(-)", "-"); + test(regex_06, "06", R"((?<=a(?:foo)?)b)", "b", "n", R"(-)", "-"); + test(regex_07, "07", R"((?)foo)", "bar>foo", "y", R"($&)", "foo"); + test(regex_50, "50", R"((?)foo)", "bar>foo", "n", R"(-)", "-"); + test(regex_51, "51", R"((?<=bar>ABC)foo)", "bar>ABCfoo", "y", R"($&)", "foo"); + test(regex_52, "52", R"((?ABC)foo)", "bar>ABCfoo", "n", R"(-)", "-"); + test(regex_53, "53", R"((?<=abcd(?<=(aaaabcd))))", "..aaaabcd..", "y", R"($1)", "aaaabcd"); + test(regex_54, "54", R"((?=xy(?<=(aaxy))))", "..aaxy..", "y", R"($1)", "aaxy"); + test(regex_55, "55", R"((?=xy(?<=(aaxyz?))))", "..aaxy..", "y", R"($1)", "aaxy"); + test(regex_56, "56", R"((?<=(?=(aaxy))aa))", "..aaxy..", "y", R"($1)", "aaxy"); + std::cout << std::endl; + } +} +main: () = { + test_tests_20_lookbehind().run(); +} diff --git a/regression-tests/test-results/apple-clang-14-c++2b/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/apple-clang-14-c++2b/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/apple-clang-14-c++2b/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/test-results/apple-clang-15-c++2b/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/apple-clang-15-c++2b/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/apple-clang-15-c++2b/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/test-results/clang-15-c++20-libcpp/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/clang-15-c++20-libcpp/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/clang-15-c++20-libcpp/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/test-results/clang-15-c++20/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/clang-15-c++20/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/clang-15-c++20/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/test-results/clang-19-c++20/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/clang-19-c++20/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/clang-19-c++20/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/test-results/clang-19-c++23-libcpp/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/clang-19-c++23-libcpp/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/clang-19-c++23-libcpp/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/test-results/gcc-13-c++2b/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/gcc-13-c++2b/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/gcc-13-c++2b/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/test-results/gcc-14-c++2b/pure2-regex_20_lookbehind.cpp.execution b/regression-tests/test-results/gcc-14-c++2b/pure2-regex_20_lookbehind.cpp.execution new file mode 100644 index 000000000..cd61d4f56 --- /dev/null +++ b/regression-tests/test-results/gcc-14-c++2b/pure2-regex_20_lookbehind.cpp.execution @@ -0,0 +1,58 @@ +Running tests_20_lookbehind: +01_y: OK regex: (?<=a)b parsed_regex: (?<=a)b str: ab result_expr: $& expected_results b +02_y: OK regex: (?<=af?)b parsed_regex: (?<=af?)b str: ab result_expr: $& expected_results b +03_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: cb result_expr: - expected_results - +04_n: OK regex: (?<=a(?:fo)?)b parsed_regex: (?<=a(?:fo)?)b str: cb result_expr: - expected_results - +05_n: OK regex: (?<=a)b parsed_regex: (?<=a)b str: b result_expr: - expected_results - +06_n: OK regex: (?<=a(?:foo)?)b parsed_regex: (?<=a(?:foo)?)b str: b result_expr: - expected_results - +07_y: OK regex: (?)foo parsed_regex: (?<=bar>)foo str: bar>foo result_expr: $& expected_results foo +50_n: OK regex: (?)foo parsed_regex: (?)foo str: bar>foo result_expr: - expected_results - +51_y: OK regex: (?<=bar>ABC)foo parsed_regex: (?<=bar>ABC)foo str: bar>ABCfoo result_expr: $& expected_results foo +52_n: OK regex: (?ABC)foo parsed_regex: (?ABC)foo str: bar>ABCfoo result_expr: - expected_results - +53_y: OK regex: (?<=abcd(?<=(aaaabcd))) parsed_regex: (?<=abcd(?<=(aaaabcd))) str: ..aaaabcd.. result_expr: $1 expected_results aaaabcd +54_y: OK regex: (?=xy(?<=(aaxy))) parsed_regex: (?=xy(?<=(aaxy))) str: ..aaxy.. result_expr: $1 expected_results aaxy +55_y: OK regex: (?=xy(?<=(aaxyz?))) parsed_regex: (?=xy(?<=(aaxyz?))) str: ..aaxy.. result_expr: $1 expected_results aaxy +56_y: OK regex: (?<=(?=(aaxy))aa) parsed_regex: (?<=(?=(aaxy))aa) str: ..aaxy.. result_expr: $1 expected_results aaxy + diff --git a/regression-tests/pure2-regex_20_lookbehind.cpp b/regression-tests/test-results/pure2-regex_20_lookbehind.cpp similarity index 99% rename from regression-tests/pure2-regex_20_lookbehind.cpp rename to regression-tests/test-results/pure2-regex_20_lookbehind.cpp index 1f549a346..674d9ada9 100644 --- a/regression-tests/pure2-regex_20_lookbehind.cpp +++ b/regression-tests/test-results/pure2-regex_20_lookbehind.cpp @@ -1,4 +1,5 @@ +#define CPP2_IMPORT_STD Yes #include "cpp2regex.h" //=== Cpp2 type declarations ==================================================== @@ -6,28 +7,28 @@ #include "cpp2util.h" -#line 1 "build/20_lookbehind.cpp2" +#line 1 "pure2-regex_20_lookbehind.cpp2" -#line 166 "build/20_lookbehind.cpp2" +#line 166 "pure2-regex_20_lookbehind.cpp2" class test_tests_20_lookbehind; //=== Cpp2 type definitions and function declarations =========================== -#line 1 "build/20_lookbehind.cpp2" +#line 1 "pure2-regex_20_lookbehind.cpp2" [[nodiscard]] auto create_result(cpp2::impl::in resultExpr, auto const& r) -> std::string; -#line 113 "build/20_lookbehind.cpp2" +#line 113 "pure2-regex_20_lookbehind.cpp2" [[nodiscard]] auto sanitize(std::string str) -> std::string; -#line 125 "build/20_lookbehind.cpp2" +#line 125 "pure2-regex_20_lookbehind.cpp2" template auto test(M const& regex, cpp2::impl::in id, cpp2::impl::in regex_str, cpp2::impl::in str, cpp2::impl::in kind, cpp2::impl::in resultExpr, cpp2::impl::in resultExpected) -> void; -#line 166 "build/20_lookbehind.cpp2" +#line 166 "pure2-regex_20_lookbehind.cpp2" class test_tests_20_lookbehind { -#line 223 "build/20_lookbehind.cpp2" +#line 223 "pure2-regex_20_lookbehind.cpp2" public: auto run() const& -> void; public: template class regex_01_matcher { public: template using context = cpp2::regex::match_context; @@ -1905,15 +1906,15 @@ public: [[nodiscard]] static auto to_string() -> std::string; public: auto operator=(test_tests_20_lookbehind const&) -> void = delete; -#line 283 "build/20_lookbehind.cpp2" +#line 283 "pure2-regex_20_lookbehind.cpp2" }; auto main() -> int; //=== Cpp2 function definitions ================================================= -#line 1 "build/20_lookbehind.cpp2" +#line 1 "pure2-regex_20_lookbehind.cpp2" [[nodiscard]] auto create_result(cpp2::impl::in resultExpr, auto const& r) -> std::string{ -#line 2 "build/20_lookbehind.cpp2" +#line 2 "pure2-regex_20_lookbehind.cpp2" std::string result {""}; auto get_next {[_0 = (&resultExpr)](auto const& iter) mutable -> auto{ @@ -2025,7 +2026,7 @@ auto main() -> int; return result; } -#line 113 "build/20_lookbehind.cpp2" +#line 113 "pure2-regex_20_lookbehind.cpp2" [[nodiscard]] auto sanitize(std::string str) -> std::string { str = cpp2::string_util::replace_all(str, "\a", "\\a"); @@ -2038,7 +2039,7 @@ auto main() -> int; return cpp2::move(str); } -#line 125 "build/20_lookbehind.cpp2" +#line 125 "pure2-regex_20_lookbehind.cpp2" template auto test(M const& regex, cpp2::impl::in id, cpp2::impl::in regex_str, cpp2::impl::in str, cpp2::impl::in kind, cpp2::impl::in resultExpr, cpp2::impl::in resultExpected) -> void{ @@ -2079,7 +2080,7 @@ template auto test(M const& regex, cpp2::impl::in id, c std::cout << "" + cpp2::to_string(id) + "_" + cpp2::to_string(kind) + ": " + cpp2::to_string(cpp2::move(status)) + " " + cpp2::to_string(cpp2::move(warning)) + "regex: " + cpp2::to_string(regex_str) + " parsed_regex: " + cpp2::to_string(CPP2_UFCS(to_string)(regex)) + " str: " + cpp2::to_string(sanitize(str)) + " result_expr: " + cpp2::to_string(resultExpr) + " expected_results " + cpp2::to_string(sanitize(resultExpected)) + "" << std::endl; } -#line 223 "build/20_lookbehind.cpp2" +#line 223 "pure2-regex_20_lookbehind.cpp2" auto test_tests_20_lookbehind::run() const& -> void{ std::cout << "Running tests_20_lookbehind:" << std::endl; test(regex_01, "01", R"((?<=a)b)", "ab", "y", R"($&)", "b"); @@ -8982,7 +8983,7 @@ int i{0}; template [[nodiscard]] auto test_tests_20_lookbehind::regex_56_matcher::to_string() -> std::string{return R"((?<=(?=(aaxy))aa))"; } -#line 284 "build/20_lookbehind.cpp2" +#line 284 "pure2-regex_20_lookbehind.cpp2" auto main() -> int{ CPP2_UFCS(run)(test_tests_20_lookbehind()); } diff --git a/regression-tests/test-results/pure2-regex_20_lookbehind.cpp2.output b/regression-tests/test-results/pure2-regex_20_lookbehind.cpp2.output new file mode 100644 index 000000000..4bb5f4259 --- /dev/null +++ b/regression-tests/test-results/pure2-regex_20_lookbehind.cpp2.output @@ -0,0 +1,2 @@ +pure2-regex_20_lookbehind.cpp2... ok (all Cpp2, passes safety checks) +