Skip to content

Commit

Permalink
Review pass through cpp2regex.h2
Browse files Browse the repository at this point in the history
Up to line ~1600

Looking good, mainly formatting tweaks to follow the repo's style
  • Loading branch information
hsutter committed Jul 20, 2024
1 parent 2a8994f commit 25b1a26
Show file tree
Hide file tree
Showing 18 changed files with 1,549 additions and 1,346 deletions.
1,473 changes: 780 additions & 693 deletions include/cpp2regex.h

Large diffs are not rendered by default.

549 changes: 333 additions & 216 deletions include/cpp2regex.h2

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
//
//===========================================================================

#ifndef CPP2_UTIL_H
#define CPP2_UTIL_H
#ifndef CPP2_CPP2UTIL_H
#define CPP2_CPP2UTIL_H

// If this implementation doesn't support source_location yet, disable it
#include <version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
}


test_tests_13_posessive_modifier: @regex type = {
test_tests_13_possessive_modifier: @regex type = {
regex_01 := R"(a++a)";
regex_02 := R"(a*+a)";
regex_03 := R"(a{1,5}+a)";
Expand Down Expand Up @@ -200,7 +200,7 @@ test_tests_13_posessive_modifier: @regex type = {
regex_47 := R"(foo(aA)?+b)";
regex_48 := R"(foo(aA|bB)?+b)";
run: (this) = {
std::cout << "Running tests_13_posessive_modifier:"<< std::endl;
std::cout << "Running tests_13_possessive_modifier:"<< std::endl;
test(regex_01, "01", R"(a++a)", "aaaaa", "n", R"(-)", "-");
test(regex_02, "02", R"(a*+a)", "aaaaa", "n", R"(-)", "-");
test(regex_03, "03", R"(a{1,5}+a)", "aaaaa", "n", R"(-)", "-");
Expand Down Expand Up @@ -253,5 +253,5 @@ test_tests_13_posessive_modifier: @regex type = {
}
}
main: () = {
test_tests_13_posessive_modifier().run();
test_tests_13_possessive_modifier().run();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Running tests_13_posessive_modifier:
Running tests_13_possessive_modifier:
01_n: OK regex: a++a parsed_regex: a++a str: aaaaa result_expr: - expected_results -
02_n: OK regex: a*+a parsed_regex: a*+a str: aaaaa result_expr: - expected_results -
03_n: OK regex: a{1,5}+a parsed_regex: a{1,5}+a str: aaaaa result_expr: - expected_results -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Running tests_13_posessive_modifier:
Running tests_13_possessive_modifier:
01_n: OK regex: a++a parsed_regex: a++a str: aaaaa result_expr: - expected_results -
02_n: OK regex: a*+a parsed_regex: a*+a str: aaaaa result_expr: - expected_results -
03_n: OK regex: a{1,5}+a parsed_regex: a{1,5}+a str: aaaaa result_expr: - expected_results -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Running tests_13_posessive_modifier:
Running tests_13_possessive_modifier:
01_n: OK regex: a++a parsed_regex: a++a str: aaaaa result_expr: - expected_results -
02_n: OK regex: a*+a parsed_regex: a*+a str: aaaaa result_expr: - expected_results -
03_n: OK regex: a{1,5}+a parsed_regex: a{1,5}+a str: aaaaa result_expr: - expected_results -
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Running tests_13_posessive_modifier:
Running tests_13_possessive_modifier:
01_n: OK regex: a++a parsed_regex: a++a str: aaaaa result_expr: - expected_results -
02_n: OK regex: a*+a parsed_regex: a*+a str: aaaaa result_expr: - expected_results -
03_n: OK regex: a{1,5}+a parsed_regex: a{1,5}+a str: aaaaa result_expr: - expected_results -
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pure2-regex_13_possessive_modifier.cpp

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pure2-regex_13_possessive_modifier.cpp2... ok (all Cpp2, passes safety checks)

11 changes: 5 additions & 6 deletions source/reflect.h
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ auto cpp2_union(meta::type_declaration& t) -> void;
//
auto print(cpp2::impl::in<meta::type_declaration> t) -> void;

#line 1445 "reflect.h2"
#line 1446 "reflect.h2"
//-----------------------------------------------------------------------
//
// regex - creates regular expressions from members
Expand Down Expand Up @@ -2093,21 +2093,20 @@ auto print(cpp2::impl::in<meta::type_declaration> t) -> void
std::cout << CPP2_UFCS(print)(t) << "\n";
}

#line 1459 "reflect.h2"
#line 1460 "reflect.h2"
auto regex_gen(meta::type_declaration& t) -> void
{
auto has_default {false};
auto prefix {"regex"};
std::string postfix {"_mod"}; // TODO: Remove mod syntax when 'm.initializer()' can be '("pat", "mod")'.

std::string postfix {"_mod"}; // TODO: remove mod syntax when 'm.initializer()' can be '("pat", "mod")'
std::map<std::string,std::string> expressions {};

for ( auto& m : CPP2_UFCS(get_member_objects)(t) )
{
std::string name {CPP2_UFCS(name)(m)};

if (CPP2_UFCS(starts_with)(name, prefix)) {

if (CPP2_UFCS(starts_with)(name, prefix))
{
if (!(CPP2_UFCS(has_initializer)(m))) {
CPP2_UFCS(error)(t, "Regular expression must have an initializer.");
}
Expand Down
14 changes: 7 additions & 7 deletions source/reflect.h2
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ print: (t: meta::type_declaration) =
std::cout << t.print() << "\n";
}


//-----------------------------------------------------------------------
//
// regex - creates regular expressions from members
Expand All @@ -1458,18 +1459,17 @@ print: (t: meta::type_declaration) =
//
regex_gen: (inout t: meta::type_declaration) =
{
has_default: = false;
prefix:= "regex";
postfix: std::string = "_mod"; // TODO: Remove mod syntax when 'm.initializer()' can be '("pat", "mod")'.

expressions: std::map<std::string, std::string> = ();
has_default := false;
prefix := "regex";
postfix : std::string = "_mod"; // TODO: remove mod syntax when 'm.initializer()' can be '("pat", "mod")'
expressions : std::map<std::string, std::string> = ();

for t.get_member_objects() do (inout m)
{
name: std::string = m.name();

if name.starts_with(prefix) {

if name.starts_with(prefix)
{
if !m.has_initializer() {
t.error("Regular expression must have an initializer.");
}
Expand Down

0 comments on commit 25b1a26

Please sign in to comment.