forked from hsutter/cppfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpp2regex.h
4141 lines (3317 loc) · 166 KB
/
cpp2regex.h
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 30 "cpp2regex.h2"
namespace cpp2 {
namespace regex {
#line 47 "cpp2regex.h2"
class expression_flags;
#line 59 "cpp2regex.h2"
template<typename Iter> class match_group;
#line 69 "cpp2regex.h2"
template<typename Iter> class match_return;
#line 77 "cpp2regex.h2"
template<typename CharT, typename Iter, int max_groups> class match_context;
#line 138 "cpp2regex.h2"
class true_end_func;
#line 146 "cpp2regex.h2"
class no_reset;
#line 153 "cpp2regex.h2"
template<typename Func> class on_return;
#line 180 "cpp2regex.h2"
template<typename CharT, CharT C> class single_class_entry;
#line 189 "cpp2regex.h2"
template<typename CharT, CharT Start, CharT End> class range_class_entry;
#line 198 "cpp2regex.h2"
template<typename CharT, typename ...List> class combined_class_entry;
#line 207 "cpp2regex.h2"
template<typename CharT, CharT ...List> class list_class_entry;
#line 216 "cpp2regex.h2"
template<typename CharT, string_util::fixed_string Name, typename Inner> class named_class_entry;
#line 223 "cpp2regex.h2"
template<typename CharT, typename Inner> class negated_class_entry;
#line 232 "cpp2regex.h2"
template<typename CharT, string_util::fixed_string Name, typename Inner> class shorthand_class_entry;
#line 285 "cpp2regex.h2"
class regex_token;
#line 311 "cpp2regex.h2"
class regex_token_check;
#line 330 "cpp2regex.h2"
class regex_token_code;
#line 349 "cpp2regex.h2"
class regex_token_empty;
#line 365 "cpp2regex.h2"
class regex_token_list;
#line 407 "cpp2regex.h2"
class parse_context_group_state;
#line 468 "cpp2regex.h2"
class parse_context_branch_reset_state;
#line 511 "cpp2regex.h2"
class parse_context;
#line 909 "cpp2regex.h2"
class generation_function_context;
#line 927 "cpp2regex.h2"
class generation_context;
#line 1126 "cpp2regex.h2"
class alternative_token;
#line 1141 "cpp2regex.h2"
class alternative_token_gen;
#line 1191 "cpp2regex.h2"
template<typename CharT> class alternative_token_matcher;
#line 1220 "cpp2regex.h2"
class any_token;
#line 1251 "cpp2regex.h2"
class char_token;
#line 1388 "cpp2regex.h2"
class class_token;
#line 1545 "cpp2regex.h2"
template<typename CharT, bool negate, bool case_insensitive, typename ...List> class class_token_matcher;
#line 1661 "cpp2regex.h2"
class group_ref_token;
#line 1823 "cpp2regex.h2"
class group_token;
#line 2129 "cpp2regex.h2"
class lookahead_token;
#line 2235 "cpp2regex.h2"
class range_flags;
#line 2244 "cpp2regex.h2"
class range_token;
#line 2390 "cpp2regex.h2"
template<typename CharT, int min_count, int max_count, int kind> class range_token_matcher;
#line 2527 "cpp2regex.h2"
class special_range_token;
#line 2618 "cpp2regex.h2"
template<typename CharT, typename matcher_wrapper> class regular_expression;
#line 2710 "cpp2regex.h2"
template<typename Error_out> class regex_generator;
#line 2784 "cpp2regex.h2"
}
}
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "cpp2regex.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.
//===========================================================================
// 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;
using error_func = std::function<void(std::string)>;
#line 30 "cpp2regex.h2"
namespace cpp2 {
namespace regex {
template <typename CharT> using bview = std::basic_string_view<CharT>;
template<typename CharT> using bstring = std::basic_string<CharT>;
#line 47 "cpp2regex.h2"
class expression_flags
{
private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in<cpp2::i64> _val);
private: constexpr auto operator=(cpp2::impl::in<cpp2::i64> _val) -> expression_flags& ;
public: constexpr auto operator|=(expression_flags const& that) & -> void;
public: constexpr auto operator&=(expression_flags const& that) & -> void;
public: constexpr auto operator^=(expression_flags const& that) & -> void;
public: [[nodiscard]] constexpr auto operator|(expression_flags const& that) const& -> expression_flags;
public: [[nodiscard]] constexpr auto operator&(expression_flags const& that) const& -> expression_flags;
public: [[nodiscard]] constexpr auto operator^(expression_flags const& that) const& -> expression_flags;
public: [[nodiscard]] constexpr auto has(expression_flags const& that) const& -> bool;
public: constexpr auto set(expression_flags const& that) & -> void;
public: constexpr auto clear(expression_flags const& that) & -> void;
public: static const expression_flags case_insensitive;
public: static const expression_flags multiple_lines;
public: static const expression_flags single_line;
public: static const expression_flags no_group_captures;
public: static const expression_flags perl_code_syntax;
public: static const expression_flags perl_code_syntax_in_classes;
public: static const expression_flags none;
public: [[nodiscard]] constexpr auto get_raw_value() const& -> cpp2::u8;
public: constexpr explicit expression_flags();
public: constexpr expression_flags(expression_flags const& that);
public: constexpr auto operator=(expression_flags const& that) -> expression_flags& ;
public: constexpr expression_flags(expression_flags&& that) noexcept;
public: constexpr auto operator=(expression_flags&& that) noexcept -> expression_flags& ;
public: [[nodiscard]] auto operator<=>(expression_flags const& that) const& -> std::strong_ordering = default;
public: [[nodiscard]] auto to_string() const& -> std::string;
#line 55 "cpp2regex.h2"
};
#line 59 "cpp2regex.h2"
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 65 "cpp2regex.h2"
};
#line 69 "cpp2regex.h2"
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 73 "cpp2regex.h2"
};
#line 77 "cpp2regex.h2"
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: explicit match_context(Iter const& begin_, Iter const& end_);
#line 89 "cpp2regex.h2"
public: match_context(match_context const& that);
#line 89 "cpp2regex.h2"
public: auto operator=(match_context const& that) -> match_context& ;
#line 89 "cpp2regex.h2"
public: match_context(match_context&& that) noexcept;
#line 89 "cpp2regex.h2"
public: auto operator=(match_context&& that) noexcept -> match_context& ;
#line 93 "cpp2regex.h2"
public: [[nodiscard]] auto get_group(auto const& group) const& -> auto;
public: [[nodiscard]] auto get_group_end(auto const& group) const& -> int;
#line 101 "cpp2regex.h2"
public: [[nodiscard]] auto get_group_start(auto const& group) const& -> int;
#line 107 "cpp2regex.h2"
public: [[nodiscard]] auto get_group_string(auto const& group) const& -> std::string;
#line 114 "cpp2regex.h2"
public: auto set_group_end(auto const& group, auto const& pos) & -> void;
#line 119 "cpp2regex.h2"
public: auto set_group_invalid(auto const& group) & -> void;
#line 123 "cpp2regex.h2"
public: auto set_group_start(auto const& group, auto const& pos) & -> void;
#line 127 "cpp2regex.h2"
public: [[nodiscard]] auto size() const& -> auto;
#line 131 "cpp2regex.h2"
public: [[nodiscard]] auto fail() const& -> auto;
public: [[nodiscard]] auto pass(cpp2::impl::in<Iter> cur) const& -> auto;
};
#line 138 "cpp2regex.h2"
class true_end_func
{
public: [[nodiscard]] auto operator()(auto const& cur, auto& ctx) const& -> auto;
};
#line 146 "cpp2regex.h2"
class no_reset
{
public: auto operator()([[maybe_unused]] auto& unnamed_param_2) const& -> void;
};
#line 153 "cpp2regex.h2"
template<typename Func> class on_return
{
private: Func func;
public: explicit on_return(Func const& f);
#line 157 "cpp2regex.h2"
public: auto operator=(Func const& f) -> on_return& ;
#line 161 "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 164 "cpp2regex.h2"
};
#line 168 "cpp2regex.h2"
template<typename Func> [[nodiscard]] auto make_on_return(Func const& func) -> auto;
#line 180 "cpp2regex.h2"
template<typename CharT, CharT C> class single_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> auto;
public: [[nodiscard]] static auto to_string() -> 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 184 "cpp2regex.h2"
};
#line 189 "cpp2regex.h2"
template<typename CharT, CharT Start, CharT End> class range_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> auto;
public: [[nodiscard]] static auto to_string() -> 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 193 "cpp2regex.h2"
};
#line 198 "cpp2regex.h2"
template<typename CharT, typename ...List> class combined_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> auto;
public: [[nodiscard]] static auto to_string() -> 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 202 "cpp2regex.h2"
};
#line 207 "cpp2regex.h2"
template<typename CharT, CharT ...List> class list_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> auto;
public: [[nodiscard]] static auto to_string() -> 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 211 "cpp2regex.h2"
};
#line 216 "cpp2regex.h2"
template<typename CharT, string_util::fixed_string Name, typename Inner> class named_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> auto;
public: [[nodiscard]] static auto to_string() -> 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 220 "cpp2regex.h2"
};
#line 223 "cpp2regex.h2"
template<typename CharT, typename Inner> class negated_class_entry
: public Inner {
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> 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 227 "cpp2regex.h2"
};
#line 232 "cpp2regex.h2"
template<typename CharT, string_util::fixed_string Name, typename Inner> class shorthand_class_entry
{
public: [[nodiscard]] static auto includes(cpp2::impl::in<CharT> c) -> auto;
public: [[nodiscard]] static auto to_string() -> 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 236 "cpp2regex.h2"
};
#line 241 "cpp2regex.h2"
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'>>;
#line 247 "cpp2regex.h2"
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>>>;
#line 263 "cpp2regex.h2"
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 285 "cpp2regex.h2"
class regex_token
{
public: std::string string_rep;
public: explicit regex_token(cpp2::impl::in<std::string> str);
#line 293 "cpp2regex.h2"
public: explicit regex_token();
#line 298 "cpp2regex.h2"
public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0;
public: virtual auto add_groups([[maybe_unused]] std::set<int>& unnamed_param_2) const -> void;
public: [[nodiscard]] auto to_string() const& -> std::string;
public: auto set_string(cpp2::impl::in<std::string> s) & -> void;
public: virtual ~regex_token() noexcept;
public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token const&) -> void = delete;
#line 303 "cpp2regex.h2"
};
using token_ptr = std::shared_ptr<regex_token>;
using token_vec = std::vector<token_ptr>;
#line 309 "cpp2regex.h2"
// Adds a check in code generation.
//
class regex_token_check
: public regex_token {
#line 315 "cpp2regex.h2"
private: std::string check;
public: explicit regex_token_check(cpp2::impl::in<std::string> str, cpp2::impl::in<std::string> check_);
#line 322 "cpp2regex.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
public: virtual ~regex_token_check() noexcept;
public: regex_token_check(regex_token_check const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_check const&) -> void = delete;
#line 325 "cpp2regex.h2"
};
#line 328 "cpp2regex.h2"
// Adds code in code generation.
//
class regex_token_code
: public regex_token {
#line 334 "cpp2regex.h2"
private: std::string code;
public: explicit regex_token_code(cpp2::impl::in<std::string> str, cpp2::impl::in<std::string> code_);
#line 341 "cpp2regex.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
public: virtual ~regex_token_code() noexcept;
public: regex_token_code(regex_token_code const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_code const&) -> void = delete;
#line 344 "cpp2regex.h2"
};
#line 347 "cpp2regex.h2"
// Token that does not influence the matching. E.g. comment.
//
class regex_token_empty
: public regex_token {
#line 353 "cpp2regex.h2"
public: explicit regex_token_empty(cpp2::impl::in<std::string> str);
#line 357 "cpp2regex.h2"
public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override;
public: virtual ~regex_token_empty() noexcept;
public: regex_token_empty(regex_token_empty const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_empty const&) -> void = delete;
#line 360 "cpp2regex.h2"
};
#line 363 "cpp2regex.h2"
// Represents a list of regex tokens as one token.
//
class regex_token_list
: public regex_token {
#line 369 "cpp2regex.h2"
public: token_vec tokens;
public: explicit regex_token_list(cpp2::impl::in<token_vec> t);
#line 376 "cpp2regex.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
#line 382 "cpp2regex.h2"
public: auto add_groups(std::set<int>& groups) const -> void override;
#line 388 "cpp2regex.h2"
public: [[nodiscard]] static auto gen_string(cpp2::impl::in<token_vec> vec) -> std::string;
public: virtual ~regex_token_list() noexcept;
public: regex_token_list(regex_token_list const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_list const&) -> void = delete;
#line 395 "cpp2regex.h2"
};
#line 398 "cpp2regex.h2"
//-----------------------------------------------------------------------
//
// Parse and generation context.
//
//-----------------------------------------------------------------------
//
// State of the current capturing group. See '(<pattern>)'
//
class parse_context_group_state
{
public: token_vec cur_match_list {}; // Current list of matchers.
public: token_vec alternate_match_lists {}; // List of alternate matcher lists. E.g. ab|cd|xy.
public: expression_flags modifiers {}; // Current modifiers for the group/regular expression.
// Start a new alternative.
public: auto next_alternative() & -> void;
#line 421 "cpp2regex.h2"
// Swap this state with the other one.
public: auto swap(parse_context_group_state& t) & -> void;
#line 428 "cpp2regex.h2"
// Convert this state into a regex token.
public: [[nodiscard]] auto get_as_token() & -> token_ptr;
#line 440 "cpp2regex.h2"
// Add a token to the current matcher list.
public: auto add(cpp2::impl::in<token_ptr> token) & -> void;
#line 445 "cpp2regex.h2"
// True if current matcher list is empty.
public: [[nodiscard]] auto empty() const& -> bool;
#line 449 "cpp2regex.h2"
// Apply optimizations to the matcher list.
public: static auto post_process_list(token_vec& list) -> void;
public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_);
public: parse_context_group_state();
#line 463 "cpp2regex.h2"
};
#line 466 "cpp2regex.h2"
// State for the branch reset. Takes care of the group numbering. See '(|<pattern>)'.
//
class parse_context_branch_reset_state
{
public: bool is_active {false}; // If we have a branch reset group.
public: int cur_group {1}; // Next group identifier. 0 == global capture group.
public: int max_group {1}; // Maximum group identifier generated.
public: int from {1}; // Starting identifier on new alternative branch.
// Next group identifier.
public: [[nodiscard]] auto next() & -> int;
#line 484 "cpp2regex.h2"
// Set next group identifier.
public: auto set_next(cpp2::impl::in<int> g) & -> void;
#line 490 "cpp2regex.h2"
// Start a new alternative branch.
public: auto next_alternative() & -> void;
#line 497 "cpp2regex.h2"
// Initialize for a branch reset group.
public: auto set_active_reset(cpp2::impl::in<int> restart) & -> void;
public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_);
public: parse_context_branch_reset_state();
#line 504 "cpp2regex.h2"
};
#line 507 "cpp2regex.h2"
// Context during parsing of the regular expressions.
//
// Keeps track of the distributed group identifiers, current parsed group and branch resets.
//
class parse_context
{
private: std::string_view regex; // Regular expression string.
private: size_t pos {0}; // Current parsing position.
private: token_ptr root; // Token representing the regular expression.
private: parse_context_group_state cur_group_state {};
private: parse_context_branch_reset_state cur_branch_reset_state {};
#line 521 "cpp2regex.h2"
public: std::map<std::string,int> named_groups {};
private: error_func error_out; // TODO: Declaring std::function<void(std::string)> fails for cpp2.
private: bool has_error {false};
public: explicit parse_context(cpp2::impl::in<std::string_view> r, auto const& e);
#line 532 "cpp2regex.h2"
// State management functions
//
// Returned group state needs to be stored and provided in `end_group`.
public: [[nodiscard]] auto start_group() & -> parse_context_group_state;
#line 545 "cpp2regex.h2"
// `old_state` argument needs to be from start group.
public: [[nodiscard]] auto end_group(cpp2::impl::in<parse_context_group_state> old_state) & -> token_ptr;
#line 553 "cpp2regex.h2"
public: [[nodiscard]] auto get_modifiers() const& -> expression_flags;
#line 557 "cpp2regex.h2"
public: auto set_modifiers(cpp2::impl::in<expression_flags> mod) & -> void;
#line 561 "cpp2regex.h2"
// Branch reset management functions
//
public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state;
#line 573 "cpp2regex.h2"
public: auto branch_reset_restore_state(cpp2::impl::in<parse_context_branch_reset_state> old_state) & -> void;
#line 580 "cpp2regex.h2"
public: auto next_alternative() & -> void;
#line 586 "cpp2regex.h2"
// Regex token management
//
public: auto add_token(cpp2::impl::in<token_ptr> token) & -> void;
#line 592 "cpp2regex.h2"
public: [[nodiscard]] auto has_token() const& -> bool;
#line 596 "cpp2regex.h2"
public: [[nodiscard]] auto pop_token() & -> token_ptr;
#line 607 "cpp2regex.h2"
public: [[nodiscard]] auto get_as_token() & -> token_ptr;
#line 611 "cpp2regex.h2"
// Group management
//
public: [[nodiscard]] auto get_cur_group() const& -> int;
#line 617 "cpp2regex.h2"
public: [[nodiscard]] auto next_group() & -> int;
#line 621 "cpp2regex.h2"
public: auto set_named_group(cpp2::impl::in<std::string> name, cpp2::impl::in<int> id) & -> void;
#line 628 "cpp2regex.h2"
public: [[nodiscard]] auto get_named_group(cpp2::impl::in<std::string> name) const& -> int;
#line 639 "cpp2regex.h2"
// Position management functions
//
public: [[nodiscard]] auto current() const& -> char;
// Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers.
private: [[nodiscard]] auto get_next_position(cpp2::impl::in<bool> in_class, cpp2::impl::in<bool> no_skip) const& -> size_t;
#line 683 "cpp2regex.h2"
// Return true if next token is available.
private: [[nodiscard]] auto next_impl(cpp2::impl::in<bool> in_class, cpp2::impl::in<bool> no_skip) & -> bool;
#line 695 "cpp2regex.h2"
public: [[nodiscard]] auto next() & -> auto;
public: [[nodiscard]] auto next_in_class() & -> auto;
public: [[nodiscard]] auto next_no_skip() & -> auto;
public: [[nodiscard]] auto next_n(cpp2::impl::in<int> n) & -> bool;
#line 708 "cpp2regex.h2"
public: [[nodiscard]] auto has_next() const& -> bool;
private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in<std::string> e, cpp2::impl::out<std::string> r, cpp2::impl::in<bool> any) & -> bool;
#line 731 "cpp2regex.h2"
public: [[nodiscard]] auto grab_until(cpp2::impl::in<std::string> e, cpp2::impl::out<std::string> r) & -> auto;
public: [[nodiscard]] auto grab_until(cpp2::impl::in<char> e, cpp2::impl::out<std::string> r) & -> auto;
public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in<std::string> e, cpp2::impl::out<std::string> r) & -> auto;
public: [[nodiscard]] auto grab_n(cpp2::impl::in<int> n, cpp2::impl::out<std::string> r) & -> bool;
#line 748 "cpp2regex.h2"
public: [[nodiscard]] auto grab_number() & -> std::string;
#line 769 "cpp2regex.h2"
private: [[nodiscard]] auto peek_impl(cpp2::impl::in<bool> in_class) const& -> char;
#line 779 "cpp2regex.h2"
public: [[nodiscard]] auto peek() const& -> auto;
public: [[nodiscard]] auto peek_in_class() const& -> auto;
#line 783 "cpp2regex.h2"
// Parsing functions
//
public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in<std::string> change_str, expression_flags& parser_modifiers) & -> bool;
#line 839 "cpp2regex.h2"
public: [[nodiscard]] auto parse_until(cpp2::impl::in<char> term) & -> bool;
#line 877 "cpp2regex.h2"
public: [[nodiscard]] auto parse(cpp2::impl::in<std::string> modifiers) & -> bool;
#line 892 "cpp2regex.h2"
// Misc functions
public: [[nodiscard]] auto get_pos() const& -> auto;
public: [[nodiscard]] auto get_range(cpp2::impl::in<size_t> start, cpp2::impl::in<size_t> end) const& -> auto;
public: [[nodiscard]] auto valid() const& -> bool;
public: [[nodiscard]] auto error(cpp2::impl::in<std::string> err) & -> token_ptr;
public: parse_context(parse_context const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(parse_context const&) -> void = delete;
#line 903 "cpp2regex.h2"
};
#line 906 "cpp2regex.h2"
// Context for one function generation. Generation of functions can be interleaved,
// therefore we buffer the code for one function here.
//
class generation_function_context {
public: std::string code {""};
public: std::string tabs {""};
public: auto add_tabs(cpp2::impl::in<int> c) & -> void;
#line 920 "cpp2regex.h2"
public: auto remove_tabs(cpp2::impl::in<int> c) & -> void;
public: generation_function_context(auto const& code_, auto const& tabs_);
public: generation_function_context();
#line 923 "cpp2regex.h2"
};
#line 926 "cpp2regex.h2"
// Context for generating the state machine.
class generation_context
{
private: std::vector<generation_function_context> gen_stack {1}; // Element 0 contains all the code.
private: int matcher_func {0};
private: int reset_func {0};
private: int temp_name {0};
private: std::string entry_func {""};
// Generation helpers
//
public: [[nodiscard]] auto match_parameters() const& -> std::string;
// Code generation.
// Add code line.
public: auto add(cpp2::impl::in<std::string> s) & -> void;
#line 948 "cpp2regex.h2"
// Add check for token. The check needs to be a function call that returns a boolean.
public: auto add_check(cpp2::impl::in<std::string> check) & -> void;
#line 954 "cpp2regex.h2"
// Add a stateful check. The check needs to return a `match_return`.
public: auto add_statefull(cpp2::impl::in<std::string> next_func, cpp2::impl::in<std::string> check) & -> void;
#line 963 "cpp2regex.h2"
protected: auto start_func_named(cpp2::impl::in<std::string> name) & -> void;
#line 974 "cpp2regex.h2"
protected: [[nodiscard]] auto start_func() & -> std::string;
#line 981 "cpp2regex.h2"
protected: auto end_func_statefull(cpp2::impl::in<std::string> s) & -> void;
#line 1000 "cpp2regex.h2"
// Generate the function for a token.
public: [[nodiscard]] auto generate_func(cpp2::impl::in<token_ptr> token) & -> std::string;
#line 1010 "cpp2regex.h2"
// Generate the reset for a list of group identifiers.
public: [[nodiscard]] auto generate_reset(cpp2::impl::in<std::set<int>> groups) & -> std::string;
#line 1033 "cpp2regex.h2"
// Name generation
//
protected: [[nodiscard]] auto gen_func_name() & -> std::string;
#line 1041 "cpp2regex.h2"
public: [[nodiscard]] auto next_func_name() & -> std::string;
#line 1045 "cpp2regex.h2"
protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string;
#line 1051 "cpp2regex.h2"
public: [[nodiscard]] auto gen_temp() & -> std::string;
#line 1057 "cpp2regex.h2"
// Context management
//
public: [[nodiscard]] auto new_context() & -> generation_function_context*;
#line 1067 "cpp2regex.h2"
public: auto finish_context() & -> void;
#line 1075 "cpp2regex.h2"
// Misc functions
//
private: [[nodiscard]] auto get_current() & -> generation_function_context*;
#line 1081 "cpp2regex.h2"
private: [[nodiscard]] auto get_base() & -> generation_function_context*;
#line 1085 "cpp2regex.h2"
public: [[nodiscard]] auto get_entry_func() const& -> std::string;
#line 1089 "cpp2regex.h2"
public: [[nodiscard]] auto create_named_group_lookup(cpp2::impl::in<std::map<std::string,int>> named_groups) const& -> std::string;
#line 1113 "cpp2regex.h2"
// Run the generation for the token.
public: [[nodiscard]] auto run(cpp2::impl::in<token_ptr> token) & -> std::string;
public: generation_context() = default;
public: generation_context(generation_context const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(generation_context const&) -> void = delete;
#line 1119 "cpp2regex.h2"
};
#line 1122 "cpp2regex.h2"
// Regex syntax: | Example: ab|ba
//
// Non greedy implementation. First alternative that matches is chosen.
//
class alternative_token
: public regex_token_empty {
// No code gen here. alternative_token_gen is created in the parse_context
public: explicit alternative_token();
public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr;
public: virtual ~alternative_token() noexcept;
public: alternative_token(alternative_token const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(alternative_token const&) -> void = delete;
#line 1139 "cpp2regex.h2"
};
class alternative_token_gen
: public regex_token {
#line 1145 "cpp2regex.h2"
private: token_vec alternatives;
public: explicit alternative_token_gen(cpp2::impl::in<token_vec> a);
#line 1152 "cpp2regex.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
#line 1169 "cpp2regex.h2"
public: auto add_groups(std::set<int>& groups) const -> void override;
#line 1176 "cpp2regex.h2"
public: [[nodiscard]] static auto gen_string(cpp2::impl::in<token_vec> a) -> std::string;
public: virtual ~alternative_token_gen() noexcept;
public: alternative_token_gen(alternative_token_gen const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(alternative_token_gen const&) -> void = delete;
#line 1188 "cpp2regex.h2"
};
#line 1191 "cpp2regex.h2"
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 1197 "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 1215 "cpp2regex.h2"
};
#line 1218 "cpp2regex.h2"
// Regex syntax: .
//
class any_token
: public regex_token_check {
#line 1224 "cpp2regex.h2"
public: explicit any_token(cpp2::impl::in<bool> single_line);
#line 1228 "cpp2regex.h2"
public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr;
public: virtual ~any_token() noexcept;
public: any_token(any_token const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(any_token const&) -> void = delete;
#line 1233 "cpp2regex.h2"
};
#line 1236 "cpp2regex.h2"
template<typename CharT, bool single_line> [[nodiscard]] auto any_token_matcher(auto& cur, auto& ctx) -> bool;
#line 1249 "cpp2regex.h2"
// Regex syntax: a
//
class char_token
: public regex_token {
#line 1255 "cpp2regex.h2"
private: std::string token;
private: bool ignore_case;
public: explicit char_token(cpp2::impl::in<char> t, cpp2::impl::in<bool> ignore_case_);
#line 1264 "cpp2regex.h2"
public: [[nodiscard]] static auto parse(parse_context& ctx) -> token_ptr;
#line 1268 "cpp2regex.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
#line 1291 "cpp2regex.h2"
public: auto gen_case_insensitive(cpp2::impl::in<std::string> lower, cpp2::impl::in<std::string> upper, generation_context& ctx) const& -> void;
#line 1312 "cpp2regex.h2"
public: auto gen_case_sensitive(generation_context& ctx) const& -> void;
#line 1330 "cpp2regex.h2"