diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3token.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3token.dtx | 250 |
1 files changed, 162 insertions, 88 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx index 473cd48a82c..6d3f13581f1 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx @@ -43,7 +43,7 @@ % }^^A % } % -% \date{Released 2020-09-06} +% \date{Released 2020-09-24} % % \maketitle % @@ -737,12 +737,13 @@ % (not used by \LaTeX3). % \end{function} % -% \begin{function}[updated = 2011-05-23, EXP,pTF]{\token_if_primitive:N} +% \begin{function}[updated = 2020-09-11, EXP,pTF]{\token_if_primitive:N} % \begin{syntax} % \cs{token_if_primitive_p:N} \meta{token} \\ % \cs{token_if_primitive:NTF} \meta{token} \Arg{true code} \Arg{false code} % \end{syntax} -% Tests if the \meta{token} is an engine primitive. +% Tests if the \meta{token} is an engine primitive. In \LuaTeX{} +% this includes primitive-like commands defined using |{token.set_lua}|. % \end{function} % % \section{Peeking ahead at the next token} @@ -1112,6 +1113,10 @@ % \end{macrocode} % % \begin{macrocode} +%<*tex> +% \end{macrocode} +% +% \begin{macrocode} %<@@=char> % \end{macrocode} % @@ -1454,37 +1459,26 @@ \if_int_odd:w 0 \sys_if_engine_luatex:T { 1 } \sys_if_engine_xetex:T { 1 } \exp_stop_f: - \sys_if_engine_luatex:TF - { - \cs_new:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: - { - #3 - \exp_after:wN \exp_after:wN \exp_after:wN \exp_end: - \lua_now:e { l3kernel.charcat(#1, #2) } - } - } - { - \cs_new:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: - { - #3 - \exp_after:wN \exp_end: - \tex_Ucharcat:D #1 \exp_stop_f: #2 \exp_stop_f: - } - \cs_if_exist:NF \tex_expanded:D - { - \cs_new_eq:NN \@@_generate_auxii:nnw \@@_generate_aux:nnw - \cs_gset:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: - { - #3 - \if_int_compare:w #2 = 13 \exp_stop_f: - \__kernel_msg_expandable_error:nn { kernel } { char-active } - \else: - \@@_generate_auxii:nnw {#1} {#2} - \fi: - \exp_end: - } - } - } + \cs_new:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: + { + #3 + \exp_after:wN \exp_end: + \tex_Ucharcat:D #1 \exp_stop_f: #2 \exp_stop_f: + } + \cs_if_exist:NF \tex_expanded:D + { + \cs_new_eq:NN \@@_generate_auxii:nnw \@@_generate_aux:nnw + \cs_gset:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: + { + #3 + \if_int_compare:w #2 = 13 \exp_stop_f: + \__kernel_msg_expandable_error:nn { kernel } { char-active } + \else: + \@@_generate_auxii:nnw {#1} {#2} + \fi: + \exp_end: + } + } \else: % \end{macrocode} % For engines where \tn{Ucharcat} isn't available or emulated, we have @@ -2369,7 +2363,8 @@ % \@@_if_primitive_nullfont:N, % \@@_if_primitive_loop:N, % \@@_if_primitive:Nw, -% \@@_if_primitive_undefined:N} +% \@@_if_primitive_undefined:N, +% \@@_if_primitive_lua:N} %^^A See http://groups.google.com/group/comp.text.tex/browse_thread/thread/0a72666873f8753d# % % We filter out macros first, because they cause endless trouble later @@ -2414,67 +2409,142 @@ % \cs{tex_undefined:D}, and if it is |"| or a digit, then the token % is not a primitive. % +% For \LuaTeX{} we use a different implementation which just looks at the +% command code for the token and compaes it to a list of non-primitives. +% Again, \tn{nullfont} is a special case because it is the only primitive +% with the normally non-primitive |set_font| command code. +% % \begin{macrocode} -\tex_chardef:D \c_@@_A_int = `A ~ % -\use:x +\sys_if_engine_luatex:TF { - \prg_new_conditional:Npnn \exp_not:N \token_if_primitive:N ##1 - { p , T , F , TF } +%</tex> +%<*lua> +do + local get_next = token.get_next + local get_command = token.get_command + local get_index = token.get_index + local get_mode = token.get_mode or token.get_index + local cmd = token.command_id + local set_font = cmd'get_font' + local biggest_char = token.biggest_char() + + local mode_below_biggest_char = {} + local index_not_nil = {} + local mode_not_null = {} + local non_primitive = { + [cmd'left_brace'] = true, + [cmd'right_brace'] = true, + [cmd'math_shift'] = true, + [cmd'mac_param'] = mode_below_biggest_char, + [cmd'sup_mark'] = true, + [cmd'sub_mark'] = true, + [cmd'endv'] = true, + [cmd'spacer'] = true, + [cmd'letter'] = true, + [cmd'other_char'] = true, + [cmd'tab_mark'] = mode_below_biggest_char, + [cmd'char_given'] = true, + [cmd'math_given'] = true, + [cmd'xmath_given'] = true, + [cmd'set_font'] = mode_not_null, + [cmd'undefined_cs'] = true, + [cmd'call'] = true, + [cmd'long_call'] = true, + [cmd'outer_call'] = true, + [cmd'long_outer_call'] = true, + [cmd'assign_glue'] = index_not_nil, + [cmd'assign_mu_glue'] = index_not_nil, + [cmd'assign_toks'] = index_not_nil, + [cmd'assign_int'] = index_not_nil, + [cmd'assign_attr'] = true, + [cmd'assign_dimen'] = index_not_nil, + } + + luacmd("@@_if_primitive_lua:N", function() + local tok = get_next() + local is_non_primitive = non_primitive[get_command(tok)] + return put_next( + is_non_primitive == true + and false_tok + or is_non_primitive == nil + and true_tok + or is_non_primitive == mode_not_null + and (get_mode(tok) == 0 and true_tok or false_tok) + or is_non_primitive == index_not_nil + and (get_index(tok) and false_tok or true_tok) + or is_non_primitive == mode_below_biggest_char + and (get_mode(tok) > biggest_char and true_tok or false_tok)) + end, "global") +end +%</lua> +%<*tex> + \prg_new_conditional:Npnn \token_if_primitive:N #1 { p , T , F , TF } { - \exp_not:N \token_if_macro:NTF ##1 - \exp_not:N \prg_return_false: - { - \exp_not:N \exp_after:wN \exp_not:N \@@_if_primitive:NNw - \exp_not:N \token_to_meaning:N ##1 - \tl_to_str:n { : : : } \s_@@_stop ##1 - } + \@@_if_primitive_lua:N #1 } - \cs_new:Npn \exp_not:N \@@_if_primitive:NNw - ##1##2 ##3 \c_colon_str ##4 \s_@@_stop + } + { + \tex_chardef:D \c_@@_A_int = `A ~ % + \use:x { - \exp_not:N \tl_if_empty:oTF - { \exp_not:N \@@_if_primitive_space:w ##3 ~ } + \prg_new_conditional:Npnn \exp_not:N \token_if_primitive:N ##1 + { p , T , F , TF } { - \exp_not:N \@@_if_primitive_loop:N ##3 - \c_colon_str \s_@@_stop + \exp_not:N \token_if_macro:NTF ##1 + \exp_not:N \prg_return_false: + { + \exp_not:N \exp_after:wN \exp_not:N \@@_if_primitive:NNw + \exp_not:N \token_to_meaning:N ##1 + \tl_to_str:n { : : : } \s_@@_stop ##1 + } + } + \cs_new:Npn \exp_not:N \@@_if_primitive:NNw + ##1##2 ##3 \c_colon_str ##4 \s_@@_stop + { + \exp_not:N \tl_if_empty:oTF + { \exp_not:N \@@_if_primitive_space:w ##3 ~ } + { + \exp_not:N \@@_if_primitive_loop:N ##3 + \c_colon_str \s_@@_stop + } + { \exp_not:N \@@_if_primitive_nullfont:N } } - { \exp_not:N \@@_if_primitive_nullfont:N } } - } -\cs_new:Npn \@@_if_primitive_space:w #1 ~ { } -\cs_new:Npn \@@_if_primitive_nullfont:N #1 - { - \if_meaning:w \tex_nullfont:D #1 - \prg_return_true: - \else: - \prg_return_false: - \fi: - } -\cs_new:Npn \@@_if_primitive_loop:N #1 - { - \if_int_compare:w `#1 < \c_@@_A_int % - \exp_after:wN \@@_if_primitive:Nw - \exp_after:wN #1 - \else: - \exp_after:wN \@@_if_primitive_loop:N - \fi: - } -\cs_new:Npn \@@_if_primitive:Nw #1 #2 \s_@@_stop - { - \if:w : #1 - \exp_after:wN \@@_if_primitive_undefined:N - \else: - \prg_return_false: - \exp_after:wN \use_none:n - \fi: - } -\cs_new:Npn \@@_if_primitive_undefined:N #1 - { - \if_cs_exist:N #1 - \prg_return_true: - \else: - \prg_return_false: - \fi: + \cs_new:Npn \@@_if_primitive_space:w #1 ~ { } + \cs_new:Npn \@@_if_primitive_nullfont:N #1 + { + \if_meaning:w \tex_nullfont:D #1 + \prg_return_true: + \else: + \prg_return_false: + \fi: + } + \cs_new:Npn \@@_if_primitive_loop:N #1 + { + \if_int_compare:w `#1 < \c_@@_A_int % + \exp_after:wN \@@_if_primitive:Nw + \exp_after:wN #1 + \else: + \exp_after:wN \@@_if_primitive_loop:N + \fi: + } + \cs_new:Npn \@@_if_primitive:Nw #1 #2 \s_@@_stop + { + \if:w : #1 + \exp_after:wN \@@_if_primitive_undefined:N + \else: + \prg_return_false: + \exp_after:wN \use_none:n + \fi: + } + \cs_new:Npn \@@_if_primitive_undefined:N #1 + { + \if_cs_exist:N #1 + \prg_return_true: + \else: + \prg_return_false: + \fi: + } } % \end{macrocode} % \end{macro} @@ -2869,6 +2939,10 @@ % \end{macro} % % \begin{macrocode} +%</tex> +% \end{macrocode} +% +% \begin{macrocode} %</package> % \end{macrocode} % |