1 ;; Tests for the regular expression builder
3 (add-to-list 'load-path
".")
9 (should (equal (rst-re "xy") "xy"))
10 (should (equal (rst-re ?A
) "A"))
11 (should (equal (rst-re ?$
) "\\$"))
12 (should (equal (rst-re 'exm-tag
) "\\.\\."))
13 (should (equal (rst-re "xy" ?A ?$
'exm-tag
) "xyA\\$\\.\\."))
14 (should (equal (rst-re '(:seq
"xy" ?A ?$ exm-tag
)) "xyA\\$\\.\\."))
15 (should (equal (rst-re '(:shy
"xy" ?A ?$ exm-tag
)) "\\(?:xyA\\$\\.\\.\\)"))
16 (should (equal (rst-re '(:grp
"xy" ?A ?$ exm-tag
)) "\\(xyA\\$\\.\\.\\)"))
17 (should (equal (rst-re '(:alt
"xy" ?A ?$ exm-tag
))
18 "\\(?:xy\\|A\\|\\$\\|\\.\\.\\)"))
19 (should (equal (rst-re '(:seq
(:seq
"xy" ?A ?$ exm-tag
))) "xyA\\$\\.\\."))
20 (should (equal (rst-re '(:grp
(:alt
"xy" ?A ?$ exm-tag
)))
21 "\\(\\(?:xy\\|A\\|\\$\\|\\.\\.\\)\\)"))
22 (should (equal (rst-re '(:alt
(:grp
"xy" ?A ?$ exm-tag
)))
23 "\\(?:\\(xyA\\$\\.\\.\\)\\)"))
24 (should (equal (rst-re '(:alt
"xy" ?A
) '(:grp ?$ exm-tag
))
25 "\\(?:xy\\|A\\)\\(\\$\\.\\.\\)"))
26 (should-error (rst-re '(:unknown
"xy")))
27 (should-error (rst-re [1]))
30 (defun re-equal-modify-orig (orig loc refactored repls)
31 (let ((case-fold-search nil))
32 (while (string-match "\\[ \t]" orig)
33 ;; Transpose horizontal whitespace
34 (setq orig (replace-match "[\t ]" t nil orig)))
35 (while (string-match "\\\\s \\*\\$" orig)
36 ;; Replace symbolic whitespace
37 (setq orig (replace-match "[\t ]*$" t nil orig)))
38 (dolist (regex-repl repls)
39 (if (string-match (car regex-repl) orig)
40 (setq orig (replace-match (cdr regex-repl) t t orig))
41 (error "Replacement regex /%s/ didn't match in '%s' for location '%s'"
42 (car regex-repl) orig loc)))
46 (defun re-equal (orig loc refactored &rest repls)
47 "Compare regex ORIG at location LOC to REFACTORED.
48 REPLS starts with a list of cons cells telling where regex in car
49 is replaced by cdr in ORIG."
50 (equal (re-equal-modify-orig orig loc refactored repls) refactored))
52 (defun re-equal-explain (orig loc refactored &rest repls)
53 (setq orig (re-equal-modify-orig orig loc refactored repls))
54 (ert--explain-not-equal orig refactored))
56 (put 're-equal 'ert-explainer 're-equal-explain)
58 (defun re-check-matches (orig loc refactored s pairs)
59 "Check matches and return those pairs which didn't work"
60 (let ((case-fold-search nil)
62 (dolist (pair pairs failed)
63 (let ((orig-mtc (if (string-match orig s)
64 (match-string (car pair) s)))
65 (refa-mtc (if (string-match refactored s)
66 (match-string (cdr pair) s))))
68 (error "Original regex '%s' didn't match string '%s' for location '%s'"
71 (error "Refactored regex '%s' didn't match string '%s' for location '%s'"
73 (if (not (equal orig-mtc refa-mtc))
74 (push pair failed))))))))
76 (defun re-equal-matches (orig loc refactored matches &rest repls)
77 "Like `re-equal'. However, if MATCHES is non-nil it must be a
78 list with a string and cons cells each consisting of two numbers.
79 For each cons cell the string is matched with ORIG and REFACTORED
80 and the numbered matches are compared."
81 (and (equal (re-equal-modify-orig orig loc refactored repls) refactored)
82 (not (re-check-matches orig loc refactored
83 (car matches) (cdr matches)))))
85 (defun re-equal-matches-explain (orig loc refactored matches &rest repls)
86 (if (not (equal (re-equal-modify-orig orig loc refactored repls) refactored))
87 (apply 're-equal-explain orig loc refactored repls)
89 (dolist (failed (re-check-matches orig loc refactored
90 (car matches) (cdr matches)) result)
91 (push (list 'matchers-didnt-match (car failed) (cdr failed))
94 (put 're-equal-matches 'ert-explainer 're-equal-matches-explain)
96 (ert-deftest rst-re-refactoring ()
97 "Test the refactorings done based on rst_el_1_68."
98 ;; Any comment or string "=== rst.el.~rst_el_1_68~:..." gives the line number
99 ;; of the refactored code in the original file for the previous expression.
102 ;; === rst.el.~rst_el_1_68~:451
104 (format "\\([%s][ \t]\\)[^ \t]" (regexp-quote (concat rst-bullets))))
105 ;; === rst.el.~rst_el_1_68~:1604
111 (ado-re (regexp-quote adornment))
116 "=== rst.el.~rst_el_1_68~:398"
117 (rst-re "^" 'exm-sta)
118 (cons " $" "[ ]+") ;; Any whitespace may follow
121 "^[ \t]*\\S *\\w\\S *"
122 "=== rst.el.~rst_el_1_68~:567"
123 (rst-re 'lin-beg "\\S *\\w\\S *")
127 "=== rst.el.~rst_el_1_68~:591"
128 (rst-re 'dcl-tag 'lin-end)
132 "=== rst.el.~rst_el_1_68~:592"
133 (rst-re 'ell-tag 'lin-end)
137 "=== rst.el.~rst_el_1_68~:594"
138 (rst-re "." 'lin-end)
142 "=== rst.el.~rst_el_1_68~:605"
144 (cons "^^" "") ;; No need to anchor for looking-at
148 "=== rst.el.~rst_el_1_68~:744"
150 (cons "^^" "") ;; No need to anchor for looking-at
154 "=== rst.el.~rst_el_1_68~:1517"
156 (cons "^^" "") ;; No need to anchor for looking-at
160 "=== rst.el.~rst_el_1_68~:1545"
162 (cons "^^" "") ;; No need to anchor for looking-at
166 "=== rst.el.~rst_el_1_68~:1548"
168 (cons "^^" "") ;; No need to anchor for looking-at
172 "=== rst.el.~rst_el_1_68~:1657"
177 "=== rst.el.~rst_el_1_68~:1661"
182 "=== rst.el.~rst_el_1_68~:1677"
187 "=== rst.el.~rst_el_1_68~:1685"
192 "=== rst.el.~rst_el_1_68~:1762"
193 (rst-re "[ \t\n]*\\'")
197 "=== rst.el.~rst_el_1_68~:1767"
198 (rst-re "\\S .*\\S ")
202 "=== rst.el.~rst_el_1_68~:2066"
207 "=== rst.el.~rst_el_1_68~:2366"
212 "=== rst.el.~rst_el_1_68~:2414"
214 (cons "^^" "") ;; No need to anchor for looking-at
218 "=== rst.el.~rst_el_1_68~:2610"
223 "=== rst.el.~rst_el_1_68~:2612"
228 "=== rst.el.~rst_el_1_68~:2645"
232 "[^ \t]\\|[ \t]*\\.\\.[^ \t]\\|.*::$"
233 "=== rst.el.~rst_el_1_68~:3177"
236 (:seq hws-tag exm-tag "[^ \t]")
237 (:seq ".*" dcl-tag lin-end)))
238 (cons "^" "\\(?:") (cons "$" "\\)") ;; Add outermost shy group
239 (cons "::\\$" "::[ ]*$") ;; Allow trailing space after double
244 "=== rst.el.~rst_el_1_68~:3209"
249 "=== rst.el.~rst_el_1_68~:3215"
254 "=== rst.el.~rst_el_1_68~:3253"
259 "=== rst.el.~rst_el_1_68~:3256"
261 (cons "\\\\s \\*" "[\t ]*") ;; Replace symbolic by real whitespace
265 "=== rst.el.~rst_el_1_68~:3261"
270 "=== rst.el.~rst_el_1_68~:3268"
272 (cons "\\\\s \\*" "[\t ]*") ;; Replace symbolic by real whitespace
275 (regexp-quote adornment)
276 "=== rst.el.~rst_el_1_68~:3346"
277 (rst-re (regexp-quote adornment))
281 "=== rst.el.~rst_el_1_68~:3354"
286 "=== rst.el.~rst_el_1_68~:3358"
291 "=== rst.el.~rst_el_1_68~:3374"
295 (concat "\\(" ado-re "\\)\\s *$")
296 "=== rst.el.~rst_el_1_68~:3377"
302 (concat "\\(" ado-re "\\)\\s *$")
303 "=== rst.el.~rst_el_1_68~:3393"
309 (concat "^" (regexp-quote (string fromchar)) "+\\( *\\)$")
310 "=== rst.el.~rst_el_1_68~:3590"
311 (rst-re "^" fromchar "+\\( *\\)$")
314 "\f\\|>*[ \t]*$\\|>*[ \t]*[-+*] \\|>*[ \t]*[0-9#]+\\. "
315 "=== rst.el.~rst_el_1_68~:391"
319 (:seq hws-tag itmany-sta-1)))
320 (cons "^" "\\(?:") (cons "$" "\\)") ;; Add outermost shy group
321 (cons (regexp-quote "[-+*] \\|>*[ ]*[0-9#]+\\. ")
322 "\\(\\(?:\\(?:\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)\\.\\|(?\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\))\\)\\|[-*+\u2022\u2023\u2043]\\)\\)[ ]+"
323 ) ;; Now matches all items
324 (cons ">\\*" "") ;; Remove ">" prefix
325 (cons ">\\*" "") ;; Remove another ">" prefix
326 (cons "\\[\t ]\\+" "\\(?:[\t ]+\\|$\\)") ;; Item tag needs no
327 ;; trailing whitespace
330 (format "[%s]+[ \t]*$" (char-to-string c))
331 "=== rst.el.~rst_el_1_68~:587"
332 (rst-re c "+" 'lin-end)
333 (cons "\\[\\*]" "\\*") ;; Use quoting instead of char class
337 (regexp-quote (make-string len char))
339 "=== rst.el.~rst_el_1_68~:941"
340 (rst-re "^" char (format "\\{%d\\}" len) "$")
341 (cons "\\(\\\\\\+\\)\\{9\\}\\$"
342 "\\{10\\}$") ;; Use regex repeat instead of explicit repeat
346 (regexp-quote (concat rst-bullets)))
347 "=== rst.el.~rst_el_1_68~:1653"
351 (cons "^" "\\(?:") (cons "$" "\\)") ;; Add outermost shy group
352 (cons (regexp-quote "[-\\*\\+]")
353 "[-*+\u2022\u2023\u2043]") ;; Wrongly quoted characters in
354 ;; class and more bullets
355 (cons "#\\." "\\(?:#\\.\\|(?#)\\)") ;; Use all auto enumerators
359 "=== rst.el.~rst_el_1_68~:1672"
361 (cons "\\+$" "") ;; Wrong in source
365 "=== rst.el.~rst_el_1_68~:1735"
367 (cons (regexp-quote "[-\\*\\+]")
368 "[-*+\u2022\u2023\u2043]") ;; Wrongly quoted characters in
369 ;; class and more bullets
370 (cons "\\[^ \t]" "") ;; Accept bullets without content
371 (cons "^\\\\(" "") (cons "\\\\)" "") ;; Remove superfluous group
372 (cons "$" "+") ;; Allow more whitespace
373 (cons "\\[\t ]\\+" "\\(?:[\t ]+\\|$\\)") ;; Item tag needs no
374 ;; trailing whitespace
377 "^\\.\\. contents[ \t]*::\\(.*\\)\n\\([ \t]+:\\w+:.*\n\\)*\\.\\."
378 "=== rst.el.~rst_el_1_68~:2056"
379 (rst-re "^" 'exm-sta "contents" 'dcl-tag ".*\n"
380 "\\(?:" 'hws-sta 'fld-tag ".*\n\\)*" 'exm-tag)
381 (cons " contents\\[\t ]\\*"
382 "[\t ]+contents") ;; Any whitespace before but no after
383 (cons "\\\\(\\.\\*\\\\)" ".*") ;; Remove superfluous group
384 (cons "\\\\(" "\\(?:") ;; Make group shy
385 (cons ":\\\\w\\+:" ":\\(?:[^:\n]\\|\\\\:\\)+:") ;; Use improved
390 "=== rst.el.~rst_el_1_68~:2065"
391 (rst-re 'hws-sta "\\S ")
392 (cons "\\[^ \t]" "\\S ") ;; Require non-whitespace instead
393 ;; of only non-horizontal whitespace
397 (ert-deftest rst-re-refactoring-complicated ()
398 "Try to test complicated refactorings done based on rst_el_1_68."
399 :expected-result :failed ;; These have been reviewed logically and are ok
402 ;; === rst.el.~rst_el_1_68~:451
403 (rst-re-enumerator "\\(?:[a-zA-Z]\\|[0-9IVXLCDMivxlcdm]+\\)")
404 ;; === rst.el.~rst_el_1_68~:1608
406 (format "^[ \t]*\\(%s.\\|(?%s)\\)[ \t]"
409 ;; === rst.el.~rst_el_1_68~:1610
411 (format "^[ \t]*\\([%s]\\|\\(#\\|%s\\)\\.\\|(?%s)\\)[ \t]"
412 (regexp-quote (concat rst-bullets))
415 ;; === rst.el.~rst_el_1_68~:1616
421 "=== rst.el.~rst_el_1_68~:2718"
422 (rst-re 'itmany-sta-1)
423 (cons "^^\\[\t ]\\*" "") ;; Wrongly anchored at the beginning of
425 (cons (regexp-quote "\\(#\\|\\(?:[a-zA-Z]\\|[0-9IVXLCDMivxlcdm]+\\)\\)")
426 "\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)"
427 ) ;; Replace counter for "\\."
428 (cons (regexp-quote "\\(?:[a-zA-Z]\\|[0-9IVXLCDMivxlcdm]+\\)")
429 "\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)"
430 ) ;; Replace counter for "(?)"
431 (cons "$" "+") ;; Allow more whitespace
432 (cons "^\\\\(" "\\(\\(?:") (cons "\\[\t ]\\+$" "\\)[\t ]+"
433 ) ;; Add superfluous shy group
434 (cons (regexp-quote "[-\\*\\+]\\|") "") ;; Remove wrongly quoted
436 (cons (regexp-quote "\\)\\)[\t ]+")
437 "\\|[-*+\u2022\u2023\u2043]\\)\\)[\t ]+"
442 "=== rst.el.~rst_el_1_68~:2724"
443 (rst-re 'itmany-beg-1)
447 "=== rst.el.~rst_el_1_68~:1649"
448 (rst-re 'itmany-beg-1)
452 "=== rst.el.~rst_el_1_68~:1671"
457 "=== rst.el.~rst_el_1_68~:1719"
458 (rst-re 'itmany-beg-1)
463 "\\(\\(?:[0-9a-zA-Z#]\\{1,3\\}[.):-]\\|[*+-]\\)[ \t]+\\)[^ \t\n]"
465 (format "\\(%s%s+[ \t]+\\)[^ \t\n]"
466 (regexp-quote (char-to-string char))
467 (regexp-quote (char-to-string char)))
469 "=== rst.el.~rst_el_1_68~:2430"
474 (:seq ,(char-after) "\\{2,\\}"))
477 (cons "^\\\\(\\?:" "") (cons "\\\\)$" "") ;; Remove superfluous
479 (cons (regexp-quote "[0-9a-zA-Z#]\\{1,3\\}[.):-]\\|[*+-]")
480 "\\(\\(?:\\(?:\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)\\.\\|(?\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\))\\)\\|[-*+\u2022\u2023\u2043]\\)\\)"
481 ) ;; Replace wrong item tag by correct one
482 (cons (regexp-quote "\\+\\++")
483 "\\+\\{2,\\}") ;; Use regex repeat instead of explicit repeat
484 (cons "\\[^ \t\n]" "\\S ") ;; Use symbolic non-whitespace
485 (cons "\\[^ \t\n]" "\\S ") ;; Use symbolic non-whitespace again
486 (cons "\\\\S " "") ;; Factor out symbolic non-whitespace
490 (ert-deftest rst-re-refactoring-font-lock ()
491 "Test the refactorings in font-lock done based on rst_el_1_68."
492 ;; Any comment or string "=== rst.el.~rst_el_1_68~:..." gives the line number
493 ;; of the refactored code in the original file for the previous expression.
494 (let* ((rst-use-char-classes t)
496 ;; horizontal white space
498 ;; beginning of line with possible indentation
499 (re-bol (concat "^" re-hws "*"))
500 ;; Separates block lead-ins from their content
501 (re-blksep1 (concat "\\(" re-hws "+\\|$\\)"))
502 ;; explicit markup tag
504 ;; explicit markup start
505 (re-ems (concat re-emt re-hws "+"))
506 ;; inline markup prefix
507 (re-imp1 (concat "\\(^\\|" re-hws "\\|[-'\"([{<"
509 "\u2018\u201c\u00ab\u2019"
512 ;; inline markup suffix
513 (re-ims1 (concat "\\(" re-hws "\\|[]-'\")}>"
517 "/:.,;!?\\]\\|$\\)"))
519 (re-sym1 "\\(\\sw\\|\\s_\\)")
520 ;; inline markup content begin
521 (re-imbeg2 "\\(\\S \\|\\S \\([^")
523 ;; There seems to be a bug leading to error "Stack overflow in regexp
524 ;; matcher" when "|" or "\\*" are the characters searched for
526 (if (< emacs-major-version 21)
529 ;; inline markup content end
530 (re-imendbeg (concat re-imendbegbeg "\\)\\{0,"
531 (format "%d" rst-max-inline-length)
533 (re-imendend "\\\\]\\)")
534 ;; inline markup content without asterisk
535 (re-ima2 (concat re-imbeg2 "*" re-imendbeg "*" re-imendend))
536 ;; inline markup content without backquote
537 (re-imb2 (concat re-imbeg2 "`" re-imendbeg "`" re-imendend))
538 ;; inline markup content without vertical bar
539 (re-imv2 (concat re-imbeg2 "|" re-imendbeg "|" re-imendend))
540 ;; Supported URI schemes
541 (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\\)")
542 ;; Line starting with adornment and optional whitespace; complete
543 ;; adornment is in (match-string 1); there must be at least 3
544 ;; characters because otherwise explicit markup start would be
546 (re-ado2 (concat "^\\(\\(["
547 (if rst-use-char-classes
548 "^[:word:][:space:][:cntrl:]"
550 "]\\)\\2\\2+\\)" re-hws "*$"))
552 (should (re-equal-matches
554 (concat re-bol "\\([-*+]" re-blksep1 "\\)")
555 "=== rst.el.~rst_el_1_68~:3011"
556 (rst-re 'lin-beg '(:grp bul-sta))
559 (cons (regexp-quote "[-*+]")
560 "[-*+\u2022\u2023\u2043]") ;; More bullets
561 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
563 (should (re-equal-matches
564 ;; `Enumerated Lists`_
565 (concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]"
567 "=== rst.el.~rst_el_1_68~:3015"
568 (rst-re 'lin-beg '(:grp enmany-sta))
572 "(?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]")
573 "\\(?:\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\)\\.\\|(?\\(?:[a-zA-Z]\\|[0-9]+\\|[IVXLCDMivxlcdm]+\\|#\\))\\)"
574 ) ;; Enumeration tags are more sophisticated
575 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
577 (should (re-equal-matches
579 (concat re-bol "\\(:[^:\n]+:\\)" re-blksep1)
580 "=== rst.el.~rst_el_1_68~:3021"
581 (rst-re 'lin-beg '(:grp fld-tag) 'bli-sfx)
582 (list " :some field: "
584 (cons "\\[^:\n]" "\\(?:[^:\n]\\|\\\\:\\)") ;; Field name more
586 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
588 (should (re-equal-matches
590 (concat re-bol "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*"
591 "\\([ =]\\S +\\)?\\)\\(,[\t ]\\)?\\)+\\)\\($\\|[\t ]\\{2\\}\\)")
592 "=== rst.el.~rst_el_1_68~:3025"
593 (rst-re 'lin-beg '(:grp opt-tag (:shy optsep-tag opt-tag) "*")
594 '(:alt "$" (:seq hws-prt "\\{2\\}")))
595 (list " --len=length, -l length Explanation"
597 (cons (regexp-quote "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*\\([ =]\\S +\\)?\\)\\(,[ ]\\)?\\)+\\)")
598 "\\(\\(?:\\(?:[-+/]\\|--\\)\\sw\\(?:-\\|\\sw\\)*\\(?:[ =]\\S +\\)?\\)\\(?:\\(?:,[ ]\\)\\(?:\\(?:[-+/]\\|--\\)\\sw\\(?:-\\|\\sw\\)*\\(?:[ =]\\S +\\)?\\)\\)*\\)"
599 ) ;; Option recognition more sophisticated
600 (cons "\\\\(\\$" "\\(?:$") ;; Make a group shy
602 (should (re-equal-matches
604 (concat re-bol "\\(|" re-blksep1 "\\)[^|\n]*$")
605 "=== rst.el.~rst_el_1_68~:3030"
606 (rst-re 'lin-beg '(:grp "|" bli-sfx) "[^|\n]*$")
609 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
611 (should (re-equal-matches
612 ;; `Footnotes`_ / `Citations`_
613 (concat re-bol "\\(" re-ems "\\[[^[\n]+\\]\\)" re-blksep1)
614 "=== rst.el.~rst_el_1_68~:3038"
615 (rst-re 'lin-beg '(:grp exm-sta fnc-tag) 'bli-sfx)
618 (cons "\\[^\\[" "[^]") ;; Error correction in old code
619 (cons "\\\\]" "]") ;; Remove superfluous quote
620 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
622 (should (re-equal-matches
623 ;; `Directives`_ / `Substitution Definitions`_
624 (concat re-bol "\\(" re-ems "\\)\\(\\(|[^|\n]+|[\t ]+\\)?\\)\\("
625 re-sym1 "+::\\)" re-blksep1)
626 "=== rst.el.~rst_el_1_68~:3042"
627 (rst-re 'lin-beg '(:grp exm-sta)
628 '(:grp (:shy subdef-tag hws-sta) "?")
629 '(:grp sym-tag dcl-tag) 'bli-sfx)
630 (list ".. |attr| replace:: val"
634 (cons "\\\\(|" "\\(?:|") ;; Make a group shy
635 (cons "\\[^|\n]\\+" "\\(?:\\S \\|\\S \\(?:[^|\\\n]\\|\\\\.\\)\\{0,1000\\}[^ |\\]\\)"
636 ) ;; Symbol name more sophisticated
637 (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
638 "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
640 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
642 (should (re-equal-matches
643 ;; `Hyperlink Targets`_
644 (concat re-bol "\\(" re-ems "_\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+:\\)"
646 "=== rst.el.~rst_el_1_68~:3049"
648 '(:grp exm-sta "_" (:alt
649 (:seq "`" ilcbkqdef-tag "`")
650 (:seq (:alt "[^:\\\n]" "\\\\.") "+")) ":")
652 (list ".. _`some\\: target`:"
654 (cons (regexp-quote "\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+")
655 "\\(?:`\\(?:\\S \\|\\S \\(?:[^`\\\n]\\|\\\\.\\)\\{0,1000\\}[^ `\\]\\)`\\|\\(?:[^:\\\n]\\|\\\\.\\)+\\)"
656 ) ;; Hyperlink name recognition more sophisticated
657 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
659 (should (re-equal-matches
660 ;; `Hyperlink Targets`_
661 (concat re-bol "\\(__\\)" re-blksep1)
662 "=== rst.el.~rst_el_1_68~:3053"
663 (rst-re 'lin-beg '(:grp "__") 'bli-sfx)
666 (cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
668 (should (re-equal-matches
669 ;; `Strong Emphasis`_
670 (concat re-imp1 "\\(\\*\\*" re-ima2 "\\*\\*\\)" re-ims1)
671 "=== rst.el.~rst_el_1_68~:3062"
672 (rst-re 'ilm-pfx '(:grp "\\*\\*" ilcast-tag "\\*\\*") 'ilm-sfx)
673 (list "abc **def** ghi"
675 (cons "^\\\\(" "\\(?:") ;; Make a group shy
676 (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
677 (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
678 (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
679 (cons (regexp-quote "\\|$") "")
680 (cons (regexp-quote "\\([\t ]")
681 "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
683 (should (re-equal-matches
685 (concat re-imp1 "\\(\\*" re-ima2 "\\*\\)" re-ims1)
686 "=== rst.el.~rst_el_1_68~:3066"
687 (rst-re 'ilm-pfx '(:grp "\\*" ilcast-tag "\\*") 'ilm-sfx)
690 (cons "^\\\\(" "\\(?:") ;; Make a group shy
691 (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
692 (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
693 (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
694 (cons (regexp-quote "\\|$") "")
695 (cons (regexp-quote "\\([\t ]")
696 "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
698 (should (re-equal-matches
699 ;; `Inline Literals`_
700 (concat re-imp1 "\\(``" re-imb2 "``\\)" re-ims1)
701 "=== rst.el.~rst_el_1_68~:3070"
702 (rst-re 'ilm-pfx '(:grp "``" ilcbkq-tag "``") 'ilm-sfx)
705 (cons "^\\\\(" "\\(?:") ;; Make a group shy
706 (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
707 (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
708 (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
709 (cons (regexp-quote "\\|$") "")
710 (cons (regexp-quote "\\([\t ]")
711 "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
713 (should (re-equal-matches
714 ;; `Inline Internal Targets`_
715 (concat re-imp1 "\\(_`" re-imb2 "`\\)" re-ims1)
716 "=== rst.el.~rst_el_1_68~:3074"
717 (rst-re 'ilm-pfx '(:grp "_`" ilcbkq-tag "`") 'ilm-sfx)
718 (list "_`Inline\ntarget`"
720 (cons "^\\\\(" "\\(?:") ;; Make a group shy
721 (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
722 (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
723 (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
724 (cons (regexp-quote "\\|$") "")
725 (cons (regexp-quote "\\([\t ]")
726 "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
728 (should (re-equal-matches
729 ;; `Hyperlink References`_
730 (concat re-imp1 "\\(\\(`" re-imb2 "`\\|\\(\\sw\\(\\sw\\|-\\)+\\sw\\)\\)__?\\)" re-ims1)
731 "=== rst.el.~rst_el_1_68~:3079"
732 (rst-re 'ilm-pfx '(:grp (:alt (:seq "`" ilcbkq-tag "`")
733 (:seq "\\sw" (:alt "\\sw" "-") "+\\sw"))
737 (cons "^\\\\(" "\\(?:") ;; Make a group shy
738 (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
739 (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
740 (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
741 (cons (regexp-quote "\\|$") "")
742 (cons (regexp-quote "\\([\t ]")
743 "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
744 (cons "\\\\(`" "\\(?:`") ;; Make a group shy
745 (cons "\\\\(\\\\sw" "\\sw")
746 (cons "\\\\sw\\\\)" "\\sw") ;; Remove a group
747 (cons "sw\\\\(\\\\sw" "sw\\(?:\\sw") ;; Make a group shy
749 (should (re-equal-matches
750 ;; `Interpreted Text`_
751 (concat re-imp1 "\\(\\(:" re-sym1 "+:\\)?\\)\\(`" re-imb2 "`\\)\\(\\(:"
752 re-sym1 "+:\\)?\\)" re-ims1)
753 "=== rst.el.~rst_el_1_68~:3083"
754 (rst-re 'ilm-pfx '(:grp (:shy ":" sym-tag ":") "?")
755 '(:grp "`" ilcbkq-tag "`")
756 '(:grp (:shy ":" sym-tag ":") "?") 'ilm-sfx)
757 (list "`Interpreted`"
761 (cons "^\\\\(" "\\(?:") ;; Make a group shy
762 (cons "\\\\(\\\\S" "\\(?:\\S") ;; Make a group shy
763 (cons "\\\\(\\[^" "\\(?:[^") ;; Make a group shy
764 (cons "\\\\(:" "\\(?::") ;; Make a group shy
765 (cons "\\\\(:" "\\(?::") ;; Make a group shy
766 (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
767 "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
769 (cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
770 "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
772 (cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
773 (cons (regexp-quote "\\|$") "")
774 (cons (regexp-quote "\\([\t ]")
775 "\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy
777 (should (re-equal-matches
778 ;; `Footnote References`_ / `Citation References`_
779 (concat re-imp1 "\\(\\[[^]]+\\]_\\)" re-ims1)
780 "=== rst.el.~rst_el_1_68~:3090"
781 (rst-re 'ilm-pfx '(:grp fnc-tag "_") 'ilm-sfx)
784 (cons "^
\\\\(" "\\(?
:") ;; Make a group shy
785 (cons "]]" "]\n]") ;; A reference may not contain \n
786 (cons "\\\\]" "]") ;; Remove superfluous quote
787 (cons (regexp-quote "\\|$
") "")
788 (cons (regexp-quote "\\([\t ]")
789 "\\(?
:$
\\|
[\t ]") ;; Move "$
" in regex and make a group shy
791 (should (re-equal-matches
792 ;; `Substitution References`_
793 (concat re-imp1 "\\(|
" re-imv2 "|
\\)" re-ims1)
794 "=== rst.el.~rst_el_1_68~
:3094"
795 (rst-re 'ilm-pfx '(:grp sub-tag) 'ilm-sfx)
798 (cons "^
\\\\(" "\\(?
:") ;; Make a group shy
799 (cons "\\\\(\\\\S
" "\\(?
:\\S
") ;; Make a group shy
800 (cons (regexp-quote "\\([^|
") "\\(?
:[^|
") ;; Make a group shy
801 (cons "\\\\]" "]") ;; Remove superfluous quote
802 (cons "\\\\]" "]") ;; Remove superfluous quote
803 (cons "\\[^|
]" "[^|
\\]") ;; Improve recognition
804 (cons (regexp-quote "\\|$
") "")
805 (cons (regexp-quote "\\([\t ]")
806 "\\(?
:$
\\|
[\t ]") ;; Move "$
" in regex and make a group shy
808 (should (re-equal-matches
809 ;; `Standalone Hyperlinks`_
810 (concat re-imp1 "\\(" re-uris1 ":\\S
+\\)" re-ims1)
811 "=== rst.el.~rst_el_1_68~
:3099"
812 (rst-re 'ilm-pfx '(:grp uri-tag ":\\S
+") 'ilm-sfx)
813 (list "http
://example.com
/"
815 (cons "^
\\\\(" "\\(?
:") ;; Make a group shy
816 (cons "\\\\(acap" "\\(?
:acap
") ;; Make a group shy
817 (cons (regexp-quote "\\|$
") "")
818 (cons (regexp-quote "\\([\t ]")
819 "\\(?
:$
\\|
[\t ]") ;; Move "$
" in regex and make a group shy
821 (should (re-equal-matches
822 ;; `Standalone Hyperlinks`_
823 (concat re-imp1 "\\(" re-sym1 "+@" re-sym1 "+\\)" re-ims1)
824 "=== rst.el.~rst_el_1_68~
:3102"
825 (rst-re 'ilm-pfx '(:grp sym-tag "@" sym-tag ) 'ilm-sfx)
826 (list "someone
@example
"
828 (cons "^
\\\\(" "\\(?
:") ;; Make a group shy
829 (cons (regexp-quote "\\(\\sw
\\|
\\s_
\\)+")
830 "\\(?
:\\sw
+\\(?
:[-
+.
:_
]\\sw
+\\)*\\)") ;; New syntax for
832 (cons (regexp-quote "\\(\\sw
\\|
\\s_
\\)+")
833 "\\(?
:\\sw
+\\(?
:[-
+.
:_
]\\sw
+\\)*\\)") ;; New syntax for
835 (cons (regexp-quote "\\|$
") "")
836 (cons (regexp-quote "\\([\t ]")
837 "\\(?
:$
\\|
[\t ]") ;; Move "$
" in regex and make a group shy
840 ;; Sections_ / Transitions_
842 "=== rst.el.~rst_el_1_68~
:3109"
843 (rst-re 'ado-beg-2-1)
844 (cons "\\^
\\[:word
:]\\[:space
:]\\[:cntrl
:]"
845 "]!\"#$%
&'()*+,.
/:;<=>?@[\\^_`{|}~-") ;; Use real adornment
847 (cons "2\\+" "{2,\\}") ;; Use repeat count
851 (concat re-bol
"\\(" re-ems
"\\)\[^[|_\n]\\([^:\n]\\|:\\([^:\n]\\|$\\)\\)*$")
852 "=== rst.el.~rst_el_1_68~:3128"
853 (rst-re 'lin-beg
'(:grp exm-sta
) "[^\[|_\n]"
854 '(:alt
"[^:\n]" (:seq
":" (:alt
"[^:\n]" "$"))) "*$")
855 (cons "\\\\(\\[^:" "\\(?:[^:") ;; Make a group shy
856 (cons "\\\\(\\[^:" "\\(?:[^:") ;; Make a group shy
858 (should (re-equal-matches
860 (concat re-bol
"\\(" re-emt
"\\)\\(\\s *\\)$")
861 "=== rst.el.~rst_el_1_68~:3135"
862 (rst-re 'lin-beg
'(:grp exm-tag
) '(:grp hws-tag
) "$")
866 (cons "\\\\s " "[\t ]") ;; Only horizontal space
868 (should (re-equal-matches
870 (concat re-bol
"\\(\\([^.\n]\\|\\.[^.\n]\\).*\\)?\\(::\\)$")
871 "=== rst.el.~rst_el_1_68~:3145"
872 (rst-re 'lin-beg
'(:shy
(:alt
"[^.\n]" "\\.[^.\n]") ".*") "?"
876 (cons "\\\\(\\\\(" "\\(?:\\(?:") ;; Make two groups shy
878 (should (re-equal-matches
880 (concat re-bol
"\\(>>>\\|\\.\\.\\.\\)\\(.+\\)")
881 "=== rst.el.~rst_el_1_68~:3154"
882 (rst-re 'lin-beg
'(:grp
(:alt
">>>" ell-tag
)) '(:grp
".+"))
886 (cons ">>>" "\\(?:>>>") (cons "\\.\\\\)" ".\\)\\)") ;; Add a shy