File: re.el

package info (click to toggle)
python-docutils 0.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 11,448 kB
  • sloc: python: 53,302; lisp: 14,475; xml: 1,807; javascript: 1,032; makefile: 102; sh: 96
file content (889 lines) | stat: -rw-r--r-- 32,273 bytes parent folder | download | duplicates (5)
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
;; Tests for the regular expression builder  -*- lexical-binding: t -*-

(add-to-list 'load-path ".")
(load "init" nil t)
(init-rst-ert t)

(ert-deftest rst-re ()
  "Tests `rst-re'."
  (should (equal (rst-re "xy") "xy"))
  (should (equal (rst-re ?A) "A"))
  (should (equal (rst-re ?$) "\\$"))
  (should (equal (rst-re 'exm-tag) "\\.\\."))
  (should (equal (rst-re "xy" ?A ?$ 'exm-tag) "xyA\\$\\.\\."))
  (should (equal (rst-re '(:seq "xy" ?A ?$ exm-tag)) "xyA\\$\\.\\."))
  (should (equal (rst-re '(:shy "xy" ?A ?$ exm-tag)) "\\(?:xyA\\$\\.\\.\\)"))
  (should (equal (rst-re '(:grp "xy" ?A ?$ exm-tag)) "\\(xyA\\$\\.\\.\\)"))
  (should (equal (rst-re '(:alt "xy" ?A ?$ exm-tag))
		 "\\(?:xy\\|A\\|\\$\\|\\.\\.\\)"))
  (should (equal (rst-re '(:seq (:seq "xy" ?A ?$ exm-tag))) "xyA\\$\\.\\."))
  (should (equal (rst-re '(:grp (:alt "xy" ?A ?$ exm-tag)))
		 "\\(\\(?:xy\\|A\\|\\$\\|\\.\\.\\)\\)"))
  (should (equal (rst-re '(:alt (:grp "xy" ?A ?$ exm-tag)))
		 "\\(?:\\(xyA\\$\\.\\.\\)\\)"))
  (should (equal (rst-re '(:alt "xy" ?A) '(:grp ?$ exm-tag))
		 "\\(?:xy\\|A\\)\\(\\$\\.\\.\\)"))
  (should-error (rst-re '(:unknown "xy")))
  (should-error (rst-re [1]))
  )

(defun re-equal-modify-orig (orig loc refactored repls)
  (let ((case-fold-search nil))
    (while (string-match "\\[ \t]" orig)
      ;; Transpose horizontal whitespace
      (setq orig (replace-match "[\t ]" t nil orig)))
    (while (string-match "\\\\s \\*\\$" orig)
      ;; Replace symbolic whitespace
      (setq orig (replace-match "[\t ]*$" t nil orig)))
    (dolist (regex-repl repls)
      (if (string-match (car regex-repl) orig)
	  (setq orig (replace-match (cdr regex-repl) t t orig))
	(error "Replacement regex /%s/ didn't match in '%s' for location '%s'"
	       (car regex-repl) orig loc)))
    orig))
  

(defun re-equal (orig loc refactored &rest repls)
  "Compare regex ORIG at location LOC to REFACTORED.
REPLS starts with a list of cons cells telling where regex in car
is replaced by cdr in ORIG."
  (equal (re-equal-modify-orig orig loc refactored repls) refactored))

(defun re-equal-explain (orig loc refactored &rest repls)
  (setq orig (re-equal-modify-orig orig loc refactored repls))
  (ert--explain-not-equal orig refactored))

(put 're-equal 'ert-explainer 're-equal-explain)

(defun re-check-matches (orig loc refactored s pairs)
  "Check matches and return those pairs which didn't work"
  (let ((case-fold-search nil)
	failed)
    (dolist (pair pairs failed)
      (let ((orig-mtc (if (string-match orig s)
			  (match-string (car pair) s)))
	    (refa-mtc (if (string-match refactored s)
			  (match-string (cdr pair) s))))
	(if (not orig-mtc)
	    (error "Original regex '%s' didn't match string '%s' for location '%s'"
		   orig s loc)
	  (if (not refa-mtc)
	      (error "Refactored regex '%s' didn't match string '%s' for location '%s'"
		     refactored s loc)
	    (if (not (equal orig-mtc refa-mtc))
		(push pair failed))))))))

(defun re-equal-matches (orig loc refactored matches &rest repls)
  "Like `re-equal'. However, if MATCHES is non-nil it must be a
list with a string and cons cells each consisting of two numbers.
For each cons cell the string is matched with ORIG and REFACTORED
and the numbered matches are compared."
  (and (equal (re-equal-modify-orig orig loc refactored repls) refactored)
       (not (re-check-matches orig loc refactored
			      (car matches) (cdr matches)))))

(defun re-equal-matches-explain (orig loc refactored matches &rest repls)
  (if (not (equal (re-equal-modify-orig orig loc refactored repls) refactored))
      (apply 're-equal-explain orig loc refactored repls)
    (let (result)
      (dolist (failed (re-check-matches orig loc refactored
					(car matches) (cdr matches)) result)
	(push (list 'matchers-didnt-match (car failed) (cdr failed))
	      result)))))

(put 're-equal-matches 'ert-explainer 're-equal-matches-explain)

(ert-deftest rst-re-refactoring ()
  "Test the refactorings done based on rst_el_1_68."
  ;; Any comment or string "=== rst.el.~rst_el_1_68~:..." gives the line number
  ;; of the refactored code in the original file for the previous expression.
  (let* ((rst-bullets
	  '(?- ?* ?+))
	 ;; === rst.el.~rst_el_1_68~:451
	 (rst-re-bullets
	  (format "\\([%s][ \t]\\)[^ \t]" (regexp-quote (concat rst-bullets))))
	 ;; === rst.el.~rst_el_1_68~:1604
	 ;; More parameters
	 (c ?*)
	 (len 10)
	 (char ?+)
	 (adornment "$$$$")
	 (ado-re (regexp-quote adornment))
	 (fromchar ?.)
	 )
    (should (re-equal
	     "^\\.\\. "
	     "=== rst.el.~rst_el_1_68~:398"
	     (rst-re "^" 'exm-sta)
	     (cons " $" "[	 ]+") ;; Any whitespace may follow
	     ))
    (should (re-equal
	     "^[ \t]*\\S *\\w\\S *"
	     "=== rst.el.~rst_el_1_68~:567"
	     (rst-re 'lin-beg "\\S *\\w\\S *")
	     ))
    (should (re-equal
	     "::[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:591"
	     (rst-re 'dcl-tag 'lin-end)
	     ))
    (should (re-equal
	     "\\.\\.\\.[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:592"
	     (rst-re 'ell-tag 'lin-end)
	     ))
    (should (re-equal
	     ".[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:594"
	     (rst-re "." 'lin-end)
	     ))
    (should (re-equal
	     "^[ \t]+"
	     "=== rst.el.~rst_el_1_68~:605"
	     (rst-re 'hws-sta)
	     (cons "^^" "") ;; No need to anchor for looking-at
	     ))
    (should (re-equal
	     "^[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:744"
	     (rst-re 'lin-end)
	     (cons "^^" "") ;; No need to anchor for looking-at
	     ))
    (should (re-equal
	     "^[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:1517"
	     (rst-re 'lin-end)
	     (cons "^^" "") ;; No need to anchor for looking-at
	     ))
    (should (re-equal
	     "^[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:1545"
	     (rst-re 'lin-end)
	     (cons "^^" "") ;; No need to anchor for looking-at
	     ))
    (should (re-equal
	     "^[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:1548"
	     (rst-re 'lin-end)
	     (cons "^^" "") ;; No need to anchor for looking-at
	     ))
    (should (re-equal
	     "[0-9]+"
	     "=== rst.el.~rst_el_1_68~:1657"
	     (rst-re 'num-tag)
	     ))
    (should (re-equal
	     "[IVXLCDMivxlcdm]+"
	     "=== rst.el.~rst_el_1_68~:1661"
	     (rst-re 'rom-tag)
	     ))
    (should (re-equal
	     "[IVXLCDMivxlcdm]+"
	     "=== rst.el.~rst_el_1_68~:1677"
	     (rst-re 'rom-tag)
	     ))
    (should (re-equal
	     "[a-zA-Z]"
	     "=== rst.el.~rst_el_1_68~:1685"
	     (rst-re 'ltr-tag)
	     ))
    (should (re-equal
	     "[ \t\n]*\\'"
	     "=== rst.el.~rst_el_1_68~:1762"
	     (rst-re "[ \t\n]*\\'")
	     ))
    (should (re-equal
	     "\\S .*\\S "
	     "=== rst.el.~rst_el_1_68~:1767"
	     (rst-re "\\S .*\\S ")
	     ))
    (should (re-equal
	     "[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:2066"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:2366"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "^[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:2414"
	     (rst-re 'lin-end)
	     (cons "^^" "") ;; No need to anchor for looking-at
	     ))
    (should (re-equal
	     "[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:2610"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:2612"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "[ \t]*$"
	     "=== rst.el.~rst_el_1_68~:2645"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "[^ \t]\\|[ \t]*\\.\\.[^ \t]\\|.*::$"
	     "=== rst.el.~rst_el_1_68~:3177"
	     (rst-re '(:alt
		       "[^ \t]"
		       (:seq hws-tag exm-tag "[^ \t]")
		       (:seq ".*" dcl-tag lin-end)))
	     (cons "^" "\\(?:") (cons "$" "\\)") ;; Add outermost shy group
	     (cons "::\\$" "::[	 ]*$") ;; Allow trailing space after double
				       ;; colon
	     ))
    (should (re-equal
	     "\\s *$"
	     "=== rst.el.~rst_el_1_68~:3209"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "^\\s *$"
	     "=== rst.el.~rst_el_1_68~:3215"
	     (rst-re 'linemp-tag)
	     ))
    (should (re-equal
	     "\\s *$"
	     "=== rst.el.~rst_el_1_68~:3253"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "\\s *"
	     "=== rst.el.~rst_el_1_68~:3256"
	     (rst-re 'hws-tag)
	     (cons "\\\\s \\*" "[\t ]*") ;; Replace symbolic by real whitespace
	     ))
    (should (re-equal
	     "\\s *$"
	     "=== rst.el.~rst_el_1_68~:3261"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "\\s *"
	     "=== rst.el.~rst_el_1_68~:3268"
	     (rst-re 'hws-tag)
	     (cons "\\\\s \\*" "[\t ]*") ;; Replace symbolic by real whitespace
	     ))
    (should (re-equal
	     (regexp-quote adornment)
	     "=== rst.el.~rst_el_1_68~:3346"
	     (rst-re (regexp-quote adornment))
	     ))
    (should (re-equal
	     "\\s *$"
	     "=== rst.el.~rst_el_1_68~:3354"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "\\s *$"
	     "=== rst.el.~rst_el_1_68~:3358"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     "\\s *$"
	     "=== rst.el.~rst_el_1_68~:3374"
	     (rst-re 'lin-end)
	     ))
    (should (re-equal
	     (concat "\\(" ado-re "\\)\\s *$")
	     "=== rst.el.~rst_el_1_68~:3377"
	     (rst-re (list :grp
			   ado-re)
		     'lin-end)
	     ))
    (should (re-equal
	     (concat "\\(" ado-re "\\)\\s *$")
	     "=== rst.el.~rst_el_1_68~:3393"
	     (rst-re (list :grp
			   ado-re)
		     'lin-end)
	     ))
    (should (re-equal
	     (concat "^" (regexp-quote (string fromchar)) "+\\( *\\)$")
	     "=== rst.el.~rst_el_1_68~:3590"
	     (rst-re "^" fromchar "+\\( *\\)$")
	     ))
    (should (re-equal
	     "\f\\|>*[ \t]*$\\|>*[ \t]*[-+*] \\|>*[ \t]*[0-9#]+\\. "
	     "=== rst.el.~rst_el_1_68~:391"
	     (rst-re '(:alt
		       "\f"
		       lin-end
		       (:seq hws-tag itmany-sta-1)))
	     (cons "^" "\\(?:") (cons "$" "\\)") ;; Add outermost shy group
	     (cons (regexp-quote "[-+*] \\|>*[	 ]*[0-9#]+\\. ")
		   "\\(\\(?:\\(?:\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)\\.\\|(?\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\))\\)\\|[-*+\u2022\u2023\u2043]\\)\\)[	 ]+"
		   ) ;; Now matches all items
	     (cons ">\\*" "") ;; Remove ">" prefix
	     (cons ">\\*" "") ;; Remove another ">" prefix
	     (cons "\\[\t ]\\+" "\\(?:[\t ]+\\|$\\)") ;; Item tag needs no
						      ;; trailing whitespace
	     ))
    (should (re-equal
	     (format "[%s]+[ \t]*$" (char-to-string c))
	     "=== rst.el.~rst_el_1_68~:587"
	     (rst-re c "+" 'lin-end)
	     (cons "\\[\\*]" "\\*") ;; Use quoting instead of char class
	     ))
    (should (re-equal
	     (concat "^"
		     (regexp-quote (make-string len char))
		     "$")
	     "=== rst.el.~rst_el_1_68~:941"
	     (rst-re "^" char (format "\\{%d\\}" len) "$")
	     (cons "\\(\\\\\\+\\)\\{9\\}\\$"
		   "\\{10\\}$") ;; Use regex repeat instead of explicit repeat
	     ))
    (should (re-equal
	     (format "#.\\|[%s]"
		     (regexp-quote (concat rst-bullets)))
	     "=== rst.el.~rst_el_1_68~:1653"
	     (rst-re '(:alt
		       enmaut-tag
		       bul-tag))
	     (cons "^" "\\(?:") (cons "$" "\\)") ;; Add outermost shy group
	     (cons (regexp-quote "[-\\*\\+]")
		   "[-*+\u2022\u2023\u2043]") ;; Wrongly quoted characters in
					      ;; class and more bullets
	     (cons "#\\." "\\(?:#\\.\\|(?#)\\)") ;; Use all auto enumerators
	     ))
    (should (re-equal
	     "[a-zA-Z]+"
	     "=== rst.el.~rst_el_1_68~:1672"
	     (rst-re 'ltr-tag)
	     (cons "\\+$" "") ;; Wrong in source
	     ))
    (should (re-equal
	     rst-re-bullets
	     "=== rst.el.~rst_el_1_68~:1735"
	     (rst-re 'bul-sta)
	     (cons (regexp-quote "[-\\*\\+]")
		   "[-*+\u2022\u2023\u2043]") ;; Wrongly quoted characters in
					      ;; class and more bullets
	     (cons "\\[^ \t]" "") ;; Accept bullets without content
	     (cons "^\\\\(" "") (cons "\\\\)" "") ;; Remove superfluous group
	     (cons "$" "+") ;; Allow more whitespace
	     (cons "\\[\t ]\\+" "\\(?:[\t ]+\\|$\\)") ;; Item tag needs no
						      ;; trailing whitespace
	     ))
    (should (re-equal
	     "^\\.\\. contents[ \t]*::\\(.*\\)\n\\([ \t]+:\\w+:.*\n\\)*\\.\\."
	     "=== rst.el.~rst_el_1_68~:2056"
	     (rst-re "^" 'exm-sta "contents" 'dcl-tag ".*\n"
		     "\\(?:" 'hws-sta 'fld-tag ".*\n\\)*" 'exm-tag)
	     (cons " contents\\[\t ]\\*"
		   "[\t ]+contents") ;; Any whitespace before but no after
	     (cons "\\\\(\\.\\*\\\\)" ".*") ;; Remove superfluous group
	     (cons "\\\\(" "\\(?:") ;; Make group shy
	     (cons ":\\\\w\\+:" ":\\(?:[^:\n]\\|\\\\:\\)+:") ;; Use improved
							     ;; field tag
	     ))
    (should (re-equal
	     "[ \t]+[^ \t]"
	     "=== rst.el.~rst_el_1_68~:2065"
	     (rst-re 'hws-sta "\\S ")
	     (cons "\\[^ \t]" "\\S ") ;; Require non-whitespace instead
				      ;; of only non-horizontal whitespace
	     ))
    ))

(ert-deftest rst-re-refactoring-complicated ()
  "Try to test complicated refactorings done based on rst_el_1_68."
  :expected-result :failed ;; These have been reviewed logically and are ok
  (let* ((rst-bullets
	  '(?- ?* ?+))
	 ;; === rst.el.~rst_el_1_68~:451
	 (rst-re-enumerator "\\(?:[a-zA-Z]\\|[0-9IVXLCDMivxlcdm]+\\)")
	 ;; === rst.el.~rst_el_1_68~:1608
	 (rst-re-enumerations
	  (format "^[ \t]*\\(%s.\\|(?%s)\\)[ \t]"
		  rst-re-enumerator
		  rst-re-enumerator))
	 ;; === rst.el.~rst_el_1_68~:1610
	 (rst-re-items
	  (format "^[ \t]*\\([%s]\\|\\(#\\|%s\\)\\.\\|(?%s)\\)[ \t]"
		  (regexp-quote (concat rst-bullets))
		  rst-re-enumerator
		  rst-re-enumerator))
	 ;; === rst.el.~rst_el_1_68~:1616
	 ;; More parameters
	 (char ?+)
	 )
    (should (re-equal
	     rst-re-items
	     "=== rst.el.~rst_el_1_68~:2718"
	     (rst-re 'itmany-sta-1)
	     (cons "^^\\[\t ]\\*" "") ;; Wrongly anchored at the beginning of
				      ;; the line
	     (cons (regexp-quote "\\(#\\|\\(?:[a-zA-Z]\\|[0-9IVXLCDMivxlcdm]+\\)\\)")
		   "\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)"
		   ) ;; Replace counter for "\\."
	     (cons (regexp-quote "\\(?:[a-zA-Z]\\|[0-9IVXLCDMivxlcdm]+\\)")
		   "\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)"
		   ) ;; Replace counter for "(?)"
	     (cons "$" "+") ;; Allow more whitespace
	     (cons "^\\\\(" "\\(\\(?:") (cons "\\[\t ]\\+$" "\\)[\t ]+"
					      ) ;; Add superfluous shy group
	     (cons (regexp-quote "[-\\*\\+]\\|") "") ;; Remove wrongly quoted
						     ;; characters
	     (cons (regexp-quote "\\)\\)[\t ]+")
		   "\\|[-*+\u2022\u2023\u2043]\\)\\)[\t ]+"
		   ) ;; Re-add bullets
	     ))
    (should (re-equal
	     rst-re-items
	     "=== rst.el.~rst_el_1_68~:2724"
	     (rst-re 'itmany-beg-1)
	     ))
    (should (re-equal
	     rst-re-items
	     "=== rst.el.~rst_el_1_68~:1649"
	     (rst-re 'itmany-beg-1)
	     ))
    (should (re-equal
	     rst-re-enumerations
	     "=== rst.el.~rst_el_1_68~:1671"
	     (rst-re 'enmexp-beg)
	     ))
    (should (re-equal
	     rst-re-items
	     "=== rst.el.~rst_el_1_68~:1719"
	     (rst-re 'itmany-beg-1)
	     ))
    (should (re-equal
	     (concat
	      "\\(?:"
	      "\\(\\(?:[0-9a-zA-Z#]\\{1,3\\}[.):-]\\|[*+-]\\)[ \t]+\\)[^ \t\n]"
	      "\\|"
	      (format "\\(%s%s+[ \t]+\\)[^ \t\n]"
		      (regexp-quote (char-to-string char))
		      (regexp-quote (char-to-string char)))
	      "\\)")
	     "=== rst.el.~rst_el_1_68~:2430"
	     (rst-re
	      `(:grp
		(:alt
		 itmany-tag
		 (:seq ,(char-after) "\\{2,\\}"))
		hws-sta)
	      "\\S ")
	     (cons "^\\\\(\\?:" "") (cons "\\\\)$" "") ;; Remove superfluous
						       ;; shy group
	     (cons (regexp-quote "[0-9a-zA-Z#]\\{1,3\\}[.):-]\\|[*+-]")
		   "\\(\\(?:\\(?:\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)\\.\\|(?\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\))\\)\\|[-*+\u2022\u2023\u2043]\\)\\)"
		   ) ;; Replace wrong item tag by correct one
	     (cons (regexp-quote "\\+\\++")
		   "\\+\\{2,\\}") ;; Use regex repeat instead of explicit repeat
	     (cons "\\[^ \t\n]" "\\S ") ;; Use symbolic non-whitespace
	     (cons "\\[^ \t\n]" "\\S ") ;; Use symbolic non-whitespace again
	     (cons "\\\\S " "") ;; Factor out symbolic non-whitespace
	     ))
    ))

(ert-deftest rst-re-refactoring-font-lock ()
  "Test the refactorings in font-lock done based on rst_el_1_68."
  ;; Any comment or string "=== rst.el.~rst_el_1_68~:..." gives the line number
  ;; of the refactored code in the original file for the previous expression.
  (let* ((rst-use-char-classes t)
	 (rst-use-unicode t)
	 ;; horizontal white space
	 (re-hws "[\t ]")
	 ;; beginning of line with possible indentation
	 (re-bol (concat "^" re-hws "*"))
	 ;; Separates block lead-ins from their content
	 (re-blksep1 (concat "\\(" re-hws "+\\|$\\)"))
	 ;; explicit markup tag
	 (re-emt "\\.\\.")
	 ;; explicit markup start
	 (re-ems (concat re-emt re-hws "+"))
	 ;; inline markup prefix
	 (re-imp1 (concat "\\(^\\|" re-hws "\\|[-'\"([{<"
			  (if rst-use-unicode
			      "\u2018\u201c\u00ab\u2019"
			    "")
			  "/:]\\)"))
	 ;; inline markup suffix
	 (re-ims1 (concat "\\(" re-hws "\\|[]-'\")}>"
			  (if rst-use-unicode
			      "\u2019\u201d\u00bb"
			    "")
			  "/:.,;!?\\]\\|$\\)"))
	 ;; symbol character
	 (re-sym1 "\\(\\sw\\|\\s_\\)")
	 ;; inline markup content begin
	 (re-imbeg2 "\\(\\S \\|\\S \\([^")

	 ;; There seems to be a bug leading to error "Stack overflow in regexp
	 ;; matcher" when "|" or "\\*" are the characters searched for
	 (re-imendbegbeg
	  (if (< emacs-major-version 21)
	      "]"
	    "\\]\\|\\\\."))
	 ;; inline markup content end
	 (re-imendbeg (concat re-imendbegbeg "\\)\\{0,"
			   (format "%d" rst-max-inline-length)
			   "\\}[^\t "))
	 (re-imendend "\\\\]\\)")
	 ;; inline markup content without asterisk
	 (re-ima2 (concat re-imbeg2 "*" re-imendbeg "*" re-imendend))
	 ;; inline markup content without backquote
	 (re-imb2 (concat re-imbeg2 "`" re-imendbeg "`" re-imendend))
	 ;; inline markup content without vertical bar
	 (re-imv2 (concat re-imbeg2 "|" re-imendbeg "|" re-imendend))
	 ;; Supported URI schemes
	 (re-uris1 "\\(acap\\|cid\\|data\\|dav\\|fax\\|file\\|ftp\\|gopher\\|http\\|https\\|imap\\|ldap\\|mailto\\|mid\\|modem\\|news\\|nfs\\|nntp\\|pop\\|prospero\\|rtsp\\|service\\|sip\\|tel\\|telnet\\|tip\\|urn\\|vemmi\\|wais\\)")
	 ;; Line starting with adornment and optional whitespace; complete
	 ;; adornment is in (match-string 1); there must be at least 3
	 ;; characters because otherwise explicit markup start would be
	 ;; recognized
	 (re-ado2 (concat "^\\(\\(["
			  (if rst-use-char-classes
			      "^[:word:][:space:][:cntrl:]"
			    "^\\w \t\x00-\x1F")
			  "]\\)\\2\\2+\\)" re-hws "*$"))
	 )
    (should (re-equal-matches
	     ;; `Bullet Lists`_
	     (concat re-bol "\\([-*+]" re-blksep1 "\\)")
	     "=== rst.el.~rst_el_1_68~:3011"	      
	     (rst-re 'lin-beg '(:grp bul-sta))
	     (list "*"
		   (cons 1 1))
	     (cons (regexp-quote "[-*+]")
		   "[-*+\u2022\u2023\u2043]") ;; More bullets
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Enumerated Lists`_
	     (concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]"
		     re-blksep1 "\\)")
	     "=== rst.el.~rst_el_1_68~:3015"
	     (rst-re 'lin-beg '(:grp enmany-sta))
	     (list "  (#) Item"
		   (cons 1 1))
	     (cons (regexp-quote
		    "(?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]")
		   "\\(?:\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)\\.\\|(?\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\))\\)"
		   ) ;; Enumeration tags are more sophisticated
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Field Lists`_
	     (concat re-bol "\\(:[^:\n]+:\\)" re-blksep1)
	     "=== rst.el.~rst_el_1_68~:3021"
	     (rst-re 'lin-beg '(:grp fld-tag) 'bli-sfx)
	     (list "  :some field: "
		   (cons 1 1))
	     (cons "\\[^:\n]" "\\(?:[^:\n]\\|\\\\:\\)") ;; Field name more
							;; sophisticated
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Option Lists`_
	     (concat re-bol "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*"
		     "\\([ =]\\S +\\)?\\)\\(,[\t ]\\)?\\)+\\)\\($\\|[\t ]\\{2\\}\\)")
	     "=== rst.el.~rst_el_1_68~:3025"
	     (rst-re 'lin-beg '(:grp opt-tag (:shy optsep-tag opt-tag) "*")
		     '(:alt "$" (:seq hws-prt "\\{2\\}")))
	     (list "  --len=length, -l length    Explanation"
		   (cons 1 1))
	     (cons (regexp-quote "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*\\([ =]\\S +\\)?\\)\\(,[	 ]\\)?\\)+\\)")
		   "\\(\\(?:\\(?:[-+/]\\|--\\)\\sw\\(?:-\\|\\sw\\)*\\(?:[ =]\\S +\\)?\\)\\(?:\\(?:,[	 ]\\)\\(?:\\(?:[-+/]\\|--\\)\\sw\\(?:-\\|\\sw\\)*\\(?:[ =]\\S +\\)?\\)\\)*\\)"
		   ) ;; Option recognition more sophisticated
	     (cons "\\\\(\\$" "\\(?:$") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Line Blocks`_
	     (concat re-bol "\\(|" re-blksep1 "\\)[^|\n]*$")
	     "=== rst.el.~rst_el_1_68~:3030"
	     (rst-re 'lin-beg '(:grp "|" bli-sfx) "[^|\n]*$")
	     (list "  | Some text"
		   (cons 1 1))
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Footnotes`_ / `Citations`_
	     (concat re-bol "\\(" re-ems "\\[[^[\n]+\\]\\)" re-blksep1)
	     "=== rst.el.~rst_el_1_68~:3038"
	     (rst-re 'lin-beg '(:grp exm-sta fnc-tag) 'bli-sfx)
	     (list ".. [#]"
		   (cons 1 1))
	     (cons "\\[^\\[" "[^]") ;; Error correction in old code
	     (cons "\\\\]" "]") ;; Remove superfluous quote
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Directives`_ / `Substitution Definitions`_
	     (concat re-bol "\\(" re-ems "\\)\\(\\(|[^|\n]+|[\t ]+\\)?\\)\\("
		     re-sym1 "+::\\)" re-blksep1)
	     "=== rst.el.~rst_el_1_68~:3042"
	     (rst-re 'lin-beg '(:grp exm-sta)
		     '(:grp (:shy subdef-tag hws-sta) "?")
		     '(:grp sym-tag dcl-tag) 'bli-sfx)
	     (list ".. |attr| replace:: val"
		   (cons 1 1)
		   (cons 2 2)
		   (cons 4 3))
	     (cons "\\\\(|" "\\(?:|") ;; Make a group shy
	     (cons "\\[^|\n]\\+" "\\(?:\\S \\|\\S \\(?:[^|\\\n]\\|\\\\.\\)\\{0,1000\\}[^	 |\\]\\)"
		   ) ;; Symbol name more sophisticated
	     (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
		   "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
							 ;; symbols
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Hyperlink Targets`_
	     (concat re-bol "\\(" re-ems "_\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+:\\)"
		     re-blksep1)
	     "=== rst.el.~rst_el_1_68~:3049"
	     (rst-re 'lin-beg
		     '(:grp exm-sta "_" (:alt
					 (:seq "`" ilcbkqdef-tag "`")
					 (:seq (:alt "[^:\\\n]" "\\\\.") "+")) ":")
		     'bli-sfx)
	     (list ".. _`some\\: target`:"
		   (cons 1 1))
	     (cons (regexp-quote "\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+")
		   "\\(?:`\\(?:\\S \\|\\S \\(?:[^`\\\n]\\|\\\\.\\)\\{0,1000\\}[^	 `\\]\\)`\\|\\(?:[^:\\\n]\\|\\\\.\\)+\\)"
		   ) ;; Hyperlink name recognition more sophisticated
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Hyperlink Targets`_
	     (concat re-bol "\\(__\\)" re-blksep1)
	     "=== rst.el.~rst_el_1_68~:3053"
	     (rst-re 'lin-beg '(:grp "__") 'bli-sfx)
	     (list "  __"
		   (cons 1 1))
	     (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Strong Emphasis`_
	     (concat re-imp1 "\\(\\*\\*" re-ima2 "\\*\\*\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3062"
	     (rst-re 'ilm-pfx '(:grp "\\*\\*" ilcast-tag "\\*\\*") 'ilm-sfx)
	     (list "abc **def** ghi"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
	     (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
	     (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Emphasis`_
	     (concat re-imp1 "\\(\\*" re-ima2 "\\*\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3066"
	     (rst-re 'ilm-pfx '(:grp "\\*" ilcast-tag "\\*") 'ilm-sfx)
	     (list "*x*"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
	     (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
	     (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Inline Literals`_
	     (concat re-imp1 "\\(``" re-imb2 "``\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3070"
	     (rst-re 'ilm-pfx '(:grp "``" ilcbkq-tag "``") 'ilm-sfx)
	     (list "``co de``"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
	     (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
	     (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Inline Internal Targets`_
	     (concat re-imp1 "\\(_`" re-imb2 "`\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3074"
	     (rst-re 'ilm-pfx '(:grp "_`" ilcbkq-tag "`") 'ilm-sfx)
	     (list "_`Inline\ntarget`"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
	     (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
	     (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Hyperlink References`_
	     (concat re-imp1 "\\(\\(`" re-imb2 "`\\|\\(\\sw\\(\\sw\\|-\\)+\\sw\\)\\)__?\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3079"
	     (rst-re 'ilm-pfx '(:grp (:alt (:seq "`" ilcbkq-tag "`")
					   (:seq "\\sw" (:alt "\\sw" "-") "+\\sw"))
				     "__?") 'ilm-sfx)
	     (list "<`xxx`__>"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
	     (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
	     (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     (cons "\\\\(`" "\\(?:`") ;; Make a group shy
	     (cons "\\\\(\\\\sw" "\\sw")
	     (cons "\\\\sw\\\\)" "\\sw") ;; Remove a group
	     (cons "sw\\\\(\\\\sw" "sw\\(?:\\sw") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Interpreted Text`_
	     (concat re-imp1 "\\(\\(:" re-sym1 "+:\\)?\\)\\(`" re-imb2 "`\\)\\(\\(:"
		     re-sym1 "+:\\)?\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3083"
	     (rst-re 'ilm-pfx '(:grp (:shy ":" sym-tag ":") "?")
		     '(:grp "`" ilcbkq-tag "`")
		     '(:grp (:shy ":" sym-tag ":") "?") 'ilm-sfx)
	     (list "`Interpreted`"
		   (cons 2 1)
		   (cons 5 2)
		   (cons 8 3))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
	     (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
	     (cons "\\\\(:" "\\(?::") ;; Make a group shy
	     (cons "\\\\(:" "\\(?::") ;; Make a group shy
	     (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
		   "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
							 ;; symbols
	     (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
		   "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
							 ;; symbols
	     (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Footnote References`_ / `Citation References`_
	     (concat re-imp1 "\\(\\[[^]]+\\]_\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3090"
	     (rst-re 'ilm-pfx '(:grp fnc-tag "_") 'ilm-sfx)
	     (list "[1]_"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "]]" "]\n]") ;; A reference may not contain \n
	     (cons "\\\\]" "]") ;; Remove superfluous quote
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Substitution References`_
	     (concat re-imp1 "\\(|" re-imv2 "|\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3094"
	     (rst-re 'ilm-pfx '(:grp sub-tag) 'ilm-sfx)
	     (list "|attr|"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
	     (cons (regexp-quote "\\([^|") "\\(?:[^|") ;; Make a group shy
	     (cons "\\\\]" "]") ;; Remove superfluous quote
	     (cons "\\\\]" "]") ;; Remove superfluous quote
	     (cons "\\[^|]" "[^|\\]") ;; Improve recognition
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Standalone Hyperlinks`_
	     (concat re-imp1 "\\(" re-uris1 ":\\S +\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3099"
	     (rst-re 'ilm-pfx '(:grp uri-tag ":\\S +") 'ilm-sfx)
	     (list "http://example.com/"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons "\\\\(acap" "\\(?:acap") ;; Make a group shy
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Standalone Hyperlinks`_
	     (concat re-imp1 "\\(" re-sym1 "+@" re-sym1 "+\\)" re-ims1)
	     "=== rst.el.~rst_el_1_68~:3102"
	     (rst-re 'ilm-pfx '(:grp sym-tag "@" sym-tag ) 'ilm-sfx)
	     (list "someone@example"
		   (cons 2 1))
	     (cons "^\\\\(" "\\(?:") ;; Make a group shy
	     (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
		   "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
							 ;; symbols
	     (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
		   "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
							 ;; symbols
	     (cons (regexp-quote "\\|$") "")
	     (cons (regexp-quote "\\([\t ]")
		   "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
	     ))
    (should (re-equal
	     ;; Sections_ / Transitions_
	     re-ado2
	     "=== rst.el.~rst_el_1_68~:3109"
	     (rst-re 'ado-beg-2-1)
	     (cons "\\^\\[:word:]\\[:space:]\\[:cntrl:]"
		   "]!\"#$%&'()*+,./:;<=>?@[\\^_`{|}~-") ;; Use real adornment
							 ;; characters
	     (cons "2\\+" "{2,\\}") ;; Use repeat count
	     ))
    (should (re-equal
	     ;; `Comments`_
	     (concat re-bol "\\(" re-ems "\\)\[^[|_\n]\\([^:\n]\\|:\\([^:\n]\\|$\\)\\)*$")
	     "=== rst.el.~rst_el_1_68~:3128"
	     (rst-re 'lin-beg '(:grp exm-sta) "[^\[|_\n]"
		     '(:alt "[^:\n]" (:seq ":" (:alt "[^:\n]" "$"))) "*$")
	     (cons "\\\\(\\[^:" "\\(?:[^:") ;; Make a group shy
	     (cons "\\\\(\\[^:" "\\(?:[^:") ;; Make a group shy
	     ))
    (should (re-equal-matches
	     ;; `Comments`_
	     (concat re-bol "\\(" re-emt "\\)\\(\\s *\\)$")
	     "=== rst.el.~rst_el_1_68~:3135"
	     (rst-re 'lin-beg '(:grp exm-tag) '(:grp hws-tag) "$")
	     (list ".. "
		   (cons 1 1)
		   (cons 2 2))
	     (cons "\\\\s " "[\t ]") ;; Only horizontal space
	     ))
    (should (re-equal-matches
	     ;; `Literal Blocks`_
	     (concat re-bol "\\(\\([^.\n]\\|\\.[^.\n]\\).*\\)?\\(::\\)$")
	     "=== rst.el.~rst_el_1_68~:3145"
	     (rst-re 'lin-beg '(:shy (:alt "[^.\n]" "\\.[^.\n]") ".*") "?"
		     '(:grp dcl-tag) "$")
	     (list "Some text ::"
		   (cons 3 1))
	     (cons "\\\\(\\\\(" "\\(?:\\(?:") ;; Make two groups shy
	     ))
    (should (re-equal-matches
	     ;; `Doctest Blocks`_
	     (concat re-bol "\\(>>>\\|\\.\\.\\.\\)\\(.+\\)")
	     "=== rst.el.~rst_el_1_68~:3154"
	     (rst-re 'lin-beg '(:grp (:alt ">>>" ell-tag)) '(:grp ".+"))
	     (list ">>> content"
		   (cons 1 1)
		   (cons 2 2))
	     (cons ">>>" "\\(?:>>>") (cons "\\.\\\\)" ".\\)\\)") ;; Add a shy
								 ;; group
	     ))
    ))