[latex3-commits] [git/LaTeX3-latex3-latex3] luaintarray: Implement intarray range functions in Lua (0e2066a14)
Marcel Fabian Krüger
tex at 2krueger.de
Sun Nov 7 10:41:19 CET 2021
Repository : https://github.com/latex3/latex3
On branch : luaintarray
Link : https://github.com/latex3/latex3/commit/0e2066a14f489fae1c825805b21ceaefbff07975
>---------------------------------------------------------------
commit 0e2066a14f489fae1c825805b21ceaefbff07975
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sun Nov 7 09:04:28 2021 +0100
Implement intarray range functions in Lua
>---------------------------------------------------------------
0e2066a14f489fae1c825805b21ceaefbff07975
l3kernel/l3intarray.dtx | 68 +++++++++++++++++++++++++++++--------------------
1 file changed, 40 insertions(+), 28 deletions(-)
diff --git a/l3kernel/l3intarray.dtx b/l3kernel/l3intarray.dtx
index 4b3c6d7ee..ca6c1778c 100644
--- a/l3kernel/l3intarray.dtx
+++ b/l3kernel/l3intarray.dtx
@@ -269,6 +269,7 @@ local get_csname = token.get_csname
local put_next = token.put_next
local s_@@ = token.create's_@@'
local use_none
+local comma = token.create(string.byte',')
local use_i = token.create'use:n'
if use_i.cmdname == "undefined_cs" then
@@ -521,49 +522,60 @@ end, 'global')
%<*tex>
\cs_new:Npn \__kernel_intarray_range_to_clist:Nnn #1#2#3
{
- \exp_last_unbraced:Nf \use_none:n
- {
- \exp_after:wN \@@_range_to_clist:ww
- \int_value:w \int_eval:w #2 \exp_after:wN ;
- \int_value:w \int_eval:w #3 ;
- #1 \prg_break_point:
- }
- }
-\cs_new:Npn \@@_range_to_clist:ww #1 ; #2 ; #3
- {
- \if_int_compare:w #1 > #2 \exp_stop_f:
- \prg_break:n
- \fi:
- , \__kernel_intarray_item:Nn #3 {#1}
\exp_after:wN \@@_range_to_clist:ww
- \int_value:w \int_eval:w #1 + \c_one_int ; #2 ; #3
+ \int_value:w \int_eval:w #2 \exp_after:wN ;
+ \int_value:w \int_eval:w #3
+ #1
}
+%</tex>
+%<*lua>
+luacmd('@@_range_to_clist:ww', function()
+ local from = scan_int()
+ scan_token()
+ local to = scan_int()
+ local t = @@_table()
+ sprint(-2, concat(t, ',', from, to))
+end, 'global')
+%</lua>
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{\__kernel_intarray_gset_range_from_clist:Nnn, \@@_gset_range:Nw}
-% Loop through part of the array.
+% \begin{macro}{\__kernel_intarray_gset_range_from_clist:Nnn, \@@_gset_range:nNw}
+% Loop through part of the array. We allow additional commas at the end.
% \begin{macrocode}
+%<*tex>
\cs_new_protected:Npn \__kernel_intarray_gset_range_from_clist:Nnn #1#2#3
{
- \int_set:Nn \l_@@_loop_int {#2}
- \@@_gset_range:Nw #1 #3 , , \prg_break_point:
- }
-\cs_new_protected:Npn \@@_gset_range:Nw #1 #2 ,
- {
- \if_catcode:w \scan_stop: \tl_to_str:n {#2} \scan_stop:
- \prg_break:n
- \fi:
- \__kernel_intarray_gset:Nnn #1 \l_@@_loop_int {#2}
- \int_incr:N \l_@@_loop_int
- \@@_gset_range:Nw #1
+ \@@_gset_range:wNw \int_eval:w #2 #1 #3 , , \scan_stop:
}
+%</tex>
+%<*lua>
+luacmd('@@_gset_range:wNw', function()
+ local from = scan_int()
+ local t = @@_table()
+ while true do
+ local tok = scan_token()
+ if tok == comma then
+ repeat
+ tok = scan_token()
+ until tok ~= comma
+ break
+ else
+ put_next(tok)
+ end
+ t[from] = scan_int()
+ scan_token()
+ from = from + 1
+ end
+ end, 'global', 'protected')
+%</lua>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\intarray_show:N, \intarray_show:c, \intarray_log:N, \intarray_log:c}
% Convert the list to a comma list (with spaces after each comma)
% \begin{macrocode}
+%<*tex>
\cs_new_protected:Npn \intarray_show:N { \@@_show:NN \msg_show:nnxxxx }
\cs_generate_variant:Nn \intarray_show:N { c }
\cs_new_protected:Npn \intarray_log:N { \@@_show:NN \msg_log:nnxxxx }
More information about the latex3-commits
mailing list.