-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/regular expression metafunction #904
Merged
hsutter
merged 179 commits into
hsutter:main
from
MaxSagebaum:feature/regular_expression_metafunction
Jul 21, 2024
+122,033
−300
Merged
Changes from 1 commit
Commits
Show all changes
179 commits
Select commit
Hold shift + click to select a range
6496423
Missing trailing '...' in variadic template arguments.
MaxSagebaum 30098c6
Regular expressions initial setup.
MaxSagebaum 32e76e3
Current working status.
MaxSagebaum d7abbf7
Handling of groups.
MaxSagebaum 34be3d3
Handling of alternatives.
MaxSagebaum 54cb500
Refactor to position based matching.
MaxSagebaum d048884
Added regular expression class.
MaxSagebaum 93c0511
Added class matching.
MaxSagebaum fc8031b
Add line start and end match.
MaxSagebaum 5d26075
Compatibility fixes.
MaxSagebaum f36bbbe
Added test file for regular expressions.
MaxSagebaum d10faca
Basic state machine for range matchers.
MaxSagebaum 4d58428
Proper range printing and group invalidation on alternatives.
MaxSagebaum d149512
State management for ranges. No longer invalid groups if last match f…
MaxSagebaum 1b3456c
Range check in class_matcher and restore of groups in ranges_matcher.
MaxSagebaum e30bce2
Fix for list matcher and state for alternatives.
MaxSagebaum f16fcd2
Improved handling of empty matches and ranges.
MaxSagebaum 0383119
Bugfix for missing semaphore in typed template parameters.
MaxSagebaum 2ddeffa
Support for posix character classes.
MaxSagebaum 654b2e3
Fix for missing escape of '\'.
MaxSagebaum b87b08f
Missing group clear in alternate matcher.
MaxSagebaum ed4fba9
Whitespace errors from cppfront.
MaxSagebaum 4717892
Include regular expressions in cpp2utils.hpp.
MaxSagebaum 6d98bb3
Update for tests.
MaxSagebaum e261ea3
Remove initialization from context.
MaxSagebaum fff7cf1
Basic char matching.
MaxSagebaum 1466a02
Removed need of end logic.
MaxSagebaum 1c04824
Basic group matching.
MaxSagebaum bff2933
Added alternative.
MaxSagebaum 0602023
Added range matcher logic.
MaxSagebaum 545f905
Added remaining regex patterns.
MaxSagebaum a3e35ce
Fixes for range matcher.
MaxSagebaum e52a217
Improved group handling.
MaxSagebaum 671d6dc
Proper reset of ranges.
MaxSagebaum c82076a
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 1e0fecc
Refactor.
MaxSagebaum 42287e8
Moved begin and end to context.
MaxSagebaum 526f405
Removed Iter as template argument.
MaxSagebaum 1073a73
Refactor.
MaxSagebaum 6153cda
Refactor of parser.
MaxSagebaum e155cc5
Regular expression update.
MaxSagebaum c074dc0
Update of test and header files.
MaxSagebaum c0738a4
Addressed review comments.
MaxSagebaum 32df485
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 628c791
Review updates.
MaxSagebaum c3e28fe
Removed static annotation.
MaxSagebaum 5686639
Added greedy matching for alternatives.
MaxSagebaum 437f19d
Greedy version of alternative regex.
MaxSagebaum 907e961
Helpers in match return and first shorthand character class.
MaxSagebaum 6fd7240
Proper error handling.
MaxSagebaum 80a05db
Escaped characters from perl.
MaxSagebaum 14d873c
Group escapes and named group handling.
MaxSagebaum fb36751
Named group access in regex result.
MaxSagebaum 5485acd
Case insensitive matching flag.
MaxSagebaum 0ba2194
Added modifiers to regular expressions.
MaxSagebaum b5cd31e
Fixing bugs in implementation.
MaxSagebaum 3c13276
Non-greedy and possessive matching.
MaxSagebaum f45e7ed
Added horizontal and vertical white spaces.
MaxSagebaum e8d745d
Additional handling of excapes.
MaxSagebaum 0b8d691
Update of tests.
MaxSagebaum 4b463a6
Make regex generation public.
MaxSagebaum ab39d54
Performance fixes for greedy matching.
MaxSagebaum 77c36d0
Added modifiers to matching logic.
MaxSagebaum 930c3f4
Added (?<mod>) notation.
MaxSagebaum 90bb000
Added (?:) notation.
MaxSagebaum 6d05445
Added m and s modifiers.
MaxSagebaum d0b4c00
Bugfix for wrong none-greedy parsing.
MaxSagebaum 1022c48
Fixes for regex results.
MaxSagebaum cb68faa
Update for tests.
MaxSagebaum fb3ea39
Added support for 'n' modifier.
MaxSagebaum c00bf90
Added perquisites for per syntax parsing.
MaxSagebaum 7b927d0
Remove direkt position handling from parser.
MaxSagebaum 0beaa0c
Added named groups with '.
MaxSagebaum 03cdda0
Escape of space in character classes.
MaxSagebaum 2eb0b05
Proper handliing of x and xx modifier switches.
MaxSagebaum 92a24f1
Added parsing for comment groups.
MaxSagebaum d74458d
Aded branch reset support.
MaxSagebaum 3d53f89
Update of tests and header.
MaxSagebaum 8362c8d
Added support for \x.
MaxSagebaum 0a5c9a0
Added \000 and \o{000} handles.
MaxSagebaum 93af009
Added lookahead matchers.
MaxSagebaum ee5d81e
Addes statefull match tail.
MaxSagebaum a64ccfb
Helper functions for match_return creation.
MaxSagebaum 46ce90b
Refactor of matcher naming and helpers.
MaxSagebaum 9d3151e
Cleanup of to_string.
MaxSagebaum 05a632e
Matcher cleanup.
MaxSagebaum 210f2a1
Parser refactor.
MaxSagebaum 86fa6e9
Header update and tests update.
MaxSagebaum 6adf9b4
Fix for greedy range matching.
MaxSagebaum a054d74
Better template arguments for range matchers.
MaxSagebaum f5fe452
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum a7daf80
Update for regex tests.
MaxSagebaum 8ea4561
Changes for new analysis.
MaxSagebaum 599cc56
Remove <format> dependency, get warning-clean build
hsutter b5e9879
Create pure2-regex-partial.cpp2
hsutter c3afdc8
Fix for compile time degradation.
MaxSagebaum ddf291d
Added first conversion to matcher generator.
MaxSagebaum 97eb938
Basic generation of char matchers.
MaxSagebaum 268cfb9
Basic code generation via regegx tokens.
MaxSagebaum 702aa6a
Moved and renamed char token matcher.
MaxSagebaum 586788a
Parsing of ranges.
MaxSagebaum 38ad020
Moved code generation to generation context.
MaxSagebaum bd83019
Generation of statefull matcher.
MaxSagebaum 1321d8b
Cleanup of ranger matcher implementation.
MaxSagebaum ef7c931
Added special range matching.
MaxSagebaum b2fc15f
Removed old range parsers.
MaxSagebaum 84716a3
Moved parse_until into parser context.
MaxSagebaum c889182
Added to_string output.
MaxSagebaum 3abd68c
Added group handling.
MaxSagebaum c3e7435
Added logic for alternative.
MaxSagebaum c2e94b5
Added '.' regex expression.
MaxSagebaum 9b78205
Added group reference matchers.
MaxSagebaum 84b0280
Added anchor matchers.
MaxSagebaum b009a27
Added class matchers.
MaxSagebaum 590ee3c
Added full group matcher parsing.
MaxSagebaum 459fdc7
Added basic character escapes.
MaxSagebaum c726707
Added word boundary matchers.
MaxSagebaum a894f25
Added named start and end line matchers.
MaxSagebaum 14646c3
Added named class matchers.
MaxSagebaum e0382ef
Added \K token.
MaxSagebaum 1cb8883
Added hexadicimal token and octal token.
MaxSagebaum 64fc6cf
Added lookahead parsing and matching.
MaxSagebaum 0ea40c7
Group gathering is now done in a set.
MaxSagebaum 698b02a
Added modifier handling.
MaxSagebaum 4ce2148
Removal of unused funtionality and proper parsing of global modifiers.
MaxSagebaum b7a4478
Moved name group lookup creation.
MaxSagebaum 28ae594
Fixes for generation.
MaxSagebaum 97f4ddc
Merge remote-tracking branch 'origin/main' into temp
MaxSagebaum 19e72ee
Bugfix for nonconst has in generated flag_enums.
MaxSagebaum 2b0d72b
Removed modifiers from arguments and fixed a few wanrings.
MaxSagebaum 8bdd23d
Removed templates for regular arguments.
MaxSagebaum b138737
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 94ffb10
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum d834167
Agglomeration of character matchers.
MaxSagebaum d11cde9
Refactored function generation to do .. while loop.
MaxSagebaum c68dcfe
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 4a498f2
Removed UFCS calls.
MaxSagebaum e9ff730
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 9646d37
Fixes for new cppfront analysis.
MaxSagebaum 8ab0e98
Fixes for new char matcher logic.
MaxSagebaum b69fab4
Added handling of raw strings and using raw strings.
MaxSagebaum d02e1ad
Escape adaptions for to_string and other to_string fixes.
MaxSagebaum 302e4b0
General refactor.
MaxSagebaum 65406dc
Continuation of cleanup.
MaxSagebaum 8f250d3
Added namespace ot string_util.h.
MaxSagebaum 4c492c1
Fixes for compiler warnings.
MaxSagebaum edf0b74
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 7fa74b1
Added new tests.
MaxSagebaum 617b042
Changes for regression tests.
MaxSagebaum 5cefc73
Fixes for regex and non-regex tests.
MaxSagebaum a65350b
Remove UFCS from regex and more non-regex test fixes.
MaxSagebaum 8db3c70
Update for TODOs.
MaxSagebaum e4ba57d
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum bcf9c61
Update for generated header files.
MaxSagebaum e106333
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum dc2a9f1
Update of generated header files.
MaxSagebaum 98ce0fd
Updates for regression tests.
MaxSagebaum 47b2370
Enable modules build on MSVC by removing #includes when using modules
hsutter ccaf546
Updates for regression tests.
MaxSagebaum f62b856
Changes for regression-tests.
MaxSagebaum ca6774d
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 2eaac0b
Updates for regression tests.
MaxSagebaum bb27c43
Updates for regression tests.
MaxSagebaum 5208006
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum 57f8e15
Update for \e escape.
MaxSagebaum 4cfbe00
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum f0a76a9
CI update tests
jarzec 5942bdd
Update for tests.
MaxSagebaum 0172e35
Merge branch 'main' into feature/regular_expression_metafunction
MaxSagebaum 8dedcc7
Merge remote-tracking branch 'temp/ci-update-tests' into feature/regu…
MaxSagebaum b99d10e
Update for test results.
MaxSagebaum 788cf3d
Merge remote-tracking branch 'origin/main' into feature/regular_expre…
MaxSagebaum b089f02
Update for regression tests.
MaxSagebaum 9577a0b
Reran regressions on my box - whitespace changes only
hsutter 85b8458
Move & rename source/regex.h2 to include/cpp2regex.h2
hsutter 2a8994f
Merge string_util.h into cpp2util.h
hsutter 25b1a26
Review pass through cpp2regex.h2
hsutter de8348f
Finish tweaking pass through cpp2regex.h2
hsutter ae9fa61
Merge branch 'main' into feature/regular_expression_metafunction
hsutter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Regular expressions initial setup.
commit 30098c63a9f80d55ebc8521e800f7bb10afefcd5
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
|
||
#ifndef REGEX_H_CPP2 | ||
#define REGEX_H_CPP2 | ||
|
||
|
||
//=== Cpp2 type declarations ==================================================== | ||
|
||
|
||
#include "cpp2util.h" | ||
|
||
#line 1 "regex.h2" | ||
|
||
#line 13 "regex.h2" | ||
namespace cpp2 { | ||
|
||
namespace regex { | ||
|
||
#line 20 "regex.h2" | ||
class list_end; | ||
|
||
class match_return; | ||
|
||
#line 37 "regex.h2" | ||
template<typename CharT, size_t max_groups> class match_context; | ||
|
||
#line 49 "regex.h2" | ||
template<typename CharT> class any_matcher_logic; | ||
|
||
#line 55 "regex.h2" | ||
template<typename CharT, CharT C> class char_matcher_logic; | ||
|
||
#line 61 "regex.h2" | ||
template<typename CharT, typename ...List> class list_matcher_logic; | ||
|
||
#line 120 "regex.h2" | ||
} | ||
} | ||
|
||
|
||
//=== Cpp2 type definitions and function declarations =========================== | ||
|
||
#line 1 "regex.h2" | ||
|
||
// Copyright (c) Herb Sutter | ||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0 | ||
|
||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#line 13 "regex.h2" | ||
namespace cpp2 { | ||
|
||
namespace regex { | ||
|
||
template<typename CharT> using view = std::basic_string_view<CharT>; | ||
template<typename CharT> using bstring = std::basic_string<CharT>; | ||
|
||
class list_end { | ||
public: list_end() = default; | ||
public: list_end(list_end const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(list_end const&) -> void = delete; | ||
}; | ||
#line 21 "regex.h2" | ||
|
||
class match_return | ||
{ | ||
public: bool matched {false}; | ||
public: size_t length {0}; | ||
|
||
public: [[nodiscard]] static auto create(auto const& m, auto const& l) -> match_return; | ||
|
||
#line 35 "regex.h2" | ||
}; | ||
|
||
template<typename CharT, size_t max_groups> class match_context | ||
{ | ||
|
||
private: std::array<view<CharT>,max_groups> groups; | ||
public: match_context() = default; | ||
public: match_context(match_context const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(match_context const&) -> void = delete; | ||
|
||
|
||
#line 42 "regex.h2" | ||
}; | ||
|
||
/*regular_expression: @interface <CharT> type = { | ||
match: <Ctx> (str: view<CharT>, inout ctx: Ctx) -> bool; | ||
}*/ | ||
|
||
template<typename CharT> class any_matcher_logic | ||
{ | ||
public: [[nodiscard]] static auto match(cpp2::in<view<CharT>> str, auto& ctx) -> match_return; | ||
public: [[nodiscard]] static auto to_string() -> bstring<CharT>; | ||
public: any_matcher_logic() = default; | ||
public: any_matcher_logic(any_matcher_logic const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(any_matcher_logic const&) -> void = delete; | ||
|
||
#line 53 "regex.h2" | ||
}; | ||
|
||
template<typename CharT, CharT C> class char_matcher_logic | ||
{ | ||
public: [[nodiscard]] static auto match(cpp2::in<view<CharT>> str, auto& ctx) -> match_return; | ||
public: [[nodiscard]] static auto to_string() -> bstring<CharT>; | ||
public: char_matcher_logic() = default; | ||
public: char_matcher_logic(char_matcher_logic const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(char_matcher_logic const&) -> void = delete; | ||
|
||
#line 59 "regex.h2" | ||
}; | ||
|
||
template<typename CharT, typename ...List> class list_matcher_logic | ||
{ | ||
public: [[nodiscard]] static auto match(cpp2::in<view<CharT>> str, auto& ctx) -> match_return; | ||
|
||
#line 67 "regex.h2" | ||
public: [[nodiscard]] static auto to_string() -> bstring<CharT>; | ||
|
||
#line 71 "regex.h2" | ||
private: template<typename First, typename ...Other> [[nodiscard]] static auto match_all(cpp2::in<view<CharT>> str, auto& ctx) -> match_return; | ||
|
||
#line 90 "regex.h2" | ||
private: [[nodiscard]] static auto match_all(cpp2::in<view<CharT>> str, auto& ctx) -> match_return; | ||
public: list_matcher_logic() = default; | ||
public: list_matcher_logic(list_matcher_logic const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(list_matcher_logic const&) -> void = delete; | ||
|
||
|
||
#line 94 "regex.h2" | ||
}; | ||
|
||
[[nodiscard]] auto generate_template(cpp2::in<std::string_view> regex) -> std::string; | ||
|
||
#line 120 "regex.h2" | ||
} | ||
} | ||
|
||
|
||
//=== Cpp2 function definitions ================================================= | ||
|
||
#line 1 "regex.h2" | ||
|
||
#line 13 "regex.h2" | ||
namespace cpp2 { | ||
|
||
namespace regex { | ||
|
||
#line 27 "regex.h2" | ||
[[nodiscard]] auto match_return::create(auto const& m, auto const& l) -> match_return{ | ||
if (m) { | ||
return { true, l }; | ||
} | ||
else { | ||
return { false, 0 }; | ||
} | ||
} | ||
|
||
#line 51 "regex.h2" | ||
template <typename CharT> [[nodiscard]] auto any_matcher_logic<CharT>::match(cpp2::in<view<CharT>> str, auto& ctx) -> match_return { return match_return::create(!(CPP2_UFCS(empty)(str)), 1); } | ||
template <typename CharT> [[nodiscard]] auto any_matcher_logic<CharT>::to_string() -> bstring<CharT> { return bstring<CharT>(1, '.'); } | ||
|
||
#line 57 "regex.h2" | ||
template <typename CharT, CharT C> [[nodiscard]] auto char_matcher_logic<CharT,C>::match(cpp2::in<view<CharT>> str, auto& ctx) -> match_return { return match_return::create(!(CPP2_UFCS(empty)(str)) && CPP2_UFCS(front)(str) == C, 1); } | ||
template <typename CharT, CharT C> [[nodiscard]] auto char_matcher_logic<CharT,C>::to_string() -> bstring<CharT> { return bstring<CharT>(1, C); } | ||
|
||
#line 63 "regex.h2" | ||
template <typename CharT, typename ...List> [[nodiscard]] auto list_matcher_logic<CharT,List...>::match(cpp2::in<view<CharT>> str, auto& ctx) -> match_return{ | ||
return match_all<List...>(str, ctx); | ||
} | ||
|
||
template <typename CharT, typename ...List> [[nodiscard]] auto list_matcher_logic<CharT,List...>::to_string() -> bstring<CharT>{ | ||
return { (bstring<CharT>() + ... + List::to_string()) }; | ||
} | ||
|
||
template <typename CharT, typename ...List> template<typename First, typename ...Other> [[nodiscard]] auto list_matcher_logic<CharT,List...>::match_all(cpp2::in<view<CharT>> str, auto& ctx) -> match_return{ | ||
match_return r {First::match(str, ctx)}; | ||
|
||
if (r.matched) { | ||
if constexpr (0 != sizeof...(Other)) { | ||
match_return o {match_all<Other...>(CPP2_UFCS(substr)(str, 1), ctx)}; | ||
|
||
if (o.matched) { | ||
r.length += std::move(o).length; | ||
} | ||
else { | ||
r = { false, 0 }; | ||
} | ||
} | ||
} | ||
|
||
return r; | ||
} | ||
|
||
template <typename CharT, typename ...List> [[nodiscard]] auto list_matcher_logic<CharT,List...>::match_all(cpp2::in<view<CharT>> str, auto& ctx) -> match_return{ | ||
// TODO: Assert End == list_end | ||
return { true, 0 }; | ||
} | ||
|
||
#line 96 "regex.h2" | ||
[[nodiscard]] auto generate_template(cpp2::in<std::string_view> regex) -> std::string{ | ||
std::string template_expression {""}; | ||
std::string seperator {""}; | ||
|
||
template_expression += "::cpp2::regex::list_matcher_logic<char, "; | ||
|
||
for ( auto const& c : regex ) { | ||
template_expression += seperator; | ||
if (c == '.') { | ||
template_expression += "::cpp2::regex::any_matcher_logic<char>"; | ||
} | ||
else { | ||
template_expression += "::cpp2::regex::char_matcher_logic<char, '" + cpp2::to_string(c) + "'>"; | ||
} | ||
|
||
seperator = ", "; | ||
} | ||
template_expression += ">"; | ||
|
||
return template_expression; | ||
|
||
#line 118 "regex.h2" | ||
} | ||
|
||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
|
||
// Copyright (c) Herb Sutter | ||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0 | ||
|
||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
cpp2: namespace = { | ||
|
||
regex: namespace = { | ||
|
||
view: <CharT> type == std::basic_string_view<CharT>; | ||
bstring: <CharT> type == std::basic_string<CharT>; | ||
|
||
list_end: type = {} | ||
|
||
match_return: @struct type = | ||
{ | ||
matched: bool = false; | ||
length: size_t = 0; | ||
|
||
create: (m, l) -> match_return = { | ||
if m { | ||
return (true, l); | ||
} | ||
else { | ||
return (false, 0); | ||
} | ||
} | ||
} | ||
|
||
match_context: <CharT, max_groups: size_t> type = | ||
{ | ||
|
||
groups: std::array<view<CharT>, max_groups>; | ||
|
||
} | ||
|
||
/*regular_expression: @interface <CharT> type = { | ||
|
||
match: <Ctx> (str: view<CharT>, inout ctx: Ctx) -> bool; | ||
}*/ | ||
|
||
any_matcher_logic: <CharT> type = | ||
{ | ||
match: (str: view<CharT>, inout ctx: _) -> match_return = match_return::create(!str.empty(), 1); | ||
to_string: () -> bstring<CharT> = bstring<CharT>(1, '.'); | ||
} | ||
|
||
char_matcher_logic: <CharT, C: CharT> type = | ||
{ | ||
match: (str: view<CharT>, inout ctx: _) -> match_return = match_return::create(!str.empty() && str.front() == C, 1); | ||
to_string: () -> bstring<CharT> = bstring<CharT>(1, C); | ||
} | ||
|
||
list_matcher_logic: <CharT, List ...> type = | ||
{ | ||
match: (str: view<CharT>, inout ctx: _) -> match_return = { | ||
return match_all<List...>(str, ctx); | ||
} | ||
|
||
to_string: () -> bstring<CharT> = { | ||
return (bstring<CharT>() + ... + List::to_string()); | ||
} | ||
|
||
private match_all: <First, Other ...> (str: view<CharT>, inout ctx: _) -> match_return = { | ||
r: match_return = First::match(str, ctx); | ||
|
||
if r.matched { | ||
if constexpr 0 != sizeof...(Other) { | ||
o: match_return = match_all<Other...>(str.substr(1), ctx); | ||
|
||
if o.matched { | ||
r.length += o.length; | ||
} | ||
else { | ||
r = (false, 0); | ||
} | ||
} | ||
} | ||
|
||
return r; | ||
} | ||
|
||
private match_all: (str: view<CharT>, inout ctx: _) -> match_return = { | ||
// TODO: Assert End == list_end | ||
return (true, 0); | ||
} | ||
} | ||
|
||
generate_template: (regex: std::string_view) -> std::string = { | ||
template_expression: std::string = ""; | ||
seperator: std::string = ""; | ||
|
||
template_expression += "::cpp2::regex::list_matcher_logic<char, "; | ||
|
||
for regex do (c) { | ||
template_expression += seperator; | ||
if c == '.' { | ||
template_expression += "::cpp2::regex::any_matcher_logic<char>"; | ||
} | ||
else { | ||
template_expression += "::cpp2::regex::char_matcher_logic<char, '(c)$'>"; | ||
} | ||
|
||
seperator = ", "; | ||
} | ||
template_expression += ">"; | ||
|
||
return template_expression; | ||
|
||
|
||
} | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several variables here that are explicitly typed that seem like they could easily be implicitly typed. This
bool
and severalstd::string
vars.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the type from bool and regex. But for
name
andexpr
I would rather keep it.In addition, I simplified the name handling logic.
name
:m.name()
returns a string view. The overload of map.operator [] has problems with this.expr: std::string = m.initializer();
: This one could be removed. But sincem.initializer()
could also return a view in the future, I would rather keep it.