11#include " cucumber_cpp/library/StepRegistry.hpp"
2- #include " cucumber_cpp/library/Context.hpp"
2+ #include " cucumber_cpp/library/cucumber_expression/Matcher.hpp"
3+ #include " cucumber_cpp/library/engine/StepType.hpp"
34#include < algorithm>
45#include < cstddef>
5- #include < memory>
66#include < ranges>
77#include < regex>
8- #include < source_location>
98#include < string>
109#include < utility>
10+ #include < variant>
1111#include < vector>
1212
1313namespace cucumber_cpp ::library
1414{
1515 namespace
1616 {
17- std::string ToString (std::string toString)
18- {
19- return toString;
20- }
17+ // std::string ToString(std::string toString)
18+ // {
19+ // return toString;
20+ // }
2121
22- std::vector<std::string> ToVector (const std::smatch& matchResults)
23- {
24- auto range = matchResults | std::views::drop (1 ) | std::views::transform (ToString);
25- return { range.begin (), range.end () };
26- }
22+ // std::vector<std::string> ToVector(const std::smatch& matchResults)
23+ // {
24+ // auto range = matchResults | std::views::drop(1) | std::views::transform(ToString);
25+ // return { range.begin(), range.end() };
26+ // }
2727
28- std::string ParseCucumberExpression (std::string string)
29- {
30- if (!(string.starts_with (' ^' ) && string.ends_with (' $' )))
31- {
32- string = std::regex_replace (string, std::regex (R"( \(.*\))" ), R"( (?:$&)?)" );
28+ // std::string ParseCucumberExpression(std::string string)
29+ // {
30+ // if (!(string.starts_with('^') && string.ends_with('$')))
31+ // {
32+ // string = std::regex_replace(string, std::regex(R"(\(.*\))"), R"((?:$&)?)");
3333
34- string = std::regex_replace (string, std::regex (R"( \{int\})" ), R"( (-?\d+))" );
35- string = std::regex_replace (string, std::regex (R"( \{biginteger\})" ), R"( (-?\d+))" );
36- string = std::regex_replace (string, std::regex (R"( \{byte\})" ), R"( (-?\d+))" );
37- string = std::regex_replace (string, std::regex (R"( \{short\})" ), R"( (-?\d+))" );
38- string = std::regex_replace (string, std::regex (R"( \{long\})" ), R"( (-?\d+))" );
34+ // string = std::regex_replace(string, std::regex(R"(\{int\})"), R"((-?\d+))");
35+ // string = std::regex_replace(string, std::regex(R"(\{biginteger\})"), R"((-?\d+))");
36+ // string = std::regex_replace(string, std::regex(R"(\{byte\})"), R"((-?\d+))");
37+ // string = std::regex_replace(string, std::regex(R"(\{short\})"), R"((-?\d+))");
38+ // string = std::regex_replace(string, std::regex(R"(\{long\})"), R"((-?\d+))");
3939
40- string = std::regex_replace (string, std::regex (R"( \{float\})" ), R"( (-?\d+\.\d+))" );
41- string = std::regex_replace (string, std::regex (R"( \{bigdecimal\})" ), R"( (-?\d+\.\d+))" );
42- string = std::regex_replace (string, std::regex (R"( \{double\})" ), R"( (-?\d+\.\d+))" );
40+ // string = std::regex_replace(string, std::regex(R"(\{float\})"), R"((-?\d+\.\d+))");
41+ // string = std::regex_replace(string, std::regex(R"(\{bigdecimal\})"), R"((-?\d+\.\d+))");
42+ // string = std::regex_replace(string, std::regex(R"(\{double\})"), R"((-?\d+\.\d+))");
4343
44- string = std::regex_replace (string, std::regex (R"( \{word\})" ), R"( ([^\s]+))" );
45- string = std::regex_replace (string, std::regex (R"( \{string\})" ), R"-( "+([^"]+)"+)-" );
44+ // string = std::regex_replace(string, std::regex(R"(\{word\})"), R"(([^\s]+))");
45+ // string = std::regex_replace(string, std::regex(R"(\{string\})"), R"-("+([^"]+)"+)-");
4646
47- string = std::regex_replace (string, std::regex (R"( \{\})" ), R"( (.*))" );
47+ // string = std::regex_replace(string, std::regex(R"(\{\})"), R"((.*))");
4848
49- string = " ^" + string + " $" ;
50- }
49+ // string = "^" + string + "$";
50+ // }
5151
52- return string;
53- }
52+ // return string;
53+ // }
5454
5555 auto TypeFilter (engine::StepType stepType)
5656 {
@@ -61,37 +61,37 @@ namespace cucumber_cpp::library
6161 };
6262 }
6363
64- RegexMatch::RegexMatch (const std::regex& regex, const std::string& expression)
65- {
66- std::smatch smatch;
67- matched = std::regex_search (expression, smatch, regex);
68- matches = ToVector (smatch);
69- }
70-
71- bool RegexMatch::Matched () const
72- {
73- return matched;
74- }
75-
76- std::vector<std::string> RegexMatch::Matches () const
77- {
78- return matches;
79- }
80-
81- StepRegex::StepRegex (const std::string& string)
82- : string{ string }
83- , regex{ ParseCucumberExpression (string) }
84- {}
85-
86- std::unique_ptr<RegexMatch> StepRegex::Match (const std::string& expression) const
87- {
88- return std::make_unique<RegexMatch>(regex, expression);
89- }
90-
91- std::string StepRegex::String () const
92- {
93- return string;
94- }
64+ // RegexMatch::RegexMatch(const std::regex& regex, const std::string& expression)
65+ // {
66+ // std::smatch smatch;
67+ // matched = std::regex_search(expression, smatch, regex);
68+ // matches = ToVector(smatch);
69+ // }
70+
71+ // bool RegexMatch::Matched() const
72+ // {
73+ // return matched;
74+ // }
75+
76+ // std::vector<std::string> RegexMatch::Matches() const
77+ // {
78+ // return matches;
79+ // }
80+
81+ // StepRegex::StepRegex(const std::string& string)
82+ // : string{ string }
83+ // , regex{ ParseCucumberExpression(string) }
84+ // {}
85+
86+ // std::unique_ptr<RegexMatch> StepRegex::Match(const std::string& expression) const
87+ // {
88+ // return std::make_unique<RegexMatch>(regex, expression);
89+ // }
90+
91+ // std::string StepRegex::String() const
92+ // {
93+ // return string;
94+ // }
9595
9696 StepRegistry& StepRegistry::Instance ()
9797 {
@@ -104,11 +104,14 @@ namespace cucumber_cpp::library
104104 std::vector<StepMatch> matches;
105105
106106 for (Entry& entry : registry | std::views::filter (TypeFilter (stepType)))
107- if (auto match = entry.regex .Match (expression); match->Matched ())
107+ {
108+ auto match = std::visit (cucumber_expression::MatchVisitor{ expression }, entry.regex );
109+ if (match)
108110 {
109- matches.emplace_back (entry.factory , match-> Matches () , entry.regex . String ( ));
111+ matches.emplace_back (entry.factory , * match, std::visit (cucumber_expression::patternVisitor , entry.regex ));
110112 ++entry.used ;
111113 }
114+ }
112115
113116 if (matches.empty ())
114117 throw StepNotFoundError{};
0 commit comments