From 6681c50cb65e04296087b8a96610993066386dcf Mon Sep 17 00:00:00 2001 From: Joseph Wright Date: Mon, 1 Oct 2018 20:49:47 +0100 Subject: [PATCH] Rearrange cctab code to collect LuaTeX branch --- l3experimental/l3cctab/l3cctab.dtx | 165 +++++++++++++++-------------- 1 file changed, 85 insertions(+), 80 deletions(-) diff --git a/l3experimental/l3cctab/l3cctab.dtx b/l3experimental/l3cctab/l3cctab.dtx index 4508821528..963c3e5f20 100644 --- a/l3experimental/l3cctab/l3cctab.dtx +++ b/l3experimental/l3cctab/l3cctab.dtx @@ -157,7 +157,30 @@ % \end{variable} % \end{variable} % +% \begin{variable}{\l_@@_tmp_tl} +% Scratch space. +% \begin{macrocode} +%<*initex> +\tl_new:N \l_@@_tmp_tl +% +% \end{macrocode} +% \end{variable} +% % \begin{macro}{\cctab_new:N} +% \begin{macro}{\cctab_begin:N} +% \begin{macro}{\cctab_end:} +% \begin{macro}{\cctab_gset:Nn} +% As \LuaTeX{} offers engine support for category code tables, and this is +% entirely lacking from the other engines, we need two complementary +% approaches here. Rather than intermix them, we split the set up based on +% engine. (Some future \XeTeX{} may add support, at which point the +% conditional here would be subtly different.) +% +% First, the \LuaTeX{} case. +% \begin{macrocode} +\sys_if_engine_luatex:TF + { +% \end{macrocode} % Creating a new category code table is done slightly differently % from other registers. Low-numbered tables are more efficiently-stored % than high-numbered ones. There is also a need to have a stack of @@ -166,113 +189,95 @@ % tables, and even ones for the stack. Here, therefore, the odd numbers % are allocated. % \begin{macrocode} -\cs_new_protected:Npn \cctab_new:N #1 - { - \__kernel_chk_if_free_cs:N #1 - \int_gadd:Nn \g_@@_allocate_int { 2 } - \int_compare:nNnTF - \g_@@_allocate_int < { \c_max_register_int + 1 } - { - \tex_global:D \tex_chardef:D #1 \g_@@_allocate_int - \tex_initcatcodetable:D #1 - } - { \__kernel_msg_fatal:nnx { kernel } { out-of-registers } { cctab } } - } -\sys_if_engine_luatex:F - { - \cs_set_protected:Npn \cctab_new:N #1 - { - \__kernel_msg_error:nnx { kernel } { bad-engine } - { \exp_not:N \cctab_new:N } - } - } -%<*package> -\sys_if_engine_luatex:T - { - \cs_set_protected:Npn \cctab_new:N #1 + \cs_new_protected:Npn \cctab_new:N #1 { \__kernel_chk_if_free_cs:N #1 +%<*initex> + \int_gadd:Nn \g_@@_allocate_int { 2 } + \int_compare:nNnTF + \g_@@_allocate_int < { \c_max_register_int + 1 } + { + \tex_global:D \tex_chardef:D #1 \g_@@_allocate_int + \tex_initcatcodetable:D #1 + } + { + \__kernel_msg_fatal:nnx + { kernel } { out-of-registers } { cctab } + } +% +%<*package> \newcatcodetable #1 \tex_initcatcodetable:D #1 - } - } % + } % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\cctab_begin:N} -% \begin{macro}{\cctab_end:} -% \begin{variable}{\l_@@_tmp_tl} % The aim here is to ensure that the saved tables are read-only. This is % done by using a stack of tables which are not read only, and actually % having them as \enquote{in use} copies. % \begin{macrocode} -\cs_new_protected:Npn \cctab_begin:N #1 - { - \seq_gpush:Nx \g_@@_stack_seq { \tex_the:D \tex_catcodetable:D } - \tex_catcodetable:D #1 - \int_gadd:Nn \g_@@_stack_int { 2 } - \int_compare:nNnT \g_@@_stack_int > \c_max_register_int - { \__kernel_msg_fatal:nn { kernel } { cctab-stack-full } } - \tex_savecatcodetable:D \g_@@_stack_int - \tex_catcodetable:D \g_@@_stack_int - } -\cs_new_protected_nopar:Npn \cctab_end: - { - \int_gsub:Nn \g_@@_stack_int { 2 } - \seq_if_empty:NTF \g_@@_stack_seq - { \tl_set:Nn \l_@@_tmp_tl { 0 } } - { \seq_gpop:NN \g_@@_stack_seq \l_@@_tmp_tl } - \tex_catcodetable:D \l_@@_tmp_tl \scan_stop: - } -\sys_if_engine_luatex:F - { - \cs_set_protected:Npn \cctab_begin:N #1 + \cs_new_protected:Npn \cctab_begin:N #1 { - \__kernel_msg_error:nnxx { kernel } { bad-engine } - { \exp_not:N \cctab_begin:N } {#1} +%<*initex> + \seq_gpush:Nx \g_@@_stack_seq { \tex_the:D \tex_catcodetable:D } + \tex_catcodetable:D #1 + \int_gadd:Nn \g_@@_stack_int { 2 } + \int_compare:nNnT \g_@@_stack_int > \c_max_register_int + { \__kernel_msg_fatal:nn { kernel } { cctab-stack-full } } + \tex_savecatcodetable:D \g_@@_stack_int + \tex_catcodetable:D \g_@@_stack_int +% +%<*package> + \BeginCatcodeRegime #1 +% } - \cs_set_protected_nopar:Npn \cctab_end: + \cs_new_protected:Npn \cctab_end: { - \__kernel_msg_error:nnx { kernel } { bad-engine } - { \exp_not:N \cctab_end: } - } - } +%<*initex> + \int_gsub:Nn \g_@@_stack_int { 2 } + \seq_if_empty:NTF \g_@@_stack_seq + { \tl_set:Nn \l_@@_tmp_tl { 0 } } + { \seq_gpop:NN \g_@@_stack_seq \l_@@_tmp_tl } + \tex_catcodetable:D \l_@@_tmp_tl \scan_stop: +% %<*package> -\sys_if_engine_luatex:T - { - \cs_set_protected:Npn \cctab_begin:N #1 { \BeginCatcodeRegime #1 } - \cs_set_protected_nopar:Npn \cctab_end: { \EndCatcodeRegime } - } + \EndCatcodeRegime % -\tl_new:N \l_@@_tmp_tl + } % \end{macrocode} -% \end{variable} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\cctab_gset:Nn} % Category code tables are always global, so only one version is needed. % The set up here is simple, and means that at the point of use there is % no need to worry about escaping category codes. % \begin{macrocode} -\cs_new_protected:Npn \cctab_gset:Nn #1#2 - { - \group_begin: - #2 - \tex_savecatcodetable:D #1 - \group_end: + \cs_new_protected:Npn \cctab_gset:Nn #1#2 + { + \group_begin: + #2 + \tex_savecatcodetable:D #1 + \group_end: + } } -\sys_if_engine_luatex:F +% \end{macrocode} +% Now the case for other engines. +% \begin{macrocode} { - \cs_set_protected:Npn \cctab_gset:Nn #1#2 + \cs_new_protected:Npn \cctab_new:N #1 + { + } + \cs_new_protected:Npn \cctab_begin:N #1 + { + } + \cs_new_protected:Npn \cctab_end: + { + } + \cs_new_protected:Npn \cctab_gset:Nn #1#2 { - \__kernel_msg_error:nnxx { kernel } { bad-engine } - { \exp_not:N \cctab_gset:Nn } { #1 {#2} } } } % \end{macrocode} % \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} % % \begin{variable}{\c_code_cctab} % \begin{variable}{\c_document_cctab}