%%
%% This is file `primargs.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% primargs.dtx  (with options: `package')
%% 
%% Communicate any suggestions for changing this package
%% to Bruno Le Floch (blflatex@gmail.com).
%% 
%% 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
%% 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
%%
%% -----------------------------------------------------------------------
\RequirePackage {expl3} [2017/03/18]
\ProvidesExplPackage
  {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:
  {
    \tex_afterassignment:D \tex_relax:D
    \if_int_compare:w 0 > \tex_globaldefs:D
      \int_zero:N \tex_globaldefs:D
    \fi:
  }
\cs_new_protected:Npn \primargs_read_x_token:N
  {
    \group_begin:
      \__primargs_safe:
      \__primargs_read_x_token:N
  }
\cs_new_protected:Npn \__primargs_read_x_token:N
  {
    \tex_afterassignment:D \__primargs_read_x_token_aux:N
    \tex_global:D \tex_futurelet:D \g_primargs_token
  }
\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: \use_i:nnnn
    \fi:
    \exp_after:wN \__primargs_read_x_token:N \exp_after:wN
  }
\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_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_safe:
      \tex_aftergroup:D #1
      \tex_afterassignment:D \group_end:
      \tex_global:D \tex_let:D \g_primargs_token = ~
  }
\cs_new_protected:Npn \primargs_remove_one_optional_space:N #1
  {
    \group_begin:
      \__primargs_safe:
      \tex_aftergroup:D #1
      \primargs_read_x_token:N \__primargs_remove_one_optional_space:
  }
\cs_new_protected:Npn \__primargs_remove_one_optional_space:
  {
    \if_catcode:w \c_space_token \exp_not:N \g_primargs_token
      \exp_after:wN \primargs_remove_token:N
    \fi:
    \group_end:
  }
\cs_new_protected:Npn \primargs_remove_optional_spaces:N #1
  {
    \group_begin:
      \__primargs_safe:
      \tex_aftergroup:D #1
      \__primargs_remove_optional_spaces:
  }
\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:
  {
    \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:
      \exp_after:wN \group_end:
    \fi:
  }
\cs_new_protected:Npn \primargs_remove_equals:N #1
  {
    \group_begin:
      \tex_aftergroup:D #1
      \primargs_remove_optional_spaces:N \__primargs_remove_equals:
  }
\cs_new_protected:Npn \__primargs_remove_equals:
  {
      \if_meaning:w = \g_primargs_token
        \exp_after:wN \__primargs_remove_equals_aux:NN
      \fi:
    \group_end:
  }
\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_safe:
      \tex_aftergroup:D #3
      \tl_gset:Nn \g__primargs_code_tl
        {
          \use:x
            {
              \exp_not:n { #1 = #2 \group_end: }
              { \tex_the:D #1 }
            }
        }
      \tex_afterassignment:D \g__primargs_code_tl
      #1 =
  }
\cs_generate_variant:Nn \__primargs_get_rhs:NnN { No }
\cs_new_protected:Npn \primargs_get_number:N
  {
    \__primargs_get_rhs:NoN \tex_deadcycles:D
      { \tex_the:D \tex_deadcycles:D }
  }
\cs_new_protected:Npn \primargs_get_dimen:N
  {
    \__primargs_get_rhs:NoN \tex_hoffset:D
      { \tex_the:D \tex_hoffset:D }
  }
\cs_new_protected:Npn \primargs_get_glue:N
  {
    \__primargs_get_rhs:NoN \tex_topskip:D
      { \tex_the:D \tex_topskip:D }
  }
\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:Npn \primargs_get_muglue:N
  {
    \__primargs_get_rhs:NoN \tex_thinmuskip:D
      { \tex_the:D \tex_thinmuskip:D }
  }
\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_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: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_space: }
          { \primargs_remove_token:N \__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
        \token_to_meaning:N \g_primargs_token
        \q_stop
      }
    \primargs_read_x_token:N \__primargs_get_file_name_test:
  }
\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'.
