summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/morewrites/primargs.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2017-04-16 22:19:40 +0000
committerKarl Berry <karl@freefriends.org>2017-04-16 22:19:40 +0000
commitcacc7d77918eb955a4bc5bed894e8ea1445a6ba4 (patch)
tree54307a98b0d3dafd1998f2135dcfe9237f38f9af /Master/texmf-dist/tex/latex/morewrites/primargs.sty
parentb1e4ebb4febbc920047445c1f1416bb2f6a563f7 (diff)
morewrites (14apr17)
git-svn-id: svn://tug.org/texlive/trunk@43862 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/morewrites/primargs.sty')
-rw-r--r--Master/texmf-dist/tex/latex/morewrites/primargs.sty242
1 files changed, 196 insertions, 46 deletions
diff --git a/Master/texmf-dist/tex/latex/morewrites/primargs.sty b/Master/texmf-dist/tex/latex/morewrites/primargs.sty
index e4b0d10abc3..908e61f948d 100644
--- a/Master/texmf-dist/tex/latex/morewrites/primargs.sty
+++ b/Master/texmf-dist/tex/latex/morewrites/primargs.sty
@@ -9,7 +9,7 @@
%% Communicate any suggestions for changing this package
%% to Bruno Le Floch (blflatex@gmail.com).
%%
-%% File: primargs.dtx Copyright (C) 2012-2013 Bruno Le Floch
+%% File: primargs.dtx Copyright (C) 2012-2017 Bruno Le Floch
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -19,49 +19,58 @@
%% http://www.latex-project.org/lppl.txt
%%
%% -----------------------------------------------------------------------
-\RequirePackage {expl3} [2012/08/14]
+\RequirePackage {expl3} [2017/03/18]
\ProvidesExplPackage
- {primargs} {2013/01/08} {0.2e} {Parsing arguments of primitives}
-\cs_new_protected_nopar:Npn \g__primargs_code_tl { }
-\cs_new_protected_nopar:Npn \__primargs_no_afterassignment:
- { \tex_afterassignment:D \tex_relax:D }
-\cs_new_protected_nopar:Npn \__primargs_no_localdefs:
+ {primargs} {2017/04/10} {} {Parsing arguments of primitives}
+\tl_new:N \g__primargs_code_tl
+\tl_new:N \g__primargs_file_name_tl
+\tl_new:N \g__primargs_file_name_level_tl
+\cs_new_protected:Npn \__primargs_safe:
{
- \__primargs_no_afterassignment:
- \int_compare:nNnF \tex_globaldefs:D > \c_zero
- { \tex_globaldefs:D = \c_zero }
+ \tex_afterassignment:D \tex_relax:D
+ \if_int_compare:w 0 > \tex_globaldefs:D
+ \int_zero:N \tex_globaldefs:D
+ \fi:
}
-\cs_new_protected_nopar:Npn \primargs_read_x_token:N
+\cs_new_protected:Npn \primargs_read_x_token:N
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\__primargs_read_x_token:N
}
-\cs_new_protected_nopar:Npn \__primargs_read_x_token:N
+\cs_new_protected:Npn \__primargs_read_x_token:N
{
- \tex_afterassignment:D \__primargs_read_x_token_ii:N
+ \tex_afterassignment:D \__primargs_read_x_token_aux:N
\tex_global:D \tex_futurelet:D \g_primargs_token
}
-\cs_new_protected_nopar:Npn \__primargs_read_x_token_ii:N
+\cs_new_protected:Npn \__primargs_read_x_token_std:N
{
\exp_after:wN
\if_meaning:w \exp_not:N \g_primargs_token \g_primargs_token
- \group_end:
- \exp_after:wN \use_none:nnn
+ \group_end: \use_i:nnnn
\fi:
\exp_after:wN \__primargs_read_x_token:N \exp_after:wN
}
-\cs_new_protected_nopar:Npn \primargs_read_token:N
+\cs_new_eq:NN \__primargs_read_x_token_aux:N
+ \__primargs_read_x_token_std:N
+\cs_new_protected:Npn \__primargs_read_x_token_file:N
+ {
+ \if_meaning:w \tex_input:D \g_primargs_token
+ \use_i_ii:nnn \group_end:
+ \fi:
+ \__primargs_read_x_token_std:N
+ }
+\cs_new_protected:Npn \primargs_read_token:N
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_afterassignment:D \group_end:
\tex_global:D \tex_futurelet:D \g_primargs_token
}
\cs_new_protected:Npn \primargs_remove_token:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #1
\tex_afterassignment:D \group_end:
\tex_global:D \tex_let:D \g_primargs_token = ~
@@ -69,13 +78,13 @@
\cs_new_protected:Npn \primargs_remove_one_optional_space:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #1
\primargs_read_x_token:N \__primargs_remove_one_optional_space:
}
-\exp_args:NNo \cs_new_protected_nopar:Npn \__primargs_remove_one_optional_space:
+\cs_new_protected:Npn \__primargs_remove_one_optional_space:
{
- \use:n { \if_catcode:w } ~ \exp_not:N \g_primargs_token
+ \if_catcode:w \c_space_token \exp_not:N \g_primargs_token
\exp_after:wN \primargs_remove_token:N
\fi:
\group_end:
@@ -83,15 +92,15 @@
\cs_new_protected:Npn \primargs_remove_optional_spaces:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #1
\__primargs_remove_optional_spaces:
}
-\cs_new_protected_nopar:Npn \__primargs_remove_optional_spaces:
- { \primargs_read_x_token:N \__primargs_remove_optional_spaces_ii: }
-\exp_args:NNo \cs_new_protected_nopar:Npn \__primargs_remove_optional_spaces_ii:
+\cs_new_protected:Npn \__primargs_remove_optional_spaces:
+ { \primargs_read_x_token:N \__primargs_remove_optional_spaces_aux: }
+\cs_new_protected:Npn \__primargs_remove_optional_spaces_aux:
{
- \use:n { \if_catcode:w } ~ \exp_not:N \g_primargs_token
+ \if_catcode:w \c_space_token \exp_not:N \g_primargs_token
\exp_after:wN \primargs_remove_token:N
\exp_after:wN \__primargs_remove_optional_spaces:
\else:
@@ -104,19 +113,45 @@
\tex_aftergroup:D #1
\primargs_remove_optional_spaces:N \__primargs_remove_equals:
}
-\cs_new_protected_nopar:Npn \__primargs_remove_equals:
+\cs_new_protected:Npn \__primargs_remove_equals:
{
\if_meaning:w = \g_primargs_token
- \exp_after:wN \__primargs_remove_equals_ii:NN
+ \exp_after:wN \__primargs_remove_equals_aux:NN
\fi:
\group_end:
}
-\cs_new_protected:Npn \__primargs_remove_equals_ii:NN #1#2
+\cs_new_protected:Npn \__primargs_remove_equals_aux:NN #1#2
{ \tl_if_eq:nnTF { #2 } { = } { #1 } { #1 #2 } }
+\cs_new_protected:Npn \primargs_remove_filler:N #1
+ {
+ \group_begin:
+ \__primargs_safe:
+ \tex_aftergroup:D #1
+ \__primargs_remove_filler:
+ }
+\cs_new_protected:Npn \__primargs_remove_filler:
+ { \primargs_read_x_token:N \__primargs_remove_filler_aux: }
+\cs_new_protected:Npn \__primargs_remove_filler_aux:
+ {
+ \if_catcode:w \c_space_token \exp_not:N \g_primargs_token
+ \else:
+ \if_meaning:w \tex_relax:D \g_primargs_token
+ \else:
+ \exp_after:wN
+ \if_meaning:w \exp_not:N \prg_do_nothing: \g_primargs_token
+ \else:
+ \__primargs_remove_filler_end:NNNNN
+ \fi:
+ \fi:
+ \fi:
+ \primargs_remove_token:N \__primargs_remove_filler:
+ }
+\cs_new_protected:Npn \__primargs_remove_filler_end:NNNNN #1#2#3#4#5
+ { #1 #2 #3 \group_end: }
\cs_new_protected:Npn \__primargs_get_rhs:NnN #1#2#3
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #3
\tl_gset:Nn \g__primargs_code_tl
{
@@ -130,58 +165,103 @@
#1 =
}
\cs_generate_variant:Nn \__primargs_get_rhs:NnN { No }
-\cs_new_protected_nopar:Npn \primargs_get_number:N
+\cs_new_protected:Npn \primargs_get_number:N
{
\__primargs_get_rhs:NoN \tex_deadcycles:D
{ \tex_the:D \tex_deadcycles:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_dimen:N
+\cs_new_protected:Npn \primargs_get_dimen:N
{
\__primargs_get_rhs:NoN \tex_hoffset:D
{ \tex_the:D \tex_hoffset:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_glue:N
+\cs_new_protected:Npn \primargs_get_glue:N
{
\__primargs_get_rhs:NoN \tex_topskip:D
{ \tex_the:D \tex_topskip:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_mudimen:N
+\cs_new_protected:Npn \primargs_get_mudimen:N
{
\msg_warning:nn { primargs } { get-mudimen }
\primargs_get_muglue:N
}
\msg_new:nnn { primargs } { get-mudimen }
{ The~\iow_char:N\\primargs_get_mudimen:N~function~is~buggy. }
-\cs_new_protected_nopar:Npn \primargs_get_muglue:N
+\cs_new_protected:Npn \primargs_get_muglue:N
{
\__primargs_get_rhs:NoN \tex_thinmuskip:D
{ \tex_the:D \tex_thinmuskip:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_general_text:N
- { \__primargs_get_rhs:NoN \tex_errhelp:D { { } } }
-\tl_new:N \g__primargs_file_name_tl
+\cs_new_protected:Npn \primargs_get_general_text:N #1
+ {
+ \group_begin:
+ \__primargs_safe:
+ \tex_aftergroup:D #1
+ \tex_aftergroup:D { \if_false: } \fi:
+ \primargs_remove_filler:N \__primargs_get_general_text:
+ }
+\cs_new_protected:Npn \__primargs_get_general_text:
+ {
+ \if_catcode:w \c_group_begin_token \g_primargs_token
+ \exp_after:wN \primargs_remove_token:N
+ \else:
+ \group_begin:
+ \tex_aftergroup:D \__primargs_get_general_text_error:n
+ \if_catcode:w \c_group_end_token \g_primargs_token
+ \tex_aftergroup:D {
+ \tex_aftergroup:D }
+ \fi:
+ \fi:
+ \group_end:
+ }
+\cs_new_protected:Npn \__primargs_get_general_text_error:n #1
+ {
+ \exp_after:wN \group_end:
+ \etex_unexpanded:D \if_int_compare:w `{ = \c_zero \fi: #1 }
+ }
\cs_new_protected:Npn \primargs_get_file_name:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
+ \cs_gset_eq:NN \__primargs_read_x_token_aux:N
+ \__primargs_read_x_token_file:N
\tex_aftergroup:D #1
\tl_gclear:N \g__primargs_file_name_tl
+ \tl_gset:Nn \g__primargs_file_name_level_tl { 0 }
\primargs_remove_optional_spaces:N \__primargs_get_file_name_test:
}
-\cs_new_protected_nopar:Npn \__primargs_get_file_name_test:
+\cs_new_protected:Npn \__primargs_get_file_name_test:
{
\token_if_cs:NTF \g_primargs_token
{ \__primargs_get_file_name_end: }
{
\token_if_eq_charcode:NNTF \c_space_token \g_primargs_token
- { \primargs_remove_token:N \__primargs_get_file_name_end: }
+ { \primargs_remove_token:N \__primargs_get_file_name_space: }
{ \primargs_remove_token:N \__primargs_get_file_name_char: }
}
}
-\cs_new_protected_nopar:Npn \__primargs_get_file_name_end:
- { \exp_args:No \group_end: \g__primargs_file_name_tl }
-\cs_new_protected_nopar:Npn \__primargs_get_file_name_char:
+\cs_new_protected:Npn \__primargs_get_file_name_end:
+ {
+ \cs_gset_eq:NN \__primargs_read_x_token_aux:N
+ \__primargs_read_x_token_std:N
+ \exp_args:No \group_end: \g__primargs_file_name_tl
+ }
+\cs_new_protected:Npn \__primargs_get_file_name_space:
+ {
+ \int_if_odd:nTF { \g__primargs_file_name_level_tl }
+ {
+ \tl_gput_right:Nn \g__primargs_file_name_tl { ~ }
+ \primargs_read_x_token:N \__primargs_get_file_name_test:
+ }
+ { \__primargs_get_file_name_end: }
+ }
+\cs_new_protected:Npn \__primargs_get_file_name_char:
{
+ \token_if_eq_charcode:NNT " \g_primargs_token
+ {
+ \tl_set:Nx \g__primargs_file_name_level_tl
+ { \int_eval:n { 1 - \g__primargs_file_name_level_tl } }
+ }
\tl_gput_right:Nx \g__primargs_file_name_tl
{
\exp_after:wN \__primargs_get_file_name_char_ii:w
@@ -193,6 +273,76 @@
\cs_new:Npn \__primargs_get_file_name_char_ii:w #1 ~ #2 ~ #3 \q_stop
{ \__primargs_get_file_name_char_iii:w #3 ~ #3 ~ \q_stop }
\cs_new:Npn \__primargs_get_file_name_char_iii:w #1 ~ #2 ~ #3 \q_stop {#2}
+\sys_if_engine_luatex:TF
+ {
+ \cs_new_protected:Npn \primargs_get_input_file_name:N #1
+ {
+ \group_begin:
+ \__primargs_safe:
+ \tex_aftergroup:D #1
+ \tl_gclear:N \g__primargs_file_name_tl
+ \tl_gset:Nn \g__primargs_file_name_level_tl { 1 }
+ \primargs_remove_filler:N \__primargs_get_input_file_name_first:
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_first:
+ {
+ \token_if_eq_catcode:NNTF \g_primargs_token \c_group_begin_token
+ { \primargs_remove_token:N \__primargs_get_input_file_name_loop: }
+ { \primargs_get_file_name:N \group_end: }
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_loop:
+ { \primargs_read_x_token:N \__primargs_get_input_file_name_test: }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_test:
+ {
+ \token_if_eq_catcode:NNTF \g_primargs_token \c_group_begin_token
+ {
+ \tl_gset:Nx \g__primargs_file_name_level_tl
+ { \int_eval:n { \g__primargs_file_name_level_tl + 1 } }
+ \primargs_remove_token:N \__primargs_get_input_file_name_brace:
+ }
+ {
+ \token_if_eq_catcode:NNTF \g_primargs_token \c_group_end_token
+ {
+ \tl_gset:Nx \g__primargs_file_name_level_tl
+ { \int_eval:n { \g__primargs_file_name_level_tl - 1 } }
+ \int_compare:nNnTF { \g__primargs_file_name_level_tl } > 0
+ { \primargs_remove_token:N \__primargs_get_input_file_name_brace: }
+ { \primargs_remove_token:N \__primargs_get_file_name_end: }
+ }
+ {
+ \token_if_eq_meaning:NNTF \g_primargs_token \c_space_token
+ {
+ \tl_gput_right:Nn \g__primargs_file_name_tl { ~ }
+ \primargs_remove_token:N \__primargs_get_input_file_name_loop:
+ }
+ { \exp_after:wN \__primargs_get_input_file_name_aux:N \exp_not:N }
+ }
+ }
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_brace:
+ {
+ \tl_gput_right:Nx \g__primargs_file_name_tl
+ {
+ \exp_after:wN \__primargs_get_file_name_char_ii:w
+ \token_to_meaning:N \g_primargs_token
+ \q_stop
+ }
+ \__primargs_get_input_file_name_loop:
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_aux:N #1
+ {
+ \exp_after:wN \str_if_eq_x:nnT
+ \exp_after:wN { \token_to_str:N #1 } { \token_to_str:N \par }
+ { \use_none:nnn }
+ \tex_xdef:D \g__primargs_file_name_tl
+ {
+ \g__primargs_file_name_tl
+ \exp_after:wN \tl_to_str:n \exp_after:wN { \exp_not:N #1 }
+ }
+ \__primargs_get_input_file_name_loop:
+ }
+ }
+ { \cs_new_eq:NN \primargs_get_input_file_name:N \primargs_get_file_name:N }
%%
%%
%% End of file `primargs.sty'.