diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/xint/xintexpr.sty')
-rw-r--r-- | Master/texmf-dist/tex/generic/xint/xintexpr.sty | 197 |
1 files changed, 102 insertions, 95 deletions
diff --git a/Master/texmf-dist/tex/generic/xint/xintexpr.sty b/Master/texmf-dist/tex/generic/xint/xintexpr.sty index e65c9ecae28..5c2f726146b 100644 --- a/Master/texmf-dist/tex/generic/xint/xintexpr.sty +++ b/Master/texmf-dist/tex/generic/xint/xintexpr.sty @@ -21,7 +21,7 @@ %% same distribution. (The sources need not necessarily be %% in the same archive or directory.) %% --------------------------------------------------------------- -%% The xint bundle v1.2d 2015/11/18 +%% The xint bundle v1.2e 2015/11/22 %% Copyright (C) 2013-2015 by Jean-Francois Burnol %% xintexpr: Expandable expression parser %% --------------------------------------------------------------- @@ -81,7 +81,7 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintexpr}% - [2015/11/18 v1.2d Expandable expression parser (jfB)]% + [2015/11/22 v1.2e Expandable expression parser (jfB)]% \catcode`! 11 \def\xint_gob_til_! #1!{}% catcode 11 ! default in xintexpr.sty code. \edef\XINT_expr_lockscan#1!% not used for decimal numbers in xintexpr 1.2 @@ -509,10 +509,11 @@ }% \def\XINT_expr_scanfunc_b #1% {% + \ifx !#1\xint_dothis{(_}\fi \ifcat \relax#1\xint_dothis{(_}\fi \if (#1\xint_dothis{\xint_firstoftwo{(`}}\fi - \if _#1\xint_dothis \XINT_expr_scanfunc_a \fi \if @#1\xint_dothis \XINT_expr_scanfunc_a \fi + \if _#1\xint_dothis \XINT_expr_scanfunc_a \fi \ifnum \xint_c_ix<1\string#1 \xint_dothis \XINT_expr_scanfunc_a \fi \ifcat a#1\xint_dothis \XINT_expr_scanfunc_a \fi \xint_orthat {(_}% @@ -1261,6 +1262,43 @@ {\xint_zapspaces #2 \xint_gobble_i}\endcsname}% \catcode`[ 12 \catcode`* 12 +\def\XINT_tmpa #1#2#3{% + \def #1##1% + {% + \ifcsname XINT_#3_func_##1\endcsname + \xint_dothis{\expandafter\expandafter + \csname XINT_#3_func_##1\endcsname\romannumeral`&&@#2}\fi + \ifcsname XINT_expr_onlitteral_##1\endcsname + \xint_dothis{\csname XINT_expr_onlitteral_##1\endcsname}\fi + \xint_orthat{\XINT_expr_unknown_function {##1}% + \expandafter\XINT_expr_func_unknown\romannumeral`&&@#2}% + }% +}% +\def\XINT_expr_unknown_function #1{\xintError:removed \xint_gobble_i {#1}}% +\xintFor #1 in {expr,flexpr,iiexpr} \do {% + \expandafter\XINT_tmpa + \csname XINT_#1_op_`\expandafter\endcsname + \csname XINT_#1_oparen\endcsname + {#1}% +}% +\def\XINT_expr_func_unknown #1#2#3% + {\expandafter #1\expandafter #2\csname .=0\endcsname }% +\def\XINT_expr_onlitteral_bool #1)% + {\expandafter\XINT_expr_getop\csname .=\xintBool{#1}\endcsname }% +\def\XINT_expr_onlitteral_togl #1)% + {\expandafter\XINT_expr_getop\csname .=\xintToggle{#1}\endcsname }% +\def\XINT_expr_onlitteral_protect #1)% + {\expandafter\XINT_expr_getop\csname .=\detokenize{#1}\endcsname }% +\def\XINT_expr_func_break #1#2#3% + {\expandafter #1\expandafter #2\csname.=?\romannumeral`&&@\XINT_expr_unlock #3\endcsname }% +\let\XINT_flexpr_func_break \XINT_expr_func_break +\let\XINT_iiexpr_func_break \XINT_expr_func_break +\def\XINT_expr_onlitteral_qint #1)% + {\expandafter\XINT_expr_getop\csname .=\xintiNum{#1}\endcsname }% +\def\XINT_expr_onlitteral_qfrac #1)% + {\expandafter\XINT_expr_getop\csname .=\xintRaw{#1}\endcsname }% +\def\XINT_expr_onlitteral_qfloat #1)% + {\expandafter\XINT_expr_getop\csname .=\XINTinFloatdigits{#1}\endcsname }% \def\XINT_expr_op__ #1% op__ with two _'s {% \ifcsname XINT_expr_var_#1\endcsname @@ -1276,82 +1314,89 @@ \def\XINT_expr_unknown_variable #1{\xintError:removed \xint_gobble_i {#1}}% \let\XINT_flexpr_op__ \XINT_expr_op__ \let\XINT_iiexpr_op__ \XINT_expr_op__ -\catcode`: 12 -\def\xintdefvar #1:=#2;{% - \edef\XINT_expr_tmpa{#1}% - \edef\XINT_expr_tmpa - {\expandafter\xint_zapspaces\detokenize\expandafter{\XINT_expr_tmpa} \xint_gobble_i}% - \edef\XINT_expr_tmpb {\romannumeral0\xintbareeval #2\relax }% - \ifxintverbose\xintMessage {info}{xintexpr} - {Variable \XINT_expr_tmpa\space defined with value - \expandafter\XINT_expr_unlock\XINT_expr_tmpb.}% - \fi - \expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname +\catcode`* 11 +\def\XINT_expr_defvar #1#2#3;{% + \edef\XINT_expr_tmpa{#2}% + \edef\XINT_expr_tmpa {\xint_zapspaces_o\XINT_expr_tmpa}% + \ifnum\expandafter\xintLength\expandafter{\XINT_expr_tmpa}=\z@ + \xintMessage {xintexpr}{Warning} + {Error: impossible to declare variable with empty name.}% + \else + \edef\XINT_expr_tmpb {\romannumeral0#1#3\relax }% + \expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname {\expandafter\noexpand\XINT_expr_tmpb}% - \expandafter\edef\csname XINT_expr_onlitteral_\XINT_expr_tmpa\endcsname - {\noexpand\XINT_expr_getop\expandafter\noexpand\XINT_expr_tmpb *(}% -}% -\def\xintdefiivar #1:=#2;{% - \edef\XINT_expr_tmpa{#1}% - \edef\XINT_expr_tmpa - {\expandafter\xint_zapspaces\detokenize\expandafter{\XINT_expr_tmpa} \xint_gobble_i}% - \edef\XINT_expr_tmpb {\romannumeral0\xintbareiieval #2\relax }% - \ifxintverbose\xintMessage {info}{xintexpr} - {Variable \XINT_expr_tmpa\space defined with value + \expandafter\edef\csname XINT_expr_onlitteral_\XINT_expr_tmpa\endcsname + {\XINT_expr_precedence_*** *\expandafter\noexpand\XINT_expr_tmpb (}% + \ifxintverbose\xintMessage {xintexpr}{Info} + {Variable "\XINT_expr_tmpa" defined with value \expandafter\XINT_expr_unlock\XINT_expr_tmpb.}% + \fi \fi - \expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname - {\expandafter\noexpand\XINT_expr_tmpb}% - \expandafter\edef\csname XINT_expr_onlitteral_\XINT_expr_tmpa\endcsname - {\noexpand\XINT_expr_getop\expandafter\noexpand\XINT_expr_tmpb *(}% }% -\def\xintdeffloatvar #1:=#2;{% +\catcode`* 12 +\catcode`: 12 +\def\xintdefvar #1:={\XINT_expr_defvar\xintbareeval {#1}}% +\def\xintdefiivar #1:={\XINT_expr_defvar\xintbareiieval {#1}}% +\def\xintdeffloatvar #1:={\XINT_expr_defvar\xintbarefloateval {#1}}% +\catcode`: 11 +\def\xintunassignvar #1{% \edef\XINT_expr_tmpa{#1}% - \edef\XINT_expr_tmpa - {\expandafter\xint_zapspaces\detokenize\expandafter{\XINT_expr_tmpa} - \xint_gobble_i}% - \edef\XINT_expr_tmpb {\romannumeral0\xintbarefloateval #2\relax }% - \ifxintverbose\xintMessage {info}{xintexpr} - {Variable \XINT_expr_tmpa\space defined with value - \expandafter\XINT_expr_unlock\XINT_expr_tmpb.}% + \edef\XINT_expr_tmpa {\xint_zapspaces_o\XINT_expr_tmpa}% + \ifcsname XINT_expr_var_\XINT_expr_tmpa\endcsname + \ifnum\expandafter\xintLength\expandafter{\XINT_expr_tmpa}=\@ne + \expandafter\XINT_expr_makedummy \XINT_expr_tmpa + \ifxintverbose\xintMessage {xintexpr}{Info} + {Character \XINT_expr_tmpa\space usable as dummy variable (if letter).}% + \fi + \else + \expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname + {\csname .=0\endcsname\noexpand\XINT_expr_undefined {\XINT_expr_tmpa}}% + \expandafter\edef\csname XINT_expr_onlitteral_\XINT_expr_tmpa\endcsname + {\csname .=0\endcsname\noexpand\XINT_expr_undefined {\XINT_expr_tmpa}*}% + \ifxintverbose\xintMessage {xintexpr}{Info} + {Variable \XINT_expr_tmpa\space has been ``unassigned''.}% + \fi + \fi + \else + \xintMessage {xintexpr}{Warning} + {Error: there was no such variable \XINT_expr_tmpa\space to unassign.}% \fi - \expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname - {\expandafter\noexpand\XINT_expr_tmpb}% - \expandafter\edef\csname XINT_expr_onlitteral_\XINT_expr_tmpa\endcsname - {\noexpand\XINT_expr_getop\expandafter\noexpand\XINT_expr_tmpb *(}% }% -\catcode`: 11 -\def\XINT_tmpa #1% +\def\XINT_expr_undefined #1{\xintError:replaced_by_zero\xint_gobble_i {#1}}% +\catcode`* 11 +\def\XINT_expr_makedummy #1% {% \expandafter\def\csname XINT_expr_var_#1\endcsname ##1\relax !#1##2% {##2##1\relax !#1##2}% \expandafter\def\csname XINT_expr_onlitteral_#1\endcsname ##1\relax !#1##2% - {\XINT_expr_getop ##2*(##1\relax !#1##2}% + {\XINT_expr_precedence_*** *##2(##1\relax !#1##2}% }% -\xintApplyUnbraced \XINT_tmpa {abcdefghijklmnopqrstuvwxyz}% -\xintApplyUnbraced \XINT_tmpa {ABCDEFGHIJKLMNOPQRSTUVWXYZ}% +\xintApplyUnbraced \XINT_expr_makedummy {abcdefghijklmnopqrstuvwxyz}% +\xintApplyUnbraced \XINT_expr_makedummy {ABCDEFGHIJKLMNOPQRSTUVWXYZ}% \edef\XINT_expr_var_nil {\expandafter\noexpand\csname .= \endcsname}% \edef\XINT_expr_onlitteral_nil - {\noexpand\XINT_expr_getop\expandafter\noexpand\csname .= \endcsname *(}% + {\XINT_expr_precedence_*** *\expandafter\noexpand\csname .= \endcsname (}% +\catcode`* 12 \edef\XINT_expr_var_omit #1\relax !{1\string !?!\relax !}% \edef\XINT_expr_var_abort #1\relax !{1\string !?^\relax !}% \def\XINT_expr_op_!? #1#2\relax {\expandafter\XINT_expr_foundend\csname .=#2\endcsname}% \let\XINT_iiexpr_op_!? \XINT_expr_op_!? \let\XINT_flexpr_op_!? \XINT_expr_op_!? -\catcode`? 3 +\catcode`? 3 \catcode`* 11 \def\XINT_expr_var_@ #1~#2{#2#1~#2}% \expandafter\let\csname XINT_expr_var_@1\endcsname \XINT_expr_var_@ \expandafter\def\csname XINT_expr_var_@2\endcsname #1~#2#3{#3#1~#2#3}% \expandafter\def\csname XINT_expr_var_@3\endcsname #1~#2#3#4{#4#1~#2#3#4}% \expandafter\def\csname XINT_expr_var_@4\endcsname #1~#2#3#4#5{#5#1~#2#3#4#5}% -\def\XINT_expr_onlitteral_@ #1~#2{\XINT_expr_getop #2*(#1~#2}% +\def\XINT_expr_onlitteral_@ #1~#2{\XINT_expr_precedence_*** *#2(#1~#2}% \expandafter\let\csname XINT_expr_onlitteral_@1\endcsname \XINT_expr_onlitteral_@ \expandafter\def\csname XINT_expr_onlitteral_@2\endcsname #1~#2#3% - {\XINT_expr_getop #3*(#1~#2#3}% + {\XINT_expr_precedence_*** *#3(#1~#2#3}% \expandafter\def\csname XINT_expr_onlitteral_@3\endcsname #1~#2#3#4% - {\XINT_expr_getop #4*(#1~#2#3#4}% + {\XINT_expr_precedence_*** *#4(#1~#2#3#4}% \expandafter\def\csname XINT_expr_onlitteral_@4\endcsname #1~#2#3#4#5% - {\XINT_expr_getop #5*(#1~#2#3#4#5}% + {\XINT_expr_precedence_*** *#5(#1~#2#3#4#5}% +\catcode`* 12 \def\XINT_expr_func_@@ #1#2#3#4~#5?% {% \expandafter#1\expandafter#2\romannumeral0\xintntheltnoexpand @@ -1386,43 +1431,6 @@ {\XINT_expr_unlock#3}{#7}#4~#5~#6~#7?% }% \catcode`? 11 -\def\XINT_tmpa #1#2#3{% - \def #1##1% - {% - \ifcsname XINT_#3_func_##1\endcsname - \xint_dothis{\expandafter\expandafter - \csname XINT_#3_func_##1\endcsname\romannumeral`&&@#2}\fi - \ifcsname XINT_expr_onlitteral_##1\endcsname - \xint_dothis{\csname XINT_expr_onlitteral_##1\endcsname}\fi - \xint_orthat{\XINT_expr_unknown_function {##1}% - \expandafter\XINT_expr_func_unknown\romannumeral`&&@#2}% - }% -}% -\def\XINT_expr_unknown_function #1{\xintError:removed \xint_gobble_i {#1}}% -\xintFor #1 in {expr,flexpr,iiexpr} \do {% - \expandafter\XINT_tmpa - \csname XINT_#1_op_`\expandafter\endcsname - \csname XINT_#1_oparen\endcsname - {#1}% -}% -\def\XINT_expr_func_unknown #1#2#3% - {\expandafter #1\expandafter #2\csname .=0\endcsname }% -\def\XINT_expr_onlitteral_bool #1)% - {\expandafter\XINT_expr_getop\csname .=\xintBool{#1}\endcsname }% -\def\XINT_expr_onlitteral_togl #1)% - {\expandafter\XINT_expr_getop\csname .=\xintToggle{#1}\endcsname }% -\def\XINT_expr_onlitteral_protect #1)% - {\expandafter\XINT_expr_getop\csname .=\detokenize{#1}\endcsname }% -\def\XINT_expr_func_break #1#2#3% - {\expandafter #1\expandafter #2\csname.=?\romannumeral`&&@\XINT_expr_unlock #3\endcsname }% -\let\XINT_flexpr_func_break \XINT_expr_func_break -\let\XINT_iiexpr_func_break \XINT_expr_func_break -\def\XINT_expr_onlitteral_qint #1)% - {\expandafter\XINT_expr_getop\csname .=\xintiNum{#1}\endcsname }% -\def\XINT_expr_onlitteral_qfrac #1)% - {\expandafter\XINT_expr_getop\csname .=\xintRaw{#1}\endcsname }% -\def\XINT_expr_onlitteral_qfloat #1)% - {\expandafter\XINT_expr_getop\csname .=\XINTinFloatdigits{#1}\endcsname }% \def\XINT_expr_onlitteral_seq {\expandafter\XINT_expr_onlitteral_seq_f\romannumeral`&&@\XINT_expr_onlitteral_seq_a {}}% \def\XINT_expr_onlitteral_seq_f #1#2{\xint_c_xviii `{seqx}#2)\relax #1}% @@ -2183,12 +2191,11 @@ \catcode`: 12 \def\XINT_tmpa #1#2#3#4% {% - \def #1##1(##2):=##3;{% - \edef\XINT_expr_tmpa{##1}% - \edef\XINT_expr_tmpa - {\expandafter\xint_zapspaces\detokenize\expandafter{\XINT_expr_tmpa} \xint_gobble_i}% + \def #1##1(##2)##3=##4;{% + \edef\XINT_expr_tmpa {##1}% + \edef\XINT_expr_tmpa {\xint_zapspaces_o \XINT_expr_tmpa}% \def\XINT_expr_tmpb {0}% - \def\XINT_expr_tmpc {##3}% + \def\XINT_expr_tmpc {##4}% \xintFor ####1 in {##2} \do {\edef\XINT_expr_tmpb {\the\numexpr\XINT_expr_tmpb+\xint_c_i}% \edef\XINT_expr_tmpc {subs(\unexpanded\expandafter{\XINT_expr_tmpc},% @@ -2199,7 +2206,7 @@ \expandafter\XINT_expr_defuserfunc \csname XINT_#2_func_\XINT_expr_tmpa\expandafter\endcsname \csname XINT_#2_userfunc_\XINT_expr_tmpa\endcsname - \ifxintverbose\xintMessage {info}{xintexpr} + \ifxintverbose\xintMessage {xintexpr}{Info} {Function \XINT_expr_tmpa\space for \string\xint #4 parser associated to \string\XINT_#2_userfunc_\XINT_expr_tmpa\space with meaning \expandafter\meaning @@ -2430,7 +2437,7 @@ {\scantokens\expandafter{\expandafter\XINT_newexpr_clean\meaning\XINT_tmpb}}@ \the\toks0\expandafter{\XINT_tmpa{%%1}{%%2}{%%3}{%%4}{%%5}{%%6}{%%7}{%%8}{%%9}}@ %1{\ifxintverbose - \xintMessage{info}{xintexpr}@ + \xintMessage{xintexpr}{Info}@ {\string%3\space now with meaning \meaning%3}@ \fi}@ }@ |