diff options
author | Karl Berry <karl@freefriends.org> | 2012-02-06 01:22:53 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-02-06 01:22:53 +0000 |
commit | a851d6714a00e2a09b93ba3e251d8665290c0ab8 (patch) | |
tree | 3ba045c487cc9e5e28e73714cb6312d0e556b924 /Master/texmf-dist/tex/latex/l3experimental | |
parent | a9533a6794104fad593912e3481304047dcd0025 (diff) |
l3experimental 3287
git-svn-id: svn://tug.org/texlive/trunk@25308 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3experimental')
7 files changed, 2057 insertions, 1283 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3dt/l3dt.sty b/Master/texmf-dist/tex/latex/l3experimental/l3dt/l3dt.sty new file mode 100644 index 00000000000..5346944521c --- /dev/null +++ b/Master/texmf-dist/tex/latex/l3experimental/l3dt/l3dt.sty @@ -0,0 +1,459 @@ +%% +%% This is file `l3dt.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% l3dt.dtx (with options: `package') +%% +%% EXPERIMENTAL CODE +%% +%% Do not distribute this file without also distributing the +%% source files specified above. +%% +%% Do not distribute a modified version of this file. +%% +%% File l3dt.dtx Copyright (C) 2011,2012 The LaTeX3 Project +%% +%% It may be distributed and/or modified under the conditions of the +%% LaTeX Project Public License (LPPL), either version 1.3c of this +%% license or (at your option) any later version. The latest version +%% of this license is in the file +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This file is part of the "l3experimental bundle" (The Work in LPPL) +%% and all files in that bundle must be distributed together. +%% +%% The released version of this bundle is available from CTAN. +%% +%% ----------------------------------------------------------------------- +%% +%% The development version of the bundle can be found at +%% +%% http://www.latex-project.org/svnroot/experimental/trunk/ +%% +%% for those people who are interested. +%% +%%%%%%%%%%% +%% NOTE: %% +%%%%%%%%%%% +%% +%% Snapshots taken from the repository represent work in progress and may +%% not work or may contain conflicting material! We therefore ask +%% people _not_ to put them into distributions, archives, etc. without +%% prior consultation with the LaTeX Project Team. +%% +%% ----------------------------------------------------------------------- +%% +\RequirePackage{expl3} +\GetIdInfo$Id: l3dt.dtx 3251 2012-01-28 09:42:44Z joseph $ + {L3 Experimental data tables} +\ProvidesExplPackage + {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} +\package_check_loaded_expl: +\quark_new:N \q_dt +\quark_new:N \q_dt_row +\quark_new:N \q_dt_header +\tl_const:Nn \c_empty_dt + { + { 0 } + \q_dt + \q_nil + \q_dt_header + \q_dt_row + } +\cs_new_protected:Npn \dt_new:N #1 { \cs_new_eq:NN #1 \c_empty_dt } +\cs_new_protected:Npn \dt_clear:N #1 { \cs_set_eq:NN #1 \c_empty_dt } +\cs_new_protected:Npn \dt_gclear:N #1 { \cs_gset_eq:NN #1 \c_empty_dt } +\cs_new_protected:Npn \dt_clear_new:N #1 + { \cs_if_exist:NTF #1 { \dt_clear:N #1 } { \dt_new:N #1 } } +\cs_new_protected:Npn \dt_gclear_new:N #1 + { \cs_if_exist:NTF #1 { \dt_gclear:N #1 } { \dt_new:N #1 } } +\cs_new_eq:NN \dt_set_eq:NN \tl_set_eq:NN +\cs_new_eq:NN \dt_gset_eq:NN \tl_gset_eq:NN +\dt_new:N \l_tmpa_dt +\dt_new:N \l_tmpb_dt +\dt_new:N \g_tmpa_dt +\dt_new:N \g_tmpb_dt +\cs_new_protected:Npn \dt_split_aux:nnnn #1#2#3#4 { #3 #2 } +\cs_new_protected:Npn \dt_split_aux:w { } +\cs_new:Npn \dt_split_header:NT #1#2 + { \exp_after:wN \dt_split_header_aux:wn #1 \q_stop {#2} } +\cs_new:Npn \dt_split_header_aux:wn #1 \q_nil \q_dt_header #2 \q_stop #3 + { #3 {#1} { \q_dt_header #2 } } +\cs_new_protected:Npn \dt_split_key:nnTF #1#2 + { \exp_args:No \dt_split_key_aux:nnTF { \tl_to_str:n {#2} } {#1} } +\cs_new_protected:Npn \dt_split_key_aux:nnTF #1#2 + { + \cs_set_protected:Npn \dt_split_aux:w + ##1 \q_dt #1 \q_dt ##2##3##4 \q_mark ##5 \q_stop + { \dt_split_aux:nnnn ##3 { { ##1 \q_dt } {##2} {##4} } } + \dt_split_aux:w #2 \q_mark + \q_dt #1 \q_dt { } { ? \use_ii:nn { } } \q_mark \q_stop + } +\cs_new_protected:Npn \dt_split_key_list:NnTF #1#2 + { \exp_args:NNo \dt_split_key_list_aux:NnTF #1 { \tl_to_str:n {#2} } } +\cs_new_protected:Npn \dt_split_key_list_aux:NnTF #1#2 + { + \cs_set_protected:Npn \dt_split_aux:w + ##1##2 \q_dt #2 \q_dt ##3##4 \q_dt_header ##5 \q_mark ##6 \q_stop + { + \dt_split_aux:nnnn ##3 + { { {##1} ##2 \q_dt } { ##3##4 \q_dt_header ##5 } } + } + \exp_after:wN \dt_split_aux:w #1 \q_mark + \q_dt #2 \q_dt { ? \use_ii:nn { } } \q_dt_header \q_mark \q_stop + } +\cs_new_protected:Npn \dt_split_row:NnTF #1#2 + { \dt_split_row_aux:NfTF #1 { \int_eval:n {#2} } } +\cs_new_protected:Npn \dt_split_row_aux:NnTF #1#2 + { + \cs_set_protected:Npn \dt_split_aux:w + ##1 \q_dt_row #2 \q_dt ##2##3 \q_dt_row ##4 \q_mark ##5 \q_stop + { + \dt_split_aux:nnnn ##2 + { { ##1 \q_dt_row } { #2 \q_dt ##2##3 } {##4} } + } + \exp_after:wN \dt_split_aux:w #1 \q_mark + \q_dt_row #2 \q_dt { ? \use_ii:nn { } } \q_dt_row \q_mark \q_stop + } +\cs_generate_variant:Nn \dt_split_row_aux:NnTF { Nf } +\cs_new_protected_nopar:Npn \dt_add_key:Nn { \dt_add_key_aux:NNn \tl_set:Nx } +\cs_new_protected_nopar:Npn \dt_gadd_key:Nn { \dt_add_key_aux:NNn \tl_gset:Nx } +\cs_new_protected:Npn \dt_add_key_aux:NNn #1#2#3 + { + \dt_split_key_list:NnTF #2 {#3} + { \use_none:nn } + { + \dt_split_header:NT #2 + { \dt_add_key_aux:NNnnn #1 #2 {#3} } + } + } +\cs_new_protected:Npn \dt_add_key_aux:NNnnn #1#2#3#4#5 + { + #1 #2 + { + \exp_not:n {#4} + \tl_to_str:n {#3} + \exp_not:n { \q_dt \q_nil #5 } + } + } +\cs_new_protected_nopar:Npn \dt_add_row:N { \dt_add_row_aux:NN \tl_set:Nx } +\cs_new_protected_nopar:Npn \dt_gadd_row:N { \dt_add_row_aux:NN \tl_gset:Nx } +\cs_new_protected:Npn \dt_add_row_aux:NN #1#2 + { \exp_args:NNf \dt_add_row_aux:NnN #1 { \dt_rows:N #2 } #2 } +\cs_new_protected:Npn \dt_add_row_aux:NnN #1#2#3 + { + #1 #3 + { + { \int_eval:n { #2 + \c_one } } + \exp_after:wN \dt_add_row_aux:nw #3 \q_stop + #2 + \exp_not:n { \q_dt \q_nil \q_dt_row } + } + } +\cs_new:Npn \dt_add_row_aux:nw #1#2 \q_stop { \exp_not:n {#2} } +\cs_new_protected:Npn \dt_put:Nnn #1 + { \dt_put:Nnnn #1 { \dt_rows:N #1 - \c_one } } +\cs_new_protected:Npn \dt_gput:Nnn #1 + { \dt_gput:Nnnn #1 { \dt_rows:N #1 - \c_one } } +\cs_new_protected_nopar:Npn \dt_put:Nnnn + { \dt_put_aux:NNNnnn \dt_add_key:Nn \tl_set:Nx } +\cs_new_protected_nopar:Npn \dt_gput:Nnnn + { \dt_put_aux:NNNnnn \dt_gadd_key:Nn \tl_gset:Nx } +\cs_new_protected:Npn \dt_put_aux:NNNnnn #1#2#3#4#5#6 + { + #1 #3 {#5} + \dt_split_row:NnTF #3 {#4} + { \dt_put_aux:NNnnnnn #2 #3 {#5} {#6} } + { + \msg_kernel_error:nnxxx { dt } { unknown-row } + { \token_to_str:N #3 } { \int_eval:n {#4} } { \dt_rows:N #3 } + } + } +\cs_new_protected:Npn \dt_put_aux:NNnnnnn #1#2#3#4#5#6#7 + { + \dt_split_key:nnTF {#6} {#3} + { \dt_put_update:NNnnnnnnn #1 #2 {#3} {#4} {#5} {#7} } + { \dt_put_add_to_row:NNnnnnn #1 #2 {#3} {#4} {#5} {#6} {#7} } + } +\cs_new_protected:Npn \dt_put_update:NNnnnnnnn #1#2#3#4#5#6#7#8#9 + { + #1 #2 + { + \exp_not:n { #5 #7 } + \tl_to_str:n {#3} + \exp_not:n { \q_dt {#4} \q_dt #9 \q_dt_row #6 } + } + } +\cs_new_protected:Npn \dt_put_add_to_row:NNnnnnn #1#2#3#4#5#6#7 + { + #1 #2 + { + \exp_not:n {#5} + \exp_not:o { \dt_put_add_row_aux:w #6 } + \tl_to_str:n {#3} + \exp_not:n { \q_dt {#4} \q_dt \q_nil \q_dt_row #7 } + } + } +\cs_new:Npn \dt_put_add_row_aux:w #1 \q_nil {#1} +\cs_new:Npn \dt_keys:N #1 + { \dt_split_header:NT #1 { \dt_keys_aux:nn } } +\cs_new:Npn \dt_keys_aux:nn #1#2 + { + \int_eval:n + { + 0 + \exp_after:wN \dt_keys_aux:wN \use_none:nn #1 \q_recursion_tail \q_dt + \prg_break_point:n { } + } + } +\cs_new:Npn \dt_keys_aux:wN #1 \q_dt + { + \if_meaning:w \q_recursion_tail #1 + \exp_after:wN \prg_map_break: + \fi: + +1 + \dt_keys_aux:wN + } +\cs_new:Npn \dt_rows:N #1 + { \exp_after:wN \use_i_delimit_by_q_stop:nw #1 \q_stop } +\cs_new_protected:Npn \dt_del:Nn #1 { \dt_del:Nnn #1 + { \dt_rows:N #1 - \c_one } } +\cs_new_protected:Npn \dt_gdel:Nn #1 { \dt_gdel:Nnn #1 + { \dt_rows:N #1 - \c_one } } +\cs_new_protected_nopar:Npn \dt_del:Nnn { \dt_del_aux:NNnn \tl_set:Nn } +\cs_new_protected_nopar:Npn \dt_gdel:Nnn { \dt_del_aux:NNnn \tl_gset:Nn } +\cs_new_protected:Npn \dt_del_aux:NNnn #1#2#3#4 + { + \dt_split_row:NnTF #2 {#3} + { \dt_del_aux:NNnnnn #1 #2 {#4} } + { } + } +\cs_new_protected:Npn \dt_del_aux:NNnnnn #1#2#3#4#5#6 + { + \dt_split_key:nnTF {#5} {#3} + { \dt_del_aux:NNnnnnn #1 #2 {#4} {#6} } + { } + } +\cs_new_protected:Npn \dt_del_aux:NNnnnnn #1#2#3#4#5#6#7 + { #1 #2 { #3 #5 #7 #4 } } +\cs_new_protected_nopar:Npn \dt_remove_key:Nn + { \dt_remove_key_aux:NNn \tl_set:Nx } +\cs_new_protected_nopar:Npn \dt_gremove_key:Nn + { \dt_remove_key_aux:NNn \tl_gset:Nx } +\cs_new_protected:Npn \dt_remove_key_aux:NNn #1#2#3 + { + \dt_split_key_list:NnTF #2 {#3} + { \exp_args:No \dt_remove_key_aux:nNNnn { \tl_to_str:n {#3} } #1 #2 } + { } + } +\cs_new_protected:Npn \dt_remove_key_aux:nNNnn #1#2#3#4#5 + { + \cs_set:Npn \dt_remove_key_aux:w ##1 \q_dt #1 \q_dt ##2 ##3 + { + \exp_not:n {##1} + \if_meaning:w \q_recursion_tail ##3 + \exp_after:wN \prg_map_break: + \fi: + \dt_remove_key_aux:w ##3 + } + #2 #3 + { + \exp_not:n {#4} + \dt_remove_key_aux:w #5 \q_dt #1 \q_dt { } \q_recursion_tail + \prg_break_point:n { } + } + } +\cs_new:Npn \dt_remove_key_aux:w { } +\cs_new_protected_nopar:Npn \dt_remove_row:Nn + { \dt_remove_row_aux:NNn \tl_set:Nx } +\cs_new_protected_nopar:Npn \dt_gremove_row:Nn + { \dt_remove_row_aux:NNn \tl_gset:Nx } +\cs_new_protected:Npn \dt_remove_row_aux:NNn #1#2#3 + { + \dt_split_row:NnTF #2 {#3} + { \dt_remove_row_aux:NNnnn #1 #2 } + { } + } +\cs_new_protected:Npn \dt_remove_row_aux:NNnnn #1#2#3#4#5 + { + #1 #2 + { + { \int_eval:n { \dt_rows:N #2 - \c_one } } + \dt_remove_row_aux:nw #3 \q_stop + \dt_remove_row_loop:nw #5 \q_recursion_tail \q_dt_row + \prg_break_point:n { } + } + } +\cs_new_eq:NN \dt_remove_row_aux:nw \dt_add_row_aux:nw +\cs_new:Npn \dt_remove_row_loop:nw #1#2 \q_dt_row + { + \if_meaning:w \q_recursion_tail #1 + \exp_after:wN \prg_map_break: + \fi: + \int_eval:n { #1 - \c_one } + \exp_not:n { #2 \q_dt_row } + \dt_remove_row_loop:nw + } +\cs_new_protected:Npn \dt_get:NnnN #1#2#3#4 + { + \dt_split_row:NnTF #1 {#2} + { \dt_get_aux:nNnnn {#3} #4 } + { \tl_set:Nn #4 { \q_no_value } } + } +\cs_new_protected:Npn \dt_get_aux:nNnnn #1#2#3#4#5 + { + \dt_split_key:nnTF {#4} {#1} + { \dt_get_aux:Nnnn #2 } + { \tl_set:Nn #2 { \q_no_value } } + } +\cs_new_protected:Npn \dt_get_aux:Nnnn #1#2#3#4 { \tl_set:Nn #1 {#3} } +\prg_new_protected_conditional:Npnn \dt_get:NnnN #1#2#3#4 { T , F , TF } + { + \dt_split_row:NnTF #1 {#2} + { \dt_get_aux_true:nNnnn {#3} #4 } + { \prg_return_false: } + } +\cs_new_protected:Npn \dt_get_aux_true:nNnnn #1#2#3#4#5 + { + \dt_split_key:nnTF {#4} {#1} + { \dt_get_aux_true:Nnnn #2 } + { \prg_return_false: } + } +\cs_new_protected:Npn \dt_get_aux_true:Nnnn #1#2#3#4 + { + \tl_set:Nn #1 {#3} + \prg_return_true: + } +\cs_new_protected:Npn \dt_get:NnN #1 { \dt_get:NnnN #1 + { \dt_rows:N #1 - \c_one } } +\cs_new_protected:Npn \dt_get:NnNT #1 { \dt_get:NnnNF #1 + { \dt_rows:N #1 - \c_one } } +\cs_new_protected:Npn \dt_get:NnNF #1 { \dt_get:NnnNF #1 + { \dt_rows:N #1 - \c_one } } +\cs_new_protected:Npn \dt_get:NnNTF #1 { \dt_get:NnnNTF #1 + { \dt_rows:N #1 - \c_one } } +\int_new:N \g_dt_map_level_int +\cs_new_protected:Npn \dt_map_variables:Nnn #1#2#3 + { + \int_gincr:N \g_dt_map_level_int + \seq_gclear_new:c { g_dt_map_ \int_use:N \g_dt_map_level_int _seq } + \keyval_parse:NNn \use_none:n \dt_map_variables_key:nn {#2} + \dt_split_header:NT #1 { \dt_map_variables_aux:nnn {#3} } + } +\cs_new_protected:Npn \dt_map_variables_key:nn #1#2 + { + \seq_gput_right:cn { g_dt_map_ \int_use:N \g_dt_map_level_int _seq } + { {#1} #2 } + } +\cs_new_protected:Npn \dt_map_variables_aux:nnn #1#2#3 + { \dt_map_variables_aux:nNNw {#1} #3 \q_stop } +\cs_new_protected:Npn \dt_map_variables_aux:nNNw + #1 \q_dt_header \q_dt_row #2 \q_stop + { + \int_zero_new:c { l_dt_map_ \int_use:N \g_dt_map_level_int _row_int } + \dt_map_variables_aux:nnw {#1} #2 { } \q_recursion_tail \q_dt_row + \prg_break_point:n { \int_gdecr:N \g_dt_map_level_int } + } +\cs_new_protected:Npn \dt_map_variables_aux:nnw #1#2#3#4 \q_dt_row + { + \if_meaning:w \q_recursion_tail #3 + \exp_after:wN \dt_map_break: + \fi: + \seq_map_inline:cn { g_dt_map_ \int_use:N \g_dt_map_level_int _seq } + { \dt_get_aux:nNnnn ##1 { } {#3#4} { } } + #1 + \int_incr:c { l_dt_map_ \int_use:N \g_dt_map_level_int _row_int } + \dt_map_variables_aux:nnw {#1} + } +\cs_new_eq:NN \dt_map_break: \prg_map_break: +\cs_new_eq:NN \dt_map_break:n \prg_map_break:n +\prg_new_conditional:Npnn \dt_if_empty:N #1 { T , F , TF , p } + { + \if_meaning:w #1 \c_empty_dt + \prg_return_true: + \else: + \prg_return_false: + \fi: + } +\prg_new_conditional:Npnn \dt_if_in:Nn #1#2 { p , T , F , TF } + { \dt_split_header:NT #1 { \dt_if_in_aux:nnn {#2} } } +\cs_new:Npn \dt_if_in_aux:nnn #1#2#3 + { + \exp_last_unbraced:Nno \dt_if_in_aux:nwN {#1} { \use_none:nn #2 } + \q_recursion_tail \q_dt + \prg_break_point:n { } + } +\cs_new:Npn \dt_if_in_aux:nwN #1#2 \q_dt + { + \if_meaning:w \q_recursion_tail #2 + \exp_after:wN \prg_map_break:n + \else: + \exp_after:wN \use_none:n + \fi: + { \prg_return_false: } + \str_if_eq:nnTF {#1} {#2} + { \prg_map_break:n { \prg_return_true: } } + { \dt_if_in_aux:nwN {#1} } + } +\prg_new_conditional:Npnn \dt_if_in_row:Nnn #1#2#3 { p , T , F , TF } + { + \exp_last_unbraced:Nno \dt_if_in_row_aux:nw {#2} #1 + \q_recursion_tail \q_nil + \prg_break_point:n { } + { \tl_to_str:n {#3} } + } +\cs_new:Npn \dt_if_in_row_aux:nw #1#2 \q_dt_row #3#4 \q_nil + { + \if_meaning:w \q_recursion_tail #3 + \exp_after:wN \prg_map_break:n + \else: + \exp_after:wN \use_none:n + \fi: + { + \use_i:nn + \prg_return_false: + } + \int_compare:nNnTF {#1} = {#3} + { \prg_map_break:n { \exp_args:Nno \dt_if_in_row_aux:nn {#4} } } + { \dt_if_in_row_aux:nw {#1} } + } +\cs_new:Npn \dt_if_in_row_aux:nn #1#2 + { + \dt_if_in_row_aux:nwn {#2} #1 {#2} \q_dt { } \q_recursion_tail + \prg_break_point:n { } + } +\cs_new:Npn \dt_if_in_row_aux:nwn #1 \q_dt #2 \q_dt #3 + { + \str_if_eq:xxTF {#1} {#2} + { \dt_if_in_row_aux:N } + { \dt_if_in_row_aux:nwn {#1} } + } +\cs_new:Npn \dt_if_in_row_aux:N #1 + { + \if_meaning:w \q_dt #1 + \prg_return_true: + \else: + \prg_return_false: + \fi: + \prg_map_break: + } +\cs_new:Npn \dt_if_in_row_p:Nn #1 { \dt_if_in_row_p:Nnn #1 + { \dt_rows:N #1 - \c_one } } +\cs_new:Npn \dt_if_in_row:NnT #1 { \dt_if_in_row:NnnT #1 + { \dt_rows:N #1 - \c_one } } +\cs_new:Npn \dt_if_in_row:NnF #1 { \dt_if_in_row:NnnF #1 + { \dt_rows:N #1 - \c_one } } +\cs_new:Npn \dt_if_in_row:NnTF #1 { \dt_if_in_row:NnnTF #1 + { \dt_rows:N #1 - \c_one } } +\msg_kernel_new:nnnn { dt } { unknown-row } + { Data~table~#1~does~not~contain~a~row~'#2'. } + { + Data~table~#1~contains~#3~rows.~These~must~be~accessed~by~number:~row~ + #2~is~not~present~in~the~table. + } +%% +%% +%% End of file `l3dt.sty'. diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3flag.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3flag.sty index 2bb94e7c62a..b56100853ab 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3flag.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3flag.sty @@ -50,48 +50,56 @@ {L3 Experimental Flags} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} -\tl_new:N \g_flag_list_tl -\cs_new_protected:Npn \flag_new:N #1 +\cs_new_protected:Npn \flag_new:n #1 { - \cs_new_eq:NN #1 \c_undefined:D - \tl_if_in:NnTF \g_flag_list_tl {#1} - { - \msg_kernel_error:nnx - { flag } { already-defined } - { \token_to_str:N #1 } - } - { \tl_gput_right:Nn \g_flag_list_tl {#1} } + \cs_new:cpn { flag_trap_#1:w } ##1 ; + { \exp_after:wN \use_none:n \cs:w l_#1_##1_flag \cs_end: } } -\cs_generate_variant:Nn \flag_new:N { c } -\prg_new_conditional:Npnn \flag_test:N #1 { p , T , F , TF } +\cs_new_protected:Npn \flag_clear:n #1 + { \flag_clear_aux:ww 0 ; #1 \q_stop } +\cs_new_protected:Npn \flag_clear_aux:ww #1 ; #2 \q_stop { - \if_cs_exist:N #1 - \prg_return_true: + \if_cs_exist:w l_#2_#1_flag \cs_end: \else: - \prg_return_false: + \exp_after:wN \use_none_delimit_by_q_stop:w \fi: + \cs_set_eq:cN { l_#2_#1_flag } \c_undefined:D + \exp_after:wN \flag_clear_aux:ww + \int_use:N \int_eval:w \c_one + #1 ; + #2 \q_stop + } +\cs_new_protected:Npn \flag_clear_new:n #1 + { \flag_if_exist:nTF {#1} { \flag_clear:n } { \flag_new:n } {#1} } +\cs_new_protected:Npn \flag_set_trap:nn #1#2 + { \cs_set:cpn { flag_trap_#1:w } ##1 ; {#2} } +\prg_new_conditional:Npnn \flag_if_exist:n #1 { p , T , F , TF } + { + \cs_if_exist:cTF { flag_trap_#1:w } + { \prg_return_true: } { \prg_return_false: } } -\prg_new_conditional:Npnn \flag_test:c #1 { p , T , F , TF } +\prg_new_conditional:Npnn \flag_if_raised:n #1 { p , T , F , TF } { - \if_cs_exist:w #1 \cs_end: + \if_cs_exist:w l_#1_0_flag \cs_end: \prg_return_true: \else: \prg_return_false: \fi: } -\cs_new:Npn \flag_raise:N #1 - { \exp_after:wN \use_none:n \cs:w \cs_to_str:N #1 \cs_end: } -\cs_new:Npn \flag_raise:c #1 - { \exp_after:wN \use_none:n \cs:w #1 \cs_end: } -\cs_new_protected:Npn \flag_lower:N #1 - { \cs_set_eq:NN #1 \c_undefined:D } -\cs_generate_variant:Nn \flag_lower:N { c } -\msg_kernel_new:nnnn { flag } { already-defined } - { The~control~sequence~#1~is~already~declared~as~a~flag. } +\cs_new:Npn \flag_height:n #1 { \flag_height_loop:ww 0; #1 \q_stop } +\cs_new:Npn \flag_height_loop:ww #1 ; #2 \q_stop + { + \if_cs_exist:w l_#2_#1_flag \cs_end: + \exp_after:wN \flag_height_loop:ww \int_use:N \int_eval:w \c_one + + \else: + \exp_after:wN \flag_height_end:ww + \fi: + #1 ; #2 \q_stop + } +\cs_new:Npn \flag_height_end:ww #1 ; #2 \q_stop { #1 } +\cs_new:Npn \flag_raise:n #1 { - LaTeX~was~asked~to~define~the~flag~#1,~but~it~has~already~ - been~defined~as~a~flag.~The~flag~module~is~mostly~meant~ - for~kernel~use,~and~booleans~should~be~preferred. + \cs:w flag_trap_#1:w \exp_after:wN \cs_end: + \int_value:w \flag_height:n {#1} ; } %% %% diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty index 8d1f45803f9..f88c8fa4e15 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty @@ -46,19 +46,63 @@ %% %% ----------------------------------------------------------------------- \RequirePackage{expl3} -\GetIdInfo$Id: l3regex.dtx 3200 2012-01-16 03:50:54Z bruno $ +\GetIdInfo$Id: l3regex.dtx 3259 2012-01-29 20:50:48Z bruno $ {L3 Experimental Regular Expressions} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} \RequirePackage{l3str, l3tl-analysis, l3flag} \cs_new:Npn \regex_tmp:w { } -\tl_new:N \l_regex_tmpa_tl -\tl_new:N \l_regex_tmpb_tl -\tl_new:N \l_regex_tmpc_tl -\int_new:N \l_regex_tmpa_int -\int_new:N \l_regex_tmpb_int -\flag_new:N \l_regex_group_begin_flag -\flag_new:N \l_regex_group_end_flag +\tl_new:N \l_regex_internal_a_tl +\tl_new:N \l_regex_internal_b_tl +\int_new:N \l_regex_internal_a_int +\int_new:N \l_regex_internal_b_int +\int_new:N \l_regex_internal_c_int +\tl_new:N \g_regex_internal_tl +\tl_const:Nn \c_regex_d_tl + { \regex_item_range:nn \c_forty_eight { 57 } } % 0--9 +\tl_const:Nn \c_regex_h_tl + { + \regex_item_equal:n \c_thirty_two % space + \regex_item_equal:n \c_nine % tab + } +\tl_const:Nn \c_regex_s_tl + { + \regex_item_equal:n \c_thirty_two % space + \regex_item_equal:n \c_nine % tab + \regex_item_equal:n \c_ten % lf + \regex_item_equal:n \c_twelve % ff + \regex_item_equal:n \c_thirteen % cr + } +\tl_const:Nn \c_regex_v_tl + { \regex_item_range:nn \c_ten \c_thirteen } % lf, vtab, ff, cr +\tl_const:Nn \c_regex_w_tl + { + \regex_item_range:nn \c_ninety_seven { 122 } % a--z + \regex_item_range:nn \c_sixty_five { 90 } % A--Z + \regex_item_range:nn \c_forty_eight { 57 } % 0--9 + \regex_item_equal:n { 95 } % _ + } +\tl_const:Nn \c_regex_D_tl + { \c_regex_d_tl \regex_break_point:TF { } \regex_break_true:w } +\tl_const:Nn \c_regex_H_tl + { \c_regex_h_tl \regex_break_point:TF { } \regex_break_true:w } +\tl_const:Nn \c_regex_S_tl + { \c_regex_s_tl \regex_break_point:TF { } \regex_break_true:w } +\tl_const:Nn \c_regex_V_tl + { \c_regex_v_tl \regex_break_point:TF { } \regex_break_true:w } +\tl_const:Nn \c_regex_W_tl + { \c_regex_w_tl \regex_break_point:TF { } \regex_break_true:w } +\tl_const:Nn \c_regex_N_tl + { + \regex_item_equal:n \c_ten + \regex_break_point:TF { } { \regex_break_true:w } + } +\tl_const:cn { c_regex_._tl } + { + \if_num:w \l_regex_current_char_int > - \c_two + \exp_after:wN \regex_break_true:w + \fi: + } \int_new:N \l_regex_build_mode_int \int_new:N \l_regex_max_state_int \int_new:N \l_regex_left_state_int @@ -87,105 +131,56 @@ \int_const:Nn \c_regex_catcode_A_int { "4000000 } \int_const:Nn \c_regex_catcodes_all_int { "5515155 } \bool_new:N \l_regex_catcodes_bool -\tl_new:N \l_regex_tmpa_regex_tl -\bool_new:N \l_regex_class_bool -\tl_new:N \l_regex_class_tl -\bool_new:N \l_regex_class_saved_bool -\tl_new:N \l_regex_class_saved_tl -\tl_const:Nn \c_regex_d_tl - { - \regex_item_range:nn { \c_forty_eight } { 57 } % 0--9 - } -\tl_const:Nn \c_regex_D_tl - { - \regex_item_geq:n { \c_fifty_eight } % > `9 - \regex_item_range:nn { \c_zero } { 47 } % 0 - } -\tl_const:Nn \c_regex_h_tl - { - \regex_item_equal:n { \c_thirty_two } % space - \regex_item_equal:n { \c_nine } % tab - } -\tl_const:Nn \c_regex_H_tl - { - \regex_item_geq:n { 33 } % > space - \regex_item_range:nn { \c_ten } { 31 } % tab < ... < space - \regex_item_range:nn { \c_zero } { \c_eight } % < tab - } -\tl_const:Nn \c_regex_s_tl - { - \regex_item_equal:n { \c_thirty_two } % space - \regex_item_range:nn { \c_nine } { \c_ten } % tab, lf - \regex_item_range:nn { \c_twelve } { \c_thirteen } % ff, cr - } -\tl_const:Nn \c_regex_S_tl - { - \regex_item_geq:n { 33 } % > space - \regex_item_range:nn { \c_fourteen } { 31 } % tab < ... < space - \regex_item_range:nn { \c_zero } { \c_eight } % < tab - \regex_item_equal:n { \c_eleven } % vtab - } -\tl_const:Nn \c_regex_v_tl - { - \regex_item_range:nn { \c_ten } { \c_thirteen } % lf, vtab, ff, cr - } -\tl_const:Nn \c_regex_V_tl - { - \regex_item_geq:n { \c_fourteen } % >cr - \regex_item_range:nn { \c_zero } { \c_nine } % < lf - } -\tl_const:Nn \c_regex_w_tl - { - \regex_item_range:nn { \c_ninety_seven } { 122 } % a--z - \regex_item_range:nn { \c_sixty_five } { 90 } % A--Z - \regex_item_range:nn { \c_forty_eight } { 57 } % 0--9 - \regex_item_equal:n { 95 } % _ - } -\tl_const:Nn \c_regex_W_tl - { - \regex_item_range:nn { \c_zero } { 47 } % <`0 - \regex_item_range:nn { \c_fifty_eight } { 64 } % (`9+1)--(`A-1) - \regex_item_range:nn { \c_ninety_one } { 94 } % (`Z+1)--(`_-1) - \regex_item_equal:n { 96 } % ` - \regex_item_geq:n { \c_one_hundred_twenty_three } % z - } -\tl_const:Nn \c_regex_N_tl - { - \regex_item_geq:n { \c_eleven } % > lf - \regex_item_range:nn { \c_zero } { \c_nine } % < lf - } +\bool_new:N \l_regex_tests_bool +\tl_new:N \l_regex_tests_tl +\bool_new:N \l_regex_tests_saved_bool +\tl_new:N \l_regex_tests_saved_tl +\int_new:N \l_regex_catcodes_saved_int +\int_new:N \l_regex_min_index_int +\int_new:N \l_regex_max_index_int \int_new:N \l_regex_nesting_int -\int_new:N \l_regex_min_step_int -\int_new:N \l_regex_max_step_int -\int_new:N \l_regex_current_step_int -\int_new:N \l_regex_start_step_int -\int_new:N \l_regex_success_step_int -\int_new:N \l_regex_unique_id_int +\int_new:N \l_regex_current_index_int +\int_new:N \l_regex_start_index_int +\int_new:N \l_regex_success_index_int \int_new:N \l_regex_current_char_int \int_new:N \l_regex_current_catcode_int -\tl_new:N \l_regex_current_token_tl +\tl_new:N \l_regex_current_token_tl \int_new:N \l_regex_last_char_int \int_new:N \l_regex_case_changed_char_int \bool_new:N \l_regex_caseless_bool \int_new:N \l_regex_current_state_int \prop_new:N \l_regex_current_submatches_prop \prop_new:N \l_regex_success_submatches_prop -\int_new:N \l_regex_max_index_int +\int_new:N \l_regex_step_int +\int_new:N \l_regex_max_active_int \tl_new:N \l_regex_every_match_tl +\bool_new:N \l_regex_fresh_thread_bool +\bool_new:N \l_regex_success_empty_bool +\cs_new_eq:NN \regex_if_two_empty_matches:F \use:n \bool_new:N \g_regex_success_bool \bool_new:N \l_regex_saved_success_bool \bool_new:N \l_regex_success_match_bool -\cs_new_protected:Npn \regex_last_match_empty_no:F #1 {#1} -\cs_new_protected:Npn \regex_last_match_empty_yes:F - { \int_compare:nNnF \l_regex_start_step_int = \l_regex_current_step_int } -\cs_new_eq:NN \regex_last_match_empty:F \regex_last_match_empty_no:F -\bool_new:N \l_regex_success_empty_bool -\bool_new:N \l_regex_fresh_thread_bool -\int_new:N \l_regex_replacement_int +\tl_const:Nn \c_regex_no_match_regex + { + \regex_nfa:Nw \c_regex_no_match_regex + \l_regex_max_state_int = \c_one + \l_regex_capturing_group_int = \c_zero + \tex_toks:D \c_zero { \s_stop } + \s_stop + } +\cs_new_protected:Npn \regex_new:N #1 + { + \chk_if_free_cs:N #1 + \cs_gset_eq:NN #1 \c_regex_no_match_regex + } +\regex_new:N \l_regex_internal_regex \int_new:N \l_regex_replacement_csnames_int +\int_new:N \l_regex_replacement_int \int_new:N \l_regex_submatch_int \int_new:N \l_regex_submatch_start_int \int_new:N \l_regex_match_count_int +\flag_new:n { regex_begin } +\flag_new:n { regex_end } \cs_new_protected:Npn \regex_toks_put_left:Nx #1#2 { \cs_set_nopar:Npx \regex_tmp:w \s_stop { \s_stop #2 } @@ -198,11 +193,22 @@ \tex_toks:D #1 \exp_after:wN { \tex_the:D \tex_toks:D \exp_after:wN #1 \regex_tmp:w } } -\cs_new:Npn \regex_query_substr:nn #1#2 +\cs_new:Npn \regex_toks_range:nn #1#2 + { + \exp_after:wN \regex_toks_range:ww + \int_use:N \int_eval:w #1 \exp_after:wN ; + \int_use:N \int_eval:w #2 ; + \prg_break_point:n { } + } +\cs_new:Npn \regex_toks_range:ww #1 ; #2 ; { - \if_num:w \int_eval:w #1 < \int_eval:w #2 \int_eval_end: - \str_aux_toks_range:nn {#1} {#2} + \if_num:w #1 < #2 \exp_stop_f: + \else: + \exp_after:wN \prg_map_break: \fi: + \tex_the:D \tex_toks:D #1 \exp_stop_f: + \exp_after:wN \regex_toks_range:ww + \int_use:N \int_eval:w #1 + \c_one ; #2 ; } \cs_new:Npn \regex_query_submatch:nn #1#2 { @@ -213,41 +219,63 @@ } \cs_new:Npn \regex_query_submatch:w #1 ; { - \regex_query_substr:nn + \regex_toks_range:nn { \tex_skip:D #1 } { \etex_gluestretch:D \tex_skip:D #1 } } \cs_new_protected:Npn \regex_seq_pop_int:NN #1#2 { - \seq_pop:NN #1 \l_regex_tmpa_tl - \int_set:Nn #2 \l_regex_tmpa_tl + \seq_pop:NN #1 \l_regex_internal_a_tl + \int_set:Nn #2 \l_regex_internal_a_tl } \cs_new_protected:Npn \regex_seq_get_int:NN #1#2 { - \seq_get:NN #1 \l_regex_tmpa_tl - \int_set:Nn #2 \l_regex_tmpa_tl + \seq_get:NN #1 \l_regex_internal_a_tl + \int_set:Nn #2 \l_regex_internal_a_tl } \cs_new_protected:Npn \regex_seq_push_int:NN #1#2 { \seq_push:No #1 { \int_use:N #2 } } \cs_new_protected:Npn \regex_seq_pop_use:N #1 { - \seq_pop:NN #1 \l_regex_tmpa_tl - \l_regex_tmpa_tl + \seq_pop:NN #1 \l_regex_internal_a_tl + \l_regex_internal_a_tl } \cs_new_protected:Npn \regex_seq_get_use:N #1 { - \seq_get:NN #1 \l_regex_tmpa_tl - \l_regex_tmpa_tl + \seq_get:NN #1 \l_regex_internal_a_tl + \l_regex_internal_a_tl } -\cs_new_protected:Npn \regex_break_true:w - #1 \regex_break_point:TF #2 #3 {#2} -\cs_new_protected:Npn \regex_break_point:TF #1 #2 { #2 } -\cs_new_protected_nopar:Npn \regex_item_dot: +\cs_new_protected:Npn \regex_get_digits:nw #1 { - \if_num:w \l_regex_current_char_int > - \c_two - \exp_after:wN \regex_break_true:w + \tex_afterassignment:D \regex_tmp:w + \cs_set_nopar:Npx \regex_tmp:w + { + \exp_not:n {#1} + { \if_false: } } \fi: + \regex_get_digits_aux:NN + } +\cs_new:Npn \regex_get_digits_aux:NN #1#2 + { + \if_meaning:w \regex_build_raw:N #1 + \if_num:w 9 < 1 \exp_not:N #2 \exp_stop_f: + #2 + \else: + \regex_get_digits_end:w #1 #2 + \fi: + \else: + \regex_get_digits_end:w #1 #2 \fi: + \regex_get_digits_aux:NN + } +\cs_new:Npn \regex_get_digits_end:w #1 \fi: #2 \regex_get_digits_aux:NN + { + \fi: #2 + \if_false: { { \fi: } } + #1 } +\cs_new_protected:Npn \regex_break_true:w + #1 \regex_break_point:TF #2 #3 {#2} +\cs_new_protected:Npn \regex_break_point:TF #1 #2 { #2 } \cs_new_protected:Npn \regex_item_caseful_equal:n #1 { \if_num:w #1 = \l_regex_current_char_int @@ -316,16 +344,19 @@ \cs_set:Npn \regex_item_range:nn { \regex_item_caseful_range:nn } \cs_set:Npn \regex_item_geq:n { \regex_item_caseful_geq:n } } +\cs_new_protected:Npn \regex_item_catcode_aux: + { + " + \if_case:w \l_regex_current_catcode_int + 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 + \fi: + } \cs_new_protected:Npn \regex_item_catcode:nT #1 { - \if_int_odd:w \int_eval:w #1 / " - \if_case:w \l_regex_current_catcode_int - 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 - \fi: - \int_eval_end: + \if_int_odd:w \int_eval:w #1 / \regex_item_catcode_aux: \int_eval_end: \exp_after:wN \use:n \else: \exp_after:wN \use_none:n @@ -335,9 +366,9 @@ { \int_compare:nNnT \l_regex_current_catcode_int = \c_zero { - \tl_set:Nn \l_regex_tmpa_regex_tl {#1} + \tl_set:Nn \l_regex_internal_regex {#1} \bool_set_eq:NN \l_regex_saved_success_bool \g_regex_success_bool - \exp_args:NNx \regex_match:NnTF \l_regex_tmpa_regex_tl + \exp_args:NNx \regex_match:NnTF \l_regex_internal_regex { \exp_after:wN \exp_after:wN \exp_after:wN \cs_to_str:N \l_regex_current_token_tl @@ -349,43 +380,140 @@ { \bool_gset_eq:NN \g_regex_success_bool \l_regex_saved_success_bool } } } -\cs_new_protected:Npn \regex_get_digits:nw #1 +\cs_new_protected:Npn \regex_escape_use:nnnn #1#2#3#4 { - \tex_afterassignment:D \regex_tmp:w - \cs_set_nopar:Npx \regex_tmp:w + \group_begin: + \cs_set_nopar:Npn \regex_escape_unescaped:N ##1 { #1 } + \cs_set_nopar:Npn \regex_escape_escaped:N ##1 { #2 } + \cs_set_nopar:Npn \regex_escape_raw:N ##1 { #3 } + \int_set:Nn \tex_escapechar:D { 92 } + \str_gset_other:Nn \g_regex_internal_tl {#4} + \int_zero:N \l_regex_internal_a_int + \tl_set:Nx \l_regex_internal_a_tl + { + \exp_after:wN \regex_escape_loop:N \g_regex_internal_tl + { break } \prg_break_point:n { } + } + \use:x + { + \group_end: + \regex_toks_range:nn \c_zero \l_regex_internal_a_int + \exp_not:o \l_regex_internal_a_tl + } + } +\cs_new:Npn \regex_escape_loop:N #1 + { + \cs_if_exist_use:cF { regex_escape_\token_to_str:N #1:w } + { \regex_escape_unescaped:N #1 } + \regex_escape_loop:N + } +\cs_new_nopar:cpn { regex_escape_ \c_backslash_str :w } + \regex_escape_loop:N #1 + { + \cs_if_exist_use:cF { regex_escape_/\token_to_str:N #1:w } + { \regex_escape_escaped:N #1 } + \regex_escape_loop:N + } +\cs_new_eq:NN \regex_escape_unescaped:N ? +\cs_new_eq:NN \regex_escape_escaped:N ? +\cs_new_eq:NN \regex_escape_raw:N ? +\cs_new_eq:NN \regex_escape_break:w \prg_map_break: +\cs_new_nopar:cpn { regex_escape_/break:w } + { + \if_false: { \fi: } + \msg_kernel_error:nn { regex } { trailing-backslash } + \exp_after:wN \use_none:n \exp_after:wN { \if_false: } \fi: + } +\cs_new_nopar:cpn { regex_escape_~:w } { } +\cs_new_nopar:cpx { regex_escape_/a:w } + { \exp_not:N \regex_escape_raw:N \iow_char:N \^^G } +\cs_new_nopar:cpx { regex_escape_/t:w } + { \exp_not:N \regex_escape_raw:N \iow_char:N \^^I } +\cs_new_nopar:cpx { regex_escape_/n:w } + { \exp_not:N \regex_escape_raw:N \iow_char:N \^^J } +\cs_new_nopar:cpx { regex_escape_/f:w } + { \exp_not:N \regex_escape_raw:N \iow_char:N \^^L } +\cs_new_nopar:cpx { regex_escape_/r:w } + { \exp_not:N \regex_escape_raw:N \iow_char:N \^^M } +\cs_new_nopar:cpx { regex_escape_/e:w } + { \exp_not:N \regex_escape_raw:N \iow_char:N \^^[ } +\cs_new_nopar:cpn { regex_escape_/x:w } \regex_escape_loop:N + { + \if_false: { \fi: } + \tex_toks:D \l_regex_internal_a_int + \exp_after:wN { \l_regex_internal_a_tl } + \int_incr:N \l_regex_internal_a_int + \int_zero:N \l_regex_current_char_int + \regex_escape_x_test:N + } +\cs_new_protected:Npx \regex_escape_x_test:N #1 + { + \exp_not:N \token_if_eq_charcode:NNTF \c_space_token #1 + { \exp_not:N \regex_escape_x_test:N } { - \exp_not:n {#1} - { \if_false: } } \fi: - \regex_get_digits_aux:NN + \l_regex_current_char_int = "0 + \exp_not:N \token_if_eq_charcode:NNTF \c_lbrace_str #1 + { \exp_not:N \regex_escape_x_braced_loop:N } + { \exp_not:N \regex_escape_x_unbraced_i:N #1 } + } } -\cs_new:Npn \regex_get_digits_aux:NN #1#2 +\cs_new:Npn \regex_escape_x_unbraced_i:N #1 { - \if_meaning:w \regex_build_raw:N #1 - \if_charcode:w \c_space_token \exp_not:N #2 - \else: - \if_num:w 9 < 1 \exp_not:N #2 \exp_stop_f: - #2 - \else: - \regex_get_digits_end:w #1 #2 - \fi: - \fi: - \else: - \regex_get_digits_end:w #1 #2 - \fi: - \regex_get_digits_aux:NN + \str_aux_hexadecimal_use:NTF #1 + { \regex_escape_x_unbraced_ii:N } + { \exp_stop_f: \regex_escape_x_end: #1 } } -\cs_new:Npn \regex_get_digits_end:w #1 \fi: #2 \regex_get_digits_aux:NN +\cs_new:Npn \regex_escape_x_unbraced_ii:N #1 { - \fi: #2 - \if_false: { { \fi: } } - #1 + \token_if_eq_charcode:NNTF \c_space_token #1 + { \regex_escape_x_unbraced_ii:N } + { + \str_aux_hexadecimal_use:NTF #1 + { \exp_stop_f: \regex_escape_x_end: } + { \exp_stop_f: \regex_escape_x_end: #1 } + } + } +\cs_new:Npn \regex_escape_x_braced_loop:N #1 + { + \token_if_eq_charcode:NNTF \c_space_token #1 + { \regex_escape_x_braced_loop:N } + { + \str_aux_hexadecimal_use:NTF #1 + { \regex_escape_x_braced_loop:N } + { \exp_stop_f: \regex_escape_x_braced_end:N #1 } + } } -\prg_new_conditional:Npnn \regex_token_if_other_digit:N #1 { TF } +\cs_new_protected:Npx \regex_escape_x_braced_end:N #1 { - \if_num:w \c_nine < 1 \exp_not:N #1 \exp_stop_f: - \prg_return_true: \else: \prg_return_false: \fi: + \exp_not:N \token_if_eq_charcode:NNTF \c_rbrace_str #1 + { \exp_not:N \regex_escape_x_end: } + { + \msg_kernel_error:nnx { regex } { x-missing-rbrace } + { \int_use:N \l_regex_current_char_int } + \exp_not:N \regex_escape_x_end: #1 + } } -\prg_new_conditional:Npnn \regex_aux_char_if_special:N #1 { TF } +\group_begin: + \char_set_catcode_other:N \^^@ + \cs_new_protected_nopar:Npn \regex_escape_x_end: + { + \if_num:w \l_regex_current_char_int > \c_max_char_int + \msg_kernel_error:nnx { regex } { x-overflow } + { \int_use:N \l_regex_current_char_int } + \exp_after:wN \use:n + \else: + \tex_lccode:D \c_zero \l_regex_current_char_int + \exp_after:wN \tl_to_lowercase:n + \fi: + { + \tl_set:Nx \l_regex_internal_a_tl + { \if_false: } \fi: + \regex_escape_raw:N ^^@ + \regex_escape_loop:N + } + } +\group_end: +\prg_new_conditional:Npnn \regex_char_if_special:N #1 { TF } { \if_num:w `#1 < \c_ninety_one \if_num:w `#1 < \c_fifty_eight @@ -407,7 +535,7 @@ \fi: \fi: } -\prg_new_conditional:Npnn \regex_aux_char_if_alphanumeric:N #1 { TF } +\prg_new_conditional:Npnn \regex_char_if_alphanumeric:N #1 { TF } { \if_num:w `#1 < \c_ninety_one \if_num:w `#1 < \c_fifty_eight @@ -434,6 +562,18 @@ \exp_after:wN \use_ii:nn \fi: } +\cs_new_nopar:Npn \regex_build_if_assertions_forbidden:TF + { + \if_int_odd:w \l_regex_build_mode_int + \exp_after:wN \use_i:nn + \else: + \if_int_compare:w \l_regex_build_mode_int > \c_zero + \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 + \fi: + \fi: + } \cs_new_protected_nopar:Npn \regex_build_new_state: { \tex_toks:D \l_regex_max_state_int { \s_stop } @@ -456,61 +596,35 @@ #3 { \int_eval:n { #4 - \l_regex_left_state_int } } } } -\cs_new_protected:Npn \regex_build:n #1 - { - \int_set_eq:NN \l_regex_build_mode_int \c_zero - \regex_build:w - \regex_build_new_state: - \regex_toks_put_right:Nx \l_regex_left_state_int - { \regex_action_start_wildcard: } - \regex_build_open_aux: - \str_escape_use:NNNn - \regex_build_i_unescaped:N - \regex_build_i_escaped:N - \regex_build_i_raw:N - { #1 } - \prg_do_nothing: \prg_do_nothing: - \prg_do_nothing: \prg_do_nothing: - \regex_build_end: - } -\cs_new:Npn \regex_build_i_unescaped:N #1 - { - \regex_aux_char_if_special:NTF #1 - { \exp_not:N \regex_build_special:N #1 } - { \exp_not:N \regex_build_raw:N #1 } - } -\cs_new:Npn \regex_build_i_escaped:N #1 - { - \regex_aux_char_if_alphanumeric:NTF #1 - { \exp_not:N \regex_build_escaped:N #1 } - { \exp_not:N \regex_build_raw:N #1 } - } -\cs_new:Npn \regex_build_i_raw:N #1 - { \exp_not:N \regex_build_raw:N #1 } -\cs_new_protected:Npn \regex_build_special:N #1 - { - \cs_if_exist_use:cF { regex_build_#1: } - { \regex_build_raw:N #1 } - } -\cs_new_protected:Npn \regex_build_escaped:N #1 - { - \cs_if_exist_use:cF { regex_build_/#1: } - { \regex_build_raw:N #1 } - } \cs_new_protected_nopar:Npn \regex_build:w { \int_set_eq:NN \l_regex_catcodes_default_int \c_regex_catcodes_all_int - \int_set_eq:NN \l_regex_capturing_group_int \c_zero + \int_set_eq:NN \l_regex_catcodes_int \l_regex_catcodes_default_int + \int_set_eq:NN \l_regex_capturing_group_int \c_zero + \tl_clear:N \l_regex_tests_tl + \bool_set_true:N \l_regex_tests_bool \int_zero:N \l_regex_max_state_int \regex_build_new_state: - \tl_clear:N \l_regex_class_tl - \bool_set_true:N \l_regex_class_bool - \int_set_eq:NN \l_regex_catcodes_int \l_regex_catcodes_default_int } \cs_new_protected_nopar:Npn \regex_build_end: { - \regex_seq_push_int:NN \l_regex_capturing_group_seq \c_zero - \regex_build_close_aux: \regex_build_group_: + \regex_build_exit_class: + \regex_build_exit_groups: + \regex_toks_put_right:Nx \l_regex_right_state_int + { \regex_action_success: } + \int_incr:N \l_regex_capturing_group_int + } +\cs_new_protected_nopar:Npn \regex_build_exit_class: + { + \regex_build_if_in_class:TF + { + \msg_kernel_error:nn { regex } { missing-rbrack } + \use:c { regex_build_]: } + } + { } + } +\cs_new_protected_nopar:Npn \regex_build_exit_groups: + { \seq_if_empty:NF \l_regex_capturing_group_seq { \msg_kernel_error:nnx { regex } { missing-rparen } @@ -519,23 +633,61 @@ { \seq_length:N \l_regex_capturing_group_seq } { \regex_build_close_aux: \regex_build_group_: } } - \regex_toks_put_right:Nx \l_regex_right_state_int - { \regex_action_success: } - \int_incr:N \l_regex_capturing_group_int + } +\cs_new_protected:Npn \regex_build:n #1 + { + \regex_build:w + \int_set_eq:NN \l_regex_build_mode_int \c_zero + \regex_build_new_state: + \regex_toks_put_right:Nx \l_regex_left_state_int + { \regex_action_start_wildcard: } + \regex_build_open_aux: + \regex_escape_use:nnnn + { + \regex_char_if_special:NTF ##1 + \regex_build_special:N \regex_build_raw:N ##1 + } + { + \regex_char_if_alphanumeric:NTF ##1 + \regex_build_escaped:N \regex_build_raw:N ##1 + } + { \regex_build_raw:N ##1 } + { #1 } + \prg_do_nothing: \prg_do_nothing: + \prg_do_nothing: \prg_do_nothing: + \int_compare:nNnT \l_regex_build_mode_int < \c_zero + { + \msg_kernel_error:nn { regex } { c-missing-rbrace } + \exp_after:wN \regex_build_special:N \c_rbrace_str + } + \seq_put_right:Nn \l_regex_capturing_group_seq {0} + \regex_build_close_aux: \regex_build_group_: + \regex_build_end: + } +\cs_new_protected:Npn \regex_build_special:N #1 + { + \cs_if_exist_use:cF { regex_build_#1: } + { \regex_build_raw:N #1 } + } +\cs_new_protected:Npn \regex_build_escaped:N #1 + { + \cs_if_exist_use:cF { regex_build_/#1: } + { \regex_build_raw:N #1 } } \cs_new_protected:Npn \regex_build_one:n #1 { \regex_build_one:x { \exp_not:n {#1} } } \cs_new_protected:Npn \regex_build_one:x #1 { - \tl_put_right:Nx \l_regex_class_tl + \tl_put_right:Nx \l_regex_tests_tl { - \if_num:w \l_regex_catcodes_int = \c_regex_catcodes_all_int - \exp_after:wN \use:n - \else: + \if_num:w \l_regex_catcodes_int < \c_regex_catcodes_all_int \regex_item_catcode:nT { \int_use:N \l_regex_catcodes_int } + \else: + \exp_after:wN \use:n \fi: {#1} } + \int_set_eq:NN \l_regex_catcodes_int \l_regex_catcodes_default_int \if_num:w \l_regex_build_mode_int = \c_two \l_regex_build_mode_int = \c_zero \else: @@ -547,28 +699,21 @@ \exp_after:wN \regex_build_one_quantifier: \fi: } -\cs_new:Npn \regex_build_tmp_class:n #1 +\cs_new:Npn \regex_tests_action_cost:n #1 { - \exp_not:o \l_regex_class_tl - \bool_if:NTF \l_regex_class_bool + \exp_not:o \l_regex_tests_tl + \bool_if:NTF \l_regex_tests_bool { \regex_break_point:TF { \regex_action_cost:n {#1} } { } } { \regex_break_point:TF { } { \regex_action_cost:n {#1} } } } -\cs_new_protected:Npn \regex_class_put:N #1 - { - \tl_put_right:Nx \l_regex_class_tl - { \regex_item_equal:n { \int_value:w `#1 ~ } } - } -\cs_new_protected:Npn \regex_class_put:NN #1#2 - { - \tl_put_right:Nx \l_regex_class_tl - { \regex_item_range:nn { \int_value:w `#1 ~ } { \int_value:w `#2 ~ } } - } -\cs_new_protected:Npn \regex_build_raw_alphanum_is_error:N #1 +\cs_new_protected:Npn \regex_build_raw_error:N #1 { - \regex_aux_char_if_alphanumeric:NTF #1 - { \msg_kernel_error:nnx { regex } { class-bad-escape } { #1 } } - { \regex_build_raw:N #1 } + \if_int_odd:w \l_regex_build_mode_int + \msg_kernel_error:nnx { regex } { class-bad-escape } {#1} + \else: + \msg_kernel_error:nnx { regex } { catcode-bad-escape } {#1} + \fi: + \regex_build_raw:N #1 } \cs_new_protected:Npn \regex_build_raw:N #1#2#3 { @@ -586,39 +731,45 @@ \token_if_eq_meaning:NNTF #2 \regex_build_escaped:N % [ { \use_i:nn } { \str_if_eq:nnTF { #2#3 } { \regex_build_special:N ] } } { - \msg_kernel_warning:nnx { regex } { end-range-missing } % [ - { #1 - \if_meaning:w #3 ] \else: \c_backslash_str \fi: #3 } - \regex_class_put:N #1 - \regex_class_put:N - + \msg_kernel_warning:nnxx { regex } { range-missing-end } % [ + {#1} { \token_if_eq_charcode:NNF #3 ] { \c_backslash_str } #3 } + \tl_put_right:Nx \l_regex_tests_tl + { + \regex_item_equal:n { \int_value:w `#1 ~ } + \regex_item_equal:n { \int_value:w `- ~ } + } #2#3 } { \if_num:w `#1 > `#3 \exp_stop_f: - \msg_kernel_error:nnxx { regex } { backwards-range } {#1} {#3} + \msg_kernel_error:nnxx { regex } { range-backwards } {#1} {#3} \else: - \if_num:w `#1 = `#3 \exp_stop_f: - \regex_class_put:N #3 - \else: - \regex_class_put:NN #1#3 - \fi: + \tl_put_right:Nx \l_regex_tests_tl + { + \if_num:w `#1 = `#3 \exp_stop_f: + \regex_item_equal:n + \else: + \regex_item_range:nn { \int_value:w `#1 ~ } + \fi: + { \int_value:w `#3 ~ } + } \fi: } } -\cs_new_protected_nopar:cpn { regex_build_.: } +\cs_new_protected_nopar:cpx { regex_build_.: } { - \regex_build_if_in_class:TF + \exp_not:N \regex_build_if_in_class:TF { \regex_build_raw:N . } - { \regex_build_one:x \regex_item_dot: } + { \regex_build_one:n \exp_not:c { c_regex_._tl } } } \tl_map_inline:nn { dDhHsSvVwWN } { \cs_new_protected_nopar:cpx { regex_build_/#1: } { \regex_build_one:n \exp_not:c { c_regex_#1_tl } } } -\cs_new_protected:Npn \regex_build_simple_assertion:Nn #1#2 +\cs_new_protected:Npn \regex_build_simple_assertion:nn #1#2 { - \regex_build_if_in_class:TF - { \regex_build_raw_alphanum_is_error:N #1 } + \regex_build_if_assertions_forbidden:TF {#1} { \regex_build_new_state: \regex_toks_put_right:Nx \l_regex_left_state_int @@ -632,47 +783,50 @@ } } } - %^^A \regex_assertion_quantifier: + %^^A todo: add \regex_assertion_quantifier: } } \cs_new_protected_nopar:cpn { regex_build_^: } { - \regex_build_simple_assertion:Nn ^ - { \int_compare:nNnT \l_regex_min_step_int = \l_regex_current_step_int } + \regex_build_simple_assertion:nn { \regex_build_raw:N ^ } + { \int_compare:nNnT \l_regex_min_index_int = \l_regex_current_index_int } } \cs_new_protected_nopar:cpn { regex_build_/A: } { - \regex_build_simple_assertion:Nn A - { \int_compare:nNnT \l_regex_min_step_int = \l_regex_current_step_int } + \regex_build_simple_assertion:nn { \regex_build_raw_error:N A } + { \int_compare:nNnT \l_regex_min_index_int = \l_regex_current_index_int } } \cs_new_protected_nopar:cpn { regex_build_/G: } { - \regex_build_simple_assertion:Nn G - { \int_compare:nNnT \l_regex_start_step_int = \l_regex_current_step_int } - } -\cs_new_protected_nopar:cpn { regex_build_$: } % $ - { - \regex_build_simple_assertion:Nn $ % $ - { \int_compare:nNnT \l_regex_current_char_int < \c_minus_one } + \regex_build_simple_assertion:nn { \regex_build_raw_error:N G } + { \int_compare:nNnT \l_regex_start_index_int = \l_regex_current_index_int } } +\group_begin: + \char_set_catcode_other:N \$ + \cs_new_protected_nopar:cpn { regex_build_$: } % $ + { + \regex_build_simple_assertion:nn { \regex_build_raw:N $ } % $ + { \int_compare:nNnT \l_regex_current_char_int < \c_minus_one } + } +\group_end: \cs_new_protected_nopar:cpn { regex_build_/Z: } { - \regex_build_simple_assertion:Nn Z + \regex_build_simple_assertion:nn { \regex_build_raw_error:N Z } { \int_compare:nNnT \l_regex_current_char_int < \c_minus_one } } \cs_new_protected_nopar:cpn { regex_build_/z: } { - \regex_build_simple_assertion:Nn z + \regex_build_simple_assertion:nn { \regex_build_raw_error:N z } { \int_compare:nNnT \l_regex_current_char_int < \c_minus_one } } \cs_new_protected_nopar:cpn { regex_build_/b: } { - \regex_build_simple_assertion:Nn b - { \regex_if_word_boundary:TF \use:n \use_none:n } + \regex_build_simple_assertion:nn { \regex_build_raw_error:N b } + { \regex_if_word_boundary:T } } \cs_new_protected_nopar:cpn { regex_build_/B: } { - \regex_build_simple_assertion:Nn B + \regex_build_simple_assertion:nn { \regex_build_raw_error:N B } { \regex_if_word_boundary:TF { } } } \cs_new_protected_nopar:Npn \regex_if_word_boundary:TF @@ -685,6 +839,8 @@ { \group_end: \c_regex_w_tl } \regex_break_point:TF } +\cs_new_protected_nopar:Npn \regex_if_word_boundary:T + { \regex_if_word_boundary:TF \use:n \use_none:n } \cs_new_protected_nopar:cpn { regex_build_[: } { \regex_build_if_in_class:TF @@ -696,21 +852,22 @@ \regex_build_if_in_class:TF { \if_num:w \l_regex_build_mode_int > \c_sixteen - \tl_set:Nx \l_regex_class_tl + \tl_set:Nx \l_regex_tests_tl { - \exp_not:o \l_regex_class_saved_tl - \if_num:w \l_regex_catcodes_int < \c_regex_catcodes_all_int - \regex_item_catcode:nT { \int_use:N \l_regex_catcodes_int } + \exp_not:o \l_regex_tests_saved_tl + \if_num:w \l_regex_catcodes_saved_int < \c_regex_catcodes_all_int + \regex_item_catcode:nT + { \int_use:N \l_regex_catcodes_saved_int } \else: \exp_after:wN \use:n \fi: { - \exp_not:o \l_regex_class_tl - \bool_if:NF \l_regex_class_bool - { \regex_break_point:TF { } { \regex_break_true:w } } + \exp_not:o \l_regex_tests_tl + \bool_if:NF \l_regex_tests_bool + { \regex_break_point:TF { } \regex_break_true:w } } } - \bool_set_eq:NN \l_regex_class_bool \l_regex_class_saved_bool + \bool_set_eq:NN \l_regex_tests_bool \l_regex_tests_saved_bool \fi: \tex_advance:D \l_regex_build_mode_int - \c_fifteen \tex_divide:D \l_regex_build_mode_int \c_thirteen @@ -724,14 +881,16 @@ { \l_regex_build_mode_int = \int_value:w \l_regex_build_mode_int 3 ~ % \if_num:w \l_regex_build_mode_int > \c_sixteen - \tl_set_eq:NN \l_regex_class_saved_tl \l_regex_class_tl - \bool_set_eq:NN \l_regex_class_saved_bool \l_regex_class_bool + \tl_set_eq:NN \l_regex_tests_saved_tl \l_regex_tests_tl + \bool_set_eq:NN \l_regex_tests_saved_bool \l_regex_tests_bool + \int_set_eq:NN \l_regex_catcodes_saved_int \l_regex_catcodes_int + \int_set_eq:NN \l_regex_catcodes_int \c_regex_catcodes_all_int \fi: \token_if_eq_meaning:NNTF #1 \regex_build_special:N { \token_if_eq_charcode:NNTF #2 ^ { - \bool_set_false:N \l_regex_class_bool % [ + \bool_set_false:N \l_regex_tests_bool % [ \str_if_eq:nnTF {#3#4} { \regex_build_special:N ] } { \regex_build_raw:N } } @@ -766,8 +925,7 @@ } { \cs_if_exist_use:cF { regex_build_c_#3: } } { - \msg_kernel_error:nnxx { regex } { c-command } - { regular~expression } { #3 } + \msg_kernel_error:nnx { regex } { c-missing-category } {#3} #2 #3 } } @@ -808,8 +966,7 @@ { \regex_build_c_lbrack_end: } } { - \msg_kernel_error:nnxx { regex } { c-command } - { regular-expression } { #2 } + \msg_kernel_error:nnx { regex } { c-missing-rbrack } {#2} \regex_build_c_lbrack_end: } } @@ -830,18 +987,21 @@ \fi: } \cs_new_protected:cpn { regex_build_ \c_rbrace_str : } - { %^^A incorrect recovery for \c{...(...[...} with missing ) or ]. + { \int_compare:nNnTF \l_regex_build_mode_int < \c_zero { - \use:c { regex_build_/Z: } - \regex_toks_put_right:Nx \l_regex_right_state_int - { \regex_action_success: } - \int_incr:N \l_regex_capturing_group_int + \regex_build_exit_class: + \regex_build_exit_groups: + \regex_build_escaped:N Z + \regex_build_end: \use:x { \group_end: \regex_build_one:n - { \regex_item_cs:n { \regex_set_aux:N ? } } + { + \regex_item_cs:n + { \regex_set_aux:N \l_regex_internal_regex } + } } } { \exp_after:wN \regex_build_raw:N \c_rbrace_str } @@ -913,7 +1073,7 @@ \tl_if_empty:nTF {#2} { \regex_build_quantifier_aux:nnNN { {#1} } { n* } } { \regex_build_quantifier_aux:nnNN { {#1} {#2} } { nn } } - } %^^A todo: catch the case m>n + } { \regex_build_quantifier_end:nn { } { } \use:x @@ -928,82 +1088,101 @@ \cs_new_protected:Npn \regex_build_quantifier_end:nn #1#2 { \use:c { regex_build_ \l_regex_one_or_group_tl _ #1 : } #2 - \tl_clear:N \l_regex_class_tl - \bool_set_true:N \l_regex_class_bool - \int_set_eq:NN \l_regex_catcodes_int \l_regex_catcodes_default_int + \tl_clear:N \l_regex_tests_tl + \bool_set_true:N \l_regex_tests_bool } \cs_new_protected_nopar:Npn \regex_build_one_quantifier: { \tl_set:Nx \l_regex_one_or_group_tl { one } \regex_build_quantifier:w } -\cs_new_protected_nopar:Npn \regex_build_one_: - { - \regex_build_transition:NN - \regex_build_tmp_class:n \l_regex_right_state_int - } -\cs_new_protected_nopar:cpn { regex_build_one_?: } - { - \regex_build_transitions:NNNN - \regex_build_tmp_class:n \l_regex_right_state_int - \regex_action_free:n \l_regex_right_state_int - } -\cs_new_protected_nopar:cpn { regex_build_one_??: } - { - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_right_state_int - \regex_build_tmp_class:n \l_regex_right_state_int - } -\cs_new_protected_nopar:cpn { regex_build_one_*: } - { - \regex_build_transitions:NNNN - \regex_build_tmp_class:n \l_regex_left_state_int - \regex_action_free:n \l_regex_right_state_int - } -\cs_new_protected_nopar:cpn { regex_build_one_*?: } +\cs_new_protected:Npn \regex_build_one_n: #1 { - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_right_state_int - \regex_build_tmp_class:n \l_regex_left_state_int + \prg_replicate:nn {#1} + { + \regex_build_transition:NN + \regex_tests_action_cost:n \l_regex_right_state_int + } } -\cs_new_protected_nopar:cpn { regex_build_one_+: } +\cs_new_eq:cN { regex_build_one_n?: } \regex_build_one_n: +\cs_new_protected_nopar:Npn \regex_build_one_: + { \regex_build_one_n: \c_one } +\cs_new_protected:cpn { regex_build_one_n*: } #1 { - \regex_build_one_: - \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_tmpa_int - \regex_action_free:n \l_regex_right_state_int + \int_compare:nNnTF {#1} = \c_zero + { + \regex_build_transitions:NNNN + \regex_tests_action_cost:n \l_regex_left_state_int + \regex_action_free:n \l_regex_right_state_int + } + { + \regex_build_one_n: {#1} + \int_set_eq:NN \l_regex_internal_a_int \l_regex_left_state_int + \regex_build_transitions:NNNN + \regex_action_free:n \l_regex_internal_a_int + \regex_action_free:n \l_regex_right_state_int + } } -\cs_new_protected_nopar:cpn { regex_build_one_+?: } +\cs_new_protected:cpn { regex_build_one_n*?: } #1 { - \regex_build_one_: - \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_right_state_int - \regex_action_free:n \l_regex_tmpa_int + \int_compare:nNnTF {#1} = \c_zero + { + \regex_build_transitions:NNNN + \regex_action_free:n \l_regex_right_state_int + \regex_tests_action_cost:n \l_regex_left_state_int + } + { + \regex_build_one_n: {#1} + \int_set_eq:NN \l_regex_internal_a_int \l_regex_left_state_int + \regex_build_transitions:NNNN + \regex_action_free:n \l_regex_right_state_int + \regex_action_free:n \l_regex_internal_a_int + } } -\cs_new_protected:Npn \regex_build_one_n: #1 - { \prg_replicate:nn {#1} { \regex_build_one_: } } -\cs_new_eq:cN { regex_build_one_n?: } \regex_build_one_n: -\cs_new_protected:cpx { regex_build_one_n*: } #1 - { - \exp_not:N \prg_replicate:nn {#1} { \exp_not:N \regex_build_one_: } - \exp_not:c { regex_build_one_*: } +\cs_new_protected_nopar:cpx { regex_build_one_*: } + { \exp_not:c { regex_build_one_n*: } \c_zero } +\cs_new_protected_nopar:cpx { regex_build_one_*?: } + { \exp_not:c { regex_build_one_n*?: } \c_zero } +\cs_new_protected_nopar:cpx { regex_build_one_+: } + { \exp_not:c { regex_build_one_n*: } \c_one } +\cs_new_protected_nopar:cpx { regex_build_one_+?: } + { \exp_not:c { regex_build_one_n*?: } \c_one } +\cs_new_protected_nopar:Npn \regex_build_one_nn: + { + \regex_build_one_nn_aux:nnnn { } + { + \regex_build_transitions:NNNN + \regex_tests_action_cost:n \l_regex_right_state_int + \regex_action_free:n \l_regex_internal_a_int + } } -\cs_new_protected:cpx { regex_build_one_n*?: } #1 +\cs_new_protected_nopar:cpn { regex_build_one_nn?: } { - \exp_not:N \prg_replicate:nn {#1} { \exp_not:N \regex_build_one_: } - \exp_not:c { regex_build_one_*?: } + \regex_build_one_nn_aux:nnnn {?} + { + \regex_build_transitions:NNNN + \regex_action_free:n \l_regex_internal_a_int + \regex_tests_action_cost:n \l_regex_right_state_int + } } -\cs_new_protected:Npn \regex_build_one_nn_aux:Nnn #1#2#3 +\cs_new_protected:Npn \regex_build_one_nn_aux:nnnn #1#2#3#4 { - \prg_replicate:nn {#2} { \regex_build_one_: } - \prg_replicate:nn {#3-#2} {#1} + \regex_build_one_n: {#3} + \int_compare:nNnTF {#3} > {#4} + { + \msg_kernel_error:nnxxx + { regex } { quantifier-backwards } {#3} {#4} {#1} + } + { + \int_set:Nn \l_regex_internal_a_int + { \l_regex_right_state_int + #4 - #3 } + \prg_replicate:nn { #4 - #3 } { #2 } + } } -\cs_new_protected_nopar:Npx \regex_build_one_nn: - { \regex_build_one_nn_aux:Nnn \exp_not:c { regex_build_one_?: } } -\cs_new_protected_nopar:cpx { regex_build_one_nn?: } - { \regex_build_one_nn_aux:Nnn \exp_not:c { regex_build_one_??: } } +\cs_new_protected_nopar:cpn { regex_build_one_?: } + { \regex_build_one_nn: \c_zero \c_one } +\cs_new_protected_nopar:cpx { regex_build_one_??: } + { \exp_not:c { regex_build_one_nn?: } \c_zero \c_one } \cs_new_protected:cpn { regex_build_(: } #1#2 { \regex_build_if_in_class:TF @@ -1060,7 +1239,7 @@ \regex_seq_pop_int:NN \l_regex_left_state_seq \l_regex_left_state_int \regex_seq_pop_int:NN \l_regex_right_state_seq \l_regex_right_state_int \regex_seq_pop_use:N \l_regex_end_group_seq - \seq_pop:NN \l_regex_end_alternation_seq \l_regex_tmpa_tl + \seq_pop:NN \l_regex_end_alternation_seq \l_regex_internal_a_tl } \cs_new_protected_nopar:Npn \regex_build_begin_alternation: { @@ -1093,7 +1272,7 @@ { \cs_if_exist_use:cF { regex_build_special_group_\token_to_str:N #2 : } { - \msg_kernel_error:nnx { regex } { unsupported } + \msg_kernel_error:nnx { regex } { special-group-unknown } { (? \token_to_str:N #2 } %) \regex_build_special:N ( % ) \regex_build_raw:N ? @@ -1149,7 +1328,7 @@ \token_if_eq_meaning:NNTF \regex_build_raw:N #2 { \cs_if_exist_use:cF { regex_build_option_#1#3: } - { \msg_error:nnx { regex } { unknown-option } { #3 } } + { \msg_kernel_error:nnx { regex } { unknown-option } { #3 } } \regex_build_options:NNN #1 } { @@ -1158,7 +1337,7 @@ { ) } { } { - } { \regex_build_options:NNN - } } - { \msg_error:nnx { regex } { invalid-in-option } { #3 } } + { \msg_kernel_error:nnx { regex } { invalid-in-option } { #3 } } } } \cs_new_protected_nopar:cpn { regex_build_option_+i: } @@ -1176,53 +1355,52 @@ } \cs_new_protected:Npn \regex_build_group_submatches:NN #1#2 { - \seq_pop:NN \l_regex_capturing_group_seq \l_regex_tmpa_tl - \int_compare:nNnF { \l_regex_tmpa_tl } < \c_zero + \seq_pop:NN \l_regex_capturing_group_seq \l_regex_internal_a_tl + \int_compare:nNnF { \l_regex_internal_a_tl } < \c_zero { \regex_toks_put_left:Nx #1 - { \regex_action_submatch:n { \l_regex_tmpa_tl < } } + { \regex_action_submatch:n { \l_regex_internal_a_tl < } } \regex_toks_put_left:Nx #2 - { \regex_action_submatch:n { \l_regex_tmpa_tl > } } + { \regex_action_submatch:n { \l_regex_internal_a_tl > } } } } -\cs_new_protected_nopar:Npn \regex_build_group_: - { - \regex_build_group_submatches:NN - \l_regex_left_state_int \l_regex_right_state_int - \regex_build_transition:NN - \regex_action_free:n \l_regex_right_state_int - } -\cs_new_protected:Npn \regex_build_group_shift:N #1 +\cs_new_protected_nopar:Npn \regex_build_group_qs_aux: { - \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int + \int_set_eq:NN \l_regex_internal_a_int \l_regex_left_state_int \regex_build_new_state: - \tex_toks:D \l_regex_right_state_int = \tex_toks:D \l_regex_tmpa_int + \tex_toks:D \l_regex_right_state_int = \tex_toks:D \l_regex_internal_a_int \regex_toks_put_left:Nx \l_regex_right_state_int { - \int_set:Nn \l_regex_current_state_int - { \int_use:N \l_regex_tmpa_int } % ^^A here we lie! + \int_sub:Nn \l_regex_current_state_int + { + \int_eval:n % ^^A here we lie! + { \l_regex_right_state_int - \l_regex_internal_a_int } + } } - \cs_set:Npx \regex_tmp:w + \use:x { - \tex_toks:D \l_regex_tmpa_int + \tex_toks:D \l_regex_internal_a_int { \s_stop - #1 { \int_eval:n { \l_regex_right_state_int - \l_regex_tmpa_int } } + \regex_action_free:n + { + \int_eval:n + { \l_regex_right_state_int - \l_regex_internal_a_int } + } } } - \regex_tmp:w \regex_build_group_submatches:NN \l_regex_right_state_int \l_regex_left_state_int } \cs_new_protected:Npn \regex_build_group_qs_aux:NN #1#2 { - \regex_build_group_shift:N \regex_action_free:n + \regex_build_group_qs_aux: \int_set_eq:NN \l_regex_right_state_int \l_regex_left_state_int \regex_build_transition:NN \regex_action_free:n #1 - #2 \l_regex_tmpa_int + #2 \l_regex_internal_a_int { \regex_action_free:n - { \int_eval:n { \l_regex_right_state_int - \l_regex_tmpa_int } } + { \int_eval:n { \l_regex_right_state_int - \l_regex_internal_a_int } } } } \cs_new_protected_nopar:cpn { regex_build_group_?: } @@ -1235,99 +1413,241 @@ \regex_build_group_qs_aux:NN \l_regex_right_state_int \regex_toks_put_left:Nx } -\cs_new_protected_nopar:cpn { regex_build_group_*: } +\cs_new_protected:Npn \regex_build_group_transition_right_max: { - \regex_build_group_qs_aux:NN - \l_regex_tmpa_int \regex_toks_put_right:Nx + \regex_toks_put_right:Nx \l_regex_right_state_int + { + \regex_action_free:n + { \int_eval:n { \l_regex_max_state_int - \l_regex_right_state_int } } + } } -\cs_new_protected_nopar:cpn { regex_build_group_*?: } +\cs_new_protected:Npn \regex_build_group_n_aux:n #1 { - \regex_build_group_qs_aux:NN - \l_regex_tmpa_int \regex_toks_put_left:Nx + \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 + \int_add:Nn \l_regex_right_state_int + { ( #1 - 1 ) * ( \l_regex_max_state_int - \l_regex_left_state_int ) } + \int_set:Nn \l_regex_max_state_int + { + \l_regex_left_state_int + + (#1) * ( \l_regex_max_state_int - \l_regex_left_state_int ) + } + \int_while_do:nNnn \l_regex_internal_b_int < \l_regex_max_state_int + { + \tex_toks:D \l_regex_internal_b_int + = \tex_toks:D \l_regex_internal_a_int + \int_incr:N \l_regex_internal_a_int + \int_incr:N \l_regex_internal_b_int + } + } +\cs_new_protected:Npn \regex_build_group_n: #1 + { + \regex_build_group_transition_right_max: + \regex_build_group_n_aux:n {#1} + \regex_build_new_state: + \int_compare:nNnF {#1} = \c_zero + { + \regex_build_group_submatches:NN + \l_regex_internal_a_int \l_regex_left_state_int + } } -\cs_new_protected_nopar:cpn { regex_build_group_+: } +\cs_new_eq:cN { regex_build_group_n?: } \regex_build_group_n: +\cs_new_protected_nopar:Npn \regex_build_group_: + { \regex_build_group_n: \c_one } +\cs_new_protected_nopar:cpn { regex_build_group_n*: } { - \regex_build_group_submatches:NN - \l_regex_left_state_int \l_regex_right_state_int - \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_tmpa_int - \regex_action_free:n \l_regex_right_state_int + \regex_build_group_n_star_aux:NNn + \regex_toks_put_right:Nx \regex_toks_put_left:Nx } -\cs_new_protected_nopar:cpn { regex_build_group_+?: } +\cs_new_protected_nopar:cpn { regex_build_group_n*?: } { - \regex_build_group_submatches:NN - \l_regex_left_state_int \l_regex_right_state_int - \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_right_state_int - \regex_action_free:n \l_regex_tmpa_int + \regex_build_group_n_star_aux:NNn + \regex_toks_put_left:Nx \regex_toks_put_right:Nx } -\cs_new_protected:Npn \regex_build_group_n_aux:n #1 +\cs_new_protected:Npn \regex_build_group_n_star_aux:NNn #1#2#3 { - \regex_toks_put_right:Nx \l_regex_right_state_int + \int_compare:nNnTF {#3} = \c_zero + { \regex_build_group_qs_aux:NN \l_regex_internal_a_int #1 } { - \regex_action_free:n + \regex_build_group_transition_right_max: + \regex_build_group_n_aux:n {#3} + \regex_build_new_state: + #2 \l_regex_left_state_int { - \int_eval:n %^^A todo: document why that value. - { \l_regex_max_state_int - \c_one - \l_regex_left_state_int } + \regex_action_free:n + { + \int_eval:n + { \l_regex_internal_a_int - \l_regex_left_state_int } + } } + \regex_build_group_submatches:NN + \l_regex_internal_a_int \l_regex_left_state_int } - \int_set_eq:NN \l_regex_tmpa_int \l_regex_left_state_int - \int_set_eq:NN \l_regex_tmpb_int \l_regex_max_state_int - \int_set:Nn \l_regex_max_state_int + } +\cs_new_protected_nopar:cpx { regex_build_group_*: } + { \exp_not:c { regex_build_group_n*: } \c_zero } +\cs_new_protected_nopar:cpx { regex_build_group_*?: } + { \exp_not:c { regex_build_group_n*?: } \c_zero } +\cs_new_protected_nopar:cpx { regex_build_group_+: } + { \exp_not:c { regex_build_group_n*: } \c_one } +\cs_new_protected_nopar:cpx { regex_build_group_+?: } + { \exp_not:c { regex_build_group_n*?: } \c_one } +\cs_new_protected_nopar:Npn \regex_build_group_nn: + { + \regex_build_group_nn_aux:nnnn { } + \regex_build_group_transition_right_max: + } +\cs_new_protected_nopar:cpn { regex_build_group_nn?: } + { + \regex_build_group_nn_aux:nnnn { } { - \l_regex_left_state_int - + #1 * ( \l_regex_max_state_int - \l_regex_left_state_int ) + \use:x + { + \tex_toks:D \l_regex_right_state_int + { + \exp_after:wN \regex_build_group_nn_aux_ii:w + \tex_the:D \tex_toks:D \l_regex_right_state_int + } + } } - \int_while_do:nNnn \l_regex_tmpb_int < \l_regex_max_state_int + } +\cs_new_protected:Npn \regex_build_group_nn_aux:nnnn #1#2#3#4 + { + \int_compare:nNnTF {#3} > {#4} { - \tex_toks:D \l_regex_tmpb_int = \tex_toks:D \l_regex_tmpa_int - \int_incr:N \l_regex_tmpa_int - \int_incr:N \l_regex_tmpb_int + \msg_kernel_error:nnxxx + { regex } { quantifier-backwards } {#3} {#4} {#1} + } + { + \int_compare:nNnTF {#3} = \c_zero + { + \regex_build_group_qs_aux: + \int_set_eq:NN \l_regex_right_state_int \l_regex_left_state_int + \int_set_eq:NN \l_regex_left_state_int \l_regex_internal_a_int + \regex_build_group_transition_right_max: + \regex_build_group_n_aux:n { #4 - #3 } + \int_set_eq:NN \l_regex_internal_c_int \l_regex_right_state_int + \int_set_eq:NN \l_regex_right_state_int \l_regex_left_state_int + \prg_replicate:nn { #4 - #3 } + { + #2 + \int_add:Nn \l_regex_right_state_int + { \l_regex_internal_b_int - \l_regex_internal_a_int } + } + \int_set_eq:NN \l_regex_right_state_int \l_regex_internal_c_int + \int_set_eq:NN \l_regex_left_state_int \l_regex_internal_a_int + \regex_build_new_state: + } + { + \regex_build_group_transition_right_max: + \regex_build_group_n_aux:n {#3} + \int_set_eq:NN \l_regex_left_state_int \l_regex_internal_a_int + \regex_build_group_submatches:NN + \l_regex_left_state_int \l_regex_right_state_int + \regex_build_group_n_aux:n { #4 - #3 + \c_one } + \int_sub:Nn \l_regex_right_state_int + { \l_regex_internal_a_int - \l_regex_left_state_int } + \prg_replicate:nn { #4 - #3 } + { + #2 + \int_add:Nn \l_regex_right_state_int + { \l_regex_internal_b_int - \l_regex_internal_a_int } + } + \int_set_eq:NN \l_regex_left_state_int \l_regex_internal_a_int + \regex_build_new_state: + } } } -\cs_new_protected:Npn \regex_build_group_n: #1 - { % ^^A todo: catch case #1 <= 0. - \regex_build_group_n_aux:n {#1} - \regex_build_transition:NN - \regex_action_free:n \l_regex_right_state_int - \regex_build_group_submatches:NN - \l_regex_tmpa_int \l_regex_left_state_int +\cs_new_protected:Npn \regex_build_group_nn_aux_ii:w #1 \regex_action_free:n + { + #1 + \regex_action_free:n + { + \int_eval:n + { \l_regex_max_state_int - \l_regex_right_state_int } + } + \regex_action_free:n } -\cs_new_eq:cN { regex_build_group_n?: } \regex_build_group_n: -\cs_new_protected:cpn { regex_build_group_n*: } #1 - { % ^^A todo: catch case #1 <= 0. - \regex_build_group_n_aux:n {#1} - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_tmpa_int - \regex_action_free:n \l_regex_right_state_int - \regex_build_group_submatches:NN - \l_regex_tmpa_int \l_regex_left_state_int +\cs_new_protected:cpn { regex_build_/u: } #1#2 + { + \regex_build_if_assertions_forbidden:TF + { \regex_build_raw_error:N u #1#2 } + { + \str_if_eq:xxTF {#1#2} { \regex_build_special:N \c_lbrace_str } + { + \tl_set:Nx \l_regex_internal_a_tl { \if_false: } \fi: + \regex_build_u_loop:NN + } + { + \msg_kernel_error:nn { regex } { u-missing-lbrace } + #1#2 + } + } } -\cs_new_protected:cpn { regex_build_group_n*?: } #1 - { % ^^A todo: catch case #1 <= 0. - \regex_build_group_n_aux:n {#1} - \regex_build_transitions:NNNN - \regex_action_free:n \l_regex_right_state_int - \regex_action_free:n \l_regex_tmpa_int - \regex_build_group_submatches:NN - \l_regex_tmpa_int \l_regex_left_state_int +\cs_new:Npn \regex_build_u_loop:NN #1#2 + { + \token_if_eq_meaning:NNTF #1 \regex_build_raw:N + { #2 \regex_build_u_loop:NN } + { + \token_if_eq_meaning:NNTF #1 \regex_build_special:N + { + \exp_after:wN \token_if_eq_charcode:NNTF \c_rbrace_str #2 + { \if_false: { \fi: } \regex_build_u_end: } + { #2 \regex_build_u_loop:NN } + } + { + \if_false: { \fi: } + \msg_kernel_error:nnx { regex } { u-missing-rbrace } {#2} + \regex_build_u_end: + #1#2 + } + } + } +\cs_new_protected:Npn \regex_build_u_end: + { + \tl_set:Nv \l_regex_internal_a_tl \l_regex_internal_a_tl + \if_num:w \l_regex_build_mode_int = \c_zero + \regex_build_u_not_cs: + \else: + \regex_build_u_in_cs: + \fi: + \tl_clear:N \l_regex_tests_tl } -\cs_new_protected:Npn \regex_build_group_nn: #1#2 - { % ^^A Not Implemented Yet! - \msg_expandable_error:n { Quantifier~{m,n}~not~implemented~yet } - \use:c { regex_build_group_n*: } {#1} +\cs_new_protected:Npn \regex_build_u_in_cs: + { + \exp_args:NNo \str_gset_other:Nn \g_regex_internal_tl + { \l_regex_internal_a_tl } + \tl_map_inline:Nn \g_regex_internal_tl + { + \tl_set:Nx \l_regex_tests_tl { \regex_item_equal:n { `##1 } } + \regex_build_one_: + } } -\cs_new_protected:cpn { regex_build_group_nn?: } #1#2 - { % ^^A Not Implemented Yet! - \msg_expandable_error:n { Quantifier~{m,n}~not~implemented~yet } - \use:c { regex_build_group_n*?: } {#1} +\cs_new_protected:Npn \regex_build_u_not_cs: + { + \exp_args:No \tl_analysis_map_inline:nn { \l_regex_internal_a_tl } + { + \tl_set:Nx \l_regex_tests_tl + { + \exp_not:N \int_compare:nNnT + \l_regex_current_catcode_int = { \int_value:w "##2 } + { + \int_compare:nNnTF { "##2 } = \c_zero + { + \exp_not:n + { \str_if_eq:xxT { \l_regex_current_token_tl } {##1} } + { \regex_break_true:w } + } + { \regex_item_equal:n {##3} } + } + } + \regex_build_one_: + } } \cs_new_protected:Npn \regex_store_state:n #1 { - \int_incr:N \l_regex_max_index_int - \tex_skip:D \l_regex_max_index_int #1 sp \scan_stop: + \int_incr:N \l_regex_max_active_int + \tex_skip:D \l_regex_max_active_int #1 sp \scan_stop: \regex_store_submatches:n {#1} } \cs_new_protected_nopar:Npn \regex_state_use_with_submatches: @@ -1336,10 +1656,9 @@ { \regex_state_use_aux:n { \exp_after:wN \use_none_delimit_by_s_stop:w } } \cs_new_protected:Npn \regex_state_use_aux:n #1 { - \if_num:w \tex_dimen:D \l_regex_current_state_int - < \l_regex_unique_id_int + \if_num:w \tex_dimen:D \l_regex_current_state_int < \l_regex_step_int \tex_dimen:D \l_regex_current_state_int - = \l_regex_unique_id_int sp \scan_stop: + = \l_regex_step_int sp \scan_stop: #1 \tex_the:D \tex_toks:D \exp_after:wN \l_regex_current_state_int \fi: \scan_stop: @@ -1374,68 +1693,55 @@ { \exp_after:wN \c_zero \exp_after:wN \regex_state_submatches:nn \exp_after:wN - { - \int_value:w \int_eval:w - \l_regex_unique_id_int + \c_one - \exp_after:wN - } + { \int_value:w \int_eval:w \l_regex_step_int + \c_one \exp_after:wN } \exp_after:wN { \l_regex_current_submatches_prop } \regex_state_submatches:nn {#1} {#2} \s_stop } \cs_new_protected:Npn \regex_state_submatches:nn #1#2 { - \if_num:w #1 = \l_regex_unique_id_int + \if_num:w #1 = \l_regex_step_int \tl_set:Nn \l_regex_current_submatches_prop { #2 } \fi: } \cs_new_protected:Npn \regex_match:n #1 { - \tl_set_analysis:Nn \l_regex_tmpa_tl {#1} - \int_zero:N \l_regex_nesting_int - \int_set_eq:NN \l_regex_current_step_int \l_regex_max_state_int + \int_set_eq:NN \l_regex_current_index_int \l_regex_max_state_int \regex_query_set:nnn { } { -1 } { -2 } - \int_set_eq:NN \l_regex_min_step_int \l_regex_current_step_int - \exp_after:wN \regex_query_set_loop:ww - \l_regex_tmpa_tl - \s_tl { ? \prg_map_break: } \s_tl - \prg_break_point:n { } - \int_set_eq:NN \l_regex_max_step_int \l_regex_current_step_int + \int_set_eq:NN \l_regex_min_index_int \l_regex_current_index_int + \tl_analysis_map_inline:nn {#1} + { + \regex_query_set:nnn {##1} {"##2} {##3} + \if_case:w "##2 \exp_stop_f: + \or: \int_incr:N \l_regex_nesting_int + \or: \int_decr:N \l_regex_nesting_int + \fi: + } + \int_set_eq:NN \l_regex_max_index_int \l_regex_current_index_int \regex_query_set:nnn { } { -1 } { -2 } - \regex_match_initial_setup: \regex_match_once: } -\cs_new:Npn \regex_query_set_loop:ww #1 \s_tl #2#3 \s_tl - { - \use_none:n #2 - \regex_query_set:nnn {#1} {"#2} {#3} - \if_case:w "#2 \exp_stop_f: - \or: \int_incr:N \l_regex_nesting_int - \or: \int_decr:N \l_regex_nesting_int - \fi: - \regex_query_set_loop:ww - } \cs_new_protected:Npn \regex_query_set:nnn #1#2#3 { - \tex_muskip:D \l_regex_current_step_int + \tex_muskip:D \l_regex_current_index_int = \etex_gluetomu:D #3 sp plus #2 sp minus \l_regex_nesting_int sp \scan_stop: - \tex_toks:D \l_regex_current_step_int {#1} - \int_incr:N \l_regex_current_step_int + \tex_toks:D \l_regex_current_index_int {#1} + \int_incr:N \l_regex_current_index_int } \cs_new_protected_nopar:Npn \regex_query_get: { \tl_set:Nx \l_regex_current_token_tl - { \tex_the:D \tex_toks:D \l_regex_current_step_int } + { \tex_the:D \tex_toks:D \l_regex_current_index_int } \l_regex_current_char_int - = \etex_mutoglue:D \tex_muskip:D \l_regex_current_step_int + = \etex_mutoglue:D \tex_muskip:D \l_regex_current_index_int \l_regex_current_catcode_int = \etex_gluestretch:D - \etex_mutoglue:D \tex_muskip:D \l_regex_current_step_int + \etex_mutoglue:D \tex_muskip:D \l_regex_current_index_int } \cs_new_protected_nopar:Npn \regex_match_once: { @@ -1451,13 +1757,14 @@ } \cs_new_protected_nopar:Npn \regex_match_initial_setup: { - \prg_stepwise_inline:nnnn {0} {1} { \l_regex_max_state_int - \c_one } - { \tex_dimen:D ##1 \c_minus_one sp \scan_stop: } - \int_set_eq:NN \l_regex_unique_id_int \c_minus_one - \int_set:Nn \l_regex_start_step_int - { \l_regex_min_step_int - \c_one } - \int_set_eq:NN \l_regex_current_step_int \l_regex_min_step_int - \int_set_eq:NN \l_regex_success_step_int \l_regex_min_step_int + \int_set_eq:NN \l_regex_step_int \c_minus_one + \prg_stepwise_inline:nnnn + \c_zero \c_one { \l_regex_max_state_int - \c_one } + { \tex_dimen:D ##1 \l_regex_step_int sp \scan_stop: } + \int_set:Nn \l_regex_start_index_int + { \l_regex_min_index_int - \c_one } + \int_set_eq:NN \l_regex_current_index_int \l_regex_min_index_int + \int_set_eq:NN \l_regex_success_index_int \l_regex_min_index_int \int_set_eq:NN \l_regex_submatch_int \l_regex_max_state_int \bool_set_false:N \l_regex_success_empty_bool \bool_gset_false:N \g_regex_success_bool @@ -1466,49 +1773,48 @@ { \prop_clear:N \l_regex_current_submatches_prop \bool_if:NTF \l_regex_success_empty_bool - { \cs_set_eq:NN \regex_last_match_empty:F \regex_last_match_empty_yes:F } - { \cs_set_eq:NN \regex_last_match_empty:F \regex_last_match_empty_no:F } - \int_set_eq:NN \l_regex_start_step_int \l_regex_success_step_int - \int_set:Nn \l_regex_current_step_int - { \l_regex_start_step_int - \c_one } + { \cs_set_eq:NN \regex_if_two_empty_matches:F \regex_if_match_empty:F } + { \cs_set_eq:NN \regex_if_two_empty_matches:F \use:n } + \int_set_eq:NN \l_regex_start_index_int \l_regex_success_index_int + \int_set:Nn \l_regex_current_index_int + { \l_regex_start_index_int - \c_one } \bool_set_false:N \l_regex_success_match_bool - \int_zero:N \l_regex_max_index_int + \int_zero:N \l_regex_max_active_int \regex_store_state:n {0} %^^A _state_int! } \cs_new_protected_nopar:Npn \regex_match_loop: { - \int_incr:N \l_regex_current_step_int - \int_incr:N \l_regex_unique_id_int + \int_incr:N \l_regex_current_index_int + \int_incr:N \l_regex_step_int \bool_set_false:N \l_regex_fresh_thread_bool \int_set_eq:NN \l_regex_last_char_int \l_regex_current_char_int \regex_query_get: \regex_match_loop_case_hook: - \cs_set_nopar:Npx \regex_tmp:w + \use:x { - \int_zero:N \l_regex_max_index_int - \regex_match_one_index:w 1 ; \prg_break_point:n { } + \int_zero:N \l_regex_max_active_int + \regex_match_one_active:w 1 ; \prg_break_point:n { } \exp_not:N \prg_break_point:n { } } - \regex_tmp:w \if_num:w \l_regex_current_char_int < \c_minus_one \exp_after:wN \prg_map_break: \fi: - \if_num:w \l_regex_max_index_int = \c_zero + \if_num:w \l_regex_max_active_int = \c_zero \exp_after:wN \prg_map_break: \fi: \regex_match_loop: } -\cs_new:Npn \regex_match_one_index:w #1; +\cs_new:Npn \regex_match_one_active:w #1; { - \if_num:w #1 > \l_regex_max_index_int + \if_num:w #1 > \l_regex_max_active_int \exp_after:wN \prg_map_break: \fi: - \regex_match_one_index_aux:n + \regex_match_one_active_aux:n { \int_value:w \tex_skip:D #1 } - \exp_after:wN \regex_match_one_index:w + \exp_after:wN \regex_match_one_active:w \int_use:N \int_eval:w #1 + \c_one ; } -\cs_new_protected:Npn \regex_match_one_index_aux:n #1 +\cs_new_protected:Npn \regex_match_one_active_aux:n #1 { \int_set:Nn \l_regex_current_state_int {#1} \prop_clear:N \l_regex_current_submatches_prop @@ -1546,12 +1852,12 @@ } \cs_new_protected_nopar:Npn \regex_action_success: { - \regex_last_match_empty:F + \regex_if_two_empty_matches:F { \bool_set_true:N \l_regex_success_match_bool \bool_set_eq:NN \l_regex_success_empty_bool \l_regex_fresh_thread_bool - \int_set_eq:NN \l_regex_success_step_int \l_regex_current_step_int + \int_set_eq:NN \l_regex_success_index_int \l_regex_current_index_int \prop_set_eq:NN \l_regex_success_submatches_prop \l_regex_current_submatches_prop \prg_map_break: @@ -1559,7 +1865,7 @@ } \cs_new_protected:Npn \regex_action_free:n #1 { - \cs_set_nopar:Npx \regex_tmp:w + \use:x { \int_add:Nn \l_regex_current_state_int {#1} \regex_state_use: @@ -1568,13 +1874,16 @@ \tl_set:Nn \exp_not:N \l_regex_current_submatches_prop { \exp_not:o \l_regex_current_submatches_prop } } - \regex_tmp:w } \cs_new_protected:Npn \regex_action_submatch:n #1 { \prop_put:Nno \l_regex_current_submatches_prop {#1} - { \int_use:N \l_regex_current_step_int } + { \int_use:N \l_regex_current_index_int } } +\cs_new:Npn \regex_if_match_empty:T + { \int_compare:nNnT \l_regex_start_index_int = \l_regex_current_index_int } +\cs_new:Npn \regex_if_match_empty:F + { \int_compare:nNnF \l_regex_start_index_int = \l_regex_current_index_int } \cs_new_protected:Npn \regex_submatch_nesting_aux:n #1 { + \etex_glueshrink:D \etex_mutoglue:D \etex_muexpr:D @@ -1589,10 +1898,10 @@ \int_zero:N \l_regex_replacement_int \int_zero:N \l_regex_nesting_int \tl_clear:N \l_regex_nesting_tl - \str_escape_use:NNNn - \regex_replacement_unescaped:N - \regex_replacement_escaped:N - \regex_replacement_raw:N + \regex_escape_use:nnnn + { \regex_replacement_unescaped:N ##1 } + { \regex_replacement_escaped:N ##1 } + { \regex_replacement_raw:N ##1 } {#1} \prg_do_nothing: \prg_do_nothing: \cs_set:Npx \regex_nesting:n ##1 @@ -1604,9 +1913,9 @@ \use:x { \exp_not:n { \cs_set:Npn \regex_replacement_tl:n ##1 } - { \str_aux_toks_range:nn \c_zero \l_regex_replacement_int } + { \regex_toks_range:nn \c_zero \l_regex_replacement_int } } - % ^^A rename! Careful with \cP\#. + % ^^A rename! } \cs_new_protected:Npn \regex_replacement_raw:N #1 { \regex_replacement_put:n {#1} } @@ -1629,19 +1938,14 @@ } \cs_new_protected:Npn \regex_replacement_escaped:N #1 { - \if_charcode:w c #1 - \exp_after:wN \regex_replacement_c:w - \else: - \if_charcode:w g #1 - \exp_after:wN \exp_after:wN \exp_after:wN \regex_replacement_g:w - \else: + \cs_if_exist_use:cF { regex_replacement_#1:w } + { \if_num:w \c_one < 1#1 \exp_stop_f: \regex_replacement_put_submatch:n {#1} \else: \regex_replacement_put:n #1 \fi: - \fi: - \fi: + } } \cs_new_protected:Npn \regex_replacement_put_submatch:n #1 { @@ -1668,7 +1972,7 @@ { \exp_not:n { #1#2 } } { \regex_replacement_unescaped:N \c_lbrace_str } { - \int_zero:N \l_regex_tmpa_int + \int_zero:N \l_regex_internal_a_int \regex_replacement_g_digits:NN } { \regex_replacement_error:NNN g #1 #2 } @@ -1678,13 +1982,13 @@ \token_if_eq_meaning:NNTF #1 \regex_replacement_unescaped:N { \if_num:w \c_one < 1#2 \exp_stop_f: - \int_set:Nn \l_regex_tmpa_int { \c_ten * \l_regex_tmpa_int + #2 } + \int_set:Nn \l_regex_internal_a_int { \c_ten * \l_regex_internal_a_int + #2 } \exp_after:wN \use_i:nnn \exp_after:wN \regex_replacement_g_digits:NN \else: \if_charcode:w \c_rbrace_str #2 \exp_args:No \regex_replacement_put_submatch:n - { \int_use:N \l_regex_tmpa_int } + { \int_use:N \l_regex_internal_a_int } \exp_after:wN \exp_after:wN \exp_after:wN \use_none:nn \else: \exp_after:wN \exp_after:wN @@ -1696,6 +2000,16 @@ { \regex_replacement_error:NNN g } #1 #2 } +\cs_new_protected:Npn \regex_replacement_u:w #1#2 + { + \str_if_eq:xxTF { #1#2 } { \regex_replacement_unescaped:N \c_lbrace_str } + { + \int_incr:N \l_regex_replacement_csnames_int + \regex_replacement_put:n + { \exp_not:n { \exp_after:wN \exp_not:V \cs:w } } + } + { \regex_replacement_error:NNN u #1#2 } + } \cs_new_protected:Npn \regex_replacement_c:w #1#2 { \token_if_eq_meaning:NNTF #1 \regex_replacement_unescaped:N @@ -1711,8 +2025,6 @@ \regex_replacement_put:n { \exp_not:n { \exp_after:wN \regex_replacement_exp_not:N \cs:w } } } -\cs_new_eq:cc { regex_replacement_c_C:w } - { regex_replacement_c_ \c_lbrace_str :w } \cs_new:Npn \regex_replacement_exp_not:N #1 { \exp_not:n {#1} } \group_begin: @@ -1790,11 +2102,11 @@ { \group_begin: \regex_build:n {#3} - \cs_set_nopar:Npx \regex_tmp:w - { #1 \exp_not:N #2 { \regex_set_aux:N #2 } } - \exp_after:wN - \group_end: - \regex_tmp:w + \use:x + { + \group_end: + #1 \exp_not:N #2 { \regex_set_aux:N #2 } + } } \cs_new:Npn \regex_set_aux:N #1 { @@ -1811,7 +2123,7 @@ \regex_match_loop_caseless_hook: } \prg_stepwise_function:nnnN - {0} {1} {\l_regex_max_state_int - \c_one } + \c_zero \c_one {\l_regex_max_state_int - \c_one } \regex_set_aux:n \s_stop } @@ -1824,18 +2136,6 @@ } \cs_new_protected_nopar:Npn \regex_use:N { \exp_last_unbraced:No \use_none:nn } -\cs_new:Npn \regex_to_str:N #1 - { - \exp_after:wN \regex_to_str_aux:Nw #1 - \tex_toks:D \q_stop \prg_map_break: \tex_toks:D - \prg_break_point:n { } - } -\cs_new:Npn \regex_to_str_aux:Nw #1#2\tex_toks:D - { - \use_none_delimit_by_q_stop:w #2 \q_stop - \tl_to_str:n {#1#2} \iow_newline: - \regex_to_str_aux:Nw \tex_toks:D - } \cs_new_protected_nopar:Npn \regex_aux_return: { \if_meaning:w \c_true_bool \g_regex_success_bool @@ -1921,9 +2221,9 @@ \cs_new_protected:Npn \regex_group_end_extract_seq:N #1 { \cs_set_eq:NN \seq_item:n \scan_stop: - \flag_lower:N \l_regex_group_begin_flag - \flag_lower:N \l_regex_group_end_flag - \tl_set:Nx \l_regex_tmpa_tl + \flag_clear:n { regex_begin } + \flag_clear:n { regex_end } + \tl_set:Nx \l_regex_internal_a_tl { \prg_stepwise_function:nnnN \l_regex_max_state_int @@ -1931,12 +2231,13 @@ { \l_regex_submatch_int - \c_one } \regex_extract_seq_aux:n } - \flag_test:NF \l_regex_group_begin_flag - { \flag_test:NF \l_regex_group_end_flag { \use_none:nnn } } - \msg_kernel_error:nn { regex } { sequence-unbalanced } - \tl_set:Nx \l_regex_tmpa_tl { \l_regex_tmpa_tl } + \int_compare:nNnF + { \flag_height:n { regex_begin } + \flag_height:n { regex_end } } + = \c_zero + { \msg_kernel_error:nn { regex } { sequence-unbalanced } } + \tl_set:Nx \l_regex_internal_a_tl { \l_regex_internal_a_tl } \exp_args:NNNo \group_end: - \tl_set:Nn #1 \l_regex_tmpa_tl + \tl_set:Nn #1 \l_regex_internal_a_tl } \cs_new:Npn \regex_extract_seq_aux:n #1 { @@ -1947,14 +2248,14 @@ } } \cs_new:Npn \regex_extract_seq_aux:ww #1; #2; - { %^^A todo: use flags + { \if_num:w #1 < \c_zero - \flag_raise:N \l_regex_group_end_flag + \flag_raise:n { regex_end } \prg_replicate:nn {-#1} { \exp_not:n { { \if_false: } \fi: } } \fi: \regex_query_submatch:w #2; \if_num:w #1 > \c_zero - \flag_raise:N \l_regex_group_begin_flag + \flag_raise:n { regex_begin } \prg_replicate:nn {#1} { \exp_not:n { \if_false: { \fi: } } } \fi: } @@ -2016,20 +2317,20 @@ \group_begin: \tl_set:Nn \l_regex_every_match_tl { - \if_num:w \l_regex_start_step_int < \l_regex_success_step_int + \if_num:w \l_regex_start_index_int < \l_regex_success_index_int \regex_extract: \tex_skip:D \l_regex_submatch_start_int - = \l_regex_start_step_int sp + = \l_regex_start_index_int sp plus \tex_skip:D \l_regex_submatch_start_int \scan_stop: \fi: \regex_match_once: } #1 {#2} {#3} \tex_skip:D \l_regex_submatch_int - = \l_regex_start_step_int sp - plus \l_regex_current_step_int sp \scan_stop: + = \l_regex_start_index_int sp + plus \l_regex_current_index_int sp \scan_stop: \int_incr:N \l_regex_submatch_int - \if_num:w \l_regex_start_step_int = \l_regex_current_step_int + \if_num:w \l_regex_start_index_int = \l_regex_current_index_int \if_meaning:w \c_true_bool \l_regex_success_empty_bool \int_decr:N \l_regex_submatch_int \fi: @@ -2044,34 +2345,34 @@ \exp_args:Nno #1 {#2} #4 \if_meaning:w \c_true_bool \g_regex_success_bool \regex_extract: - \int_set:Nn \l_regex_tmpa_int + \int_set:Nn \l_regex_internal_a_int { \regex_nesting:n { \l_regex_submatch_start_int } } - \if_num:w \l_regex_tmpa_int = \c_zero + \if_num:w \l_regex_internal_a_int = \c_zero \else: \msg_kernel_error:nnx { regex } { replace-unbalanced } - { \l_regex_tmpa_int } + { \l_regex_internal_a_int } \fi: - \tl_set:Nx \l_regex_tmpa_tl + \tl_set:Nx \l_regex_internal_a_tl { - \if_num:w \l_regex_tmpa_int < \c_zero - \prg_replicate:nn { - \l_regex_tmpa_int } + \if_num:w \l_regex_internal_a_int < \c_zero + \prg_replicate:nn { - \l_regex_internal_a_int } { \exp_not:n { { \if_false: } \fi: } } \fi: - \regex_query_substr:nn - { \l_regex_min_step_int } + \regex_toks_range:nn + { \l_regex_min_index_int } { \tex_skip:D \l_regex_submatch_start_int } \regex_replacement_tl:n { \l_regex_submatch_start_int } - \regex_query_substr:nn + \regex_toks_range:nn { \etex_gluestretch:D \tex_skip:D \l_regex_submatch_start_int } - { \l_regex_max_step_int } - \if_num:w \l_regex_tmpa_int > \c_zero - \prg_replicate:nn { \l_regex_tmpa_int } + { \l_regex_max_index_int } + \if_num:w \l_regex_internal_a_int > \c_zero + \prg_replicate:nn { \l_regex_internal_a_int } { \exp_not:n { \if_false: { \fi: } } } \fi: } - \tl_set:Nx \l_regex_tmpa_tl { \l_regex_tmpa_tl } + \tl_set:Nx \l_regex_internal_a_tl { \l_regex_internal_a_tl } \exp_args:NNNo \group_end: - \tl_set:Nn #4 \l_regex_tmpa_tl + \tl_set:Nn #4 \l_regex_internal_a_tl \else: \group_end: \fi: @@ -2087,12 +2388,12 @@ \regex_extract: \tex_skip:D \l_regex_submatch_start_int = \tex_the:D \tex_skip:D \l_regex_submatch_start_int - minus \l_regex_start_step_int sp \scan_stop: + minus \l_regex_start_index_int sp \scan_stop: \regex_match_once: } \regex_replacement:n {#3} \exp_args:Nno #1 {#2} #4 - \int_set:Nn \l_regex_tmpa_int + \int_set:Nn \l_regex_internal_a_int { 0 \prg_stepwise_function:nnnN @@ -2101,15 +2402,15 @@ { \l_regex_submatch_int - \c_one } \regex_nesting:n } - \if_num:w \l_regex_tmpa_int = \c_zero + \if_num:w \l_regex_internal_a_int = \c_zero \else: \msg_kernel_error:nnx { regex } { replace-unbalanced } - { \l_regex_tmpa_int } + { \l_regex_internal_a_int } \fi: - \tl_set:Nx \l_regex_tmpa_tl + \tl_set:Nx \l_regex_internal_a_tl { - \if_num:w \l_regex_tmpa_int < \c_zero - \prg_replicate:nn { - \l_regex_tmpa_int } + \if_num:w \l_regex_internal_a_int < \c_zero + \prg_replicate:nn { - \l_regex_internal_a_int } { \exp_not:n { { \if_false: } \fi: } } \fi: \prg_stepwise_function:nnnN @@ -2117,30 +2418,144 @@ \l_regex_capturing_group_int { \l_regex_submatch_int - \c_one } \regex_replace_all_aux:n - \regex_query_substr:nn - \l_regex_start_step_int \l_regex_max_step_int - \if_num:w \l_regex_tmpa_int > \c_zero - \prg_replicate:nn { \l_regex_tmpa_int } + \regex_toks_range:nn + \l_regex_start_index_int \l_regex_max_index_int + \if_num:w \l_regex_internal_a_int > \c_zero + \prg_replicate:nn { \l_regex_internal_a_int } { \exp_not:n { \if_false: { \fi: } } } \fi: } - \tl_set:Nx \l_regex_tmpa_tl { \l_regex_tmpa_tl } + \tl_set:Nx \l_regex_internal_a_tl { \l_regex_internal_a_tl } \exp_args:NNNo \group_end: - \tl_set:Nn #4 \l_regex_tmpa_tl + \tl_set:Nn #4 \l_regex_internal_a_tl } \cs_new:Npn \regex_replace_all_aux:n #1 { - \regex_query_substr:nn + \regex_toks_range:nn { \etex_glueshrink:D \tex_skip:D #1 } { \tex_skip:D #1 } \regex_replacement_tl:n {#1} } +\msg_kernel_new:nnnn { regex } { trailing-backslash } + { Trailing~escape~character~\iow_char:N\\. } + { + A~regular~expression~or~its~replacement~text~ends~with~ + the~escape~character~\iow_char:N\\.~It~will~be~ignored. + } +\msg_kernel_new:nnnn { regex } { x-missing-rbrace } + { Missing~closing~brace~in~\iow_char:N\\x~hexadecimal~sequence. } + { + You~wrote~something~like~ + `\iow_char:N\\x\{\int_to_hexadecimal:n{#1}'.~ + The~closing~brace~is~missing. + } +\msg_kernel_new:nnnn { regex } { x-overflow } + { Character~code~'#1'~too~large~in~\iow_char:N\\x~hexadecimal~sequence. } + { + You~wrote~something~like~ + `\iow_char:N\\x\{\int_to_hexadecimal:n{#1}\}'.~ + The~character~code~'#1'~is~larger~than~\int_use:N \c_max_char_int. + } +\msg_kernel_new:nnnn { regex } { missing-rbrack } + { Missing~right~bracket~inserted~in~regular~expression. } + { + LaTeX~was~given~a~regular~expression~where~a~character~class~ + was~started~with~'[',~but~the~matching~']'~is~missing. + } +\msg_kernel_new:nnnn { regex } { missing-rparen } + { + Missing~right~parenthes\int_compare:nTF{#1=1}{i}{e}s~ + inserted~in~regular~expression. + } + { + LaTeX~was~given~a~regular~expression~with~\int_eval:n{#1}~ + more~left~parenthes\int_compare:nTF{#1=1}{i}{e}s~than~right~ + parenthes\int_compare:nTF{#1=1}{i}{e}s. + } +\msg_kernel_new:nnnn { regex } { extra-rparen } + { Extra~right~parenthesis~ignored~in~regular~expression. } + { + LaTeX~came~across~a~closing~parenthesis~when~no~submatch~group~ + was~open.~The~parenthesis~will~be~ignored. + } +\msg_kernel_new:nnnn { regex } { class-bad-escape } + { Invalid~escape~\c_backslash_str #1~in~character~class. } + { + The~escape~sequence~\iow_char:N\\#1~may~not~appear~within~ + a~character~class.~For~instance,~assertions~(which~match~zero~ + characters)~would~not~make~sense~there. + } +\msg_kernel_new:nnnn { regex } { catcode-bad-escape } + { Invalid~escape~\c_backslash_str #1~following~category~test. } + { + The~escape~sequence~\iow_char:N\\#1~may~not~appear~following~ + a~category~test~such~as~\iow_char:N\\cL~or~ + \iow_char:N\\c[\iow_char:N\^BE]. + } +\msg_kernel_new:nnnn { regex } { range-missing-end } + { Invalid~end-point~for~range~'#1-#2'~in~character~class. } + { + The~end-point~'#2'~of~the~range~'#1-#2'~may~not~serve~as~an~ + end-point~for~a~range:~alphanumeric~characters~should~not~be~ + escaped,~and~non-alphanumeric~characters~should~be~escaped. + } +\msg_kernel_new:nnnn { regex } { range-backwards } + { Range~[#1-#2]~out~of~order~in~character~class. } + { + In~ranges~of~characters~[x-y]~appearing~in~character~classes,~ + the~first~character~code~must~not~be~larger~than~the~second.~ + Here,~#1~has~character~code~\int_eval:n {`#1},~while~#2~has~ + character~code~\int_eval:n {`#2}. + } +\msg_kernel_new:nnnn { regex } { c-bad-mode } + { Invalid~nested~\iow_char:N\\c~escape~in~regular~expression. } + { + The~\iow_char:N\\c~escape~cannot~be~used~within~ + a~control~sequence~test~'\iow_char:N\\c{...}'.~ + To~combine~several~category~tests,~use~'\iow_char:N\\c[...]'. + } +\msg_kernel_new:nnnn { regex } { c-missing-rbrace } + { Missing~right~brace~inserted~for~\iow_char:N\\c~escape. } + { + LaTeX~was~given~a~regular~expression~where~a~ + '\iow_char:N\\c\iow_char:N\{...'~construction~was~not~ended~ + with~a~closing~brace~'\iow_char:N\}'. + } +\msg_kernel_new:nnnn { regex } { c-missing-rbrack } + { Missing~right~bracket~inserted~for~\iow_char:N\\c~escape. } + { + A~construction~'\iow_char:N\\c[...'~appears~in~a~ + regular~expression,~but~the~closing~']'~is~not~present. + } +\msg_kernel_new:nnnn { regex } { c-missing-category } + { Invalid~character~'#1'~following~\iow_char\\c~escape. } + { + In~regular~expressions,~the~\iow_char:N\\c~escape~sequence~ + may~only~be~followed~by~a~left~brace,~a~left~bracket,~or~a~ + capital~letter~representing~a~character~category,~namely~ + one~of~ABCDELMOPSTU. + } +\msg_kernel_new:nnnn { regex } { u-missing-lbrace } + { Missing~left~brace~following~\iow_char:N\\u~escape. } + { + The~\iow_char:N\\u~escape~sequence~must~be~followed~by~ + a~brace~group~with~the~name~of~the~variable~to~use. + } +\msg_kernel_new:nnnn { regex } { u-missing-rbrace } + { Missing~right~brace~inserted~for~\iow_char:N\\u~escape. } + { + LaTeX~ + \tl_if_empty:xTF {#2} + { reached~the~end~of~the~string~ } + { encountered~an~escaped~alphanumeric~character '\iow_char:N\\#2'~ } + when~parsing~the~argument~of~an~'\iow_char:N\\u\iow_char:N\{...\}'~escape. + } \msg_kernel_new:nnnn { regex } { sequence-unbalanced } { Missing~ - \flag_test:NTF \l_regex_group_end_flag + \flag_if_raised:nTF { regex_end } { left~ - \flag_test:NTF \l_regex_group_begin_flag + \flag_if_raised:nTF { regex_begin } { and~right~braces } { brace } } { right~brace } @@ -2170,34 +2585,6 @@ } \ inserted. } -\msg_kernel_new:nnnn { regex } { missing-rparen } - { Missing~right~parenthesis~added~in~regular~expression. } - { - LaTeX~was~given~a~regular~expression~with~\int_eval:n{#1}~ - more~left~parenthes\int_compare:nTF{#1=1}{i}{e}s~than~right~ - parenthes\int_compare:nTF{#1=1}{i}{e}s. - } -\msg_kernel_new:nnnn { regex } { extra-rparen } - { Extra~right~parenthesis~ignored~in~regular~expression. } - { - LaTeX~came~across~a~closing~parenthesis~when~no~submatch~group~ - was~open.~The~parenthesis~will~be~ignored. - } -\msg_kernel_new:nnnn { regex } { backwards-range } - { Range~[#1-#2]~out~of~order~in~character~class. } - { - In~ranges~of~characters~[x-y]~appearing~in~character~classes,~ - the~first~character~code~must~not~be~larger~than~the~second.~ - Here,~#1~has~character~code~\int_eval:n {`#1},~while~#2~has~ - character~code~\int_eval:n {`#2}. - } -\msg_kernel_new:nnnn { regex } { unsupported } - { Unsupported~construction~`#1'. } - { - The~construction~`#1'~is~not~supported~by~the~LaTeX~ - regular~expression~module.~Perhaps~some~character~should~ - have~been~escaped? - } \msg_kernel_new:nnnn { regex } { not-nfa } { This~is~not~a~regular~expression~variable. } { @@ -2206,6 +2593,8 @@ is~\\\\ \ \ \ \ \token_to_str:N #1 = \token_to_meaning:N #1 . } +\msg_kernel_new:nnn { regex } { nfa-misused } + { Automaton~#1 used~incorrectly. } \msg_kernel_new:nnnn { regex } { c-command } { Misused~\iow_char:N\\c~or\iow_char:N\\C~command~in~a~#1. } { @@ -2232,8 +2621,6 @@ submatches~are~represented~either~as~\iow_char:N \\g{dd..d},~ or~\\d,~where~`d'~are~single~digits.~Here,~a~brace~is~missing. } -\msg_kernel_new:nnn { regex } { nfa-misused } - { Automaton~#1 used~incorrectly. } %% %% %% End of file `l3regex.sty'. diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty index cc4d6716ed5..d9ef6271899 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3str.sty @@ -46,31 +46,32 @@ %% %% ----------------------------------------------------------------------- \RequirePackage{expl3} -\GetIdInfo$Id: l3str.dtx 3159 2012-01-09 00:51:58Z bruno $ +\GetIdInfo$Id: l3str.dtx 3257 2012-01-29 13:37:03Z bruno $ {L3 Experimental Strings} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} -\RequirePackage{l3tl-analysis} -\group_begin: - \cs_set_protected_nopar:Npn \str_tmp:w #1 - { - \cs_new_protected:cpx { str_ #1 :Nn } ##1##2 - { \exp_not:c { tl_ #1 :Nx } ##1 { \exp_not:N \tl_to_str:n {##2} } } - \exp_args:Nc \cs_generate_variant:Nn { str_ #1 :Nn } { Nx , cn , cx } - } - \str_tmp:w { set } - \str_tmp:w { gset } - \str_tmp:w { const } - \str_tmp:w { put_left } - \str_tmp:w { gput_left } - \str_tmp:w { put_right } - \str_tmp:w { gput_right } -\group_end: +\RequirePackage{l3tl-analysis,l3flag} +\cs_if_exist:NF \use_ii_i:nn + { \cs_new:Npn \use_ii_i:nn #1#2 { #2 #1 } } +\tl_map_inline:nn + { + { set } + { gset } + { const } + { put_left } + { gput_left } + { put_right } + { gput_right } + } + { + \cs_new_protected:cpx { str_ #1 :Nn } ##1##2 + { \exp_not:c { tl_ #1 :Nx } ##1 { \exp_not:N \tl_to_str:n {##2} } } + \exp_args:Nc \cs_generate_variant:Nn { str_ #1 :Nn } { Nx , cn , cx } + } \cs_new_protected_nopar:Npn \str_tmp:w { } -\tl_new:N \l_str_tmpa_tl -\int_new:N \l_str_tmpa_int +\tl_new:N \l_str_internal_tl +\int_new:N \l_str_internal_int \tl_new:N \g_str_result_tl -\int_new:N \l_str_char_int \int_const:Nn \c_forty_eight { 48 } \int_const:Nn \c_fifty_eight { 58 } \int_const:Nn \c_sixty_five { 65 } @@ -79,7 +80,7 @@ \int_const:Nn \c_one_hundred_twenty_three { 123 } \int_const:Nn \c_one_hundred_twenty_seven { 127 } \int_const:Nn \c_max_char_int - { \pdftex_if_engine:TF { 255 } { 1114111 } } + { \pdftex_if_engine:TF { "FF } { "10FFFF } } \int_const:Nn \c_str_replacement_char_int { "FFFD } \tl_const:Nx \c_backslash_str { \cs_to_str:N \\ } \tl_const:Nx \c_lbrace_str { \cs_to_str:N \{ } @@ -87,18 +88,25 @@ \tl_const:Nx \c_hash_str { \cs_to_str:N \# } \tl_const:Nx \c_tilde_str { \cs_to_str:N \~ } \tl_const:Nx \c_percent_str { \cs_to_str:N \% } -\prop_new:N \g_str_aliases_prop -\prop_gput:Nnn \g_str_aliases_prop { latin1 } { iso88591 } -\prop_gput:Nnn \g_str_aliases_prop { latin2 } { iso88592 } -\prop_gput:Nnn \g_str_aliases_prop { latin3 } { iso88593 } -\prop_gput:Nnn \g_str_aliases_prop { latin4 } { iso88594 } -\prop_gput:Nnn \g_str_aliases_prop { latin5 } { iso88599 } -\prop_gput:Nnn \g_str_aliases_prop { latin6 } { iso885910 } -\prop_gput:Nnn \g_str_aliases_prop { latin7 } { iso885913 } -\prop_gput:Nnn \g_str_aliases_prop { latin8 } { iso885914 } -\prop_gput:Nnn \g_str_aliases_prop { latin9 } { iso885915 } -\prop_gput:Nnn \g_str_aliases_prop { latin10 } { iso885916 } -\prop_gput:Nnn \g_str_aliases_prop { hexadecimal } { hex } +\prop_new:N \g_str_file_prop +\prop_gput:Nnn \g_str_file_prop { latin1 } { iso88591 } +\prop_gput:Nnn \g_str_file_prop { latin2 } { iso88592 } +\prop_gput:Nnn \g_str_file_prop { latin3 } { iso88593 } +\prop_gput:Nnn \g_str_file_prop { latin4 } { iso88594 } +\prop_gput:Nnn \g_str_file_prop { latin5 } { iso88599 } +\prop_gput:Nnn \g_str_file_prop { latin6 } { iso885910 } +\prop_gput:Nnn \g_str_file_prop { latin7 } { iso885913 } +\prop_gput:Nnn \g_str_file_prop { latin8 } { iso885914 } +\prop_gput:Nnn \g_str_file_prop { latin9 } { iso885915 } +\prop_gput:Nnn \g_str_file_prop { latin10 } { iso885916 } +\prop_gput:Nnn \g_str_file_prop { utf16le } { utf16 } +\prop_gput:Nnn \g_str_file_prop { utf16be } { utf16 } +\prop_gput:Nnn \g_str_file_prop { utf32le } { utf32 } +\prop_gput:Nnn \g_str_file_prop { utf32be } { utf32 } +\prop_gput:Nnn \g_str_file_prop { hexadecimal } { hex } +\bool_new:N \g_str_error_bool +\flag_new:n { str_byte } +\flag_new:n { str_error } \group_begin: \char_set_lccode:nn { `\* } { `\ } \char_set_lccode:nn { `\A } { `\A } @@ -110,7 +118,7 @@ \exp_after:wN \tl_to_other_str_loop:w \tl_to_str:n {#1} ~ % A ~ A ~ A ~ A ~ A ~ A ~ A ~ A ~ \q_mark \q_stop } - \cs_new_nopar:Npn \tl_to_other_str_loop:w + \cs_new:Npn \tl_to_other_str_loop:w #1 ~ #2 ~ #3 ~ #4 ~ #5 ~ #6 ~ #7 ~ #8 ~ #9 \q_stop { \if_meaning:w A #8 @@ -119,7 +127,7 @@ \tl_to_other_str_loop:w #9 #1 * #2 * #3 * #4 * #5 * #6 * #7 * #8 * \q_stop } - \cs_new_nopar:Npn \tl_to_other_str_end:w \fi: #1 \q_mark #2 * A #3 \q_stop + \cs_new:Npn \tl_to_other_str_end:w \fi: #1 \q_mark #2 * A #3 \q_stop { \fi: #2 } } \group_begin: @@ -133,10 +141,10 @@ \tl_gset:Nx #1 { \exp_after:wN \str_gset_other_loop:w \tl_to_str:n {#2} ~ % - A ~ A ~ A ~ A ~ A ~ A ~ A ~ A ~ A ~ \q_mark \q_stop + A ~ A ~ A ~ A ~ A ~ A ~ A ~ A ~ A ~ \q_stop } } - \cs_new_nopar:Npn \str_gset_other_loop:w + \cs_new:Npn \str_gset_other_loop:w #1 ~ #2 ~ #3 ~ #4 ~ #5 ~ #6 ~ #7 ~ #8 ~ #9 ~ { \if_meaning:w A #9 @@ -145,32 +153,42 @@ #1 * #2 * #3 * #4 * #5 * #6 * #7 * #8 * #9 \str_gset_other_loop:w * } - \cs_new_nopar:Npn \str_gset_other_end:w \fi: #1 * A #2 \q_stop + \cs_new:Npn \str_gset_other_end:w \fi: #1 * A #2 \q_stop { \fi: #1 } } -\cs_if_exist:NF \use_i:nnnnnnnn - { \cs_new:Npn \use_i:nnnnnnnn #1#2#3#4#5#6#7#8 {#1} } -\cs_new:Npn \str_aux_toks_range:nn #1#2 +\cs_new:Npn \str_count_spaces:N + { \exp_args:No \str_count_spaces:n } +\cs_new:Npn \str_count_spaces:n #1 { - \exp_after:wN \str_aux_toks_range:ww - \int_use:N \int_eval:w #1 \exp_after:wN ; - \int_use:N \int_eval:w #2 ; - \prg_break_point:n { } + \int_eval:n + { + \exp_after:wN \str_count_spaces_loop:wwwwwwwww + \tl_to_str:n {#1} ~ + X 7 ~ X 6 ~ X 5 ~ X 4 ~ X 3 ~ X 2 ~ X 1 ~ X 0 ~ X -1 ~ + \q_stop + } } -\cs_new:Npn \str_aux_toks_range:ww #1 ; #2 ; +\cs_new:Npn \str_count_spaces_loop:wwwwwwwww #1~#2~#3~#4~#5~#6~#7~#8~#9~ { - \if_num:w #1 = #2 \exp_stop_f: - \exp_after:wN \prg_map_break: + \if_meaning:w X #9 + \exp_after:wN \use_none_delimit_by_q_stop:w \fi: - \tex_the:D \tex_toks:D #1 \exp_stop_f: - \exp_after:wN \str_aux_toks_range:ww - \int_use:N \int_eval:w #1 + \c_one ; #2 ; + \c_nine + \str_count_spaces_loop:wwwwwwwww } \cs_new_nopar:Npn \str_length:N { \exp_args:No \str_length:n } \cs_new:Npn \str_length:n #1 - { \exp_args:Nf \str_length_unsafe:n { \tl_to_other_str:n {#1} } } -\cs_new_nopar:Npn \str_length_unsafe:n #1 - { \str_length_aux:n { \str_length_loop:NNNNNNNNN #1 } } + { + \str_length_aux:n + { + \str_count_spaces:n {#1} + + \exp_after:wN \str_length_loop:NNNNNNNNN \tl_to_str:n {#1} + } + } +\cs_new:Npn \str_length_unsafe:n #1 + { + \str_length_aux:n + { \str_length_loop:NNNNNNNNN #1 } + } \cs_new:Npn \str_length_ignore_spaces:n #1 { \str_length_aux:n @@ -189,7 +207,7 @@ } \cs_set:Npn \str_length_loop:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { - \if_catcode:w X #9 + \if_meaning:w X #9 \exp_after:wN \use_none_delimit_by_q_stop:w \fi: \c_nine + \str_length_loop:NNNNNNNNN @@ -201,12 +219,13 @@ \tl_to_str:n {#1} { { } } ~ \q_stop } -\cs_set_nopar:Npn \str_head_aux:w #1 ~ % +\cs_set:Npn \str_head_aux:w #1 ~ % { \use_i_delimit_by_q_stop:nw #1 { ~ } } \cs_new:Npn \str_head_ignore_spaces:n #1 - { \exp_after:wN \use_i_delimit_by_q_stop:nw \tl_to_str:n {#1} { } \q_stop } -\cs_new_nopar:Npn \str_head_unsafe:n #1 - { \use_i_delimit_by_q_stop:nw #1 { } \q_stop } + { + \exp_after:wN \use_i_delimit_by_q_stop:nw + \tl_to_str:n {#1} { } \q_stop + } \cs_new_nopar:Npn \str_tail:N { \exp_args:No \str_tail:n } \cs_set:Npn \str_tail:n #1 { @@ -214,107 +233,93 @@ \reverse_if:N \if_charcode:w \scan_stop: \tl_to_str:n {#1} X X \q_stop } -\cs_set_nopar:Npn \str_tail_aux:w #1 X #2 \q_stop { \fi: #1 } +\cs_set:Npn \str_tail_aux:w #1 X #2 \q_stop { \fi: #1 } \cs_new:Npn \str_tail_ignore_spaces:n #1 { \exp_after:wN \str_tail_aux_ii:w - \tl_to_str:n {#1} X { } X \q_stop + \tl_to_str:n {#1} X X \q_stop } -\cs_new_nopar:Npn \str_tail_unsafe:n #1 - { \str_tail_aux_ii:w #1 X { } X \q_stop } -\cs_new_nopar:Npn \str_tail_aux_ii:w #1 #2 X #3 \q_stop { #2 } -\cs_new:Npn \str_skip_do:nn #1 +\cs_new:Npn \str_tail_aux_ii:w #1 #2 X #3 \q_stop { #2 } +\cs_new:Npn \str_skip_c_zero:w #1; { - \if_num:w \int_eval:w #1 > \c_seven - \exp_after:wN \str_skip_aux:nnnnnnnnn + \if_num:w \int_eval:w #1 > \c_eight + \exp_after:wN \str_skip_aux:wNNNNNNNN \else: - \exp_after:wN \str_skip_end:n - \fi: - {#1} - } -\cs_new:Npn \str_skip_aux:nnnnnnnnn #1#2#3#4#5#6#7#8#9 - { \exp_args:Nf \str_skip_do:nn { \int_eval:n { #1 - \c_seven } } {#2} } -\cs_new:Npn \str_skip_end:n #1 - { - \if_case:w \int_eval:w #1 \int_eval_end: - \str_skip_end_ii:nwn { XXXXXXX } - \or: \str_skip_end_ii:nwn { XXXXXX } - \or: \str_skip_end_ii:nwn { XXXXX } - \or: \str_skip_end_ii:nwn { XXXX } - \or: \str_skip_end_ii:nwn { XXX } - \or: \str_skip_end_ii:nwn { XX } - \or: \str_skip_end_ii:nwn { X } - \or: \str_skip_end_ii:nwn { } - \else: \str_skip_end_ii:nwn { XXXXXXX } + \exp_after:wN \str_skip_end:w + \int_use:N \int_eval:w \fi: + #1 ; + } +\cs_new:Npn \str_skip_aux:wNNNNNNNN #1; #2#3#4#5#6#7#8#9 + { \exp_after:wN \str_skip_c_zero:w \int_use:N \int_eval:w #1 - \c_eight ; } +\cs_new:Npn \str_skip_end:w #1 ; + { + \exp_after:wN \str_skip_end_ii:NNNNNNNN + \if_case:w \if_num:w #1 > \c_zero #1 \else: 0 \fi: \exp_stop_f: + \or: \or: \or: \or: \or: \or: \or: \or: + } +\cs_new:Npn \str_skip_end_ii:NNNNNNNN #1#2#3#4#5#6#7#8 { \fi: \c_zero } +\cs_new:Npn \str_collect_delimit_by_q_stop:w #1; + { + \exp_after:wN \str_collect_aux:wn + \int_use:N \int_eval:w #1 ; + { } } -\cs_new:Npn \str_skip_end_ii:nwn #1#2 \fi: #3 - { \fi: \use_i:nnnnnnnn {#3} #1 } -\cs_new:Npn \str_collect_do:nn #1#2 - { \str_collect_aux:n {#1} { \str_collect_end_iii:nwNNNNNNN {#2} } } -\cs_new:Npn \str_collect_aux:n #1 - { - \int_compare:nNnTF {#1} > \c_seven - { \str_collect_aux:nnNNNNNNN } - { \str_collect_end:n } - {#1} - } -\cs_new:Npn \str_collect_aux:nnNNNNNNN #1#2 #3#4#5#6#7#8#9 - { - \exp_args:Nf \str_collect_aux:n - { \int_eval:n { #1 - \c_seven } } - { #2 #3#4#5#6#7#8#9 } - } -\cs_new:Npn \str_collect_end:n #1 - { - \if_case:w \int_eval:w #1 \int_eval_end: - \str_collect_end_ii:nwn { { } { } { } { } { } { } { } } - \or: \str_collect_end_ii:nwn { { } { } { } { } { } { } } - \or: \str_collect_end_ii:nwn { { } { } { } { } { } } - \or: \str_collect_end_ii:nwn { { } { } { } { } } - \or: \str_collect_end_ii:nwn { { } { } { } } - \or: \str_collect_end_ii:nwn { { } { } } - \or: \str_collect_end_ii:nwn { { } } - \or: \str_collect_end_ii:nwn { } - \else: \str_collect_end_ii:nwn { { } { } { } { } { } { } { } } +\cs_new:Npn \str_collect_aux:wn #1 ; + { + \if_num:w #1 > \c_seven + \exp_after:wN \str_collect_aux:wnNNNNNNN + \else: + \exp_after:wN \str_collect_end:wn \fi: + #1 ; + } +\cs_new:Npn \str_collect_aux:wnNNNNNNN #1; #2 #3#4#5#6#7#8#9 + { + \exp_after:wN \str_collect_aux:wn + \int_use:N \int_eval:w #1 - \c_seven ; + { #2 #3#4#5#6#7#8#9 } + } +\cs_new:Npn \str_collect_end:wn #1 ; + { + \exp_after:wN \str_collect_end_ii:nnnnnnnnw + \if_case:w \if_num:w #1 > \c_zero #1 \else: 0 \fi: \exp_stop_f: + \or: \or: \or: \or: \or: \or: \fi: } -\cs_new:Npn \str_collect_end_ii:nwn #1#2 \fi: #3 - { \fi: #3 \q_stop #1 } -\cs_new:Npn \str_collect_end_iii:nwNNNNNNN #1 #2 \q_stop #3#4#5#6#7#8#9 - { #1 {#2#3#4#5#6#7#8#9} } +\cs_new:Npn \str_collect_end_ii:nnnnnnnnw #1#2#3#4#5#6#7#8 #9 \q_stop + { #1#2#3#4#5#6#7#8 } \cs_new_nopar:Npn \str_item:Nn { \exp_args:No \str_item:nn } -\cs_new:Npn \str_item:nn #1#2 +\cs_new:Npn \str_item:nn #1 { - \exp_args:Nf \tl_to_str:n - { \exp_args:Nf \str_item_unsafe:nn { \tl_to_other_str:n {#1} } {#2} } + \exp_last_unbraced:Nf \token_to_str:N + \exp_args:Nf \str_item_unsafe:nn { \tl_to_other_str:n {#1} } } \cs_new:Npn \str_item_ignore_spaces:nn #1 { \exp_args:No \str_item_unsafe:nn { \tl_to_str:n {#1} } } -\cs_new_nopar:Npn \str_item_unsafe:nn #1#2 +\cs_new:Npn \str_item_unsafe:nn #1#2 { - \exp_args:Nff \str_item_aux:nn - { \int_eval:n {#2} } - { \str_length_unsafe:n {#1} } + \exp_after:wN \str_item_aux:ww + \int_use:N \int_eval:w #2 \exp_after:wN ; + \int_value:w \str_length_unsafe:n {#1} ; #1 \q_stop } -\cs_new_nopar:Npn \str_item_aux:nn #1#2 +\cs_new:Npn \str_item_aux:ww #1; #2; { \int_compare:nNnTF {#1} < \c_zero { \int_compare:nNnTF {#1} < {-#2} { \use_none_delimit_by_q_stop:w } { - \str_skip_do:nn { #1 + #2 } - { \use_i_delimit_by_q_stop:nw } + \exp_after:wN \use_i_delimit_by_q_stop:nw + \tex_romannumeral:D \str_skip_c_zero:w #1 + #2 ; } } { \int_compare:nNnTF {#1} < {#2} { - \str_skip_do:nn {#1} - { \use_i_delimit_by_q_stop:nw } + \exp_after:wN \use_i_delimit_by_q_stop:nw + \tex_romannumeral:D \str_skip_c_zero:w #1 ; } { \use_none_delimit_by_q_stop:w } } @@ -335,28 +340,26 @@ \exp_after:wN \str_substr_aux:www \int_value:w \str_length_unsafe:n {#1} \exp_after:wN ; \int_use:N \int_eval:w #2 + \c_zero \exp_after:wN ; - \int_use:N \int_eval:w \exp_args:Nf \str_substr_unsafe:nN {#3} \c_max_int ; + \int_use:N \int_eval:w + \exp_args:Nf \str_substr_aux:nN {#3} \c_max_int ; #1 \q_stop } -\cs_new:Npn \str_substr_unsafe:nN #1 #2 +\cs_new:Npn \str_substr_aux:nN #1 #2 { \tl_if_empty:nTF {#1} {#2} {#1} } \cs_new:Npn \str_substr_aux:www #1; #2; #3; { \exp_args:Nf \str_substr_aux:nnw - { \str_aux_normalize_range:nn {#2} {#1} } - { \str_aux_normalize_range:nn {#3} {#1} } + { \str_substr_normalize_range:nn {#2} {#1} } + { \str_substr_normalize_range:nn {#3} {#1} } } \cs_new:Npn \str_substr_aux:nnw #1#2 { - \str_skip_do:nn {#1} - { - \exp_args:Nf \str_collect_do:nn - { \int_eval:n { #2 - #1 } } - { \use_i_delimit_by_q_stop:nw } - } + \exp_after:wN \str_collect_delimit_by_q_stop:w + \int_use:N \int_eval:w #2 - #1 \exp_after:wN ; + \tex_romannumeral:D \str_skip_c_zero:w #1 ; } -\cs_new:Npn \str_aux_normalize_range:nn #1#2 +\cs_new:Npn \str_substr_normalize_range:nn #1#2 { \int_eval:n { @@ -383,7 +386,7 @@ \prg_new_conditional:Npnn \str_if_contains_char:NN #1#2 { T , TF } { \exp_after:wN \str_if_contains_char_aux:NN \exp_after:wN #2 - #1 { \prg_map_break:n { ? \fi: } } + \tl_to_str:n \exp_after:wN {#1} { \prg_map_break:n { ? \fi: } } \prg_break_point:n { } \prg_return_false: } @@ -394,14 +397,14 @@ \prg_break_point:n { } \prg_return_false: } -\cs_new_nopar:Npn \str_if_contains_char_aux:NN #1#2 +\cs_new:Npn \str_if_contains_char_aux:NN #1#2 { \if_charcode:w #1 #2 - \exp_after:wN \str_if_contains_char_end: + \exp_after:wN \str_if_contains_char_true: \fi: \str_if_contains_char_aux:NN #1 } -\cs_new_nopar:Npn \str_if_contains_char_end: +\cs_new_nopar:Npn \str_if_contains_char_true: { \prg_map_break:n { \prg_return_true: \use_none:n } } \prg_new_conditional:Npnn \str_aux_octal_use:N #1 { TF } { @@ -433,11 +436,11 @@ \fi: } \group_begin: - \tl_clear:N \l_str_tmpa_tl + \tl_clear:N \l_str_internal_tl \char_set_catcode_other:n { \c_zero } \tl_gset:Nx \g_str_result_tl { \tl_to_str:n { 0123456789ABCDEF } } - \tl_map_inline:Nn \g_str_result_tl - { \char_set_lccode:nn {`#1} {`#1} } + \exp_args:No \tl_map_inline:nn { \g_str_result_tl " } + { \char_set_lccode:nn {`#1} { \c_zero } } \tl_map_inline:Nn \g_str_result_tl { \tl_map_inline:Nn \g_str_result_tl @@ -448,12 +451,12 @@ \tl_const:cx { c_str_byte_ \int_eval:n {"#1##1} _tl } { ^^@ #1 ##1 } - \tl_put_right:Nn \l_str_tmpa_tl { ^^@ } + \tl_put_right:Nn \l_str_internal_tl { ^^@ } } } } \tl_const:Nx \c_str_positive_bytes_tl - { \exp_after:wN \use_none:n \l_str_tmpa_tl } + { \exp_after:wN \use_none:n \l_str_internal_tl } \group_end: \tl_const:cn { c_str_byte_-1_tl } { { } \use_none:n { } } \cs_new:Npn \str_output_byte:n #1 @@ -474,244 +477,166 @@ } \cs_new_nopar:Npn \str_output_end: { \int_eval_end: _tl \cs_end: } -\cs_new_protected_nopar:Npn \str_aux_gmap_result:N #1 +\cs_new:Npn \str_output_byte_pair_be:n #1 + { + \exp_args:Nf \str_output_byte_pair_aux:nnN + { \int_div_truncate:nn { #1 } { "100 } } {#1} \use:nn + } +\cs_new:Npn \str_output_byte_pair_le:n #1 + { + \exp_args:Nf \str_output_byte_pair_aux:nnN + { \int_div_truncate:nn { #1 } { "100 } } {#1} \use_ii_i:nn + } +\cs_new:Npn \str_output_byte_pair_aux:nnN #1#2#3 + { + #3 + { \str_output_byte:n { #1 } } + { \str_output_byte:n { #2 - #1 * "100 } } + } +\cs_new_protected:Npn \str_convert_gmap:N #1 { \tl_gset:Nx \g_str_result_tl { - \exp_after:wN \str_aux_gmap_result_loop:NN + \exp_after:wN \str_convert_gmap_loop:NN \exp_after:wN #1 \g_str_result_tl { ? \prg_map_break: } \prg_break_point:n { } } } -\cs_new_nopar:Npn \str_aux_gmap_result_loop:NN #1#2 +\cs_new:Npn \str_convert_gmap_loop:NN #1#2 { \use_none:n #2 #1#2 - \str_aux_gmap_result_loop:NN #1 + \str_convert_gmap_loop:NN #1 } -\cs_new_protected_nopar:Npn \str_aux_gmap_internal_result:N #1 +\cs_new_protected:Npn \str_convert_gmap_internal:N #1 { \tl_gset:Nx \g_str_result_tl { - \exp_after:wN \str_aux_gmap_internal_result_loop:Nww + \exp_after:wN \str_convert_gmap_internal_loop:Nww \exp_after:wN #1 \g_str_result_tl \s_tl \q_stop \prg_map_break: \s_tl \prg_break_point:n { } } } -\cs_new_nopar:Npn \str_aux_gmap_internal_result_loop:Nww #1 #2 \s_tl #3 \s_tl +\cs_new:Npn \str_convert_gmap_internal_loop:Nww #1 #2 \s_tl #3 \s_tl { \use_none_delimit_by_q_stop:w #3 \q_stop #1 {#3} - \str_aux_gmap_internal_result_loop:Nww #1 - } -\cs_new_protected:Npn \str_input:Nn #1#2 - { - \str_aux_escape:NNNn \token_to_str:N \token_to_str:N \token_to_str:N {#2} - \tl_set_eq:NN #1 \g_str_result_tl - } -\cs_new_protected:Npn \str_ginput:Nn #1#2 - { - \str_aux_escape:NNNn \token_to_str:N \token_to_str:N \token_to_str:N {#2} - \tl_gset_eq:NN #1 \g_str_result_tl - } -\cs_new_protected:Npn \str_escape_use:NNNn #1#2#3#4 - { - \str_aux_escape:NNNn #1#2#3 {#4} - \g_str_result_tl - } -\cs_new_protected:Npn \str_aux_escape:NNNn #1#2#3#4 + \str_convert_gmap_internal_loop:Nww #1 + } +\cs_new_protected:Npn \str_if_flag_error:nnx #1 + { + \flag_if_raised:nTF {#1} + { \msg_kernel_error:nnx { str } } + { \use_none:nn } + } +\cs_new_protected:Npn \str_if_flag_no_error:nnx #1#2#3 + { \flag_if_raised:nT {#1} { \bool_gset_true:N \g_str_error_bool } } +\cs_new_protected:Npn \str_if_flag_times:nT #1#2 + { \flag_if_raised:nT {#1} { #2~(x \flag_height:n {#1} ) } } +\cs_new_protected_nopar:Npn \str_set_convert:Nnnn + { \str_convert_aux_i:nNNnnn { } \tl_set_eq:NN } +\cs_new_protected_nopar:Npn \str_gset_convert:Nnnn + { \str_convert_aux_i:nNNnnn { } \tl_gset_eq:NN } +\prg_new_protected_conditional:Npnn + \str_set_convert:Nnnn #1#2#3#4 { T , F , TF } + { + \bool_gset_false:N \g_str_error_bool + \str_convert_aux_i:nNNnnn + { \cs_set_eq:NN \str_if_flag_error:nnx \str_if_flag_no_error:nnx } + \tl_set_eq:NN #1 {#2} {#3} {#4} + \bool_if:NTF \g_str_error_bool \prg_return_false: \prg_return_true: + } +\prg_new_protected_conditional:Npnn + \str_gset_convert:Nnnn #1#2#3#4 { T , F , TF } + { + \bool_gset_false:N \g_str_error_bool + \str_convert_aux_i:nNNnnn + { \cs_set_eq:NN \str_if_flag_error:nnx \str_if_flag_no_error:nnx } + \tl_gset_eq:NN #1 {#2} {#3} {#4} + \bool_if:NTF \g_str_error_bool \prg_return_false: \prg_return_true: + } +\cs_new_protected:Npn \str_convert_aux_i:nNNnnn #1#2#3#4#5#6 { \group_begin: - \cs_set_nopar:Npn \str_aux_escape_unescaped:N { #1 } - \cs_set_nopar:Npn \str_aux_escape_escaped:N { #2 } - \cs_set_nopar:Npn \str_aux_escape_raw:N { #3 } - \int_set:Nn \tex_escapechar:D { 92 } + #1 \str_gset_other:Nn \g_str_result_tl {#4} - \int_zero:N \l_str_tmpa_int - \tl_gset:Nx \g_str_result_tl - { - \exp_after:wN \str_aux_escape_loop:N \g_str_result_tl - \q_recursion_tail \q_recursion_stop - } - \tl_gput_left:Nx \g_str_result_tl - { \str_aux_toks_range:nn \c_zero \l_str_tmpa_int } - \group_end: - } -\cs_new_nopar:Npn \str_aux_escape_loop:N #1 - { - \cs_if_exist_use:cF { str_aux_escape_\token_to_str:N #1:w } - { \str_aux_escape_unescaped:N #1 } - \str_aux_escape_loop:N - } -\cs_new_nopar:cpn { str_aux_escape_ \c_backslash_str :w } - \str_aux_escape_loop:N #1 - { - \cs_if_exist_use:cF { str_aux_escape_/\token_to_str:N #1:w } - { \str_aux_escape_escaped:N #1 } - \str_aux_escape_loop:N - } -\cs_new_eq:NN \str_aux_escape_unescaped:N \prg_do_nothing: -\cs_new_eq:NN \str_aux_escape_escaped:N \prg_do_nothing: -\cs_new_eq:NN \str_aux_escape_raw:N \prg_do_nothing: -\cs_new_eq:cN - { str_aux_escape_ \c_backslash_str q_recursion_tail :w } - \use_none_delimit_by_q_recursion_stop:w -\cs_new_eq:cN - { str_aux_escape_ / \c_backslash_str q_recursion_tail :w } - \use_none_delimit_by_q_recursion_stop:w -\cs_new_nopar:cpn { str_aux_escape_~:w } { } -\cs_new_nopar:cpx { str_aux_escape_/a:w } - { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^G } -\cs_new_nopar:cpx { str_aux_escape_/t:w } - { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^I } -\cs_new_nopar:cpx { str_aux_escape_/n:w } - { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^J } -\cs_new_nopar:cpx { str_aux_escape_/f:w } - { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^L } -\cs_new_nopar:cpx { str_aux_escape_/r:w } - { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^M } -\cs_new_nopar:cpx { str_aux_escape_/e:w } - { \exp_not:N \str_aux_escape_raw:N \iow_char:N \^^[ } -\cs_new_nopar:cpn { str_aux_escape_/x:w } \str_aux_escape_loop:N - { - \if_false: { \fi: } - \tex_toks:D \l_str_tmpa_int \exp_after:wN { \g_str_result_tl } - \int_incr:N \l_str_tmpa_int - \int_zero:N \l_str_char_int - \str_aux_escape_x_test:N - } -\cs_new_protected_nopar:Npx \str_aux_escape_x_test:N #1 - { - \exp_not:N \token_if_eq_charcode:NNTF \c_space_token #1 - { \exp_not:N \str_aux_escape_x_test:N } - { - \l_str_char_int = "0 - \exp_not:N \token_if_eq_charcode:NNTF \c_lbrace_str #1 - { \exp_not:N \str_aux_escape_x_braced_loop:N } - { \exp_not:N \str_aux_escape_x_unbraced_i:N #1 } - } - } -\cs_new_nopar:Npn \str_aux_escape_x_unbraced_i:N #1 - { - \str_aux_hexadecimal_use:NTF #1 - { \str_aux_escape_x_unbraced_ii:N } - { \exp_stop_f: \str_aux_escape_x_end: #1 } - } -\cs_new_nopar:Npn \str_aux_escape_x_unbraced_ii:N #1 - { - \token_if_eq_charcode:NNTF \c_space_token #1 - { \str_aux_escape_x_unbraced_ii:N } - { - \str_aux_hexadecimal_use:NTF #1 - { \exp_stop_f: \str_aux_escape_x_end: } - { \exp_stop_f: \str_aux_escape_x_end: #1 } - } - } -\cs_new_nopar:Npn \str_aux_escape_x_braced_loop:N #1 - { - \token_if_eq_charcode:NNTF \c_space_token #1 - { \str_aux_escape_x_braced_loop:N } - { - \str_aux_hexadecimal_use:NTF #1 - { \str_aux_escape_x_braced_loop:N } - { \exp_stop_f: \str_aux_escape_x_braced_end:N #1 } - } - } -\cs_new_protected_nopar:Npx \str_aux_escape_x_braced_end:N #1 - { - \exp_not:N \token_if_eq_charcode:NNTF \c_rbrace_str #1 - { \exp_not:N \str_aux_escape_x_end: } - { - \msg_kernel_error:nn { str } { x-missing-brace } - \exp_not:N \str_aux_escape_x_end: #1 - } - } -\group_begin: - \char_set_catcode_other:N \^^@ - \cs_new_protected_nopar:Npn \str_aux_escape_x_end: - { - \tex_lccode:D \c_zero \l_str_char_int - \tl_to_lowercase:n - { - \tl_gset:Nx \g_str_result_tl - { \if_false: } \fi: - \str_aux_escape_raw:N ^^@ - \str_aux_escape_loop:N - } - } -\group_end: -\cs_new_protected:Npn \str_set_convert:Nnnn - { \str_convert_aux_i:NNnnn \tl_set_eq:NN } -\cs_new_protected:Npn \str_gset_convert:Nnnn - { \str_convert_aux_i:NNnnn \tl_gset_eq:NN } -\cs_new_protected:Npn \str_convert_aux_i:NNnnn #1#2#3#4#5 - { - \group_begin: - \str_gset_other:Nn \g_str_result_tl {#5} - \exp_after:wN \str_convert_aux_ii:wwwnn - \tl_to_str:n {#3} /// \q_stop - { from } { input } \str_convert_from_native: \use_i:nn - + \tl_to_str:n {#5} /// \q_stop + { decode } { unescape } + \prg_do_nothing: + \str_convert_decode_: \exp_after:wN \str_convert_aux_ii:wwwnn - \tl_to_str:n {#4} /// \q_stop - { to } { output } \str_convert_to_native: \use_ii:nn - + \tl_to_str:n {#6} /// \q_stop + { encode } { escape } + \use_ii_i:nn + \str_convert_encode_: \group_end: - #1 #2 \g_str_result_tl + #2 #3 \g_str_result_tl } -\cs_new_protected:Npn \str_convert_aux_ii:wwwnn #1 / #2 // #3 \q_stop #4#5 +\cs_new_protected:Npn \str_convert_aux_ii:wwwnn + #1 / #2 // #3 \q_stop #4#5 { - \str_convert_aux_iii:nnF {#4} {#1} {native} - \str_convert_aux_iii:nnF {#5} {#2} { } - \exp_args:Ncc \str_convert_aux_v:NNnNN + \str_convert_aux_iv:nnn {enc} {#4} {#1} + \str_convert_aux_iv:nnn {esc} {#5} {#2} + \exp_args:Ncc \str_convert_aux_iii:NNnNN { str_convert_#4_#1: } { str_convert_#5_#2: } {#2} } -\cs_new_protected:Npn \str_convert_aux_iii:nnF #1#2#3 +\cs_new_protected:Npn \str_convert_aux_iii:NNnNN #1#2#3#4#5 { - \cs_if_exist:cF { str_convert_#1_#2: } - { - \exp_args:Nx \str_convert_aux_iv:nnnF - { \str_aux_lowercase_alphanum:n {#2} } - {#1} {#2} {#3} - } + \if_meaning:w #1 #5 + \tl_if_empty:nF {#3} + { \msg_kernel_error:nnx { str } { native-escaping } {#3} } + #1 + \else: + #4 #2 #1 + \fi: } -\cs_new_protected:Npn \str_convert_aux_iv:nnnF #1#2#3#4 +\cs_new_protected:Npn \str_convert_aux_iv:nnn #1#2#3 { - \cs_if_exist:cF { str_convert_#2_#1: } + \cs_if_exist:cF { str_convert_#2_#3: } { - \group_begin: - \str_load_catcodes: - \str_load_one:n {#1} - \group_end: - } - \cs_if_exist:cTF { str_convert_#2_#1: } - { \cs_gset_eq:cc { str_convert_#2_#3: } { str_convert_#2_#1: } } - { - \msg_kernel_error:nnx { str } { unknown-#2 } {#3} - \cs_gset_eq:cc { str_convert_#2_#3: } { str_convert_#2_#4: } + \exp_args:Nx \str_convert_aux_v:nnnn + { \str_convert_lowercase_alphanum:n {#3} } + {#1} {#2} {#3} } } -\cs_new_protected:Npn \str_convert_aux_v:NNnNN #1#2#3#4#5 +\cs_new_protected:Npn \str_convert_aux_v:nnnn #1#2#3#4 { - #5 { } {#1} - \cs_if_eq:NNTF #1 #4 + \cs_if_exist:cF { str_convert_#3_#1: } { - \tl_if_empty:nF {#3} - { \msg_kernel_error:nnx { str } { native-ignore-escaping } {#3} } + \prop_get:NnNF \g_str_file_prop {#1} \l_str_internal_tl + { \tl_set:Nn \l_str_internal_tl {#1} } + \cs_if_exist:cF { str_convert_#3_ \l_str_internal_tl : } + { + \file_if_exist:nTF { l3str-#2- \l_str_internal_tl .def } + { + \group_begin: + \str_load_catcodes: + \file_input:n { l3str-#2- \l_str_internal_tl .def } + \group_end: + } + { + \tl_clear:N \l_str_internal_tl + \msg_kernel_error:nnxx { str } { unknown-#2 } {#4} {#1} + } + } + \cs_if_exist:cF { str_convert_#3_#1: } + { + \cs_gset_eq:cc { str_convert_#3_#1: } + { str_convert_#3_ \l_str_internal_tl : } + } } - { #2 } - #5 {#1} { } + \cs_gset_eq:cc { str_convert_#3_#4: } { str_convert_#3_#1: } } -\cs_new:Npn \str_aux_lowercase_alphanum:n #1 +\cs_new:Npn \str_convert_lowercase_alphanum:n #1 { - \exp_after:wN \str_aux_lowercase_alphanum_loop:N + \exp_after:wN \str_convert_lowercase_alphanum_loop:N \tl_to_str:n {#1} { ? \prg_map_break: } \prg_break_point:n { } } -\cs_new:Npn \str_aux_lowercase_alphanum_loop:N #1 +\cs_new:Npn \str_convert_lowercase_alphanum_loop:N #1 { \use_none:n #1 \if_num:w `#1 < \c_ninety_one @@ -730,312 +655,287 @@ \fi: \fi: \fi: - \str_aux_lowercase_alphanum_loop:N - } -\cs_new_protected_nopar:Npn \str_convert_from_internal: { } -\cs_new_protected_nopar:Npn \str_convert_to_internal: { } -\cs_new_protected:Npn \str_load:n #1 - { - \group_begin: - \str_load_catcodes: - \clist_map_inline:nn {#1} - { - \exp_args:Nx \str_load_one:n - { \str_aux_lowercase_alphanum:n {#1} } - } - \group_end: - } -\cs_new_protected:Npn \str_load_one:n #1 - { - \cs_if_exist:cF { str_convert_from_ #1 : } - { - \cs_if_exist:cF { str_convert_input_#1: } - { - \file_if_exist:nTF { l3str- #1 .def } - { \file_input:n { l3str- #1 .def } } - { \str_load_alias:n {#1} } - } - } + \str_convert_lowercase_alphanum_loop:N } -\cs_new_protected:Npn \str_load_alias:n #1 - { - \exp_args:NNx \prop_get:NnNTF \g_str_aliases_prop {#1} \l_str_tmpa_tl - { - \str_load_one:n { \l_str_tmpa_tl } - \cs_if_exist:cTF - { str_convert_from_ \l_str_tmpa_tl : } - { - \str_load_alias_aux:nnn {#1} { \l_str_tmpa_tl } { from } - \str_load_alias_aux:nnn {#1} { \l_str_tmpa_tl } { to } - } - { - \str_load_alias_aux:nnn {#1} { \l_str_tmpa_tl } { input } - \str_load_alias_aux:nnn {#1} { \l_str_tmpa_tl } { output } - } - } - { \msg_kernel_error:nnx { str } { file-not-found } {#1} } - } -\cs_new_protected:Npn \str_load_alias_aux:nnn #1#2#3 - { \cs_new_eq:cc { str_convert_#3_#1: } { str_convert_#3_#2: } } \cs_new_protected:Npn \str_load_catcodes: { \char_set_catcode_escape:N \\ \char_set_catcode_group_begin:N \{ \char_set_catcode_group_end:N \} + \char_set_catcode_math_toggle:N \$ + \char_set_catcode_alignment:N \& + \char_set_catcode_parameter:N \# \char_set_catcode_math_superscript:N \^ \char_set_catcode_ignore:N \ % - \tl_map_function:nN { abcdefghijklmnopqrstuvwxyz_:ABCDEFN } + \char_set_catcode_space:N \~ + \tl_map_function:nN { abcdefghijklmnopqrstuvwxyz_:ABCDEFILNPSTUX } \char_set_catcode_letter:N - \tl_map_function:nN { 0123456789"'?*+ } + \tl_map_function:nN { 0123456789"'?*+-.(),`!/<>[];= } \char_set_catcode_other:N \char_set_catcode_comment:N \% \int_set:Nn \tex_endlinechar:D {32} } -\cs_new_protected:Npn \str_convert_from_eight_bit:n #1 +\pdftex_if_engine:TF + { \cs_new_eq:NN \str_filter_bytes:n \use:n } + { + \cs_new:Npn \str_filter_bytes:n #1 + { + \str_filter_bytes_aux:N #1 + { ? \prg_map_break: } + \prg_break_point:n { } + } + \cs_new:Npn \str_filter_bytes_aux:N #1 + { + \use_none:n #1 + \if_num:w `#1 < 256 \exp_stop_f: + #1 + \else: + \flag_raise:n { str_byte } + \fi: + \str_filter_bytes_aux:N + } + } +\pdftex_if_engine:TF + { \cs_new_protected_nopar:Npn \str_convert_unescape_: { } } + { + \cs_new_protected_nopar:Npn \str_convert_unescape_: + { + \flag_clear:n { str_byte } + \tl_gset:Nx \g_str_result_tl + { \exp_args:No \str_filter_bytes:n \g_str_result_tl } + \str_if_flag_error:nnx { str_byte } { non-byte } { bytes } + } + } +\cs_new_eq:NN \str_convert_unescape_bytes: \str_convert_unescape_: +\cs_new_protected_nopar:Npn \str_convert_escape_: { } +\cs_new_eq:NN \str_convert_escape_bytes: \str_convert_escape_: +\cs_new_protected_nopar:Npn \str_convert_decode_: + { \str_convert_gmap:N \str_decode_native_char:N } +\cs_new:Npn \str_decode_native_char:N #1 + { #1 \s_tl \int_value:w `#1 \s_tl } +\group_begin: + \char_set_catcode_other:n { 0 } + \pdftex_if_engine:TF + { + \cs_new_protected_nopar:Npn \str_convert_encode_: + { + \flag_clear:n { str_error } + \str_convert_gmap_internal:N \str_encode_native_char:n + \str_if_flag_error:nnx { str_error } + { pdfTeX-native-overflow } { } + } + \cs_new:Npn \str_encode_native_char:n #1 + { + \if_num:w #1 < \c_two_hundred_fifty_six + \str_output_byte:n {#1} + \else: + \flag_raise:n { str_error } + ? + \fi: + } + \msg_kernel_new:nnnn { str } { pdfTeX-native-overflow } + { Character~code~too~large~for~pdfTeX. } + { + The~pdfTeX~engine~only~supports~8-bit~characters:~ + valid~character~codes~are~in~the~range~[0,255].~ + To~manipulate~arbitrary~Unicode,~use~LuaTeX~or~XeTeX. + } + } + { + \cs_new_protected_nopar:Npn \str_convert_encode_: + { + \tex_lccode:D \c_zero \c_zero + \int_zero:N \l_str_internal_int + \tl_set_eq:NN \l_str_internal_tl \g_str_result_tl + \tl_gclear:N \g_str_result_tl + \exp_after:wN \str_encode_native_loop:w + \l_str_internal_tl \s_tl { \q_stop \prg_map_break: } \s_tl + \prg_break_point:n { \str_encode_native_flush: } + } + \cs_new_protected:Npn \str_encode_native_loop:w #1 \s_tl #2 \s_tl + { + \use_none_delimit_by_q_stop:w #2 \q_stop + \if_num:w \l_str_internal_int = \c_two_hundred_fifty_five + \str_encode_native_flush: + \l_str_internal_int \c_zero + \fi: + \tex_advance:D \l_str_internal_int \c_one + \tex_lccode:D \l_str_internal_int \int_eval:w #2 \int_eval_end: + \str_encode_native_loop:w + } + \cs_new_protected_nopar:Npn \str_encode_native_flush: + { + \use:x + { + \tl_to_lowercase:n + { + \tl_gput_right:Nx \exp_not:N \g_str_result_tl + { + \exp_after:wN \str_encode_native_filter:N + \c_str_positive_bytes_tl + { ? = \c_zero \fi: \prg_map_break: } + \prg_break_point:n { } + } + } + } + } + \cs_new:Npn \str_encode_native_filter:N #1 + { + \if_num:w `#1 > \l_str_internal_int + \exp_after:wN \prg_map_break: + \fi: + \if_num:w \tex_lccode:D `#1 = \c_zero + ^^@ + \else: + #1 + \fi: + \str_encode_native_filter:N + } + } +\group_end: +\cs_new_protected:Npn \str_declare_eight_bit_encoding:nnn #1#2#3 + { + \tl_set:Nn \l_str_internal_tl {#1} + \cs_new_protected_nopar:cpn { str_convert_decode_#1: } + { \str_convert_decode_eight_bit:n {#1} } + \cs_new_protected_nopar:cpn { str_convert_encode_#1: } + { \str_convert_encode_eight_bit:n {#1} } + \tl_const:cn { c_str_encoding_#1_tl } {#2} + \tl_const:cn { c_str_encoding_#1_missing_tl } {#3} + } +\cs_new_protected:Npn \str_convert_decode_eight_bit:n #1 { \group_begin: - \int_zero:N \l_str_tmpa_int - \exp_last_unbraced:Nx \str_convert_from_eight_bit_load:nn + \int_zero:N \l_str_internal_int + \exp_last_unbraced:Nx \str_decode_eight_bit_load:nn { \tl_use:c { c_str_encoding_#1_tl } } { \q_stop \prg_map_break: } { } \prg_break_point:n { } - \exp_last_unbraced:Nx \str_convert_from_eight_bit_load_missing:n + \exp_last_unbraced:Nx \str_decode_eight_bit_load_missing:n { \tl_use:c { c_str_encoding_#1_missing_tl } } { \q_stop \prg_map_break: } \prg_break_point:n { } - \str_aux_gmap_result:N \str_convert_from_eight_bit_aux:N + \flag_clear:n { str_error } + \str_convert_gmap:N \str_decode_eight_bit_char:N + \str_if_flag_error:nnx { str_error } { decode-8-bit } {#1} \group_end: } -\cs_new_protected_nopar:Npn \str_convert_from_eight_bit_load:nn #1#2 +\cs_new_protected:Npn \str_decode_eight_bit_load:nn #1#2 { \use_none_delimit_by_q_stop:w #1 \q_stop - \tex_dimen:D "#1 = \l_str_tmpa_int sp \scan_stop: - \tex_skip:D \l_str_tmpa_int = "#1 sp \scan_stop: - \tex_toks:D \l_str_tmpa_int \exp_after:wN { \int_value:w "#2 } - \tex_advance:D \l_str_tmpa_int \c_one - \str_convert_from_eight_bit_load:nn + \tex_dimen:D "#1 = \l_str_internal_int sp \scan_stop: + \tex_skip:D \l_str_internal_int = "#1 sp \scan_stop: + \tex_toks:D \l_str_internal_int \exp_after:wN { \int_value:w "#2 } + \tex_advance:D \l_str_internal_int \c_one + \str_decode_eight_bit_load:nn } -\cs_new_protected_nopar:Npn \str_convert_from_eight_bit_load_missing:n #1 +\cs_new_protected:Npn \str_decode_eight_bit_load_missing:n #1 { \use_none_delimit_by_q_stop:w #1 \q_stop - \tex_dimen:D "#1 = \l_str_tmpa_int sp \scan_stop: - \tex_skip:D \l_str_tmpa_int = "#1 sp \scan_stop: - \tex_toks:D \l_str_tmpa_int \exp_after:wN + \tex_dimen:D "#1 = \l_str_internal_int sp \scan_stop: + \tex_skip:D \l_str_internal_int = "#1 sp \scan_stop: + \tex_toks:D \l_str_internal_int \exp_after:wN { \int_use:N \c_str_replacement_char_int } - \tex_advance:D \l_str_tmpa_int \c_one - \str_convert_from_eight_bit_load_missing:n + \tex_advance:D \l_str_internal_int \c_one + \str_decode_eight_bit_load_missing:n } -\cs_new:Npn \str_convert_from_eight_bit_aux:N #1 +\cs_new:Npn \str_decode_eight_bit_char:N #1 { #1 \s_tl - \if_num:w \tex_dimen:D `#1 < \l_str_tmpa_int + \if_num:w \tex_dimen:D `#1 < \l_str_internal_int \if_num:w \tex_skip:D \tex_dimen:D `#1 = `#1 \exp_stop_f: \tex_the:D \tex_toks:D \tex_dimen:D \fi: \fi: \int_value:w `#1 \s_tl } -\cs_new_protected:Npn \str_convert_to_eight_bit:n #1 +\cs_new_protected:Npn \str_convert_encode_eight_bit:n #1 { \group_begin: - \int_zero:N \l_str_tmpa_int - \exp_last_unbraced:Nx \str_convert_to_eight_bit_load:nn + \int_zero:N \l_str_internal_int + \exp_last_unbraced:Nx \str_encode_eight_bit_load:nn { \tl_use:c { c_str_encoding_#1_tl } } { \q_stop \prg_map_break: } { } \prg_break_point:n { } - \str_aux_gmap_internal_result:N \str_convert_to_eight_bit_aux:n + \flag_clear:n { str_error } + \str_convert_gmap_internal:N \str_encode_eight_bit_char:n + \str_if_flag_error:nnx { str_error } { encode-8-bit } {#1} \group_end: } -\cs_new_protected_nopar:Npn \str_convert_to_eight_bit_load:nn #1#2 +\cs_new_protected:Npn \str_encode_eight_bit_load:nn #1#2 { \use_none_delimit_by_q_stop:w #1 \q_stop - \tex_dimen:D "#2 = \l_str_tmpa_int sp \scan_stop: - \tex_skip:D \l_str_tmpa_int = "#2 sp \scan_stop: - \exp_args:NNf \tex_toks:D \l_str_tmpa_int + \tex_dimen:D "#2 = \l_str_internal_int sp \scan_stop: + \tex_skip:D \l_str_internal_int = "#2 sp \scan_stop: + \exp_args:NNf \tex_toks:D \l_str_internal_int { \str_output_byte:n { "#1 } } - \tex_advance:D \l_str_tmpa_int \c_one - \str_convert_to_eight_bit_load:nn + \tex_advance:D \l_str_internal_int \c_one + \str_encode_eight_bit_load:nn } -\cs_new:Npn \str_convert_to_eight_bit_aux:n #1 +\cs_new:Npn \str_encode_eight_bit_char:n #1 { \if_num:w #1 > \c_max_register_int - \msg_expandable_kernel_error:nnn - { str } { eight-bit-to-byte-overflow } {#1} + \flag_raise:n { str_error } \else: - \if_num:w \tex_dimen:D #1 < \l_str_tmpa_int + \if_num:w \tex_dimen:D #1 < \l_str_internal_int \if_num:w \tex_skip:D \tex_dimen:D #1 = #1 \exp_stop_f: \tex_the:D \tex_toks:D \tex_dimen:D #1 \exp_stop_f: \exp_after:wN \exp_after:wN \exp_after:wN \use_none:nn \fi: \fi: - \str_convert_to_eight_bit_aux_ii:n {#1} + \str_encode_eight_bit_char_aux:n {#1} \fi: } -\cs_new:Npn \str_convert_to_eight_bit_aux_ii:n #1 +\cs_new:Npn \str_encode_eight_bit_char_aux:n #1 { \if_num:w #1 < \c_two_hundred_fifty_six \str_output_byte:n {#1} \else: - \msg_expandable_kernel_error:nn { str } { eight-bit-to-byte } + \flag_raise:n { str_error } \fi: } -\cs_new_protected:Npn \str_encoding_eight_bit:n #1 +\msg_kernel_new:nnn { str } { unknown-esc } + { Escaping~scheme~'#1'~(filtered:~'#2')~unknown. } +\msg_kernel_new:nnn { str } { unknown-enc } + { Encoding~scheme~'#1'~(filtered:~'#2')~unknown. } +\msg_kernel_new:nnnn { str } { native-escaping } + { The~'native'~encoding~scheme~does~not~support~any~escaping. } { - \cs_new_protected:cpn { str_convert_from_#1: } - { \str_convert_from_eight_bit:n {#1} } - \cs_new_protected:cpn { str_convert_to_#1: } - { \str_convert_to_eight_bit:n {#1} } - } -\pdftex_if_engine:TF - { \cs_new_eq:NN \str_filter_bytes:n \use:n } - { - \cs_new_nopar:Npn \str_filter_bytes:n #1 - { - \str_filter_bytes_aux:N #1 - { ? \prg_map_break: } - \prg_break_point:n { } - } - \cs_new_nopar:Npn \str_filter_bytes_aux:N #1 - { - \use_none:n #1 - \if_num:w `#1 < 256 \exp_stop_f: #1 \fi: - \str_filter_bytes_aux:N - } + Since~native~strings~do~not~consist~in~bytes,~ + none~of~the~escaping~methods~make~sense.~ + The~specified~escaping,~'#1',~will be ignored. } -\pdftex_if_engine:TF - { \cs_new_protected_nopar:Npn \str_convert_input_: { } } +\msg_kernel_new:nnn { str } { file-not-found } + { File~'l3str-#1.def'~not~found. } +\pdftex_if_engine:F { - \cs_new_protected_nopar:Npn \str_convert_input_: + \msg_kernel_new:nnnn { str } { non-byte } + { String~invalid~in~escaping~'#1':~it~may~only~contain~bytes. } { - \tl_gset:Nx \g_str_result_tl - { \exp_args:No \str_filter_bytes:n \g_str_result_tl } - } - } -\cs_new_eq:NN \str_convert_input_bytes: \str_convert_input_: -\cs_new_protected_nopar:Npn \str_convert_output_: { } -\cs_new_eq:NN \str_convert_output_bytes: \str_convert_output_: -\cs_new_protected_nopar:Npn \str_convert_from_native: - { \str_aux_gmap_result:N \str_convert_from_native_aux:N } -\cs_new:Npn \str_convert_from_native_aux:N #1 - { #1 \s_tl \int_value:w `#1 \s_tl } -\cs_new_protected_nopar:Npn \str_convert_to_native: - { - \tl_set_eq:NN \l_str_tmpa_tl \g_str_result_tl - \str_aux_convert_to_native:n - { - \exp_after:wN \str_convert_to_native_aux:w - \l_str_tmpa_tl \s_tl { \q_stop \prg_map_break: } \s_tl - } - } -\cs_new_protected_nopar:Npn \str_convert_to_native_aux:w #1 \s_tl #2 \s_tl - { - \use_none_delimit_by_q_stop:w #2 \q_stop - \str_aux_convert_to_native_step:n {#2} - \str_convert_to_native_aux:w - } -\cs_new_protected_nopar:Npn \str_aux_convert_to_native:n #1 - { - \tex_lccode:D \c_zero \c_zero - \int_zero:N \l_str_tmpa_int - \tl_gclear:N \g_str_result_tl - #1 - \prg_break_point:n { \str_aux_convert_to_native_flush: } - } -\cs_new_protected_nopar:Npn \str_aux_convert_to_native_step:n #1 - { - \if_num:w \l_str_tmpa_int = \c_two_hundred_fifty_five - \str_aux_convert_to_native_flush: - \l_str_tmpa_int \c_zero - \fi: - \tex_advance:D \l_str_tmpa_int \c_one - \if_int_compare:w #1 > \c_max_char_int - \msg_kernel_error:nnx { str } { overflow } {#1} - \tex_lccode:D \l_str_tmpa_int \c_str_replacement_char_int - \else: - \tex_lccode:D \l_str_tmpa_int \int_eval:w #1 \int_eval_end: - \fi: - } -\cs_new_protected_nopar:Npn \str_aux_convert_to_native_flush: - { - \use:x - { - \tl_to_lowercase:n + Some~characters~in~the~string~you~asked~to~convert~are~not~ + 8-bit~characters.~Perhaps~the~string~is~a~'native'~Unicode~string?~ + If~it~is,~try~using\\ + \\ + \iow_indent:n { - \tl_gput_right:Nx \exp_not:N \g_str_result_tl - { - \exp_after:wN \str_aux_convert_to_native_filter:N - \c_str_positive_bytes_tl - { ? = \c_zero \fi: \prg_map_break: } - \prg_break_point:n { } - } + \iow_char:N\\str_set_convert:Nnnn \\ + \ \ <str~var>~\{~<string>~\}~\{~native~\}~\{~<target~encoding>~\} } } } -\group_begin: - \char_set_catcode_other:n { 0 } - \cs_new:Npn \str_aux_convert_to_native_filter:N #1 - { - \if_num:w `#1 > \l_str_tmpa_int - \exp_after:wN \prg_map_break: - \fi: - \if_num:w \tex_lccode:D `#1 = \c_zero - ^^@ - \else: - #1 - \fi: - \str_aux_convert_to_native_filter:N - } -\group_end: -\msg_kernel_new:nnnn { str } { x-missing-brace } - { Missing~closing~brace~in~ \token_to_str:N \x ~byte~sequence. } +\msg_kernel_new:nnnn { str } { decode-8-bit } + { Invalid~string~in~encoding~'#1'. } { - You~wrote~something~like~ - `\iow_char:N\\x\{ \int_to_hexadecimal:n { \l_str_char_int }'.~ - The~closing~brace~is~missing. + LaTeX~came~across~a~byte~which~is~not~defined~to~represent~ + any~character~in~the~encoding~'#1'. } -\msg_kernel_new:nnnn { str } { overflow } - { Character~code~#1~too~big. } +\msg_kernel_new:nnnn { str } { encode-8-bit } + { Unicode~string~cannot~be~converted~to~encoding~'#1'. } { - \int_compare:nNnTF {#1} > { 1114111 } - { The~Unicode~standard~limits~code~points~to~1114111. } - { - The~pdfTeX~engine~only~supports~8-bit~characters:~ - valid~character~codes~are~in~the~range~[0,255].~ - To~manipulate~arbitrary~Unicode,~use~LuaTeX~or~XeTeX. - } + The~encoding~'#1'~only~contains~a~subset~of~all~Unicode~characters.~ + LaTeX~was~asked~to~convert~a~string~to~that~encoding,~but~that~ + string~contains~a~character~that~'#1'~does~not~support. } -\msg_kernel_new:nnn { str } { convert-input } - { Input~scheme~`#1'~unknown. } -\msg_kernel_new:nnn { str } { convert-from } - { Encoding~`#1'~unknown. } -\msg_kernel_new:nnn { str } { convert-to } - { Encoding~`#1'~unknown.~Using~UTF-8. } -\msg_kernel_new:nnn { str } { convert-output } - { Output~scheme~`#1~unknown. } -\msg_kernel_new:nnn { str } { to-native } - { Use~\str_set_convert:Nnn to~convert~to~native~strings. } -\msg_kernel_new:nnn { str } { unicode-surrogate } - { Code~point~#1~is~an~unpaired~surrogate. } -\msg_kernel_new:nnn { str } { utf16-surrogate } - { UTF-16~unpaired~surrogate~#1. } -\msg_kernel_new:nnn { str } { utf16-odd } - { UTF-16~dangling~byte~#1. } -\msg_kernel_new:nnn { str } { utf8-extra-conti } - { UTF-8~extra~continuation~byte~#1. } -\msg_kernel_new:nnn { str } { utf8-missing-conti } - { UTF-8~missing~continuation~byte~#1. } -\msg_kernel_new:nnn { str } { utf8-invalid-byte } - { Byte~#1~cannot~appear~in~UTF-8. } -\msg_kernel_new:nnn { str } { utf8-overlong } - { Overlong~UTF-8~byte~sequence~for~code~point~#1. } -\msg_kernel_new:nnn { str } { utf8-premature-end } - { Incomplete~last~UTF-8~character. } -\msg_kernel_new:nnn { str } { utf8-overflow } - { Code~point~#1~too~large~(UTF-8). } -\msg_kernel_new:nnn { str } { utf32-overflow } - { Code~point~too~large~(UTF-32~`#1'). } -\msg_kernel_new:nnn { str } { utf32-truncated } - { Truncated~UTF-32~string~`...#1'. } \cs_set:Npn \str_length_skip_spaces:N { \exp_args:No \str_length_skip_spaces:n } \cs_set_eq:NN \str_length_skip_spaces:n \str_length_ignore_spaces:n diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3tl-analysis.sty b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3tl-analysis.sty index d45f996bdc4..6f82415d186 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/l3str/l3tl-analysis.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/l3str/l3tl-analysis.sty @@ -91,32 +91,6 @@ \group_align_safe_end: \group_end: } -\cs_new_protected:Npn \tl_set_analysis:Nn #1#2 - { - \tl_analysis:n {#2} - \tl_set_eq:NN #1 \g_tl_analysis_result_tl - } -\cs_new_protected:Npn \tl_set_analysis_from_str:Nn #1#2 - { - \str_gset_other:Nn \g_tl_analysis_result_tl {#2} - \tl_set:Nx #1 - { - \exp_after:wN \tl_analysis_from_str_loop:N - \g_tl_analysis_result_tl \prg_map_break: - \prg_break_point:n { } - } - } -\group_begin: - \char_set_catcode_other:N A - \char_set_catcode_other:N C - \cs_new_protected:Npn \tl_analysis_from_str_loop:N #1 - { - #1 \s_tl - \if_charcode:w #1 ~ A \else: C \fi: - \int_value:w `#1 \s_tl - \tl_analysis_from_str_loop:N - } -\group_end: \cs_new_protected:Npn \tl_analysis_setup:n #1 { \int_set_eq:NN \tex_escapechar:D \c_minus_one @@ -363,6 +337,26 @@ 32 \s_tl \tl_analysis_ii_loop:w #1 ; } +\cs_new_protected:Npn \tl_analysis_map_inline:nn #1 + { + \tl_analysis:n {#1} + \int_gincr:N \g_prg_map_int + \exp_args:Nc \tl_analysis_map_inline_aux:Nn + { tl_analysis_map_inline_ \int_use:N \g_prg_map_int :wNw } + } +\cs_new_protected:Npn \tl_analysis_map_inline_aux:Nn #1#2 + { + \cs_gset_protected:Npn #1 ##1 \s_tl ##2 ##3 \s_tl + { + \use_none:n ##2 + #2 + #1 + } + \exp_after:wN #1 + \g_tl_analysis_result_tl + \s_tl { ? \prg_map_break: } \s_tl + \prg_break_point:n { \int_gdecr:N \g_prg_map_int } + } \cs_new_protected:Npn \tl_show_analysis:N #1 { \exp_args:No \tl_analysis:n {#1} diff --git a/Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty b/Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty index d95d1b691d5..590062f47ae 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/xgalley/l3galley.sty @@ -14,7 +14,7 @@ %% Do not distribute a modified version of this file. %% %% File: l3galley.dtx Copyright (C) 1999-2001, 2004-2009 Frank Mittelbach -%% (C) 2010,2011 The LaTeX3 Project +%% (C) 2010-2012 The LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of the %% LaTeX Project Public License (LPPL), either version 1.3c of this @@ -47,8 +47,8 @@ %% %% ----------------------------------------------------------------------- %% -\RequirePackage{l3names} -\GetIdInfo$Id: l3galley.dtx 3205 2012-01-18 22:09:05Z joseph $ +\RequirePackage{xparse} +\GetIdInfo$Id: l3galley.dtx 3253 2012-01-28 14:59:55Z joseph $ {L3 Experimental galley code} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} @@ -252,7 +252,7 @@ } \par } -\cs_new_protected_nopar:Npn \galley_display_penalty:N #1 +\cs_new_protected:Npn \galley_display_penalty:N #1 { \tl_if_empty:NF #1 { @@ -264,7 +264,7 @@ \int_gset:Nn \g_galley_penalty_int {#1} } } -\cs_new_protected_nopar:Npn \galley_display_vspace:N #1 +\cs_new_protected:Npn \galley_display_vspace:N #1 { \tl_if_empty:NF #1 { @@ -397,7 +397,7 @@ \g_galley_restore_running_tl \tl_gclear:N \g_galley_restore_running_tl } -\cs_new_protected_nopar:Npn \galley_margins_set_absolute:nn #1#2 +\cs_new_protected:Npn \galley_margins_set_absolute:nn #1#2 { \dim_set:Nn \l_galley_total_left_margin_dim {#1} \dim_set:Nn \l_galley_total_right_margin_dim {#2} @@ -408,7 +408,7 @@ - \l_galley_total_right_margin_dim } } -\cs_new_protected_nopar:Npn \galley_margins_set_relative:nn #1#2 +\cs_new_protected:Npn \galley_margins_set_relative:nn #1#2 { \dim_add:Nn \l_galley_total_left_margin_dim {#1} \dim_add:Nn \l_galley_total_right_margin_dim {#2} @@ -419,7 +419,7 @@ - \l_galley_total_right_margin_dim } } -\cs_new_protected_nopar:Npn \galley_parshape_fixed_lines:nnn #1#2#3 +\cs_new_protected:Npn \galley_parshape_fixed_lines:nnn #1#2#3 { \bool_gset_true:N \g_galley_parshape_set_bool \bool_set_true:N \l_galley_parshape_fixed_lines_bool @@ -428,7 +428,7 @@ \clist_set:Nn \l_galley_parshape_right_indent_clist {#3} \bool_set_true:N \l_galley_parshape_resume_std_bool } -\cs_new_protected_nopar:Npn \galley_parshape_multi_par:nnnN #1#2#3#4 +\cs_new_protected:Npn \galley_parshape_multi_par:nnnN #1#2#3#4 { \bool_gset_true:N \g_galley_parshape_set_bool \bool_set_true:N \l_galley_parshape_multipar_bool @@ -438,7 +438,7 @@ \clist_set:Nn \l_galley_parshape_right_indent_clist {#3} \bool_set_eq:NN \l_galley_parshape_resume_std_bool #4 } -\cs_new_protected_nopar:Npn \galley_parshape_single_par:nnnN #1#2#3#4 +\cs_new_protected:Npn \galley_parshape_single_par:nnnN #1#2#3#4 { \bool_gset_true:N \g_galley_parshape_set_bool \bool_set_false:N \l_galley_parshape_multipar_bool @@ -503,13 +503,12 @@ \dim_use:N \l_galley_text_width_dim } } -\cs_new_nopar:Npn \galley_set_parshape_map:nn #1#2 +\cs_new:Npn \galley_set_parshape_map:nn #1#2 { \galley_set_parshape_map_aux:nw { } #1 , \q_mark #2 , \q_stop } \cs_generate_variant:Nn \galley_set_parshape_map:nn { oo } -\cs_new_nopar:Npn \galley_set_parshape_map_aux:nw - #1#2 , #3 \q_mark #4 , #5 \q_stop +\cs_new:Npn \galley_set_parshape_map_aux:nw #1#2 , #3 \q_mark #4 , #5 \q_stop { - \bool_if:nTF { \tl_if_empty_p:n {#3} || \tl_if_empty_p:n {#4} } + \bool_if:nTF { \tl_if_empty_p:n {#3} || \tl_if_empty_p:n {#5} } { #1 \dim_eval:n { \l_galley_total_left_margin_dim + ( #2 ) } @@ -548,15 +547,15 @@ \dim_use:N \l_galley_text_width_dim } } -\cs_new_nopar:Npn \galley_generate_parshape_lines_aux:n #1 +\cs_new:Npn \galley_generate_parshape_lines_aux:n #1 { \etex_parshapeindent:D #1 ~ \etex_parshapelength:D #1 } -\cs_new_protected_nopar:Npn \galley_set_user_penalty:n #1 +\cs_new_protected:Npn \galley_set_user_penalty:n #1 { \tl_gset:Nx \g_galley_interpar_penalty_user_tl { \int_eval:n {#1} } } -\cs_new_protected_nopar:Npn \galley_set_user_vspace:n #1 +\cs_new_protected:Npn \galley_set_user_vspace:n #1 { \tl_gset:Nx \g_galley_interpar_vspace_user_tl { \skip_eval:n {#1} } } \dim_set:Nn \parskip \c_zero_dim \cs_undefine:N \parskip @@ -567,7 +566,7 @@ \cs_new_eq:NN \l_galley_par_end_skip \tex_parfillskip:D \cs_new_eq:NN \l_galley_par_indent_dim \tex_parindent:D \cs_new_eq:NN \l_galley_last_line_fit_int \etex_lastlinefit:D -\cs_new_protected_nopar:Npn \galley_set_interword_spacing:N #1 +\cs_new_protected:Npn \galley_set_interword_spacing:N #1 { \bool_if:NTF #1 { % TODO Hook for font changes required! @@ -578,6 +577,8 @@ } { \tex_spaceskip:D \c_zero_dim } } +\int_new:N \l_galley_hyphen_left_int +\int_set:Nn \l_galley_hyphen_left_int { \tex_lefthyphenmin:D } \cs_new_eq:NN \l_galley_binop_penalty_int \tex_binoppenalty:D \cs_new_eq:NN \l_galley_double_hyphen_demerits_int \tex_doublehyphendemerits:D \cs_new_eq:NN \l_galley_emergency_stretch_skip \tex_emergencystretch:D @@ -589,6 +590,21 @@ \cs_new_eq:NN \l_galley_mismatch_demerits_int \tex_adjdemerits:D \cs_new_eq:NN \l_galley_relation_penalty_int \tex_relpenalty:D \cs_new_eq:NN \l_galley_linebreak_tolerance_int \tex_tolerance:D +\cs_new_protected:Npn \galley_break_line:Nn #1#2 + { + \mode_if_vertical:TF + { \msg_kernel_error:nn { galley } { no-line-to-end } } + { + \tex_unskip:D + \bool_if:NF #1 + { \tex_vadjust:D { \tex_penalty:D \c_ten_thousand } } + \dim_compare:nNnF {#2} = \c_zero_dim + { \tex_vadjust:D { \skip_vertical:n {#2} } } + \tex_penalty:D \c_ten_thousand + \tex_hfil:D + \tex_penalty:D -\c_ten_thousand + } + } \cs_new_eq:NN \l_galley_broken_penalty_int \tex_brokenpenalty:D \cs_new_eq:NN \l_galley_interline_penalty_int \tex_interlinepenalty:D \cs_new_eq:NN \l_galley_parbreak_badness_int \tex_vbadness:D @@ -597,7 +613,7 @@ \cs_new_eq:NN \l_galley_pre_display_penalty_int \tex_predisplaypenalty:D \clist_new:N \l_galley_club_penalties_clist \clist_new:N \l_galley_line_penalties_clist -\cs_new_protected_nopar:Npn \galley_set_display_widow_penalties:n #1 +\cs_new_protected:Npn \galley_set_display_widow_penalties:n #1 { \etex_displaywidowpenalties:D \int_eval:w \clist_length:n {#1} + \c_one \int_eval_end: @@ -605,7 +621,7 @@ \c_zero } \cs_generate_variant:Nn \galley_set_display_widow_penalties:n { V , v } -\cs_new_protected_nopar:Npn \galley_set_widow_penalties:n #1 +\cs_new_protected:Npn \galley_set_widow_penalties:n #1 { \etex_widowpenalties:D \int_eval:w \clist_length:n {#1} + \c_one \int_eval_end: @@ -613,20 +629,20 @@ \c_zero } \cs_generate_variant:Nn \galley_set_widow_penalties:n { V , v } -\cs_new_nopar:Npn \galley_set_aux:n #1 { #1 ~ } -\cs_new_protected_nopar:Npn \galley_set_club_penalties:n #1 +\cs_new:Npn \galley_set_aux:n #1 { #1 ~ } +\cs_new_protected:Npn \galley_set_club_penalties:n #1 { \clist_set:Nn \l_galley_club_penalties_clist {#1} \galley_calc_interline_penalties: } \cs_generate_variant:Nn \galley_set_club_penalties:n { V , v } -\cs_new_protected_nopar:Npn \galley_set_interline_penalties:n #1 +\cs_new_protected:Npn \galley_set_interline_penalties:n #1 { \clist_set:Nn \l_galley_line_penalties_clist {#1} \galley_calc_interline_penalties: } \cs_generate_variant:Nn \galley_set_interline_penalties:n { V , v } -\cs_new_protected_nopar:Npn \galley_set_display_club_penalties:n #1 +\cs_new_protected:Npn \galley_set_display_club_penalties:n #1 { \etex_clubpenalties:D \int_eval:w \clist_length:n {#1} + \c_one \int_eval_end: @@ -635,7 +651,7 @@ \galley_calc_interline_penalties: } \cs_generate_variant:Nn \galley_set_display_club_penalties:n { V , v } -\cs_new_protected_nopar:Npn \galley_set_interline_penalty:n #1 +\cs_new_protected:Npn \galley_set_interline_penalty:n #1 { \int_compare:nNnTF { \etex_interlinepenalties:D \c_zero } = \c_zero { @@ -643,7 +659,7 @@ \galley_calc_interline_penalties: } { - \cs_set_nopar:Npn \galley_set_interline_penalty_aux_ii:n ##1 + \cs_set:Npn \galley_set_interline_penalty_aux_ii:n ##1 { \int_eval:w \etex_interlinepenalties:D ##1 @@ -655,7 +671,7 @@ { \clist_length:N \l_galley_line_penalties_clist } {#1} } } -\cs_new_protected_nopar:Npn \galley_set_interline_penalty_aux:nn #1#2 +\cs_new_protected:Npn \galley_set_interline_penalty_aux:nn #1#2 { \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero @@ -666,9 +682,9 @@ \galley_set_interline_penalty_aux_ii:n \int_eval:w #2 \int_eval_end: } -\cs_new_nopar:Npn \galley_set_interline_penalty_aux_i:n #1 +\cs_new:Npn \galley_set_interline_penalty_aux_i:n #1 { \etex_interlinepenalties:D \int_eval:w #1 \int_eval_end: } -\cs_new_nopar:Npn \galley_set_interline_penalty_aux_ii:n #1 { } +\cs_new:Npn \galley_set_interline_penalty_aux_ii:n #1 { } \cs_new_protected_nopar:Npn \galley_calc_interline_penalties: { \exp_args:Nff \galley_calc_interline_penalties_aux:nn @@ -692,8 +708,7 @@ } { \clist_length:N \l_galley_line_penalties_clist } } -\cs_new_protected_nopar:Npn \galley_calc_interline_penalties_aux:nn - #1#2 +\cs_new_protected:Npn \galley_calc_interline_penalties_aux:nn #1#2 { \etex_interlinepenalties:D #1 ~ \prg_stepwise_function:nnnN \c_one \c_one {#2} @@ -702,8 +717,7 @@ \galley_calc_interline_penalties_aux_ii:n \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero } -\cs_new_nopar:Npn \galley_calc_interline_penalties_aux_i:n - #1 +\cs_new:Npn \galley_calc_interline_penalties_aux_i:n #1 { \int_eval:w \clist_item:Nn \l_galley_line_penalties_clist { #1 - \c_one } @@ -712,8 +726,7 @@ - \etex_clubpenalties:D #1 ~ \int_eval_end: } -\cs_new_nopar:Npn \galley_calc_interline_penalties_aux_ii:n - #1 +\cs_new:Npn \galley_calc_interline_penalties_aux_ii:n #1 { \int_eval:w \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero @@ -722,11 +735,11 @@ - \etex_clubpenalties:D #1 ~ \int_eval_end: } -\cs_new_protected_nopar:Npn \galley_save_club_penalties:N #1 +\cs_new_protected:Npn \galley_save_club_penalties:N #1 { \clist_set_eq:NN #1 \l_galley_club_penalties_clist } -\cs_new_protected_nopar:Npn \galley_save_interline_penalties:N #1 +\cs_new_protected:Npn \galley_save_interline_penalties:N #1 { \clist_set_eq:NN #1 \l_galley_line_penalties_clist } -\cs_new_protected_nopar:Npn \galley_save_display_club_penalties:N #1 +\cs_new_protected:Npn \galley_save_display_club_penalties:N #1 { \clist_set:Nx #1 { @@ -735,9 +748,9 @@ \galley_save_display_club_penalties:_aux:n } } -\cs_new_nopar:Npn \galley_save_display_club_penalties:_aux:n #1 +\cs_new:Npn \galley_save_display_club_penalties:_aux:n #1 { \int_use:N \etex_clubpenaltes:D \int_eval:w #1 \int_eval_end: , } -\cs_new_protected_nopar:Npn \galley_save_display_widow_penalties:N #1 +\cs_new_protected:Npn \galley_save_display_widow_penalties:N #1 { \clist_set:Nx #1 { @@ -746,9 +759,9 @@ \galley_save_display_widow_penalties:_aux:n } } -\cs_new_nopar:Npn \galley_save_display_widow_penalties:_aux:n #1 +\cs_new:Npn \galley_save_display_widow_penalties:_aux:n #1 { \int_use:N \etex_displaywidowpenalties:D \int_eval:w #1 \int_eval_end: , } -\cs_new_protected_nopar:Npn \galley_save_widow_penalties:N #1 +\cs_new_protected:Npn \galley_save_widow_penalties:N #1 { \clist_set:Nx #1 { @@ -757,23 +770,29 @@ \galley_save_widow_penalties:_aux:n } } -\cs_new_nopar:Npn \galley_save_widow_penalties:_aux:n #1 +\cs_new:Npn \galley_save_widow_penalties:_aux:n #1 { \int_use:N \etex_widowpenalties:D \int_eval:w #1 \int_eval_end: , } \cs_new_protected_nopar:Npn \galley_interline_penalty: { \int_use:N \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero } -\cs_set_protected_nopar:Npn \nobreak +\msg_kernel_new:nnn { galley } { no-line-to-end } + { There's~no~line~here~to~end. } +\RenewDocumentCommand \nobreak { } { \bool_gset_true:N \g_galley_no_break_next_bool } -\cs_set_protected_nopar:Npn \noindent +\RenewDocumentCommand \noindent { } { \tex_noindent:D \bool_gset_false:N \g_galley_omit_next_indent_bool } -\cs_set_protected_nopar:Npn \vspace #1 +\RenewDocumentCommand \vspace { m } { \@ifstar { \galley_set_user_vspace:n {#1} } { \galley_set_user_vspace:n {#1} } } +\RenewDocumentCommand \\ { s O { 0 pt } } + { \galley_break_line:Nn #1 {#2} } +\RenewDocumentCommand \newline { } + { \galley_break_line:Nn \c_true_bool { 0 pt } } \cs_set_eq:NN \@@par \galley_std_par: \cs_set_protected_nopar:Npn \@afterheading { @@ -797,6 +816,7 @@ \bool_gset_true:N \g_galley_omit_next_indent_bool \box \@tempboxa } +\cs_set_eq:Nc \@normalcr { \token_to_str:N \\ } %% %% %% End of file `l3galley.sty'. diff --git a/Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty b/Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty index 5ebe766a12b..3e3d251791a 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/xgalley/xgalley.sty @@ -14,7 +14,7 @@ %% Do not distribute a modified version of this file. %% %% File: xgalley.dtx Copyright (C) 1999-2001, 2004-2009 Frank Mittelbach -%% (C) 2010,2011 The LaTeX3 Project +%% (C) 2010-2012 The LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of the %% LaTeX Project Public License (LPPL), either version 1.3c of this @@ -48,7 +48,7 @@ %% ----------------------------------------------------------------------- %% \RequirePackage{l3names} -\GetIdInfo$Id: xgalley.dtx 2922 2011-10-17 19:01:04Z joseph $ +\GetIdInfo$Id: xgalley.dtx 3253 2012-01-28 14:59:55Z joseph $ {L3 Experimental galley} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} @@ -195,11 +195,17 @@ \int_set:Nn \tex_lefthyphenmin:D { \bool_if:NTF \l_galley_hyphen_enable_bool - { \l_galley_hyphen_left_int } { 63 } + { \l_galley_hyphen_left_int } + { 63 } } \int_set:Nn \tex_uchyph:D - { \bool_if:NTF \l_galley_hyphen_uppercase_bool { 1 } { 0 } } + { + \bool_if:NTF \l_galley_hyphen_uppercase_bool + { 1 } + { 0 } + } } +\UseTemplate { hyphenation } { std } { } \tex_defaulthyphenchar:D 45 \scan_stop: \tl_new:N \l_galley_justification_other_tl \DeclareObjectType { justification } { 0 } @@ -260,7 +266,7 @@ \bool_if:NTF \l_galley_fixed_spacing_bool { \bool_set_true:N \exp_not:N \l_galley_fixed_spacing_bool } { \bool_set_false:N \exp_not:N \l_galley_fixed_spacing_bool } - \galley_set_interword_space:N + \galley_set_interword_spacing:N \exp_not:N \l_galley_fixed_spacing_bool \dim_set:Nn \exp_not:N \l_galley_par_indent_dim { \dim_use:N \l_galley_par_indent_dim } @@ -268,8 +274,8 @@ { \skip_use:N \l_galley_line_left_skip } \skip_set:Nn \exp_not:N \l_galley_line_right_skip { \skip_use:N \l_galley_line_right_skip } - \skip_set:Nn \exp_not:N \l_galley_par_start_skip - { \skip_use:N \l_galley_par_start_skip } + \skip_set:Nn \exp_not:N \l_galley_par_begin_skip + { \skip_use:N \l_galley_par_begin_skip } \int_set:Nn \exp_not:N \l_galley_last_line_fit_int { \int_use:N \l_galley_last_line_fit_int } \skip_set:Nn \exp_not:N \@rightskip |