diff options
author | Karl Berry <karl@freefriends.org> | 2013-10-10 22:28:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-10-10 22:28:42 +0000 |
commit | 3364dcae66a703d52a1a30f21e324f988eb37d73 (patch) | |
tree | 0e0cc26c6a7dd1ba3c904814d270ebd4015caf30 /Master/texmf-dist/tex/generic/xint/xintexpr.sty | |
parent | efa300558205320b779ab9de9ac92cc0b6c1872e (diff) |
xint (10oct13)
git-svn-id: svn://tug.org/texlive/trunk@31876 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.sty | 289 |
1 files changed, 132 insertions, 157 deletions
diff --git a/Master/texmf-dist/tex/generic/xint/xintexpr.sty b/Master/texmf-dist/tex/generic/xint/xintexpr.sty index 76b1537d209..3c753a77e5c 100644 --- a/Master/texmf-dist/tex/generic/xint/xintexpr.sty +++ b/Master/texmf-dist/tex/generic/xint/xintexpr.sty @@ -22,7 +22,7 @@ %% in the same archive or directory.) %% %%---------------------------------------------------------------- -%% The xint bundle (version 1.09b of October 3, 2013) +%% The xint bundle (version 1.09c of October 9, 2013) %% xintexpr: Expandable expression parser %% Copyright (C) 2013 by Jean-Francois Burnol %%---------------------------------------------------------------- @@ -86,12 +86,11 @@ \catcode45=12 % - \catcode46=12 % . \catcode58=12 % : - \expandafter - \ifx\csname PackageInfo\endcsname\relax - \def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}% - \else + \ifdefined\PackageInfo \def\y#1#2{\PackageInfo{#1}{#2}}% - \fi + \else + \def\y#1#2{\immediate\write-1{Package #1 Info: #2.}}% + \fi \def\empty {}% \expandafter\let\expandafter\w\csname ver@xintfrac.sty\endcsname \ifx\w\relax % Plain TeX, user gave a file name at the prompt @@ -106,13 +105,12 @@ \XINTsetupcatcodes% \XINT_providespackage \ProvidesPackage{xintexpr}% - [2013/10/03 v1.09b Expandable expression parser (jfB)]% + [2013/10/09 v1.09c Expandable expression parser (jfB)]% \def\xint_gob_til_dot #1.{}% \def\xint_gob_til_dot_andstop #1.{ }% \def\xint_gob_til_! #1!{}% nota bene: ! is of catcode 11 \def\XINT_expr_unexpectedtoken {\xintError:ignored }% \def\XINT_newexpr_stripprefix #1>{\noexpand\romannumeral-`0}% -\def\xint_firstofone #1{#1}% \def\XINT_expr_lock #1!{\expandafter\space\csname .#1\endcsname }% \def\XINT_expr_unlock {\expandafter\xint_gob_til_dot\string }% \def\XINT_expr_usethe {use_xintthe!\xintError:use_xintthe! }% @@ -121,6 +119,10 @@ \def\XINT_flexpr_done {!\XINT_expr_usethe\XINT_flexpr_print }% \def\XINT_flexpr_print #1{\xintFloat:csv{\XINT_expr_unlock #1}}% \def\XINT_numexpr_print #1{\xintRound:csv{\XINT_expr_unlock #1}}% +\def\XINT_boolexpr_print #1{\xintIsTrue:csv{\XINT_expr_unlock #1}}% +\def\xintifboolexpr #1{\romannumeral0\xintifnotzero {\xinttheexpr #1\relax}}% +\def\xintifboolfloatexpr #1{\romannumeral0\xintifnotzero + {\xintthefloatexpr #1\relax}}% \def\xintexpr {\romannumeral0\xinteval }% \def\xinteval {% @@ -133,6 +135,11 @@ \def\xintnumexpr {\romannumeral0\expandafter\XINT_numexpr_post \romannumeral0\xinteval }% \def\xintthenumexpr {\romannumeral-`0\xintthe\xintnumexpr }% +\def\XINT_boolexpr_post !\XINT_expr_usethe\XINT_expr_print% + { !\XINT_expr_usethe\XINT_boolexpr_print }% +\def\xintboolexpr {\romannumeral0\expandafter\XINT_boolexpr_post + \romannumeral0\xinteval }% +\def\xinttheboolexpr {\romannumeral-`0\xintthe\xintboolexpr }% \def\xintfloatexpr {\romannumeral0\xintfloateval }% \def\xintfloateval {% @@ -192,7 +199,7 @@ \def\XINT_expr_getnext_onetoken_fork #1% {% The * is in truth catcode 12 #. For (clever!) use with \xintNewExpr. \XINT_expr_sixwayfork - #1-.+*\dummy {\xint_c_x ({}}% back to until to trigger oparen + #1-.+*\dummy {\xint_c_xviii ({}}% back to until to trigger oparen (#1.+*\dummy -% (-#1+*\dummy {\XINT_expr_scandec_II.}% (-.#1*\dummy \XINT_expr_getnext% @@ -227,12 +234,18 @@ }% \def\XINT_expr_scanfunc_b #1% {% - \if #1(\else\expandafter \XINT_expr_scanfunc_c \fi #1% + \if #1(\expandafter \xint_gobble_iii\fi + \xint_firstofone + {% added in 1.09c for bool and togl + \if #1)\expandafter \xint_gobble_i + \else \expandafter \xint_firstoftwo + \fi }% + {\XINT_expr_scanfunc_c #1}(% }% \def\XINT_expr_scanfunc_panic {\xintError:bigtroubleahead(0\relax }% \def\XINT_expr_func #1(% common to expr and flexpr {% - \xint_c_x @{#1}% + \xint_c_xviii @{#1}% functions have the highest priority. }% \def\XINT_expr_scandec_I {% @@ -493,19 +506,6 @@ \csname XINT_flexpr_until_,_b\expandafter\endcsname \csname XINT_flexpr_op_-vi\expandafter\endcsname \csname XINT_expr_precedence_,\endcsname {flexpr}% -\def \XINT_expr_precedence_? #1#2#3#4% -{% - \xintifZero{\XINT_expr_unlock #2}% - {\XINT_expr_getnext #4}% - {\XINT_expr_getnext #3}% -}% -\def \XINT_expr_precedence_: #1#2#3#4#5% -{% - \xintifSgn {\XINT_expr_unlock #2}% - {\XINT_expr_getnext #3}% - {\XINT_expr_getnext #4}% - {\XINT_expr_getnext #5}% -}% \def\xint_tmp_def #1#2% {% \expandafter\xint_tmp_do_defs @@ -538,33 +538,72 @@ }% \xintApplyInline{\xint_tmp_def {expr}}{{vi}{vii}{viii}{ix}}% \xintApplyInline{\xint_tmp_def {flexpr}}{{vi}{vii}{viii}{ix}}% -\expandafter\def\csname XINT_expr_precedence_!\endcsname #1#2% - {\expandafter\XINT_expr_getop - \csname .\xintFac{\XINT_expr_unlock #2}[0]\endcsname }% +\let\XINT_expr_precedence_? \xint_c_x +\def \XINT_expr_op_? #1#2#3% +{% + \xintifZero{\XINT_expr_unlock #1}% + {\XINT_expr_getnext #3}% + {\XINT_expr_getnext #2}% +}% +\let\XINT_flexpr_op_?\XINT_expr_op_? +\let\XINT_expr_precedence_: \xint_c_x +\def \XINT_expr_op_: #1#2#3#4% +{% + \xintifSgn {\XINT_expr_unlock #1}% + {\XINT_expr_getnext #2}% + {\XINT_expr_getnext #3}% + {\XINT_expr_getnext #4}% +}% +\let\XINT_flexpr_op_:\XINT_expr_op_: +\let\XINT_expr_precedence_! \xint_c_x +\def\XINT_expr_op_! #1{\expandafter\XINT_expr_getop + \csname .\xintFac{\XINT_expr_unlock #1}\endcsname }% [0] removed in 1.09c +\let\XINT_flexpr_op_!\XINT_expr_op_! \let\xint_tmp_def\empty \let\xint_tmp_do_defs\empty \def\XINT_expr_op_@ #1% {% + \ifcsname XINT_expr_onlitteral_#1\endcsname + \expandafter\XINT_expr_funcoflitteral + \else + \expandafter\XINT_expr_op_@@ + \fi {#1}% +}% +\def\XINT_flexpr_op_@ #1% +{% + \ifcsname XINT_expr_onlitteral_#1\endcsname + \expandafter\XINT_expr_funcoflitteral + \else + \expandafter\XINT_flexpr_op_@@ + \fi {#1}% +}% +\def\XINT_expr_funcoflitteral #1% +{% + \expandafter\expandafter\csname XINT_expr_onlitteral_#1\endcsname + \romannumeral-`0\XINT_expr_scanfunc +}% +\def\XINT_expr_op_@@ #1% +{% \ifcsname XINT_expr_func_#1\endcsname - \xint_afterfi{% - \expandafter\expandafter\csname XINT_expr_func_#1\endcsname - }% + \xint_afterfi{\expandafter\expandafter\csname XINT_expr_func_#1\endcsname}% \else \xintError:unknownfunction \xint_afterfi{\expandafter\XINT_expr_func_unknown}% \fi \romannumeral-`0\XINT_expr_oparen }% -\def\XINT_flexpr_op_@ #1% +\def\XINT_flexpr_op_@@ #1% {% \ifcsname XINT_flexpr_func_#1\endcsname - \xint_afterfi{% - \expandafter\expandafter\csname XINT_flexpr_func_#1\endcsname - }% + \xint_afterfi{\expandafter\expandafter\csname XINT_flexpr_func_#1\endcsname}% \else \xintError:unknownfunction - \xint_afterfi{\expandafter\XINT_expr_func_unknown}% + \xint_afterfi{\expandafter\XINT_expr_func_unknown}% \fi \romannumeral-`0\XINT_flexpr_oparen }% +\def\XINT_expr_onlitteral_bool #1#2#3{\expandafter\XINT_expr_getop + \csname .\xintBool{#3}\endcsname }% +\def\XINT_expr_onlitteral_togl #1#2#3{\expandafter\XINT_expr_getop + \csname .\xintToggle{#3}\endcsname }% \def\XINT_expr_func_unknown #1#2#3% {% \expandafter #1\expandafter #2\csname .0[0]\endcsname @@ -784,139 +823,75 @@ \expandafter\xint_secondoftwo \fi {_xintListWithSep,{#1}}{\xint_firstofone#1}}% -\def\XINT_expr_tmp #1% - {\expandafter\def\csname xint#1\endcsname {_xint#1}}% -\expandafter\def\expandafter\XINT_expr_protect\expandafter -{% - \romannumeral0% - \xintapplyunbraced\XINT_expr_tmp{\xintCSVtoList{% - Floor,Ceil,iRound,Round,iTrunc,Trunc,% - Lt,Gt,Eq,AND,OR,% - IsNotZero,IsZero,% - ifNotZero,ifSgn,% - Irr,Num,Abs,Sgn,Opp,Quo,Rem,% - Add,Sub,Mul,Sqr,Div,Pow,Fac,fE}}% - \def\xintGCDof:csv ##1{_xintGCDof {\xintCSVtoList {##1}}}% - \def\xintLCMof:csv ##1{_xintLCMof {\xintCSVtoList {##1}}}% - \def\xintMaxof:csv ##1{_xintMaxof {\xintCSVtoList {##1}}}% - \def\xintMinof:csv ##1{_xintMinof {\xintCSVtoList {##1}}}% - \def\xintSum:csv ##1{_xintSum {\xintCSVtoList {##1}}}% - \def\xintPrd:csv ##1{_xintPrd {\xintCSVtoList {##1}}}% - \def\xintANDof:csv ##1{_xintANDof {\xintCSVtoList {##1}}}% - \def\xintORof:csv ##1{_xintORof {\xintCSVtoList {##1}}}% - \def\xintXORof:csv ##1{_xintXORof {\xintCSVtoList {##1}}}% - \def\XINTinFloat {_XINTinFloat}% - \def\XINTinFloatSqrt {_XINTinFloatSqrt}% - \def\XINTdigits {_XINTdigits}% - \def\XINT_expr_print ##1{\expandafter\XINT_newexpr_print\expandafter - {\romannumeral0\xintcsvtolist{\XINT_expr_unlock ##1}}}% -}% -\catcode`* 13 -\def\xintNewExpr #1[#2]% -{% - \begingroup - \ifcase #2\relax - \toks0 {\xdef #1}% - \or \toks0 {\xdef #1##1}% - \or \toks0 {\xdef #1##1##2}% - \or \toks0 {\xdef #1##1##2##3}% - \or \toks0 {\xdef #1##1##2##3##4}% - \or \toks0 {\xdef #1##1##2##3##4##5}% - \or \toks0 {\xdef #1##1##2##3##4##5##6}% - \or \toks0 {\xdef #1##1##2##3##4##5##6##7}% - \or \toks0 {\xdef #1##1##2##3##4##5##6##7##8}% - \or \toks0 {\xdef #1##1##2##3##4##5##6##7##8##9}% - \fi - \xintexprSafeCatcodes - \XINT_NewExpr -}% -\def\XINT_NewExpr #1% -{% - \def\xintTmp ##1##2##3##4##5##6##7##8##9{#1}% - \XINT_expr_protect - \lccode`\*=`_ \lowercase {\def*}{!noexpand!}% - \catcode`_ 13 \catcode`: 11 \endlinechar -1 - \everyeof {\noexpand }% - \edef\XINTtmp ##1##2##3##4##5##6##7##8##9% - {\scantokens - \expandafter{\romannumeral-`0\xinttheexpr - \xintTmp {####1}{####2}{####3}% - {####4}{####5}{####6}% - {####7}{####8}{####9}% - \relax}}% - \lccode`\*=`\$ \lowercase {\def*}{####}% - \catcode`\$ 13 \catcode`! 0 \catcode`_ 11 % - \the\toks0 - {\scantokens\expandafter{\expandafter - \XINT_newexpr_stripprefix\meaning\XINTtmp}}% -\endgroup -}% -\def\XINT_newflexpr_print #1{\ifnum\xintNthElt{0}{#1}>1 +\xintForpair #1#2 in {(fl,Float),(num,iRound0),(bool,IsTrue)} \do {% + \expandafter\def\csname XINT_new#1expr_print\endcsname + ##1{\ifnum\xintNthElt{0}{##1}>1 \expandafter\xint_firstoftwo \else \expandafter\xint_secondoftwo \fi - {_xintListWithSep,{\xintApply{_xintFloat}{#1}}} - {_xintFloat#1}}% -\expandafter\def\expandafter\XINT_flexpr_protect\expandafter -{% - \romannumeral0% - \xintapplyunbraced\XINT_expr_tmp{\xintCSVtoList{% - Floor,Ceil,iRound,Round,iTrunc,Trunc,% - Lt,Gt,Eq,AND,OR,% - IsNotZero,IsZero,% - ifNotZero,ifSgn,% - Irr,Num,Abs,Sgn,Opp,Quo,Rem,Fac}}% - \def\xintGCDof:csv ##1{_xintGCDof {\xintCSVtoList {##1}}}% - \def\xintLCMof:csv ##1{_xintLCMof {\xintCSVtoList {##1}}}% - \def\xintFloatMaxof:csv ##1{_xintFloatMaxof {\xintCSVtoList {##1}}}% - \def\xintFloatMinof:csv ##1{_xintFloatMinof {\xintCSVtoList {##1}}}% - \def\xintFloatSum:csv ##1{_xintFloatSum {\xintCSVtoList {##1}}}% - \def\xintFloatPrd:csv ##1{_xintFloatPrd {\xintCSVtoList {##1}}}% - \def\xintANDof:csv ##1{_xintANDof {\xintCSVtoList {##1}}}% - \def\xintORof:csv ##1{_xintORof {\xintCSVtoList {##1}}}% - \def\xintXORof:csv ##1{_xintXORof {\xintCSVtoList {##1}}}% - \def\XINTinFloat {_XINTinFloat}% - \def\XINTinFloatSqrt {_XINTinFloatSqrt}% - \def\XINTinFloatAdd {_XINTinFloatAdd}% - \def\XINTinFloatSub {_XINTinFloatSub}% - \def\XINTinFloatMul {_XINTinFloatMul}% - \def\XINTinFloatDiv {_XINTinFloatDiv}% - \def\XINTinFloatPower {_XINTinFloatPower}% - \def\XINTinFloatfE {_XINTinFloatfE}% - \def\XINTdigits {_XINTdigits}% - \def\XINT_flexpr_print ##1{\expandafter\XINT_newflexpr_print\expandafter + {_xintListWithSep,{\xintApply{_xint#2}{##1}}} + {_xint#2##1}}}% +\toks0 {}% +\xintFor #1 in {Bool,Toggle,Floor,Ceil,iRound,Round,iTrunc,Trunc,% + Lt,Gt,Eq,AND,OR,IsNotZero,IsZero,ifNotZero,ifSgn,% + Irr,Num,Abs,Sgn,Opp,Quo,Rem,Add,Sub,Mul,Sqr,Div,Pow,Fac,fE} \do + {\toks0 + \expandafter{\the\toks0\expandafter\def\csname xint#1\endcsname {_xint#1}}}% +\xintFor #1 in {GCDof,LCMof,Maxof,Minof,ANDof,ORof,XORof,% + FloatMaxof,FloatMinof,Sum,Prd,FloatSum,FloatPrd} \do + {\toks0 + \expandafter{\the\toks0\expandafter\def\csname xint#1:csv\endcsname + ####1{_xint#1 {\xintCSVtoList {####1}}}}}% +\xintFor #1 in {,Sqrt,Add,Sub,Mul,Div,Power,fE} \do + {\toks0 + \expandafter{\the\toks0\expandafter\def\csname XINTinFloat#1\endcsname + {_XINTinFloat#1}}}% +\expandafter\def\expandafter\XINT_expr_protect\expandafter{\the\toks0 + \def\XINTdigits {_XINTdigits}% + \def\XINT_expr_print ##1{\expandafter\XINT_newexpr_print\expandafter + {\romannumeral0\xintcsvtolist{\XINT_expr_unlock ##1}}}% + \def\XINT_flexpr_print ##1{\expandafter\XINT_newflexpr_print\expandafter + {\romannumeral0\xintcsvtolist{\XINT_expr_unlock ##1}}}% + \def\XINT_numexpr_print ##1{\expandafter\XINT_newnumexpr_print\expandafter + {\romannumeral0\xintcsvtolist{\XINT_expr_unlock ##1}}}% + \def\XINT_boolexpr_print ##1{\expandafter\XINT_newboolexpr_print\expandafter {\romannumeral0\xintcsvtolist{\XINT_expr_unlock ##1}}}% }% -\let\XINT_expr_tmp\empty -\def\xintNewFloatExpr #1[#2]% -{% - \begingroup - \ifcase #2\relax - \toks0 {\xdef #1}% - \or \toks0 {\xdef #1##1}% - \or \toks0 {\xdef #1##1##2}% - \or \toks0 {\xdef #1##1##2##3}% - \or \toks0 {\xdef #1##1##2##3##4}% - \or \toks0 {\xdef #1##1##2##3##4##5}% - \or \toks0 {\xdef #1##1##2##3##4##5##6}% - \or \toks0 {\xdef #1##1##2##3##4##5##6##7}% - \or \toks0 {\xdef #1##1##2##3##4##5##6##7##8}% - \or \toks0 {\xdef #1##1##2##3##4##5##6##7##8##9}% +\toks0 {}% +\def\xintNewExpr {\xint_NewExpr\xinttheexpr }% +\def\xintNewFloatExpr {\xint_NewExpr\xintthefloatexpr }% +\def\xintNewNumExpr {\xint_NewExpr\xintthenumexpr }% +\def\xintNewBoolExpr {\xint_NewExpr\xinttheboolexpr }% +\def\xint_NewExpr #1#2[#3]% +{% + \begingroup + \ifcase #3\relax + \toks0 {\xdef #2}% + \or \toks0 {\xdef #2##1}% + \or \toks0 {\xdef #2##1##2}% + \or \toks0 {\xdef #2##1##2##3}% + \or \toks0 {\xdef #2##1##2##3##4}% + \or \toks0 {\xdef #2##1##2##3##4##5}% + \or \toks0 {\xdef #2##1##2##3##4##5##6}% + \or \toks0 {\xdef #2##1##2##3##4##5##6##7}% + \or \toks0 {\xdef #2##1##2##3##4##5##6##7##8}% + \or \toks0 {\xdef #2##1##2##3##4##5##6##7##8##9}% \fi \xintexprSafeCatcodes - \XINT_NewFloatExpr + \XINT_NewExpr #1% }% -\def\XINT_NewFloatExpr #1% +\catcode`* 13 +\def\XINT_NewExpr #1#2% {% - \def\xintTmp ##1##2##3##4##5##6##7##8##9{#1}% - \XINT_flexpr_protect + \def\xintTmp ##1##2##3##4##5##6##7##8##9{#2}% + \XINT_expr_protect \lccode`\*=`_ \lowercase {\def*}{!noexpand!}% - \catcode`_ 13 \catcode`: 11 \endlinechar -1 % + \catcode`_ 13 \catcode`: 11 \endlinechar -1 \everyeof {\noexpand }% \edef\XINTtmp ##1##2##3##4##5##6##7##8##9% {\scantokens - \expandafter{\romannumeral-`0\xintthefloatexpr + \expandafter{\romannumeral-`0#1% \xintTmp {####1}{####2}{####3}% {####4}{####5}{####6}% {####7}{####8}{####9}% @@ -924,9 +899,9 @@ \lccode`\*=`\$ \lowercase {\def*}{####}% \catcode`\$ 13 \catcode`! 0 \catcode`_ 11 % \the\toks0 - {\scantokens\expandafter - {\expandafter\XINT_newexpr_stripprefix\meaning\XINTtmp}}% -\endgroup + {\scantokens\expandafter{\expandafter + \XINT_newexpr_stripprefix\meaning\XINTtmp}}% + \endgroup }% \let\xintexprRestoreCatcodes\relax \def\xintexprSafeCatcodes |