diff options
author | Karl Berry <karl@freefriends.org> | 2017-03-08 23:01:35 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-03-08 23:01:35 +0000 |
commit | 6fca20c09474a7f6a3559af1c984243a83669f61 (patch) | |
tree | cbfda048c91853241ef903a84a088c1e3a66fd50 /Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty | |
parent | ddbc1f2a5f193876d6f1df544e286029c6d671f8 (diff) |
l3 (8mar17)
git-svn-id: svn://tug.org/texlive/trunk@43432 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty | 422 |
1 files changed, 253 insertions, 169 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty index 5c1c9b8be80..7c49cc0c059 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex-trace.sty @@ -18,9 +18,9 @@ %% This file is part of the "l3experimental bundle" (The Work in LPPL) %% and all files in that bundle must be distributed together. %% -%% File: l3regex.dtx Copyright (C) 2011-2016 The LaTeX3 Project -\RequirePackage{expl3}[2017/02/10] -\@ifpackagelater{expl3}{2017/02/10} +%% File: l3regex.dtx Copyright (C) 2011-2017 The LaTeX3 Project +\RequirePackage{expl3}[2017/03/07] +\@ifpackagelater{expl3}{2017/03/07} {} {% \PackageError{l3regex}{Support package l3kernel too old} @@ -32,11 +32,11 @@ }% \endinput } -\GetIdInfo$Id: l3regex.dtx 6878 2017-02-10 07:40:59Z joseph $ +\GetIdInfo$Id: l3regex.dtx 6984 2017-03-07 20:53:23Z joseph $ {L3 Experimental regular expressions} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} -\RequirePackage{l3tl-build, l3tl-analysis, l3flag, l3str-convert} +\RequirePackage{l3tl-build, l3tl-analysis, l3str-convert} \cs_generate_variant:Nn \tl_to_str:n { V } \cs_new:Npn \__regex_tmp:w { } \tl_new:N \l__regex_internal_a_tl @@ -107,17 +107,15 @@ \cs_new_protected:Npn \__regex_compute_case_changed_char: { \int_set_eq:NN \l__regex_case_changed_char_int \l__regex_current_char_int - \if_int_compare:w \l__regex_current_char_int < \c_ninety_one - \if_int_compare:w \l__regex_current_char_int < \c_sixty_five - \else: - \int_add:Nn \l__regex_case_changed_char_int { \c_thirty_two } + \if_int_compare:w \l__regex_current_char_int > `Z \exp_stop_f: + \if_int_compare:w \l__regex_current_char_int > `z \exp_stop_f: \else: + \if_int_compare:w \l__regex_current_char_int < `a \exp_stop_f: \else: + \int_sub:Nn \l__regex_case_changed_char_int { \c__str_ascii_lower_int } + \fi: \fi: \else: - \if_int_compare:w \l__regex_current_char_int < \c_one_hundred_twenty_three - \if_int_compare:w \l__regex_current_char_int < \c_ninety_seven - \else: - \int_sub:Nn \l__regex_case_changed_char_int { \c_thirty_two } - \fi: + \if_int_compare:w \l__regex_current_char_int < `A \exp_stop_f: \else: + \int_add:Nn \l__regex_case_changed_char_int { \c__str_ascii_lower_int } \fi: \fi: } @@ -130,7 +128,7 @@ 1 \or: 4 \or: 10 \or: 40 \or: 100 \or: \or: 1000 \or: 4000 \or: 10000 \or: \or: 100000 \or: 400000 - \or: 1000000 \or: 4000000 \else: 1*\c_zero + \or: 1000000 \or: 4000000 \else: 1*0 \fi: } \cs_new_protected:Npn \__regex_item_catcode:nT #1 @@ -151,23 +149,25 @@ \fi: \fi: } -\cs_new_protected:Npn \__regex_item_exact_cs:c #1 +\cs_new_protected:Npn \__regex_item_exact_cs:n #1 { - \int_compare:nNnTF \l__regex_current_catcode_int = \c_zero + \int_compare:nNnTF \l__regex_current_catcode_int = 0 { - \str_if_eq_x:nnTF + \tl_set:Nx \l__regex_internal_a_tl { + \scan_stop: \exp_after:wN \exp_after:wN \exp_after:wN \cs_to_str:N \tex_the:D \tex_toks:D \l__regex_current_pos_int + \scan_stop: } - { #1 } + \tl_if_in:noTF { \scan_stop: #1 \scan_stop: } \l__regex_internal_a_tl { \__regex_break_true:w } { } } { } } \cs_new_protected:Npn \__regex_item_cs:n #1 { - \int_compare:nNnT \l__regex_current_catcode_int = \c_zero + \int_compare:nNnT \l__regex_current_catcode_int = 0 { \group_begin: \tl_set:Nx \l__regex_cs_name_tl @@ -189,70 +189,79 @@ } } \cs_new_protected:Npn \__regex_prop_d: - { \__regex_item_caseful_range:nn \c_forty_eight { 57 } } % 0--9 + { \__regex_item_caseful_range:nn { `0 } { `9 } } \cs_new_protected:Npn \__regex_prop_h: { - \__regex_item_caseful_equal:n \c_thirty_two % space - \__regex_item_caseful_equal:n \c_nine % tab + \__regex_item_caseful_equal:n { `\ } + \__regex_item_caseful_equal:n { `\^^I } } \cs_new_protected:Npn \__regex_prop_s: { - \__regex_item_caseful_equal:n \c_thirty_two % space - \__regex_item_caseful_equal:n \c_nine % tab - \__regex_item_caseful_equal:n \c_ten % lf - \__regex_item_caseful_equal:n \c_twelve % ff - \__regex_item_caseful_equal:n \c_thirteen % cr + \__regex_item_caseful_equal:n { `\ } + \__regex_item_caseful_equal:n { `\^^I } + \__regex_item_caseful_equal:n { `\^^J } + \__regex_item_caseful_equal:n { `\^^L } + \__regex_item_caseful_equal:n { `\^^M } } \cs_new_protected:Npn \__regex_prop_v: - { \__regex_item_caseful_range:nn \c_ten \c_thirteen } % lf, vtab, ff, cr + { \__regex_item_caseful_range:nn { `\^^J } { `\^^M } } % lf, vtab, ff, cr \cs_new_protected:Npn \__regex_prop_w: { - \__regex_item_caseful_range:nn \c_ninety_seven { 122 } % a--z - \__regex_item_caseful_range:nn \c_sixty_five { 90 } % A--Z - \__regex_item_caseful_range:nn \c_forty_eight { 57 } % 0--9 - \__regex_item_caseful_equal:n { 95 } % _ + \__regex_item_caseful_range:nn { `a } { `z } + \__regex_item_caseful_range:nn { `A } { `Z } + \__regex_item_caseful_range:nn { `0 } { `9 } + \__regex_item_caseful_equal:n { `_ } } \cs_new_protected:Npn \__regex_prop_N: - { \__regex_item_reverse:n { \__regex_item_caseful_equal:n \c_ten } } + { + \__regex_item_reverse:n + { \__regex_item_caseful_equal:n { `\^^J } } + } \cs_new_protected:Npn \__regex_posix_alnum: { \__regex_posix_alpha: \__regex_posix_digit: } \cs_new_protected:Npn \__regex_posix_alpha: { \__regex_posix_lower: \__regex_posix_upper: } \cs_new_protected:Npn \__regex_posix_ascii: - { \__regex_item_caseful_range:nn \c_zero \c_one_hundred_twenty_seven } + { + \__regex_item_caseful_range:nn + \c__str_ascii_min_int + \c__str_ascii_max_int + } \cs_new_eq:NN \__regex_posix_blank: \__regex_prop_h: \cs_new_protected:Npn \__regex_posix_cntrl: { - \__regex_item_caseful_range:nn \c_zero { 31 } - \__regex_item_caseful_equal:n \c_one_hundred_twenty_seven + \__regex_item_caseful_range:nn + \c__str_ascii_min_int + \c__str_ascii_max_control_int + \__regex_item_caseful_equal:n \c__str_ascii_max_int } \cs_new_eq:NN \__regex_posix_digit: \__regex_prop_d: \cs_new_protected:Npn \__regex_posix_graph: - { \__regex_item_caseful_range:nn { 33 } { 126 } } + { \__regex_item_caseful_range:nn { `! } { `\~ } } \cs_new_protected:Npn \__regex_posix_lower: - { \__regex_item_caseful_range:nn \c_ninety_seven { 122 } } + { \__regex_item_caseful_range:nn { `a } { `z } } \cs_new_protected:Npn \__regex_posix_print: - { \__regex_item_caseful_range:nn \c_thirty_two { 126 } } + { \__regex_item_caseful_range:nn { `\ } { `\~ } } \cs_new_protected:Npn \__regex_posix_punct: { - \__regex_item_caseful_range:nn { 33 } { 47 } - \__regex_item_caseful_range:nn { 58 } { 64 } - \__regex_item_caseful_range:nn { 91 } { 96 } - \__regex_item_caseful_range:nn { 123 } { 126 } + \__regex_item_caseful_range:nn { `! } { `/ } + \__regex_item_caseful_range:nn { `: } { `@ } + \__regex_item_caseful_range:nn { `[ } { `` } + \__regex_item_caseful_range:nn { `\{ } { `\~ } } \cs_new_protected:Npn \__regex_posix_space: { - \__regex_item_caseful_equal:n \c_thirty_two - \__regex_item_caseful_range:nn \c_nine \c_thirteen + \__regex_item_caseful_equal:n { `\ } + \__regex_item_caseful_range:nn { `\^^I } { `\^^M } } \cs_new_protected:Npn \__regex_posix_upper: - { \__regex_item_caseful_range:nn \c_sixty_five { 90 } } + { \__regex_item_caseful_range:nn { `A } { `Z } } \cs_new_eq:NN \__regex_posix_word: \__regex_prop_w: \cs_new_protected:Npn \__regex_posix_xdigit: { \__regex_posix_digit: - \__regex_item_caseful_range:nn \c_sixty_five { 70 } - \__regex_item_caseful_range:nn \c_ninety_seven { 102 } + \__regex_item_caseful_range:nn { `A } { `F } + \__regex_item_caseful_range:nn { `a } { `f } } \cs_new_protected:Npn \__regex_escape_use:nnnn #1#2#3#4 { @@ -261,7 +270,7 @@ \cs_set:Npn \__regex_escape_unescaped:N ##1 { #1 } \cs_set:Npn \__regex_escape_escaped:N ##1 { #2 } \cs_set:Npn \__regex_escape_raw:N ##1 { #3 } - \int_set:Nn \tex_escapechar:D { 92 } + \int_set:Nn \tex_escapechar:D { `\\ } \__str_gset_other:Nn \g__regex_internal_tl { #4 } \tl_set:Nx \l__regex_internal_b_tl { @@ -316,12 +325,12 @@ } \cs_new:Npn \__regex_escape_x_end:w #1 ; { - \int_compare:nNnTF {#1} < \c_two_hundred_fifty_six + \int_compare:nNnTF {#1} > \c__str_max_byte_int + { \__regex_escape_x_large:n {#1} } { \exp_last_unbraced:Nf \__regex_escape_raw:N { \__str_output_byte:n {#1} } } - { \__regex_escape_x_large:n {#1} } } \group_begin: \char_set_catcode_other:n { 0 } @@ -336,7 +345,7 @@ { \if_false: } \fi: } { - \char_set_lccode:nn { \c_zero } {#1} + \char_set_lccode:nn { 0 } {#1} \tex_lowercase:D { \tl_set:Nx \l__regex_internal_b_tl @@ -407,47 +416,53 @@ } \prg_new_conditional:Npnn \__regex_char_if_special:N #1 { TF } { - \if_int_compare:w `#1 < \c_ninety_one - \if_int_compare:w `#1 < \c_fifty_eight - \if_int_compare:w `#1 < \c_forty_eight - \if_int_compare:w `#1 < \c_thirty_two - \prg_return_false: \else: \prg_return_true: \fi: - \else: \prg_return_false: \fi: + \if_int_compare:w `#1 > `Z \exp_stop_f: + \if_int_compare:w `#1 > `z \exp_stop_f: + \if_int_compare:w `#1 < \c__str_ascii_max_int + \prg_return_true: \else: \prg_return_false: \fi: \else: - \if_int_compare:w `#1 < \c_sixty_five + \if_int_compare:w `#1 < `a \exp_stop_f: \prg_return_true: \else: \prg_return_false: \fi: \fi: \else: - \if_int_compare:w `#1 < \c_one_hundred_twenty_three - \if_int_compare:w `#1 < \c_ninety_seven + \if_int_compare:w `#1 > `9 \exp_stop_f: + \if_int_compare:w `#1 < `A \exp_stop_f: \prg_return_true: \else: \prg_return_false: \fi: \else: - \if_int_compare:w `#1 < \c_one_hundred_twenty_seven - \prg_return_true: \else: \prg_return_false: \fi: + \if_int_compare:w `#1 < `0 \exp_stop_f: + \if_int_compare:w `#1 < `\ \exp_stop_f: + \prg_return_false: \else: \prg_return_true: \fi: + \else: \prg_return_false: \fi: \fi: \fi: } \prg_new_conditional:Npnn \__regex_char_if_alphanumeric:N #1 { TF } { - \if_int_compare:w `#1 < \c_ninety_one - \if_int_compare:w `#1 < \c_fifty_eight - \if_int_compare:w `#1 < \c_forty_eight - \prg_return_false: \else: \prg_return_true: \fi: + \if_int_compare:w `#1 > `Z \exp_stop_f: + \if_int_compare:w `#1 > `z \exp_stop_f: + \prg_return_false: \else: - \if_int_compare:w `#1 < \c_sixty_five + \if_int_compare:w `#1 < `a \exp_stop_f: \prg_return_false: \else: \prg_return_true: \fi: \fi: \else: - \if_int_compare:w `#1 < \c_one_hundred_twenty_three - \if_int_compare:w `#1 < \c_ninety_seven + \if_int_compare:w `#1 > `9 \exp_stop_f: + \if_int_compare:w `#1 < `A \exp_stop_f: \prg_return_false: \else: \prg_return_true: \fi: \else: - \prg_return_false: + \if_int_compare:w `#1 < `0 \exp_stop_f: + \prg_return_false: \else: \prg_return_true: \fi: \fi: \fi: } \int_new:N \l__regex_group_level_int \int_new:N \l__regex_mode_int +\int_const:Nn \c__regex_cs_in_class_mode_int { -6 } +\int_const:Nn \c__regex_cs_mode_int { -2 } +\int_const:Nn \c__regex_outer_mode_int { 0 } +\int_const:Nn \c__regex_catcode_mode_int { 2 } +\int_const:Nn \c__regex_class_mode_int { 3 } +\int_const:Nn \c__regex_catcode_in_class_mode_int { 6 } \int_new:N \l__regex_catcodes_int \int_new:N \l__regex_default_catcodes_int \bool_new:N \l__regex_catcodes_bool @@ -482,7 +497,7 @@ \prg_new_conditional:Npnn \__regex_if_raw_digit:NN #1#2 { TF } { \if_meaning:w \__regex_compile_raw:N #1 - \if_int_compare:w \c_one < 1 #2 \exp_stop_f: + \if_int_compare:w 1 < 1 #2 \exp_stop_f: \prg_return_true: \else: \prg_return_false: @@ -504,7 +519,7 @@ \if_int_odd:w \l__regex_mode_int \exp_after:wN \use_ii:nn \else: - \if_int_compare:w \l__regex_mode_int < \c_zero + \if_int_compare:w \l__regex_mode_int < \c__regex_outer_mode_int \exp_after:wN \exp_after:wN \exp_after:wN \use_i:nn \else: \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nn @@ -516,7 +531,7 @@ \if_int_odd:w \l__regex_mode_int \exp_after:wN \use_i:nn \else: - \if_int_compare:w \l__regex_mode_int > \c_zero + \if_int_compare:w \l__regex_mode_int > \c__regex_outer_mode_int \exp_after:wN \exp_after:wN \exp_after:wN \use_i:nn \else: \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nn @@ -525,7 +540,7 @@ } \cs_new:Npn \__regex_if_within_catcode:TF { - \if_int_compare:w \l__regex_mode_int > \c_zero + \if_int_compare:w \l__regex_mode_int > \c__regex_outer_mode_int \exp_after:wN \use_i:nn \else: \exp_after:wN \use_ii:nn @@ -533,10 +548,10 @@ } \cs_new_protected:Npn \__regex_chk_c_allowed:T { - \if_int_compare:w \l__regex_mode_int = \c_zero + \if_int_compare:w \l__regex_mode_int = \c__regex_outer_mode_int \exp_after:wN \use:n \else: - \if_int_compare:w \l__regex_mode_int = \c_three + \if_int_compare:w \l__regex_mode_int = \c__regex_class_mode_int \exp_after:wN \exp_after:wN \exp_after:wN \use:n \else: \__msg_kernel_error:nn { regex } { c-bad-mode } @@ -546,11 +561,11 @@ } \cs_new_protected:Npn \__regex_mode_quit_c: { - \if_int_compare:w \l__regex_mode_int = \c_two - \l__regex_mode_int = \c_zero + \if_int_compare:w \l__regex_mode_int = \c__regex_catcode_mode_int + \int_set_eq:NN \l__regex_mode_int \c__regex_outer_mode_int \else: - \if_int_compare:w \l__regex_mode_int = \c_six - \l__regex_mode_int = \c_three + \if_int_compare:w \l__regex_mode_int = \c__regex_catcode_in_class_mode_int + \int_set_eq:NN \l__regex_mode_int \c__regex_class_mode_int \fi: \fi: } @@ -573,7 +588,7 @@ \prg_do_nothing: \prg_do_nothing: } { } - \if_int_compare:w \l__regex_group_level_int > \c_zero + \if_int_compare:w \l__regex_group_level_int > 0 \exp_stop_f: \__msg_kernel_error:nnx { regex } { missing-rparen } { \int_use:N \l__regex_group_level_int } \prg_replicate:nn @@ -594,8 +609,8 @@ \cs_new_protected:Npn \__regex_compile:n #1 { \__regex_compile:w - \int_set:Nn \tex_escapechar:D { 92 } - \int_set_eq:NN \l__regex_mode_int \c_zero + \int_set:Nn \tex_escapechar:D { `\\ } + \int_set_eq:NN \l__regex_mode_int \c__regex_outer_mode_int \__regex_escape_use:nnnn { \__regex_char_if_special:NTF ##1 @@ -609,14 +624,12 @@ { #1 } \prg_do_nothing: \prg_do_nothing: \prg_do_nothing: \prg_do_nothing: - \int_compare:nNnT \l__regex_mode_int = \c_two + \int_compare:nNnT \l__regex_mode_int = \c__regex_catcode_mode_int { \__msg_kernel_error:nn { regex } { c-trailing } } - \int_compare:nNnT \l__regex_mode_int < \c_zero + \int_compare:nNnT \l__regex_mode_int < \c__regex_outer_mode_int { \__msg_kernel_error:nn { regex } { c-missing-rbrace } - \__regex_compile_end: - \__regex_compile_one:x - { \__regex_item_cs:n { \exp_not:o \l__regex_internal_regex } } + \__regex_compile_end_cs: \prg_do_nothing: \prg_do_nothing: \prg_do_nothing: \prg_do_nothing: } @@ -839,7 +852,7 @@ } \cs_new_protected:cpn { __regex_prop_.: } { - \if_int_compare:w \l__regex_current_char_int > - \c_two + \if_int_compare:w \l__regex_current_char_int > - 2 \exp_stop_f: \exp_after:wN \__regex_break_true:w \fi: } @@ -906,11 +919,11 @@ { \__regex_if_in_class:TF { - \if_int_compare:w \l__regex_mode_int > \c_sixteen + \if_int_compare:w \l__regex_mode_int > \c__regex_catcode_in_class_mode_int \__tl_build_one:n { \if_false: { \fi: } } \fi: - \tex_advance:D \l__regex_mode_int - \c_fifteen - \tex_divide:D \l__regex_mode_int \c_thirteen + \tex_advance:D \l__regex_mode_int - 15 \exp_stop_f: + \tex_divide:D \l__regex_mode_int 13 \exp_stop_f: \if_int_odd:w \l__regex_mode_int \else: \exp_after:wN \__regex_compile_quantifier:w \fi: @@ -938,7 +951,7 @@ } \cs_new_protected:Npn \__regex_compile_class_catcode:w #1; { - \if_int_compare:w \l__regex_mode_int = \c_two + \if_int_compare:w \l__regex_mode_int = \c__regex_catcode_mode_int \__tl_build_one:n { \__regex_class:NnnnN \c_true_bool { \if_false: } \fi: } \fi: @@ -1040,7 +1053,7 @@ } \cs_new_protected:Npn \__regex_compile_group_end: { - \if_int_compare:w \l__regex_group_level_int > \c_zero + \if_int_compare:w \l__regex_group_level_int > 0 \exp_stop_f: \__tl_build_one:n { \if_false: { \fi: } } \__tl_build_end: \int_set_eq:NN \l__regex_catcodes_int \l__regex_default_catcodes_int @@ -1132,7 +1145,11 @@ { \int_set_eq:Nc \l__regex_catcodes_int { c__regex_catcode_#2_int } \l__regex_mode_int - = \if_case:w \l__regex_mode_int \c_two \else: \c_six \fi: + = \if_case:w \l__regex_mode_int + \c__regex_catcode_mode_int + \else: + \c__regex_catcode_in_class_mode_int + \fi: } } { \cs_if_exist_use:cF { __regex_compile_c_#2:w } } @@ -1144,7 +1161,11 @@ \cs_new_protected:cpn { __regex_compile_c_[:w } #1#2 { \l__regex_mode_int - = \if_case:w \l__regex_mode_int \c_two \else: \c_six \fi: + = \if_case:w \l__regex_mode_int + \c__regex_catcode_mode_int + \else: + \c__regex_catcode_in_class_mode_int + \fi: \int_zero:N \l__regex_catcodes_int \str_if_eq:nnTF { #1 #2 } { \__regex_compile_special:N ^ } { @@ -1197,17 +1218,72 @@ \__regex_compile:w \__regex_disable_submatches: \l__regex_mode_int - = - \if_case:w \l__regex_mode_int \c_two \else: \c_six \fi: + = \if_case:w \l__regex_mode_int + \c__regex_cs_mode_int + \else: + \c__regex_cs_in_class_mode_int + \fi: } +\flag_new:n { __regex_cs } \cs_new_protected:cpn { __regex_compile_ \c_right_brace_str : } { \__regex_if_in_cs:TF + { \__regex_compile_end_cs: } + { \exp_after:wN \__regex_compile_raw:N \c_right_brace_str } + } +\cs_new_protected:Npn \__regex_compile_end_cs: + { + \__regex_compile_end: + \flag_clear:n { __regex_cs } + \tl_set:Nx \l__regex_internal_a_tl { - \__regex_compile_end: - \__regex_compile_one:x + \exp_after:wN \__regex_compile_cs_aux:Nn \l__regex_internal_regex + \q_nil \q_nil \q_recursion_stop + } + \exp_args:Nx \__regex_compile_one:x + { + \flag_if_raised:nTF { __regex_cs } { \__regex_item_cs:n { \exp_not:o \l__regex_internal_regex } } + { \__regex_item_exact_cs:n { \tl_tail:N \l__regex_internal_a_tl } } + } + } +\cs_new:Npn \__regex_compile_cs_aux:Nn #1#2 + { + \cs_if_eq:NNTF #1 \__regex_branch:n + { + \scan_stop: + \__regex_compile_cs_aux:NNnnnN #2 + \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_recursion_stop + \__regex_compile_cs_aux:Nn + } + { + \quark_if_nil:NF #1 { \flag_raise:n { __regex_cs } } + \use_none_delimit_by_q_recursion_stop:w + } + } +\cs_new:Npn \__regex_compile_cs_aux:NNnnnN #1#2#3#4#5#6 + { + \bool_lazy_all:nTF + { + { \cs_if_eq_p:NN #1 \__regex_class:NnnnN } + {#2} + { \tl_if_head_eq_meaning_p:nN {#3} \__regex_item_caseful_equal:n } + { \int_compare_p:nNn { \tl_count:n {#3} } = { 2 } } + { \int_compare_p:nNn {#5} = { 0 } } + } + { + \prg_replicate:nn {#4} + { \char_generate:nn { \use_ii:nn #3 } {12} } + \__regex_compile_cs_aux:NNnnnN + } + { + \quark_if_nil:NF #1 + { + \flag_raise:n { __regex_cs } + \use_i_delimit_by_q_recursion_stop:nw + } + \use_none_delimit_by_q_recursion_stop:w } - { \exp_after:wN \__regex_compile_raw:N \c_right_brace_str } } \cs_new_protected:cpn { __regex_compile_/u: } #1#2 { @@ -1247,7 +1323,7 @@ \cs_new_protected:Npn \__regex_compile_u_end: { \tl_set:Nv \l__regex_internal_a_tl { \l__regex_internal_a_tl } - \if_int_compare:w \l__regex_mode_int = \c_zero + \if_int_compare:w \l__regex_mode_int = \c__regex_outer_mode_int \__regex_compile_u_not_cs: \else: \__regex_compile_u_in_cs: @@ -1277,8 +1353,8 @@ { \__regex_class:NnnnN \c_true_bool { - \if_int_compare:w "##2 = \c_zero - \__regex_item_exact_cs:c { \exp_after:wN \cs_to_str:N ##1 } + \if_int_compare:w "##2 = 0 \exp_stop_f: + \__regex_item_exact_cs:n { \exp_after:wN \cs_to_str:N ##1 } \else: \__regex_item_exact:nn { \__int_value:w "##2 } { ##3 } \fi: @@ -1289,11 +1365,11 @@ } \cs_new_protected:cpn { __regex_compile_/K: } { - \int_compare:nNnTF \l__regex_mode_int = \c_zero + \int_compare:nNnTF \l__regex_mode_int = \c__regex_outer_mode_int { \__tl_build_one:n { \__regex_command_K: } } { \__regex_compile_raw_error:N K } } -\cs_new_protected:Npn \__regex_show:Nx #1#2 +\cs_new_protected:Npn \__regex_show:Nn #1#2 { \__tl_build:Nw \l__regex_internal_a_tl \cs_set_protected:Npn \__regex_branch:n @@ -1335,16 +1411,16 @@ { \__regex_show_scope:nn { Reversed~match } } \cs_set_protected:Npn \__regex_item_exact:nn ##1##2 { \__regex_show_one:n { char~##2,~catcode~##1 } } - \cs_set_protected:Npn \__regex_item_exact_cs:c ##1 - { \__regex_show_one:n { control~sequence~\iow_char:N\\##1 } } + \cs_set_eq:NN \__regex_item_exact_cs:n \__regex_show_item_exact_cs:n \cs_set_protected:Npn \__regex_item_cs:n { \__regex_show_scope:nn { control~sequence } } \cs_set:cpn { __regex_prop_.: } { \__regex_show_one:n { any~token } } \seq_clear:N \l__regex_show_prefix_seq \__regex_show_push:n { ~ } - #1 + \cs_if_exist_use:N #1 \__tl_build_end: - \__msg_show_wrap:n { >~Compiled~regex~#2: \l__regex_internal_a_tl } + \__msg_show_variable:NNNnn #1 \cs_if_exist:NTF ? { } + { >~Compiled~regex~#2: \l__regex_internal_a_tl } } \cs_new_protected:Npn \__regex_show_one:n #1 { @@ -1439,6 +1515,14 @@ \bool_if:NF #1 { negative~ } class } } +\cs_new_protected:Npn \__regex_show_item_exact_cs:n #1 + { + \seq_set_split:Nnn \l__regex_internal_seq { \scan_stop: } {#1} + \seq_set_map:NNn \l__regex_internal_seq + \l__regex_internal_seq { \iow_char:N\\##1 } + \__regex_show_one:n + { control~sequence~ \seq_use:Nn \l__regex_internal_seq { ~or~ } } + } \int_new:N \l__regex_min_state_int \int_new:N \l__regex_max_state_int \int_new:N \l__regex_left_state_int @@ -1454,7 +1538,7 @@ \cs_new_protected:Npn \__regex_build:N #1 { \trace_push:nnn { regex } { 1 } { __regex_build } - \int_set:Nn \tex_escapechar:D { 92 } + \int_set:Nn \tex_escapechar:D { `\\ } \int_zero:N \l__regex_capturing_group_int \int_set_eq:NN \l__regex_max_state_int \l__regex_min_state_int \__regex_build_new_state: @@ -1525,7 +1609,7 @@ L=\int_use:N \l__regex_left_state_int ~ -> ~ R=\int_use:N \l__regex_right_state_int ~ -> ~ M=\int_use:N \l__regex_max_state_int ~ -> ~ - \int_eval:n { \l__regex_max_state_int + \c_one } + \int_eval:n { \l__regex_max_state_int + 1 } } \tex_toks:D \l__regex_max_state_int { } \int_set_eq:NN \l__regex_left_state_int \l__regex_right_state_int @@ -1573,7 +1657,7 @@ } \cs_new_protected:Npn \__regex_class_repeat:nN #1#2 { - \if_int_compare:w #1 = \c_zero + \if_int_compare:w #1 = 0 \exp_stop_f: \__regex_build_transitions_lazyness:NNNNN #2 \__regex_action_free:n \l__regex_right_state_int \__regex_tests_action_cost:n \l__regex_left_state_int @@ -1589,7 +1673,7 @@ { \__regex_class_repeat:n {#1} \int_set:Nn \l__regex_internal_a_int - { \l__regex_max_state_int + #2 - \c_one } + { \l__regex_max_state_int + #2 - 1 } \prg_replicate:nn { #2 } { \__regex_build_transitions_lazyness:NNNNN #3 @@ -1600,7 +1684,7 @@ \cs_new_protected:Npn \__regex_group_aux:nnnnN #1#2#3#4#5 { \trace_push:nnn { regex } { 1 } { __regex_group } - \if_int_compare:w #3 = \c_zero + \if_int_compare:w #3 = 0 \exp_stop_f: \__regex_build_new_state: \__regex_build_transition_right:nNn \__regex_action_free_group:n \l__regex_left_state_int \l__regex_right_state_int @@ -1664,9 +1748,9 @@ } \cs_new_protected:Npn \__regex_group_repeat:nn #1#2 { - \if_int_compare:w #2 = \c_zero + \if_int_compare:w #2 = 0 \exp_stop_f: \int_set:Nn \l__regex_max_state_int - { \l__regex_left_state_int - \c_one } + { \l__regex_left_state_int - 1 } \__regex_build_new_state: \else: \__regex_group_repeat_aux:n {#2} @@ -1677,7 +1761,7 @@ } \cs_new_protected:Npn \__regex_group_submatches:nNN #1#2#3 { - \if_int_compare:w #1 > - \c_one + \if_int_compare:w #1 > - 1 \exp_stop_f: \__regex_toks_put_left:Nx #2 { \__regex_action_submatch:n { #1 < } } \__regex_toks_put_left:Nx #3 { \__regex_action_submatch:n { #1 > } } \fi: @@ -1688,10 +1772,10 @@ \l__regex_right_state_int \l__regex_max_state_int \int_set_eq:NN \l__regex_internal_a_int \l__regex_left_state_int \int_set_eq:NN \l__regex_internal_b_int \l__regex_max_state_int - \if_int_compare:w \__int_eval:w #1 > \c_one + \if_int_compare:w \__int_eval:w #1 > 1 \exp_stop_f: \int_set:Nn \l__regex_internal_c_int { - ( #1 - \c_one ) + ( #1 - 1 ) * ( \l__regex_internal_b_int - \l__regex_internal_a_int ) } \tex_advance:D \l__regex_right_state_int \l__regex_internal_c_int @@ -1700,18 +1784,18 @@ { \tex_toks:D \l__regex_internal_b_int = \tex_toks:D \l__regex_internal_a_int - \tex_advance:D \l__regex_internal_a_int \c_one - \tex_advance:D \l__regex_internal_b_int \c_one + \int_incr:N \l__regex_internal_a_int + \int_incr:N \l__regex_internal_b_int } \fi: } \cs_new_protected:Npn \__regex_group_repeat:nnN #1#2#3 { - \if_int_compare:w #2 = \c_zero + \if_int_compare:w #2 = 0 \exp_stop_f: \__regex_group_submatches:nNN {#1} \l__regex_left_state_int \l__regex_right_state_int \int_set:Nn \l__regex_internal_a_int - { \l__regex_left_state_int - \c_one } + { \l__regex_left_state_int - 1 } \__regex_build_transition_right:nNn \__regex_action_free:n \l__regex_right_state_int \l__regex_internal_a_int \__regex_build_new_state: @@ -1751,16 +1835,16 @@ \l__regex_left_state_int \l__regex_max_state_int } \else: - \prg_replicate:nn { #3 - \c_one } + \prg_replicate:nn { #3 - 1 } { \int_sub:Nn \l__regex_right_state_int { \l__regex_internal_b_int - \l__regex_internal_a_int } \__regex_build_transition_right:nNn \__regex_action_free:n \l__regex_right_state_int \l__regex_max_state_int } - \if_int_compare:w #2 = \c_zero + \if_int_compare:w #2 = 0 \exp_stop_f: \int_set:Nn \l__regex_right_state_int - { \l__regex_left_state_int - \c_one } + { \l__regex_left_state_int - 1 } \else: \int_sub:Nn \l__regex_right_state_int { \l__regex_internal_b_int - \l__regex_internal_a_int } @@ -1842,7 +1926,7 @@ \trace_push:nnx { regex } { 1 } { __regex_match } \trace:nnx { regex } { 1 } { analyzing~query~token~list } \int_zero:N \l__regex_balance_int - \int_set:Nn \l__regex_current_pos_int { \c_two * \l__regex_max_state_int } + \int_set:Nn \l__regex_current_pos_int { 2 * \l__regex_max_state_int } \__regex_query_set:nnn { } { -1 } { -2 } \int_set_eq:NN \l__regex_min_pos_int \l__regex_current_pos_int \__tl_analysis_map_inline:nn {#1} @@ -1852,13 +1936,13 @@ \trace:nnx { regex } { 1 } { initializing } \bool_gset_false:N \g__regex_success_bool \int_step_inline:nnnn - \l__regex_min_state_int \c_one { \l__regex_max_state_int - \c_one } - { \tex_dimen:D ##1 \c_one sp \scan_stop: } + \l__regex_min_state_int { 1 } { \l__regex_max_state_int - 1 } + { \tex_dimen:D ##1 ~ 1 sp \scan_stop: } \int_set_eq:NN \l__regex_min_active_int \l__regex_max_state_int - \int_set_eq:NN \l__regex_step_int \c_zero + \int_zero:N \l__regex_step_int \int_set_eq:NN \l__regex_success_pos_int \l__regex_min_pos_int \int_set:Nn \l__regex_submatch_int - { \c_two * \l__regex_max_state_int } + { 2 * \l__regex_max_state_int } \bool_set_false:N \l__regex_empty_success_bool \__regex_match_once: \trace_pop:nnx { regex } { 1 } { __regex_match } @@ -1877,7 +1961,7 @@ \int_set_eq:NN \l__regex_max_active_int \l__regex_min_active_int \__regex_store_state:n { \l__regex_min_state_int } \int_set:Nn \l__regex_current_pos_int - { \l__regex_start_pos_int - \c_one } + { \l__regex_start_pos_int - 1 } \__regex_query_get: \__regex_match_loop: \l__regex_every_match_tl @@ -1900,7 +1984,7 @@ } \cs_new_protected:Npn \__regex_match_loop: { - \tex_advance:D \l__regex_step_int \c_two + \tex_advance:D \l__regex_step_int 2 \exp_stop_f: \int_incr:N \l__regex_current_pos_int \int_set_eq:NN \l__regex_last_char_int \l__regex_current_char_int \int_set_eq:NN \l__regex_case_changed_char_int \c_max_int @@ -1926,7 +2010,7 @@ { \__int_value:w \tex_skip:D #1 } { \tex_the:D \tex_toks:D #1 } \exp_after:wN \__regex_match_one_active:w - \__int_value:w \__int_eval:w #1 + \c_one \exp_after:wN ; + \__int_value:w \__int_eval:w #1 + 1 \exp_after:wN ; \fi: } \cs_new_protected:Npn \__regex_query_set:nnn #1#2#3 @@ -1958,7 +2042,7 @@ = \l__regex_step_int sp \scan_stop: \tex_the:D \tex_toks:D \l__regex_current_state_int \tex_dimen:D \l__regex_current_state_int - = \__int_eval:w \l__regex_step_int + \c_one \__int_eval_end: sp \scan_stop: + = \__int_eval:w \l__regex_step_int + 1 \__int_eval_end: sp \scan_stop: } \cs_new_protected:Npn \__regex_use_state_and_submatches:nn #1 #2 { @@ -2063,7 +2147,7 @@ \fi: \tex_the:D \tex_toks:D #1 \exp_stop_f: \exp_after:wN \__regex_query_range_loop:ww - \__int_value:w \__int_eval:w #1 + \c_one ; #2 ; + \__int_value:w \__int_eval:w #1 + 1 ; #2 ; } \cs_new:Npn \__regex_query_submatch:n #1 { @@ -2093,7 +2177,7 @@ { \__tl_build_one:n ##1 } {#1} \prg_do_nothing: \prg_do_nothing: - \if_int_compare:w \l__regex_replacement_csnames_int > \c_zero + \if_int_compare:w \l__regex_replacement_csnames_int > 0 \exp_stop_f: \__msg_kernel_error:nnx { regex } { replacement-missing-rbrace } { \int_use:N \l__regex_replacement_csnames_int } \__tl_build_one:x @@ -2123,7 +2207,7 @@ { \cs_if_exist_use:cF { __regex_replacement_#1:w } { - \if_int_compare:w \c_one < 1#1 \exp_stop_f: + \if_int_compare:w 1 < 1#1 \exp_stop_f: \__regex_replacement_put_submatch:n {#1} \else: \__tl_build_one:o { \token_to_str:N #1 } @@ -2134,7 +2218,7 @@ { \if_int_compare:w #1 < \l__regex_capturing_group_int \__tl_build_one:n { \__regex_query_submatch:n { #1 + ##1 } } - \if_int_compare:w \l__regex_replacement_csnames_int = \c_zero + \if_int_compare:w \l__regex_replacement_csnames_int = 0 \exp_stop_f: \tl_put_right:Nn \l__regex_balance_tl { + \__regex_submatch_balance:n { \__int_eval:w #1+##1 \__int_eval_end: } } \fi: @@ -2153,9 +2237,9 @@ { \token_if_eq_meaning:NNTF #1 \__tl_build_one:n { - \if_int_compare:w \c_one < 1#2 \exp_stop_f: + \if_int_compare:w 1 < 1#2 \exp_stop_f: \int_set:Nn \l__regex_internal_a_int - { \c_ten * \l__regex_internal_a_int + #2 } + { 10 * \l__regex_internal_a_int + #2 } \exp_after:wN \use_i:nnn \exp_after:wN \__regex_replacement_g_digits:NN \else: @@ -2209,7 +2293,7 @@ } \cs_new_protected:Npn \__regex_replacement_rbrace:N #1 { - \if_int_compare:w \l__regex_replacement_csnames_int > \c_zero + \if_int_compare:w \l__regex_replacement_csnames_int > 0 \exp_stop_f: \__tl_build_one:n \cs_end: \int_decr:N \l__regex_replacement_csnames_int \else: @@ -2222,7 +2306,7 @@ \if_meaning:w \prg_do_nothing: #3 \__msg_kernel_error:nn { regex } { replacement-catcode-end } \else: - \tex_lccode:D \c_zero = `#3 \scan_stop: + \tex_lccode:D 0 = `#3 \scan_stop: \tex_lowercase:D { \__tl_build_one:n {#1} } \fi: } @@ -2232,7 +2316,7 @@ \char_set_catcode_group_begin:N \^^@ \cs_new_protected:Npn \__regex_replacement_c_B:w { - \if_int_compare:w \l__regex_replacement_csnames_int = \c_zero + \if_int_compare:w \l__regex_replacement_csnames_int = 0 \exp_stop_f: \int_incr:N \l__regex_balance_int \fi: \__regex_replacement_char:nNN @@ -2246,7 +2330,7 @@ \char_set_catcode_group_end:N \^^@ \cs_new_protected:Npn \__regex_replacement_c_E:w { - \if_int_compare:w \l__regex_replacement_csnames_int = \c_zero + \if_int_compare:w \l__regex_replacement_csnames_int = 0 \exp_stop_f: \int_decr:N \l__regex_balance_int \fi: \__regex_replacement_char:nNN @@ -2272,10 +2356,10 @@ \if_meaning:w \prg_do_nothing: #2 \__msg_kernel_error:nn { regex } { replacement-catcode-end } \else: - \if_int_compare:w `#2 = \c_zero + \if_int_compare:w `#2 = 0 \exp_stop_f: \__msg_kernel_error:nn { regex } { replacement-null-space } \fi: - \tex_lccode:D 32 = `#2 \scan_stop: + \tex_lccode:D `\ = `#2 \scan_stop: \tex_lowercase:D { \__tl_build_one:n {~} } \fi: } @@ -2311,11 +2395,11 @@ \cs_new_protected:Npn \regex_show:n #1 { \__regex_compile:n {#1} - \__regex_show:Nx \l__regex_internal_regex + \__regex_show:Nn \l__regex_internal_regex { { \tl_to_str:n {#1} } } } \cs_new_protected:Npn \regex_show:N #1 - { \__regex_show:Nx #1 { variable~\token_to_str:N #1 } } + { \__regex_show:Nn #1 { variable~\token_to_str:N #1 } } \prg_new_protected_conditional:Npnn \regex_match:nn #1#2 { T , F , TF } { \__regex_if_match:nn { \__regex_build:n {#1} } {#2} @@ -2432,14 +2516,14 @@ { \s__seq \int_step_function:nnnN - { \c_two * \l__regex_max_state_int } - \c_one - { \l__regex_submatch_int - \c_one } + { 2 * \l__regex_max_state_int } + { 1 } + { \l__regex_submatch_int - 1 } \__regex_extract_seq_aux:n } \int_compare:nNnF { \flag_height:n { __regex_begin } + \flag_height:n { __regex_end } } - = \c_zero + = 0 { \__msg_kernel_error:nnxxx { regex } { result-unbalanced } { splitting~or~extracting~submatches } @@ -2462,12 +2546,12 @@ } \cs_new:Npn \__regex_extract_seq_aux:ww #1; #2; { - \if_int_compare:w #1 < \c_zero + \if_int_compare:w #1 < 0 \exp_stop_f: \flag_raise:n { __regex_end } \prg_replicate:nn {-#1} { \exp_not:n { { \if_false: } \fi: } } \fi: \__regex_query_submatch:n {#2} - \if_int_compare:w #1 > \c_zero + \if_int_compare:w #1 > 0 \exp_stop_f: \flag_raise:n { __regex_begin } \prg_replicate:nn {#1} { \exp_not:n { \if_false: { \fi: } } } \fi: @@ -2478,12 +2562,12 @@ \int_set_eq:NN \l__regex_zeroth_submatch_int \l__regex_submatch_int \prg_replicate:nn \l__regex_capturing_group_int { - \tex_skip:D \l__regex_submatch_int \c_zero sp \scan_stop: + \tex_skip:D \l__regex_submatch_int 0 sp \scan_stop: \int_incr:N \l__regex_submatch_int } \prop_map_inline:Nn \l__regex_success_submatches_prop { - \if_int_compare:w ##1 - \c_one + \if_int_compare:w ##1 - 1 \exp_stop_f: \exp_after:wN \__regex_extract_e:wn \__int_value:w \else: \exp_after:wN \__regex_extract_b:wn \__int_value:w @@ -2542,17 +2626,17 @@ { 0 \int_step_function:nnnN - { \c_two * \l__regex_max_state_int } + { 2 * \l__regex_max_state_int } \l__regex_capturing_group_int - { \l__regex_submatch_int - \c_one } + { \l__regex_submatch_int - 1 } \__regex_replacement_balance_one_match:n } \tl_set:Nx \l__regex_internal_a_tl { \int_step_function:nnnN - { \c_two * \l__regex_max_state_int } + { 2 * \l__regex_max_state_int } \l__regex_capturing_group_int - { \l__regex_submatch_int - \c_one } + { \l__regex_submatch_int - 1 } \__regex_replacement_do_one_match:n \__regex_query_range:nn \l__regex_start_pos_int \l__regex_max_pos_int @@ -2561,24 +2645,24 @@ } \cs_new_protected:Npn \__regex_group_end_replace:N #1 { - \if_int_compare:w \l__regex_balance_int = \c_zero + \if_int_compare:w \l__regex_balance_int = 0 \exp_stop_f: \else: \__msg_kernel_error:nnxxx { regex } { result-unbalanced } { replacing } - { \int_max:nn { - \l__regex_balance_int } { \c_zero } } - { \int_max:nn { \l__regex_balance_int } { \c_zero } } + { \int_max:nn { - \l__regex_balance_int } { 0 } } + { \int_max:nn { \l__regex_balance_int } { 0 } } \fi: \use:x { \group_end: \tl_set:Nn \exp_not:N #1 { - \if_int_compare:w \l__regex_balance_int < \c_zero + \if_int_compare:w \l__regex_balance_int < 0 \exp_stop_f: \prg_replicate:nn { - \l__regex_balance_int } { { \if_false: } \fi: } \fi: \l__regex_internal_a_tl - \if_int_compare:w \l__regex_balance_int > \c_zero + \if_int_compare:w \l__regex_balance_int > 0 \exp_stop_f: \prg_replicate:nn { \l__regex_balance_int } { \if_false: { \fi: } } \fi: @@ -2832,7 +2916,7 @@ { \int_step_inline:nnnn \l__regex_min_state_int - \c_one + { 1 } { \l__regex_max_state_int - 1 } { \trace:nnx { regex } { #1 } |