forked from hsutter/cppfront
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp2regex.h
More file actions
1196 lines (975 loc) · 54 KB
/
cpp2regex.h
File metadata and controls
1196 lines (975 loc) · 54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef CPP2REGEX_H_CPP2
#define CPP2REGEX_H_CPP2
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "cpp2regex.h2"
#line 22 "cpp2regex.h2"
namespace cpp2 {
namespace regex {
#line 38 "cpp2regex.h2"
template<typename Iter> class match_group;
#line 48 "cpp2regex.h2"
template<typename Iter> class match_return;
#line 56 "cpp2regex.h2"
template<typename CharT, typename Iter, int max_groups> class match_context;
#line 117 "cpp2regex.h2"
class true_end_func;
#line 125 "cpp2regex.h2"
class no_reset;
#line 132 "cpp2regex.h2"
template<typename Func> class on_return;
#line 159 "cpp2regex.h2"
template<typename CharT, CharT C> class single_class_entry;
#line 168 "cpp2regex.h2"
template<typename CharT, CharT Start, CharT End> class range_class_entry;
#line 177 "cpp2regex.h2"
template<typename CharT, typename ...List> class combined_class_entry;
#line 186 "cpp2regex.h2"
template<typename CharT, CharT ...List> class list_class_entry;
#line 195 "cpp2regex.h2"
template<typename CharT, string_util::fixed_string Name, typename Inner> class named_class_entry;
#line 202 "cpp2regex.h2"
template<typename CharT, typename Inner> class negated_class_entry;
#line 211 "cpp2regex.h2"
template<typename CharT, string_util::fixed_string Name, typename Inner> class shorthand_class_entry;
#line 259 "cpp2regex.h2"
template<typename CharT> class alternative_token_matcher;
#line 337 "cpp2regex.h2"
template<typename CharT, bool negate, bool case_insensitive, typename ...List> class class_token_matcher;
#line 492 "cpp2regex.h2"
class range_flags;
#line 501 "cpp2regex.h2"
template<typename CharT, int min_count, int max_count, int kind> class range_token_matcher;
#line 673 "cpp2regex.h2"
template<typename CharT, typename matcher_wrapper> class regular_expression;
#line 756 "cpp2regex.h2"
}
}
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "cpp2regex.h2"
// Copyright 2022-2024 Herb Sutter
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Part of the Cppfront Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/hsutter/cppfront/blob/main/LICENSE for license information.
//===========================================================================
// Regex support
//===========================================================================
#ifndef CPP2_CPP2REGEX_H
#define CPP2_CPP2REGEX_H
template<typename matcher_wrapper, typename Iter, typename CharT>
using matcher_wrapper_type = typename matcher_wrapper::template wrap<Iter, CharT>;
template<typename matcher>
using matcher_context_type = typename matcher::context;
#line 22 "cpp2regex.h2"
namespace cpp2 {
namespace regex {
template<typename CharT> using bstring = std::basic_string<CharT>;
template <typename CharT> using bview = std::basic_string_view<CharT>;
//-----------------------------------------------------------------------
//
// Helper structures for the expression matching.
//
//-----------------------------------------------------------------------
//
// Structure for storing group information.
//
template<typename Iter> class match_group
{
public: Iter start {};
public: Iter end {};
public: bool matched {false};
public: match_group(auto const& start_, auto const& end_, auto const& matched_);
public: match_group();
#line 44 "cpp2regex.h2"
};
// Return value for every matcher.
//
template<typename Iter> class match_return
{
public: bool matched {false};
public: Iter pos {};
public: match_return(auto const& matched_, auto const& pos_);
public: match_return();
#line 52 "cpp2regex.h2"
};
// Modifiable state during matching.
//
template<typename CharT, typename Iter, int max_groups> class match_context
{
public: Iter begin;
public: Iter end;
private: std::array<match_group<Iter>,max_groups> groups {};
public: match_context(Iter const& begin_, Iter const& end_);
#line 68 "cpp2regex.h2"
public: match_context(match_context const& that);
#line 68 "cpp2regex.h2"
public: auto operator=(match_context const& that) -> match_context& ;
#line 68 "cpp2regex.h2"
public: match_context(match_context&& that) noexcept;
#line 68 "cpp2regex.h2"
public: auto operator=(match_context&& that) noexcept -> match_context& ;
// Getter and setter for groups
//
public: [[nodiscard]] auto get_group(auto const& group) const& -> decltype(auto);
public: [[nodiscard]] auto get_group_end(auto const& group) const& -> int;
#line 80 "cpp2regex.h2"
public: [[nodiscard]] auto get_group_start(auto const& group) const& -> int;
#line 86 "cpp2regex.h2"
public: [[nodiscard]] auto get_group_string(auto const& group) const& -> std::string;
#line 93 "cpp2regex.h2"
public: auto set_group_end(auto const& group, auto const& pos) & -> void;
#line 98 "cpp2regex.h2"
public: auto set_group_invalid(auto const& group) & -> void;
#line 102 "cpp2regex.h2"
public: auto set_group_start(auto const& group, auto const& pos) & -> void;
#line 106 "cpp2regex.h2"
public: [[nodiscard]] auto size() const& -> decltype(auto);
// Misc functions
//
public: [[nodiscard]] auto fail() const& -> decltype(auto);
public: [[nodiscard]] auto pass(cpp2::impl::in<Iter> cur) const& -> decltype(auto);
};
#line 115 "cpp2regex.h2"
// End function that returns a valid match.
//
class true_end_func
{
public: [[nodiscard]] auto operator()(auto const& cur, auto& ctx) const& -> decltype(auto);
};
#line 123 "cpp2regex.h2"
// Empty group reset function.
//
class no_reset
{
public: auto operator()([[maybe_unused]] auto& unnamed_param_2) const& -> void;
};
#line 131 "cpp2regex.h2"
// Evaluate func on destruction of the handle.
template<typename Func> class on_return
{
private: Func func;
public: on_return(Func const& f);
#line 136 "cpp2regex.h2"
public: auto operator=(Func const& f) -> on_return& ;
#line 140 "cpp2regex.h2"
public: ~on_return() noexcept;
public: on_return(on_return const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(on_return const&) -> void = delete;
#line 143 "cpp2regex.h2"
};
#line 146 "cpp2regex.h2"
// Helper for auto deduction of the Func type.
template<typename Func> [[nodiscard]] auto make_on_return(Func const& func) -> decltype(auto);
#line 150 "cpp2regex.h2"
//-----------------------------------------------------------------------
//
// Character classes for regular expressions.
//
//-----------------------------------------------------------------------
//
// Class syntax: <any character> Example: a
//
template<typename CharT, CharT C> class single_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> decltype(auto);
public: [[nodiscard]] static auto to_string() -> decltype(auto);
public: single_class_entry() = default;
public: single_class_entry(single_class_entry const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(single_class_entry const&) -> void = delete;
#line 163 "cpp2regex.h2"
};
#line 166 "cpp2regex.h2"
// Class syntax: - Example: a-c
//
template<typename CharT, CharT Start, CharT End> class range_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> decltype(auto);
public: [[nodiscard]] static auto to_string() -> decltype(auto);
public: range_class_entry() = default;
public: range_class_entry(range_class_entry const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(range_class_entry const&) -> void = delete;
#line 172 "cpp2regex.h2"
};
#line 175 "cpp2regex.h2"
// Helper for combining two character classes
//
template<typename CharT, typename ...List> class combined_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> decltype(auto);
public: [[nodiscard]] static auto to_string() -> decltype(auto);
public: combined_class_entry() = default;
public: combined_class_entry(combined_class_entry const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(combined_class_entry const&) -> void = delete;
#line 181 "cpp2regex.h2"
};
#line 184 "cpp2regex.h2"
// Class syntax: <list of characters> Example: abcd
//
template<typename CharT, CharT ...List> class list_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> decltype(auto);
public: [[nodiscard]] static auto to_string() -> decltype(auto);
public: list_class_entry() = default;
public: list_class_entry(list_class_entry const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(list_class_entry const&) -> void = delete;
#line 190 "cpp2regex.h2"
};
#line 193 "cpp2regex.h2"
// Class syntax: [:<class name:] Example: [:alnum:]
//
template<typename CharT, string_util::fixed_string Name, typename Inner> class named_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> decltype(auto);
public: [[nodiscard]] static auto to_string() -> decltype(auto);
public: named_class_entry() = default;
public: named_class_entry(named_class_entry const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(named_class_entry const&) -> void = delete;
#line 199 "cpp2regex.h2"
};
#line 202 "cpp2regex.h2"
template<typename CharT, typename Inner> class negated_class_entry
: public Inner {
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> decltype(auto);
public: negated_class_entry() = default;
public: negated_class_entry(negated_class_entry const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(negated_class_entry const&) -> void = delete;
#line 206 "cpp2regex.h2"
};
#line 209 "cpp2regex.h2"
// Short class syntax: \<character> Example: \w
//
template<typename CharT, string_util::fixed_string Name, typename Inner> class shorthand_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> decltype(auto);
public: [[nodiscard]] static auto to_string() -> decltype(auto);
public: shorthand_class_entry() = default;
public: shorthand_class_entry(shorthand_class_entry const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(shorthand_class_entry const&) -> void = delete;
#line 215 "cpp2regex.h2"
};
#line 218 "cpp2regex.h2"
// Named basic character classes
//
template <typename CharT> using digits_class = named_class_entry<CharT,"digits",range_class_entry<CharT,'0','9'>>;
template <typename CharT> using lower_class = named_class_entry<CharT,"lower",range_class_entry<CharT,'a','z'>>;
template <typename CharT> using upper_class = named_class_entry<CharT,"upper",range_class_entry<CharT,'A','Z'>>;
// Named other classes
//
template <typename CharT> using alnum_class = named_class_entry<CharT,"alnum",combined_class_entry<CharT,lower_class<CharT>,upper_class<CharT>,digits_class<CharT>>>;
template <typename CharT> using alpha_class = named_class_entry<CharT,"alpha",combined_class_entry<CharT,lower_class<CharT>,upper_class<CharT>>>;
template <typename CharT> using ascii_class = named_class_entry<CharT,"ascii",range_class_entry<CharT,'\x00','\x7F'>>;
template <typename CharT> using blank_class = named_class_entry<CharT,"blank",list_class_entry<CharT,' ','\t'>>;
template <typename CharT> using cntrl_class = named_class_entry<CharT,"cntrl",combined_class_entry<CharT,range_class_entry<CharT,'\x00','\x1F'>,single_class_entry<CharT,'\x7F'>>>;
template <typename CharT> using graph_class = named_class_entry<CharT,"graph",range_class_entry<CharT,'\x21','\x7E'>>;
template<typename CharT> using hor_space_class = named_class_entry<CharT,"hspace",list_class_entry<CharT,'\t',' '>>;
template <typename CharT> using print_class = named_class_entry<CharT,"print",range_class_entry<CharT,'\x20','\x7E'>>;
template <typename CharT> using punct_class = named_class_entry<CharT,"punct",list_class_entry<CharT,'[','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~',']'>>;
template <typename CharT> using space_class = named_class_entry<CharT,"space",list_class_entry<CharT,' ','\t','\r','\n','\v','\f'>>;
template<typename CharT> using ver_space_class = named_class_entry<CharT,"vspace",list_class_entry<CharT,'\n','\v','\f','\r'>>;
template <typename CharT> using word_class = named_class_entry<CharT,"word",combined_class_entry<CharT,alnum_class<CharT>,single_class_entry<CharT,'_'>>>;
template <typename CharT> using xdigit_class = named_class_entry<CharT,"xdigit",combined_class_entry<CharT,range_class_entry<CharT,'A','F'>,range_class_entry<CharT,'a','f'>,digits_class<CharT>>>;
// Shorthand class entries
//
template <typename CharT> using short_digits_class = shorthand_class_entry<CharT,"\\d",digits_class<CharT>>;
template <typename CharT> using short_hor_space_class = shorthand_class_entry<CharT,"\\h",hor_space_class<CharT>>;
template <typename CharT> using short_space_class = shorthand_class_entry<CharT,"\\s",space_class<CharT>>;
template<typename CharT> using short_vert_space_class = shorthand_class_entry<CharT,"\\v",ver_space_class<CharT>>;
template <typename CharT> using short_word_class = shorthand_class_entry<CharT,"\\w",word_class<CharT>>;
template <typename CharT> using short_not_digits_class = negated_class_entry<CharT,shorthand_class_entry<CharT,"\\D",digits_class<CharT>>>;
template <typename CharT> using short_not_hor_space_class = negated_class_entry<CharT,shorthand_class_entry<CharT,"\\H",hor_space_class<CharT>>>;
template <typename CharT> using short_not_space_class = negated_class_entry<CharT,shorthand_class_entry<CharT,"\\S",space_class<CharT>>>;
template<typename CharT> using short_not_vert_space_class = negated_class_entry<CharT,shorthand_class_entry<CharT,"\\V",ver_space_class<CharT>>>;
template <typename CharT> using short_not_word_class = negated_class_entry<CharT,shorthand_class_entry<CharT,"\\W",word_class<CharT>>>;
#line 255 "cpp2regex.h2"
// Regex syntax: | Example: ab|ba
//
// Non greedy implementation. First alternative that matches is chosen.
//
template<typename CharT> class alternative_token_matcher
{
public: [[nodiscard]] static auto match(auto const& cur, auto& ctx, auto const& end_func, auto const& tail, auto const& ...functions) -> auto;
#line 265 "cpp2regex.h2"
private: template<typename ...Other> [[nodiscard]] static auto match_first(auto const& cur, auto& ctx, auto const& end_func, auto const& tail, auto const& cur_func, auto const& cur_reset, Other const& ...other) -> auto;
public: alternative_token_matcher() = default;
public: alternative_token_matcher(alternative_token_matcher const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(alternative_token_matcher const&) -> void = delete;
#line 283 "cpp2regex.h2"
};
#line 286 "cpp2regex.h2"
// Regex syntax: .
//
template<typename CharT, bool single_line> [[nodiscard]] auto any_token_matcher(auto& cur, auto& ctx) -> bool;
#line 301 "cpp2regex.h2"
// TODO: Check if vectorization works at some point with this implementation.
// char_token_matcher: <tokens: string_util::fixed_string> (inout cur, inout ctx) -> bool = {
// if !(std::distance(cur, ctx.end) < tokens..size()) {
// return false;
// }
// matched : bool = true;
// (copy i: int = 0) while i < tokens..size() next i += 1 {
// if tokens..data()[i] != cur[i] {
// matched = false; // No break for performance optimization. Without break, the loop vectorizes.
// }
// }
// if matched {
// cur += tokens..size();
// }
// return matched;
// }
// char_token_case_insensitive_matcher: <lower: string_util::fixed_string, upper: string_util::fixed_string> (inout cur, inout ctx) -> bool = {
// if !(std::distance(cur, ctx.end) < lower..size()) {
// return false;
// }
// matched : bool = true;
// (copy i : int = 0) while i < lower..size() next i += 1 {
// if !(lower..data()[i] == cur[i] || upper..data()[i] == cur[i]) {
// matched = false; // No break for performance optimization. Without break, the loop vectorizes.
// }
// }
// if matched {
// cur += lower..size();
// }
// return matched;
// }
#line 335 "cpp2regex.h2"
// Regex syntax: [<character classes>] Example: [abcx-y[:digits:]]
//
template<typename CharT, bool negate, bool case_insensitive, typename ...List> class class_token_matcher
{
public: [[nodiscard]] static auto match(auto& cur, auto& ctx) -> bool;
#line 368 "cpp2regex.h2"
private: template<typename First, typename ...Other> [[nodiscard]] static auto match_any(cpp2::impl::in<CharT> c) -> bool;
public: class_token_matcher() = default;
public: class_token_matcher(class_token_matcher const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(class_token_matcher const&) -> void = delete;
#line 381 "cpp2regex.h2"
// TODO: Implement proper to string
// to_string: () -> bstring<CharT> = {
// r: bstring<CharT> = "[";
// if negate {
// r += "^";
// }
// r += (bstring<CharT>() + ... + List::to_string());
// r += "]";
// return r;
// }
#line 392 "cpp2regex.h2"
};
#line 395 "cpp2regex.h2"
// Named short classes
//
template <typename CharT, bool case_insensitive> using named_class_no_new_line = class_token_matcher<CharT,true,case_insensitive,single_class_entry<CharT,'\n'>>;
template <typename CharT, bool case_insensitive> using named_class_digits = class_token_matcher<CharT,false,case_insensitive,digits_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_hor_space = class_token_matcher<CharT,false,case_insensitive,hor_space_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_space = class_token_matcher<CharT,false,case_insensitive,space_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_ver_space = class_token_matcher<CharT,false,case_insensitive,ver_space_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_word = class_token_matcher<CharT,false,case_insensitive,word_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_not_digits = class_token_matcher<CharT,true,case_insensitive,digits_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_not_hor_space = class_token_matcher<CharT,true,case_insensitive,hor_space_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_not_space = class_token_matcher<CharT,true,case_insensitive,space_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_not_ver_space = class_token_matcher<CharT,true,case_insensitive,ver_space_class<CharT>>;
template <typename CharT, bool case_insensitive> using named_class_not_word = class_token_matcher<CharT,true,case_insensitive,word_class<CharT>>;
#line 411 "cpp2regex.h2"
// Regex syntax: \<number> Example: \1
// \g{name_or_number}
// \k{name_or_number}
// \k<name_or_number>
// \k'name_or_number'
//
template<typename CharT, int group, bool case_insensitive> [[nodiscard]] auto group_ref_token_matcher(auto& cur, auto& ctx) -> bool;
#line 448 "cpp2regex.h2"
// Regex syntax: $ Example: aa$
//
template<typename CharT, bool match_new_line, bool match_new_line_before_end> [[nodiscard]] auto line_end_token_matcher(auto const& cur, auto& ctx) -> bool;
#line 464 "cpp2regex.h2"
// Regex syntax: ^ Example: ^aa
//
template<typename CharT, bool match_new_line> [[nodiscard]] auto line_start_token_matcher(auto const& cur, auto& ctx) -> bool;
#line 473 "cpp2regex.h2"
// Regex syntax: (?=) or (?!) or (*pla), etc. Example: (?=AA)
//
// Parsed in group_token.
//
template<typename CharT, bool positive> [[nodiscard]] auto lookahead_token_matcher(auto const& cur, auto& ctx, auto const& func) -> bool;
#line 488 "cpp2regex.h2"
// TODO: @enum as template parameter currently not working. See issue https://github.com/hsutter/cppfront/issues/1147
#line 491 "cpp2regex.h2"
// Options for range matching.
class range_flags {
public: static const int not_greedy;// Try to take as few as possible.
public: static const int greedy;// Try to take as many as possible.
public: static const int possessive;// Do not give back after a greedy match. No backtracking.
public: range_flags() = default;
public: range_flags(range_flags const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(range_flags const&) -> void = delete;
};
#line 497 "cpp2regex.h2"
#line 499 "cpp2regex.h2"
// Regex syntax: <matcher>{min, max} Example: a{2,4}
//
template<typename CharT, int min_count, int max_count, int kind> class range_token_matcher
{
public: template<typename Iter> [[nodiscard]] static auto match(Iter const& cur, auto& ctx, auto const& inner, auto const& reset_func, auto const& end_func, auto const& tail) -> auto;
#line 517 "cpp2regex.h2"
private: [[nodiscard]] static auto is_below_upper_bound(cpp2::impl::in<int> count) -> bool;
#line 522 "cpp2regex.h2"
private: [[nodiscard]] static auto is_below_lower_bound(cpp2::impl::in<int> count) -> bool;
#line 527 "cpp2regex.h2"
private: [[nodiscard]] static auto is_in_range(cpp2::impl::in<int> count) -> bool;
#line 533 "cpp2regex.h2"
private: template<typename Iter> [[nodiscard]] static auto match_min_count(Iter const& cur, auto& ctx, auto const& inner, auto const& end_func, int& count_r) -> auto;
#line 549 "cpp2regex.h2"
private: template<typename Iter> [[nodiscard]] static auto match_greedy(cpp2::impl::in<int> count, Iter const& cur, Iter const& last_valid, auto& ctx, auto const& inner, auto const& reset_func, auto const& end_func, auto const& other) -> match_return<Iter>;
#line 579 "cpp2regex.h2"
private: template<typename Iter> [[nodiscard]] static auto match_possessive(Iter const& cur, auto& ctx, auto const& inner, auto const& end_func, auto const& other) -> match_return<Iter>;
#line 607 "cpp2regex.h2"
private: template<typename Iter> [[nodiscard]] static auto match_not_greedy(Iter const& cur, auto& ctx, auto const& inner, auto const& end_func, auto const& other) -> match_return<Iter>;
public: range_token_matcher() = default;
public: range_token_matcher(range_token_matcher const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(range_token_matcher const&) -> void = delete;
#line 633 "cpp2regex.h2"
};
#line 636 "cpp2regex.h2"
// Regex syntax: \b or \B Example: \bword\b
//
// Matches the start end end of word boundaries.
//
template<typename CharT, bool negate> [[nodiscard]] auto word_boundary_token_matcher(auto& cur, auto& ctx) -> bool;
#line 665 "cpp2regex.h2"
//-----------------------------------------------------------------------
//
// Regular expression implementation.
//
//-----------------------------------------------------------------------
//
// Regular expression implementation
template<typename CharT, typename matcher_wrapper> class regular_expression
{
public: template<typename Iter> using matcher = matcher_wrapper_type<matcher_wrapper,Iter,CharT>;// TODO: Remove when nested types are allowed: https://github.com/hsutter/cppfront/issues/727
public: template<typename Iter> using context = matcher_context_type<matcher<Iter>>;// TODO: Remove when nested types are allowed: https://github.com/hsutter/cppfront/issues/727
public: template<typename Iter> class search_return
{
public: bool matched;
public: context<Iter> ctx;
public: int pos;
public: search_return(cpp2::impl::in<bool> matched_, context<Iter> const& ctx_, Iter const& pos_);
#line 690 "cpp2regex.h2"
public: [[nodiscard]] auto group_number() const& -> decltype(auto);
public: [[nodiscard]] auto group(cpp2::impl::in<int> g) const& -> decltype(auto);
public: [[nodiscard]] auto group_start(cpp2::impl::in<int> g) const& -> decltype(auto);
public: [[nodiscard]] auto group_end(cpp2::impl::in<int> g) const& -> decltype(auto);
public: [[nodiscard]] auto group(cpp2::impl::in<bstring<CharT>> g) const& -> decltype(auto);
public: [[nodiscard]] auto group_start(cpp2::impl::in<bstring<CharT>> g) const& -> decltype(auto);
public: [[nodiscard]] auto group_end(cpp2::impl::in<bstring<CharT>> g) const& -> decltype(auto);
private: [[nodiscard]] auto get_group_id(cpp2::impl::in<bstring<CharT>> g) const& -> auto;
public: search_return(search_return const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(search_return const&) -> void = delete;
#line 706 "cpp2regex.h2"
};
public: [[nodiscard]] auto match(cpp2::impl::in<bview<CharT>> str) const& -> decltype(auto);
public: [[nodiscard]] auto match(cpp2::impl::in<bview<CharT>> str, auto const& start) const& -> decltype(auto);
public: [[nodiscard]] auto match(cpp2::impl::in<bview<CharT>> str, auto const& start, auto const& length) const& -> decltype(auto);
public: template<typename Iter> [[nodiscard]] auto match(Iter const& start, Iter const& end) const& -> search_return<Iter>;
#line 719 "cpp2regex.h2"
public: [[nodiscard]] auto search(cpp2::impl::in<bview<CharT>> str) const& -> decltype(auto);
public: [[nodiscard]] auto search(cpp2::impl::in<bview<CharT>> str, auto const& start) const& -> decltype(auto);
public: [[nodiscard]] auto search(cpp2::impl::in<bview<CharT>> str, auto const& start, auto const& length) const& -> decltype(auto);
public: template<typename Iter> [[nodiscard]] auto search(Iter const& start, Iter const& end) const& -> search_return<Iter>;
#line 742 "cpp2regex.h2"
public: [[nodiscard]] auto to_string() const& -> decltype(auto);
// Helper functions
//
private: [[nodiscard]] static auto get_iter(cpp2::impl::in<bview<CharT>> str, auto const& pos) -> auto;
public: regular_expression() = default;
public: regular_expression(regular_expression const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regular_expression const&) -> void = delete;
#line 754 "cpp2regex.h2"
};
}
}
#endif
//=== Cpp2 function definitions =================================================
#line 1 "cpp2regex.h2"
#line 22 "cpp2regex.h2"
namespace cpp2 {
namespace regex {
template <typename Iter> match_group<Iter>::match_group(auto const& start_, auto const& end_, auto const& matched_)
: start{ start_ }
, end{ end_ }
, matched{ matched_ }{}
template <typename Iter> match_group<Iter>::match_group(){}
template <typename Iter> match_return<Iter>::match_return(auto const& matched_, auto const& pos_)
: matched{ matched_ }
, pos{ pos_ }{}
template <typename Iter> match_return<Iter>::match_return(){}
#line 63 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> match_context<CharT,Iter,max_groups>::match_context(Iter const& begin_, Iter const& end_)
: begin{ begin_ }
, end{ end_ }{
#line 66 "cpp2regex.h2"
}
#line 68 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> match_context<CharT,Iter,max_groups>::match_context(match_context const& that)
: begin{ that.begin }
, end{ that.end }
, groups{ that.groups }{}
#line 68 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> auto match_context<CharT,Iter,max_groups>::operator=(match_context const& that) -> match_context& {
begin = that.begin;
end = that.end;
groups = that.groups;
return *this; }
#line 68 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> match_context<CharT,Iter,max_groups>::match_context(match_context&& that) noexcept
: begin{ std::move(that).begin }
, end{ std::move(that).end }
, groups{ std::move(that).groups }{}
#line 68 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> auto match_context<CharT,Iter,max_groups>::operator=(match_context&& that) noexcept -> match_context& {
begin = std::move(that).begin;
end = std::move(that).end;
groups = std::move(that).groups;
return *this; }
#line 72 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> [[nodiscard]] auto match_context<CharT,Iter,max_groups>::get_group(auto const& group) const& -> decltype(auto) { return CPP2_ASSERT_IN_BOUNDS(groups, group); }
#line 74 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> [[nodiscard]] auto match_context<CharT,Iter,max_groups>::get_group_end(auto const& group) const& -> int{
if (cpp2::impl::cmp_greater_eq(group,max_groups) || !(CPP2_ASSERT_IN_BOUNDS(groups, group).matched)) {
return 0;
}
return cpp2::unchecked_narrow<int>(std::distance(begin, CPP2_ASSERT_IN_BOUNDS(groups, group).end));
}
#line 80 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> [[nodiscard]] auto match_context<CharT,Iter,max_groups>::get_group_start(auto const& group) const& -> int{
if (cpp2::impl::cmp_greater_eq(group,max_groups) || !(CPP2_ASSERT_IN_BOUNDS(groups, group).matched)) {
return 0;
}
return cpp2::unchecked_narrow<int>(std::distance(begin, CPP2_ASSERT_IN_BOUNDS(groups, group).start));
}
#line 86 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> [[nodiscard]] auto match_context<CharT,Iter,max_groups>::get_group_string(auto const& group) const& -> std::string{
if (cpp2::impl::cmp_greater_eq(group,max_groups) || !(CPP2_ASSERT_IN_BOUNDS(groups, group).matched)) {
return "";
}
return std::string(CPP2_ASSERT_IN_BOUNDS(groups, group).start, CPP2_ASSERT_IN_BOUNDS(groups, group).end);
}
#line 93 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> auto match_context<CharT,Iter,max_groups>::set_group_end(auto const& group, auto const& pos) & -> void{
CPP2_ASSERT_IN_BOUNDS(groups, group).end = pos;
CPP2_ASSERT_IN_BOUNDS(groups, group).matched = true;
}
#line 98 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> auto match_context<CharT,Iter,max_groups>::set_group_invalid(auto const& group) & -> void{
CPP2_ASSERT_IN_BOUNDS(groups, group).matched = false;
}
#line 102 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> auto match_context<CharT,Iter,max_groups>::set_group_start(auto const& group, auto const& pos) & -> void{
CPP2_ASSERT_IN_BOUNDS(groups, group).start = pos;
}
#line 106 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> [[nodiscard]] auto match_context<CharT,Iter,max_groups>::size() const& -> decltype(auto) { return max_groups; }
#line 110 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> [[nodiscard]] auto match_context<CharT,Iter,max_groups>::fail() const& -> decltype(auto) { return match_return<Iter>(false, end); }
#line 111 "cpp2regex.h2"
template <typename CharT, typename Iter, int max_groups> [[nodiscard]] auto match_context<CharT,Iter,max_groups>::pass(cpp2::impl::in<Iter> cur) const& -> decltype(auto) { return match_return<Iter>(true, cur); }
#line 119 "cpp2regex.h2"
[[nodiscard]] auto true_end_func::operator()(auto const& cur, auto& ctx) const& -> decltype(auto) { return ctx.pass(cur); }
#line 127 "cpp2regex.h2"
auto no_reset::operator()([[maybe_unused]] auto& unnamed_param_2) const& -> void{}
#line 136 "cpp2regex.h2"
template <typename Func> on_return<Func>::on_return(Func const& f)
: func{ f }{
#line 138 "cpp2regex.h2"
}
#line 136 "cpp2regex.h2"
template <typename Func> auto on_return<Func>::operator=(Func const& f) -> on_return& {
func = f;
return *this;
#line 138 "cpp2regex.h2"
}
#line 140 "cpp2regex.h2"
template <typename Func> on_return<Func>::~on_return() noexcept{
cpp2::move(*this).func();
}
#line 147 "cpp2regex.h2"
template<typename Func> [[nodiscard]] auto make_on_return(Func const& func) -> decltype(auto) { return on_return<Func>(func); }
#line 161 "cpp2regex.h2"
template <typename CharT, CharT C> [[nodiscard]] auto single_class_entry<CharT,C>::includes(cpp2::impl::in<CharT> c) -> decltype(auto) { return c == C; }
#line 162 "cpp2regex.h2"
template <typename CharT, CharT C> [[nodiscard]] auto single_class_entry<CharT,C>::to_string() -> decltype(auto) { return bstring<CharT>(1, C); }
#line 170 "cpp2regex.h2"
template <typename CharT, CharT Start, CharT End> [[nodiscard]] auto range_class_entry<CharT,Start,End>::includes(cpp2::impl::in<CharT> c) -> decltype(auto) { return [_0 = Start, _1 = c, _2 = End]{ return cpp2::impl::cmp_less_eq(_0,_1) && cpp2::impl::cmp_less_eq(_1,_2); }(); }
#line 171 "cpp2regex.h2"
template <typename CharT, CharT Start, CharT End> [[nodiscard]] auto range_class_entry<CharT,Start,End>::to_string() -> decltype(auto) { return "" + cpp2::to_string(Start) + "-" + cpp2::to_string(End) + ""; }
#line 179 "cpp2regex.h2"
template <typename CharT, typename ...List> [[nodiscard]] auto combined_class_entry<CharT,List...>::includes(cpp2::impl::in<CharT> c) -> decltype(auto) { return (false || ... || List::includes(c)); }
#line 180 "cpp2regex.h2"
template <typename CharT, typename ...List> [[nodiscard]] auto combined_class_entry<CharT,List...>::to_string() -> decltype(auto) { return (bstring<CharT>() + ... + List::to_string()); }
#line 188 "cpp2regex.h2"
template <typename CharT, CharT ...List> [[nodiscard]] auto list_class_entry<CharT,List...>::includes(cpp2::impl::in<CharT> c) -> decltype(auto) { return (false || ... || (List == c)); }
#line 189 "cpp2regex.h2"
template <typename CharT, CharT ...List> [[nodiscard]] auto list_class_entry<CharT,List...>::to_string() -> decltype(auto) { return (bstring<CharT>() + ... + List); }
#line 197 "cpp2regex.h2"
template <typename CharT, string_util::fixed_string Name, typename Inner> [[nodiscard]] auto named_class_entry<CharT,Name,Inner>::includes(cpp2::impl::in<CharT> c) -> decltype(auto) { return Inner::includes(c); }
#line 198 "cpp2regex.h2"
template <typename CharT, string_util::fixed_string Name, typename Inner> [[nodiscard]] auto named_class_entry<CharT,Name,Inner>::to_string() -> decltype(auto) { return "[:" + cpp2::to_string(Name.data()) + ":]"; }
#line 205 "cpp2regex.h2"
template <typename CharT, typename Inner> [[nodiscard]] auto negated_class_entry<CharT,Inner>::includes(cpp2::impl::in<CharT> c) -> decltype(auto) { return !(Inner::includes(c)); }
#line 213 "cpp2regex.h2"
template <typename CharT, string_util::fixed_string Name, typename Inner> [[nodiscard]] auto shorthand_class_entry<CharT,Name,Inner>::includes(cpp2::impl::in<CharT> c) -> decltype(auto) { return Inner::includes(c); }
#line 214 "cpp2regex.h2"
template <typename CharT, string_util::fixed_string Name, typename Inner> [[nodiscard]] auto shorthand_class_entry<CharT,Name,Inner>::to_string() -> decltype(auto) { return Name.str(); }
#line 261 "cpp2regex.h2"
template <typename CharT> [[nodiscard]] auto alternative_token_matcher<CharT>::match(auto const& cur, auto& ctx, auto const& end_func, auto const& tail, auto const& ...functions) -> auto{
return match_first(cur, ctx, end_func, tail, functions...);
}
#line 265 "cpp2regex.h2"
template <typename CharT> template<typename ...Other> [[nodiscard]] auto alternative_token_matcher<CharT>::match_first(auto const& cur, auto& ctx, auto const& end_func, auto const& tail, auto const& cur_func, auto const& cur_reset, Other const& ...other) -> auto
{
auto inner_call {[_0 = (tail), _1 = (end_func)](auto const& tail_cur, auto& tail_ctx) -> auto{
return _0(tail_cur, tail_ctx, _1);
}};
auto r {cur_func(cur, ctx, cpp2::move(inner_call))};
if (r.matched) {
return r;
}else {
cur_reset(ctx);
if constexpr (0 != sizeof...(Other)) {
return match_first(cur, ctx, end_func, tail, other...);
}else {
return ctx.fail();
}
}
}
#line 288 "cpp2regex.h2"
template<typename CharT, bool single_line> [[nodiscard]] auto any_token_matcher(auto& cur, auto& ctx) -> bool
{
if ( cur != ctx.end // any char except the end
&& (single_line || *cpp2::impl::assert_not_null(cur) != '\n')) // do not match new lines in multi line mode
{
cur += 1;
return true;
}
// Else
return false;
}
#line 339 "cpp2regex.h2"
template <typename CharT, bool negate, bool case_insensitive, typename ...List> [[nodiscard]] auto class_token_matcher<CharT,negate,case_insensitive,List...>::match(auto& cur, auto& ctx) -> bool
{
if constexpr (case_insensitive)
{
if ( cur != ctx.end
&& negate != (
match_any<List...>(string_util::safe_tolower(*cpp2::impl::assert_not_null(cur)))
|| match_any<List...>(string_util::safe_toupper(*cpp2::impl::assert_not_null(cur)))))
{
cur += 1;
return true;
}
else {
return false;
}
}
else
{
if (cur != ctx.end && negate != match_any<List...>(*cpp2::impl::assert_not_null(cur))) {
cur += 1;
return true;
}
else {
return false;
}
}
}
#line 368 "cpp2regex.h2"
template <typename CharT, bool negate, bool case_insensitive, typename ...List> template<typename First, typename ...Other> [[nodiscard]] auto class_token_matcher<CharT,negate,case_insensitive,List...>::match_any(cpp2::impl::in<CharT> c) -> bool
{
bool r {First::includes(c)};
if (!(r)) {
if constexpr (0 != sizeof...(Other)) {
r = match_any<Other...>(c);
}
}
return r;
}
#line 417 "cpp2regex.h2"
template<typename CharT, int group, bool case_insensitive> [[nodiscard]] auto group_ref_token_matcher(auto& cur, auto& ctx) -> bool
{
auto g {ctx.get_group(group)};
auto group_pos {cpp2::move(g).start};
for( ;
group_pos != g.end
&& cur != ctx.end;
(++group_pos, ++cur) )
{
if constexpr (case_insensitive) {
if (string_util::safe_tolower(*cpp2::impl::assert_not_null(group_pos)) != string_util::safe_tolower(*cpp2::impl::assert_not_null(cur))) {
return false;
}
}
else {
if (*cpp2::impl::assert_not_null(group_pos) != *cpp2::impl::assert_not_null(cur)) {
return false;
}
}
}
if (cpp2::move(group_pos) == cpp2::move(g).end) {
return true;
}
else {
return false;
}
}
#line 450 "cpp2regex.h2"
template<typename CharT, bool match_new_line, bool match_new_line_before_end> [[nodiscard]] auto line_end_token_matcher(auto const& cur, auto& ctx) -> bool
{
if (cur == ctx.end || (match_new_line && *cpp2::impl::assert_not_null(cur) == '\n')) {
return true;
}
else {if (match_new_line_before_end && (*cpp2::impl::assert_not_null(cur) == '\n' && (cur + 1) == ctx.end)) {// Special case for new line at end.
return true;
}
else {
return false;
}}
}
#line 466 "cpp2regex.h2"
template<typename CharT, bool match_new_line> [[nodiscard]] auto line_start_token_matcher(auto const& cur, auto& ctx) -> bool
{
return cur == ctx.begin || // Start of string
(match_new_line && *cpp2::impl::assert_not_null((cur - 1)) == '\n'); // Start of new line
}
#line 477 "cpp2regex.h2"
template<typename CharT, bool positive> [[nodiscard]] auto lookahead_token_matcher(auto const& cur, auto& ctx, auto const& func) -> bool
{
auto r {func(cur, ctx, true_end_func())};
if (!(positive)) {
r.matched = !(r.matched);
}
return cpp2::move(r).matched;
}
#line 493 "cpp2regex.h2"
inline CPP2_CONSTEXPR int range_flags::not_greedy{ 1 };
inline CPP2_CONSTEXPR int range_flags::greedy{ 2 };
inline CPP2_CONSTEXPR int range_flags::possessive{ 3 };
#line 504 "cpp2regex.h2"
template <typename CharT, int min_count, int max_count, int kind> template<typename Iter> [[nodiscard]] auto range_token_matcher<CharT,min_count,max_count,kind>::match(Iter const& cur, auto& ctx, auto const& inner, auto const& reset_func, auto const& end_func, auto const& tail) -> auto
{
if (range_flags::possessive == kind) {
return match_possessive(cur, ctx, inner, end_func, tail);
}
else {if (range_flags::greedy == kind) {
return match_greedy(0, cur, ctx.end, ctx, inner, reset_func, end_func, tail);
}
else { // range_flags::not_greedy == kind
return match_not_greedy(cur, ctx, inner, end_func, tail);
}}
}
#line 517 "cpp2regex.h2"
template <typename CharT, int min_count, int max_count, int kind> [[nodiscard]] auto range_token_matcher<CharT,min_count,max_count,kind>::is_below_upper_bound(cpp2::impl::in<int> count) -> bool{
if (-1 == max_count) {return true; }
else {return cpp2::impl::cmp_less(count,max_count); }
}
#line 522 "cpp2regex.h2"
template <typename CharT, int min_count, int max_count, int kind> [[nodiscard]] auto range_token_matcher<CharT,min_count,max_count,kind>::is_below_lower_bound(cpp2::impl::in<int> count) -> bool{
if (-1 == min_count) {return false; }
else {return cpp2::impl::cmp_less(count,min_count); }
}
#line 527 "cpp2regex.h2"
template <typename CharT, int min_count, int max_count, int kind> [[nodiscard]] auto range_token_matcher<CharT,min_count,max_count,kind>::is_in_range(cpp2::impl::in<int> count) -> bool{
if (-1 != min_count && cpp2::impl::cmp_less(count,min_count)) {return false; }
if (-1 != max_count && cpp2::impl::cmp_greater(count,max_count)) {return false; }
return true;
}
#line 533 "cpp2regex.h2"
template <typename CharT, int min_count, int max_count, int kind> template<typename Iter> [[nodiscard]] auto range_token_matcher<CharT,min_count,max_count,kind>::match_min_count(Iter const& cur, auto& ctx, auto const& inner, auto const& end_func, int& count_r) -> auto
{ // TODO: count_r as out parameter introduces a performance loss.
auto res {ctx.pass(cur)};
auto count {0};
while( is_below_lower_bound(count) && res.matched ) {
res = inner(res.pos, ctx, end_func);
if (res.matched) {
count += 1;
}
}
count_r = cpp2::move(count);
return res;
}
#line 549 "cpp2regex.h2"
template <typename CharT, int min_count, int max_count, int kind> template<typename Iter> [[nodiscard]] auto range_token_matcher<CharT,min_count,max_count,kind>::match_greedy(cpp2::impl::in<int> count, Iter const& cur, Iter const& last_valid, auto& ctx, auto const& inner, auto const& reset_func, auto const& end_func, auto const& other) -> match_return<Iter>
{
auto inner_call {[_0 = (count + 1), _1 = (cur), _2 = (inner), _3 = (reset_func), _4 = (end_func), _5 = (other)](auto const& tail_cur, auto& tail_ctx) -> auto{
return match_greedy(_0, tail_cur, _1, tail_ctx, _2, _3, _4, _5);
}};
auto is_m_valid {true};
auto r {ctx.fail()};
if (is_below_upper_bound(count) && (is_below_lower_bound(count) || cur != last_valid)) {
is_m_valid = false; // Group ranges in M are invalidated through the call.
r = inner(cur, ctx, cpp2::move(inner_call));