summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/xint/xintexpr.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-06-17 21:04:37 +0000
committerKarl Berry <karl@freefriends.org>2018-06-17 21:04:37 +0000
commita8356ff391b052c2df9c0e5094ad28bdc4ecc8cc (patch)
tree1d140eab26e9ec64694d88221900f07b275083c2 /Master/texmf-dist/tex/generic/xint/xintexpr.sty
parentfcd631537e8237c8d259af82841ded8d3a8b51b7 (diff)
xint (17jun18)
git-svn-id: svn://tug.org/texlive/trunk@48040 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/xint/xintexpr.sty')
-rw-r--r--Master/texmf-dist/tex/generic/xint/xintexpr.sty115
1 files changed, 71 insertions, 44 deletions
diff --git a/Master/texmf-dist/tex/generic/xint/xintexpr.sty b/Master/texmf-dist/tex/generic/xint/xintexpr.sty
index 05a7bad4a86..72a614e2692 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 1.3b 2018/05/18
+%% The xint bundle 1.3c 2018/06/17
%% Copyright (C) 2013-2018 by Jean-Francois Burnol
%% xintexpr: Expandable expression parser
%% ---------------------------------------------------------------
@@ -81,7 +81,7 @@
\XINTsetupcatcodes%
\XINT_providespackage
\ProvidesPackage{xintexpr}%
- [2018/05/18 1.3b Expandable expression parser (JFB)]%
+ [2018/06/17 1.3c Expandable expression parser (JFB)]%
\catcode`! 11
\let\XINT_Cmp \xintiiCmp
\def\xint_gob_til_! #1!{}% ! with catcode 11
@@ -190,9 +190,7 @@
\expandafter\xintPFloat::csv
\romannumeral`&&@\expandafter\XINT_expr_unlock_sp\string #1!%
}%
-\catcode`: 12
- \def\XINT_expr_unlock_sp #1.;#2.=#3!{{#2}{#3}}%
-\catcode`: 11
+\def\XINT_expr_unlock_sp #1.;#2.=#3!{{#2}{#3}}%
\def\xintboolexpr {\romannumeral0\expandafter\expandafter\expandafter
\XINT_boolexpr_done \expandafter\xint_gobble_iv\romannumeral0\xinteval }%
\def\xinttheboolexpr {\romannumeral`&&@\expandafter\expandafter\expandafter
@@ -1387,7 +1385,6 @@
\def\XINT_iiexpr_op_! #1{\expandafter\XINT_expr_getop
\csname .=\XINT:NEhook:one\xintiiFac{\XINT_expr_unlock #1}\endcsname }%
\catcode`[ 11
-\catcode`* 11
\let\XINT_expr_precedence_[ \xint_c_vii
\def\XINT_expr_op_[ #1#2]{\expandafter\XINT_expr_getop
\csname .=\xintE{\XINT_expr_unlock #1}%
@@ -1399,7 +1396,6 @@
\csname .=\XINTinFloatE{\XINT_expr_unlock #1}%
{\xint_zapspaces #2 \xint_gobble_i}\endcsname}%
\catcode`[ 12
-\catcode`* 12
\def\XINT_tmpa #1#2#3{%
\def #1##1%
{%
@@ -1437,6 +1433,8 @@
{\expandafter\XINT_expr_getop\csname .=\xintRaw{#1}\endcsname }%
\def\XINT_expr_onliteral_qfloat #1)%
{\expandafter\XINT_expr_getop\csname .=\XINTinFloatdigits{#1}\endcsname }%
+\def\XINT_expr_onliteral_qraw #1)%
+ {\expandafter\XINT_expr_getop\csname .=#1\endcsname }%
\def\XINT_expr_onliteral_random #1)%
{\expandafter\XINT_expr_getop\csname .=\XINTinRandomFloatSdigits\endcsname }%
\def\XINT_expr_onliteral_qrand #1)%
@@ -1459,20 +1457,30 @@
\catcode`* 11
\def\XINT_expr_defvar_one #1#2%
{%
+ \XINT_global
\expandafter\edef\csname XINT_expr_var_#1\endcsname
{\expandafter\noexpand#2}%
+ \XINT_global
\expandafter\edef\csname XINT_expr_onliteral_#1\endcsname
{\XINT_expr_precedence_*** *\expandafter\noexpand#2(}%
\ifxintverbose\xintMessage{xintexpr}{Info}
- {Variable "#1" defined with value \expandafter\XINT_expr_unlock#2.}%
+ {Variable "#1" \ifxintglobaldefs globally \fi
+ defined with value \expandafter\XINT_expr_unlock#2.}%
\fi
}%
\catcode`* 12
+\catcode`~\active
+\catcode`: 12
+\def\XINT_expr_defvar_getname #1:#2~{\endgroup
+ \def\XINT_expr_tmpa{#1}\edef\XINT_expr_tmpc{\xintCSVLength{#1}}}%
\def\XINT_expr_defvar #1#2#3;%
{%
+ \xintexprRestoreCatcodes
+ \begingroup\lccode`~`: \lowercase{\let~}\empty
\edef\XINT_expr_tmpa{#2}%
\edef\XINT_expr_tmpa{\xint_zapspaces_o\XINT_expr_tmpa}%
- \edef\XINT_expr_tmpc{\xintCSVLength{\XINT_expr_tmpa}}%
+ \expandafter\XINT_expr_defvar_getname
+ \detokenize\expandafter{\XINT_expr_tmpa}:~%
\ifcase\XINT_expr_tmpc
\xintMessage {xintexpr}{Warning}
{Aborting: impossible to declare variable with empty name.}%
@@ -1505,27 +1513,30 @@
\fi
\fi
}%
-\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`~ 3
\catcode`: 11
+\def\xintdefvar {\xintexprSafeCatcodes\xintdefvar_a}%
+\def\xintdefiivar {\xintexprSafeCatcodes\xintdefiivar_a}%
+\def\xintdeffloatvar {\xintexprSafeCatcodes\xintdeffloatvar_a}%
+\def\xintdefvar_a #1={\XINT_expr_defvar\xintbareeval {#1}}%
+\def\xintdefiivar_a #1={\XINT_expr_defvar\xintbareiieval {#1}}%
+\def\xintdeffloatvar_a #1={\XINT_expr_defvar\xintbarefloateval {#1}}%
\def\xintunassignvar #1{%
\edef\XINT_expr_tmpa{#1}%
\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 with catcode letter).}%
- \fi
+ \expandafter\xintnewdummy\XINT_expr_tmpa
\else
+ \XINT_global
\expandafter\edef\csname XINT_expr_var_\XINT_expr_tmpa\endcsname
{\csname .=0\endcsname\noexpand\XINT_expr_undefined {\XINT_expr_tmpa}}%
+ \XINT_global
\expandafter\edef\csname XINT_expr_onliteral_\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''.}%
+ {Variable \XINT_expr_tmpa\space has been
+ \ifxintglobaldefs globally \fi ``unassigned''.}%
\fi
\fi
\else
@@ -1537,8 +1548,10 @@
\catcode`* 11
\def\XINT_expr_makedummy #1%
{%
+ \XINT_global
\expandafter\def\csname XINT_expr_var_#1\endcsname ##1\relax !#1##2%
{##2##1\relax !#1##2}%
+ \XINT_global
\expandafter\def\csname XINT_expr_onliteral_#1\endcsname ##1\relax !#1##2%
{\XINT_expr_precedence_*** *##2(##1\relax !#1##2}%
}%
@@ -1547,7 +1560,8 @@
\def\xintnewdummy #1{%
\XINT_expr_makedummy{#1}%
\ifxintverbose\xintMessage {xintexpr}{Info}%
- {Character #1 now usable as dummy variable (if with catcode letter).}%
+ {#1 (with letter catcode) now
+ \ifxintglobaldefs globally \fi usable as dummy variable.}%
\fi
}%
\edef\XINT_expr_var_nil {\expandafter\noexpand\csname .= \endcsname}%
@@ -2165,7 +2179,7 @@
\expandafter #1\expandafter #2\csname.=%
\XINT:NEhook:one\xintSqr{\XINT_expr_unlock #3}\endcsname
}%
-\def\XINTinFloatSqr#1{\XINTinFloatMul{#1}{#1}}% revoir après
+\def\XINTinFloatSqr#1{\XINTinFloatMul{#1}{#1}}% revoir apr^^c3^^a8s
\def\XINT_flexpr_func_sqr #1#2#3%
{%
\expandafter #1\expandafter #2\csname.=%
@@ -2711,8 +2725,6 @@
\xintifCmp {#1}{#2}%
\XINT_seqb:f:csv_nc\XINT_seqb:f:csv_nb\XINT_flseqb:f:csv_na {#1}{#2}%
}%
-\catcode`: 12
-\catcode`~ 12
\def\XINT_tmpa #1#2#3#4%
{%
\def #1##1(##2)##3=##4;{%
@@ -2733,17 +2745,21 @@
\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
+ with \ifxintglobaldefs global \fi meaning \expandafter\meaning
\csname XINT_#2_userfunc_\XINT_expr_tmpa\endcsname}%
\fi
+ \xintexprRestoreCatcodes
}%
}%
-\catcode`: 11
-\XINT_tmpa\xintdeffunc {expr} \XINT_NewFunc {expr}%
-\XINT_tmpa\xintdefiifunc {iiexpr}\XINT_NewIIFunc {iiexpr}%
-\XINT_tmpa\xintdeffloatfunc{flexpr}\XINT_NewFloatFunc{floatexpr}%
+\def\xintdeffunc {\xintexprSafeCatcodes\xintdeffunc_a}%
+\def\xintdefiifunc {\xintexprSafeCatcodes\xintdefiifunc_a}%
+\def\xintdeffloatfunc {\xintexprSafeCatcodes\xintdeffloatfunc_a}%
+\XINT_tmpa\xintdeffunc_a {expr} \XINT_NewFunc {expr}%
+\XINT_tmpa\xintdefiifunc_a {iiexpr}\XINT_NewIIFunc {iiexpr}%
+\XINT_tmpa\xintdeffloatfunc_a{flexpr}\XINT_NewFloatFunc{floatexpr}%
\def\XINT_expr_defuserfunc #1#2#3%
{%
+ \XINT_global
\def #1##1##2##3{\expandafter ##1\expandafter ##2%
\csname .=\XINT:expr:userfunc{#3}{#2}{\XINT_expr_unlock ##3}\endcsname
}%
@@ -2751,8 +2767,10 @@
\def\XINT:expr:userfunc #1#2#3%
{\csname XINT_#1_userfunc_#2\expandafter\endcsname
\romannumeral0\xintcsvtolistnonstripped{#3}}%
+\catcode`~ 12
\def\XINT:newexpr:userfunc #1#2#3%
{~xintExpandArgs{XINT_#1_userfunc_#2}{\xintCSVtoListNonStripped{#3}}}%
+\catcode`~ 3
\def\XINT_expr_wrapit #1{\expandafter\XINT_expr_wrap\csname.=#1\endcsname}%
\def\xintNewFunction #1#2[#3]#4%
{%
@@ -2773,8 +2791,8 @@
\else \toks0{##1##2##3##4##5##6##7##8##9}%
\fi
\expandafter
- \endgroup
- \expandafter
+ \endgroup\expandafter
+ \XINT_global\expandafter
\def\csname XINT_expr_macrofunc_\XINT_expr_tmpa\expandafter\endcsname
\the\toks0\expandafter{\XINT_expr_tmpb
{\XINT_expr_wrapit{##1}}{\XINT_expr_wrapit{##2}}{\XINT_expr_wrapit{##3}}%
@@ -2793,12 +2811,13 @@
\xintMessage {xintexpr}{Info}
{Function \XINT_expr_tmpa\space for the expression parsers is
associated to \string\XINT_expr_macrofunc_\XINT_expr_tmpa\space
- with meaning \expandafter\meaning
+ with \ifxintglobaldefs global \fi meaning \expandafter\meaning
\csname XINT_expr_macrofunc_\XINT_expr_tmpa\endcsname}%
\fi
}%
\def\XINT_expr_newfunction #1#2#3#4%
{%
+ \XINT_global
\def#1##1##2##3{\expandafter ##1\expandafter ##2\romannumeral0%
\XINT:expr:macrofunc{#4}{#3}{#2}{\XINT_expr_unlock##3}}%
}%
@@ -2807,6 +2826,7 @@
#1\csname XINT_expr_macrofunc_#3\expandafter\endcsname
\romannumeral0\xintcsvtolistnonstripped{#4}\relax
}%
+\catcode`~ 12
\def\XINT:newexpr:macrofunc #1{%
\def\XINT:newexpr:macrofunc ##1##2##3##4%
{%
@@ -2814,6 +2834,7 @@
{\xintCSVtoListNonStripped{##4}}\endcsname
}%
}\XINT:newexpr:macrofunc { }%
+\catcode`~ 3
\def\XINT:newexpr:macrofunc:a #1#2#3%
{%
\expandafter\XINT_expr_unlock\romannumeral0\csname xintbare#1\endcsname
@@ -2886,8 +2907,8 @@
\xint_dothis {\detokenize{#3}[#4]}\fi
\if $#2\xint_dothis {~xintApply::csv{\detokenize{#3}[#4]}}\fi %$
\xint_orthat{#3[#4]}%
-}% pas complétement général, mais bon
-\def\XINT:NE:csv #1{\detokenize{#1}}% radicalement fainéant
+}% pas compl^^c3^^a9tement g^^c3^^a9n^^c3^^a9ral, mais bon
+\def\XINT:NE:csv #1{\detokenize{#1}}% radicalement fain^^c3^^a9ant
\def\XINT:newexpr:one:and:opt #1,#2,#3!#4#5%
{%
\if\relax#3\relax\expandafter\xint_firstoftwo\else
@@ -3067,18 +3088,18 @@
{%
\begingroup
\ifcase #7\relax
- \toks0 {\endgroup\def#5}%
- \or \toks0 {\endgroup\def#5##1}%
- \or \toks0 {\endgroup\def#5##1##2}%
- \or \toks0 {\endgroup\def#5##1##2##3}%
- \or \toks0 {\endgroup\def#5##1##2##3##4}%
- \or \toks0 {\endgroup\def#5##1##2##3##4##5}%
- \or \toks0 {\endgroup\def#5##1##2##3##4##5##6}%
- \or \toks0 {\endgroup\def#5##1##2##3##4##5##6##7}%
- \or \toks0 {\endgroup\def#5##1##2##3##4##5##6##7##8}%
- \or \toks0 {\endgroup\def#5##1##2##3##4##5##6##7##8##9}%
+ \toks0 {\endgroup\XINT_global\def#5}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2##3}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2##3##4}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2##3##4##5}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2##3##4##5##6}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2##3##4##5##6##7}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2##3##4##5##6##7##8}%
+ \or \toks0 {\endgroup\XINT_global\def#5##1##2##3##4##5##6##7##8##9}%
\fi
- \xintexprSafeCatcodes
+ #2\xintexprSafeCatcodes
\XINT_expr_redefinemacros
#1%
\XINT_NewExpr_a #2#3#4#5%
@@ -3102,13 +3123,16 @@
{\XINT_tmpa{%%1}{%%2}{%%3}{%%4}{%%5}{%%6}{%%7}{%%8}{%%9}}@
%1{\ifxintverbose
\xintMessage{xintexpr}{Info}@
- {\string%4\space now with meaning \meaning%4}@
+ {\string%4\space now with @
+ \ifxintglobaldefs global \fi meaning \meaning%4}@
\fi}@
}@
\catcode`% 14
+\newif\ifxintexprsafecatcodes
\let\xintexprRestoreCatcodes\empty
\def\xintexprSafeCatcodes
{%
+ \unless\ifxintexprsafecatcodes
\edef\xintexprRestoreCatcodes {%
\catcode59=\the\catcode59 % ;
\catcode34=\the\catcode34 % "
@@ -3134,7 +3158,10 @@
\catcode61=\the\catcode61 % =
\catcode96=\the\catcode96 % `
\catcode32=\the\catcode32\relax % space
+ \noexpand\xintexprsafecatcodesfalse
}%
+ \fi
+ \xintexprsafecatcodestrue
\catcode59=12 % ;
\catcode34=12 % "
\catcode63=12 % ?