diff options
author | Karl Berry <karl@freefriends.org> | 2017-01-29 22:34:57 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-01-29 22:34:57 +0000 |
commit | fabbcd2656be5dca3e1986ddcc8c827a23e9aedf (patch) | |
tree | 4f669dff01da1c31477e1e876fc878cddd5c06ab /Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx | |
parent | ebc35af4250051fed5186c59ba4eaff9949142e2 (diff) |
l3 (29jan17)
git-svn-id: svn://tug.org/texlive/trunk@43088 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx | 230 |
1 files changed, 126 insertions, 104 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx index 339595c6d2e..1936b34f888 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx @@ -1,42 +1,28 @@ % \iffalse meta-comment % %% File: l3fp-parse.dtx Copyright (C) 2011-2016 The LaTeX3 Project -%% -%% 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 -%% -%% This file is part of the "l3kernel bundle" (The Work in LPPL) -%% and all files in that bundle must be distributed together. -%% -%% The released version of this bundle is available from CTAN. -%% -%% ----------------------------------------------------------------------- -%% -%% The development version of the bundle can be found at -%% -%% http://www.latex-project.org/svnroot/experimental/trunk/ -%% -%% for those people who are interested. -%% -%%%%%%%%%%% -%% NOTE: %% -%%%%%%%%%%% -%% -%% Snapshots taken from the repository represent work in progress and may -%% not work or may contain conflicting material! We therefore ask -%% people _not_ to put them into distributions, archives, etc. without -%% prior consultation with the LaTeX Project Team. -%% -%% ----------------------------------------------------------------------- -%% +% +% 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 +% +% This file is part of the "l3kernel bundle" (The Work in LPPL) +% and all files in that bundle must be distributed together. +% +% ----------------------------------------------------------------------- +% +% The development version of the bundle can be found at +% +% https://github.com/latex3/latex3 +% +% for those people who are interested. % %<*driver> \documentclass[full]{l3doc} -\GetIdInfo$Id: l3fp-parse.dtx 6750 2016-11-21 01:24:26Z bruno $ +\GetIdInfo$Id: l3fp-parse.dtx 6805 2016-12-28 22:15:52Z joseph $ {L3 Floating-point expression parsing} \begin{document} \DocInput{\jobname.dtx} @@ -111,20 +97,57 @@ % \begin{itemize} % \item[16] Function calls with multiple arguments. % \item[15] Function calls expecting exactly one argument. -% \item[14] Binary |**| and~|^| (right to left). +% \item[13/14] Binary |**| and~|^| (right to left). % \item[12] Unary |+|, |-|, |!| (right to left). % \item[10] Binary |*|, |/|, and juxtaposition (implicit~|*|). % \item[9] Binary |+| and~|-|. % \item[7] Comparisons. -% \item[5] Logical \texttt{and}, denoted by~|&&|. -% \item[4] Logical \texttt{or}, denoted by~\verb*+||+. -% \item[3] Ternary operator |?:|, piece~|?|. -% \item[2] Ternary operator |?:|, piece~|:|. -% \item[1] Commas, and parentheses accepting commas. -% \item[0] Parentheses expecting exactly one argument. -% \item[-1] Start and end of the expression. +% \item[6] Logical \texttt{and}, denoted by~|&&|. +% \item[5] Logical \texttt{or}, denoted by~\verb*+||+. +% \item[4] Ternary operator |?:|, piece~|?|. +% \item[3] Ternary operator |?:|, piece~|:|. +% \item[2] Commas, and parentheses accepting commas. +% \item[1] Parentheses expecting exactly one argument. +% \item[0] Start and end of the expression. % \end{itemize} % +% \begin{variable} +% { +% \c_@@_prec_funcii_int, +% \c_@@_prec_func_int, +% \c_@@_prec_hatii_int, +% \c_@@_prec_hat_int, +% \c_@@_prec_not_int, +% \c_@@_prec_times_int, +% \c_@@_prec_plus_int, +% \c_@@_prec_comp_int, +% \c_@@_prec_and_int, +% \c_@@_prec_or_int, +% \c_@@_prec_quest_int, +% \c_@@_prec_colon_int, +% \c_@@_prec_comma_int, +% \c_@@_prec_paren_int, +% \c_@@_prec_end_int, +% } +% \begin{macrocode} +\int_const:Nn \c_@@_prec_funcii_int { 16 } +\int_const:Nn \c_@@_prec_func_int { 15 } +\int_const:Nn \c_@@_prec_hatii_int { 14 } +\int_const:Nn \c_@@_prec_hat_int { 13 } +\int_const:Nn \c_@@_prec_not_int { 12 } +\int_const:Nn \c_@@_prec_times_int { 10 } +\int_const:Nn \c_@@_prec_plus_int { 9 } +\int_const:Nn \c_@@_prec_comp_int { 7 } +\int_const:Nn \c_@@_prec_and_int { 6 } +\int_const:Nn \c_@@_prec_or_int { 5 } +\int_const:Nn \c_@@_prec_quest_int { 4 } +\int_const:Nn \c_@@_prec_colon_int { 3 } +\int_const:Nn \c_@@_prec_comma_int { 2 } +\int_const:Nn \c_@@_prec_paren_int { 1 } +\int_const:Nn \c_@@_prec_end_int { 0 } +% \end{macrocode} +% \end{variable} +% % \subsubsection{Storing results} % % The main question in parsing expressions expandably is to decide where @@ -215,8 +238,8 @@ % previous binary operator is, or rather, its precedence: we thus rename % it |\operand:Nw|. Let us describe as an example how the calculation % |41-2^3*4+5| will be done. Here, we abuse notations: the first -% argument of |\operand:Nw| should be an integer constant (\cs{c_three}, -% \cs{c_nine}, \ldots{}) equal to the precedence of the given operator, +% argument of |\operand:Nw| should be an integer constant (\cs{c_@@_prec_plus_int}, +% \ldots{}) equal to the precedence of the given operator, % not directly the operator itself. % \begin{itemize} % \item Clean up~|41| and find~|-|. We call |\operand:Nw|~|-| to find @@ -1736,7 +1759,7 @@ % \begin{macro}[EXP, aux]{\@@_parse_prefix_-:Nw, \@@_parse_prefix_!:Nw} % The unary~|-| and boolean not are harder: we parse the operand using % a precedence equal to the maximum of the previous precedence~|##1| -% and the precedence \cs{c_twelve} of the unary operator, then call +% and the precedence \cs{c_@@_prec_not_int} of the unary operator, then call % the appropriate |\__fp_|\meta{operation}|_o:w| function, % where the \meta{operation} is |set_sign| or |not|. % \begin{macrocode} @@ -1757,8 +1780,8 @@ \@@_parse_expand:w } } -\@@_tmp:w - \c_twelve \@@_set_sign_o:w 2 -\@@_tmp:w ! \c_twelve \@@_not_o:w ? +\@@_tmp:w - \c_@@_prec_not_int \@@_set_sign_o:w 2 +\@@_tmp:w ! \c_@@_prec_not_int \@@_not_o:w ? % \end{macrocode} % \end{macro} % @@ -1801,10 +1824,10 @@ \exp_after:wN \@@_parse_lparen_after:NwN \exp_after:wN #1 \exp:w - \if_int_compare:w #1 = \c_sixteen - \@@_parse_operand:Nw \c_one + \if_int_compare:w #1 = \c_@@_prec_funcii_int + \@@_parse_operand:Nw \c_@@_prec_comma_int \else: - \@@_parse_operand:Nw \c_zero + \@@_parse_operand:Nw \c_@@_prec_paren_int \fi: \@@_parse_expand:w } @@ -1827,31 +1850,15 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}[aux, EXP, verb]{\@@_parse_prefix_,:Nw} % \begin{macro}[aux, EXP]{\@@_parse_prefix_):Nw} -% The right parenthesis and the comma can appear as unary prefixes -% when an argument of a multi-argument function is missing (for -% instance the first and last ones in |max(,1,2,)| or in |rand()|). -% In single-argument functions (precedence~$0$ rather than~$1$) forbid -% this. +% The right parenthesis can appear as unary prefixes when arguments of +% a multi-argument function end with a comma, or when there is no +% argument, as in |max(1,2,)| or in |rand()|. In single-argument +% functions (precedence~$0$ rather than~$1$) forbid this. % \begin{macrocode} -\cs_new:cpn { @@_parse_prefix_,:Nw } #1 - { - \if_int_compare:w #1 = \c_one - \exp_after:wN \@@_parse_one:Nw - \exp_after:wN #1 - \else: - \__msg_kernel_expandable_error:nnn - { kernel } { fp-missing-number } { , } - \exp_after:wN \c_nan_fp \exp:w \exp_end_continue_f:w - \exp_after:wN \@@_parse_infix:NN - \exp_after:wN #1 - \exp_after:wN , - \fi: - } \cs_new:cpn { @@_parse_prefix_):Nw } #1 { - \if_int_compare:w #1 = \c_one + \if_int_compare:w #1 = \c_@@_prec_comma_int \else: \__msg_kernel_expandable_error:nnn { kernel } { fp-missing-number } { ) } @@ -1861,7 +1868,6 @@ } % \end{macrocode} % \end{macro} -% \end{macro} % % \subsubsection{Constants} % @@ -1958,7 +1964,7 @@ \exp_after:wN #2 \cs:w @@_#1_o:w \exp_after:wN \cs_end: \exp:w - \@@_parse_operand:Nw \c_fifteen \@@_parse_expand:w + \@@_parse_operand:Nw \c_@@_prec_func_int \@@_parse_expand:w } \cs_new:Npn \@@_parse_function:NNN #1#2#3 { @@ -1967,7 +1973,7 @@ \exp_after:wN #2 \exp_after:wN #1 \exp:w - \@@_parse_operand:Nw \c_sixteen \@@_parse_expand:w + \@@_parse_operand:Nw \c_@@_prec_funcii_int \@@_parse_expand:w } % \end{macrocode} % \end{macro} @@ -2108,7 +2114,7 @@ % Start an \cs{exp:w} expansion so that \cs{@@_parse:n} expands % in two steps. The \cs{@@_parse_operand:Nw} function will perform % computations until reaching an operation with precedence -% \cs{c_minus_one} or less, namely, the end of the expression. The +% \cs{c_@@_prec_end_int} or less, namely, the end of the expression. The % marker \cs{s_@@_mark} indicates that the next token is an already % parsed version of an infix operator, and \cs{@@_parse_infix_end:N} % has infinitely negative precedence. Finally, clean up a @@ -2120,7 +2126,7 @@ \exp:w \exp_after:wN \@@_parse_after:ww \exp:w - \@@_parse_operand:Nw \c_minus_one + \@@_parse_operand:Nw \c_@@_prec_end_int \@@_parse_expand:w #1 \s_@@_mark \@@_parse_infix_end:N \s_@@_stop @@ -2272,7 +2278,7 @@ \char_set_catcode_letter:N \) \cs_new:Npn \@@_parse_infix_):N #1 { - \if_int_compare:w #1 < \c_zero + \if_int_compare:w #1 < \c_@@_prec_paren_int \__msg_kernel_expandable_error:nnn { kernel } { fp-extra } { ) } \exp_after:wN \@@_parse_infix:NN \exp_after:wN #1 @@ -2288,37 +2294,53 @@ % \end{macro} % % \begin{macro}[aux, verb, EXP]{\__fp_parse_infix_,:N} +% \begin{macro}[aux, EXP]{\@@_parse_infix_comma:w, \@@_parse_infix_comma_error:w} +% \begin{macro}[aux, verb, EXP]{\__fp_,_o:ww} +% \cs{@@_,_o:ww} is a complicated way of replacing any number of +% floating point arguments by \texttt{nan}. % \begin{macrocode} \group_begin: \char_set_catcode_letter:N \, \cs_new:Npn \@@_parse_infix_,:N #1 { - \if_int_compare:w #1 > \c_one + \if_int_compare:w #1 > \c_@@_prec_comma_int \exp_after:wN @ \exp_after:wN \use_none:n \exp_after:wN \@@_parse_infix_,:N \else: - \if_int_compare:w #1 = \c_one - \exp_after:wN \@@_parse_infix_comma:w - \exp:w - \else: - \exp_after:wN \@@_parse_infix_comma_gobble:w - \exp:w + \if_int_compare:w #1 < \c_@@_prec_comma_int + \@@_parse_infix_comma_error:w \fi: - \@@_parse_operand:Nw \c_one + \exp_after:wN \@@_parse_infix_comma:w + \exp:w \@@_parse_operand:Nw \c_@@_prec_comma_int \exp_after:wN \@@_parse_expand:w \fi: } \cs_new:Npn \@@_parse_infix_comma:w #1 @ { #1 @ \use_none:n } - \cs_new:Npn \@@_parse_infix_comma_gobble:w #1 @ + \cs_new:Npn \@@_parse_infix_comma_error:w #1 \exp:w { + \fi: \__msg_kernel_expandable_error:nn { kernel } { fp-extra-comma } - @ \use_none:n + \exp_after:wN @ + \exp_after:wN \@@_parse_apply_binary:NwNwN + \exp_after:wN , + \exp:w + } + \cs_new:Npn \@@_,_o:ww #1 + { + \if_meaning:w \s_@@ #1 + \exp_after:wN \@@_use_i_until_s:nw + \exp_after:wN \@@_,_o:ww + \fi: + \exp_after:wN \c_nan_fp + #1 } \group_end: % \end{macrocode} % \end{macro} +% \end{macro} +% \end{macro} % % \subsubsection{Usual infix operators} % @@ -2367,13 +2389,13 @@ \fi: } } - \@@_tmp:w \@@_parse_infix_^:N ^ \c_fifteen \c_fourteen - \@@_tmp:w \@@_parse_infix_/:N / \c_ten \c_ten - \@@_tmp:w \@@_parse_infix_mul:N * \c_ten \c_ten - \@@_tmp:w \@@_parse_infix_-:N - \c_nine \c_nine - \@@_tmp:w \@@_parse_infix_+:N + \c_nine \c_nine - \@@_tmp:w \@@_parse_infix_and:N & \c_five \c_five - \@@_tmp:w \@@_parse_infix_or:N | \c_four \c_four + \@@_tmp:w \@@_parse_infix_^:N ^ \c_@@_prec_hatii_int \c_@@_prec_hat_int + \@@_tmp:w \@@_parse_infix_/:N / \c_@@_prec_times_int \c_@@_prec_times_int + \@@_tmp:w \@@_parse_infix_mul:N * \c_@@_prec_times_int \c_@@_prec_times_int + \@@_tmp:w \@@_parse_infix_-:N - \c_@@_prec_plus_int \c_@@_prec_plus_int + \@@_tmp:w \@@_parse_infix_+:N + \c_@@_prec_plus_int \c_@@_prec_plus_int + \@@_tmp:w \@@_parse_infix_and:N & \c_@@_prec_and_int \c_@@_prec_and_int + \@@_tmp:w \@@_parse_infix_or:N | \c_@@_prec_or_int \c_@@_prec_or_int \group_end: % \end{macrocode} % \end{macro} @@ -2403,11 +2425,11 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_infix_juxtapose:N #1 { - \if_int_compare:w #1 < \c_ten + \if_int_compare:w #1 < \c_@@_prec_times_int \exp_after:wN @ \exp_after:wN \@@_parse_apply_juxtapose:NwwN \exp:w - \@@_parse_operand:Nw \c_ten + \@@_parse_operand:Nw \c_@@_prec_times_int \exp_after:wN \@@_parse_expand:w \else: \exp_after:wN @ @@ -2493,11 +2515,11 @@ \char_set_catcode_letter:N \? \cs_new:Npn \@@_parse_infix_?:N #1 { - \if_int_compare:w #1 < \c_three + \if_int_compare:w #1 < \c_@@_prec_quest_int \exp_after:wN @ \exp_after:wN \@@_ternary:NwwN \exp:w - \@@_parse_operand:Nw \c_three + \@@_parse_operand:Nw \c_@@_prec_quest_int \exp_after:wN \@@_parse_expand:w \else: \exp_after:wN @ @@ -2507,13 +2529,13 @@ } \cs_new:Npn \@@_parse_infix_::N #1 { - \if_int_compare:w #1 < \c_three + \if_int_compare:w #1 < \c_@@_prec_quest_int \__msg_kernel_expandable_error:nnnn { kernel } { fp-missing } { ? } { ~for~?: } \exp_after:wN @ \exp_after:wN \@@_ternary_auxii:NwwN \exp:w - \@@_parse_operand:Nw \c_two + \@@_parse_operand:Nw \c_@@_prec_colon_int \exp_after:wN \@@_parse_expand:w \else: \exp_after:wN @ @@ -2574,7 +2596,7 @@ } \cs_new:Npn \@@_parse_compare:NNNNNNN #1 { - \if_int_compare:w #1 < \c_seven + \if_int_compare:w #1 < \c_@@_prec_comp_int \exp_after:wN \@@_parse_compare_auxi:NNNNNNN \exp_after:wN \@@_parse_excl_error: \else: @@ -2587,7 +2609,7 @@ { \if_case:w \if_catcode:w \scan_stop: \exp_not:N #7 - \c_minus_one + \c_four \else: \__int_eval:w `#7 - `< \__int_eval_end: \fi: @@ -2620,7 +2642,7 @@ \exp_after:wN #3 \exp_after:wN #4 \exp:w - \@@_parse_operand:Nw \c_seven \@@_parse_expand:w #5 + \@@_parse_operand:Nw \c_@@_prec_comp_int \@@_parse_expand:w #5 } \cs_new:Npn \@@_parse_apply_compare:NwNNNNNwN #1 #2@ #3 #4#5#6#7 #8@ #9 @@ -2677,7 +2699,7 @@ \exp_after:wN \@@_function_apply:nw \exp_after:wN #1 \exp:w - \@@_parse_operand:Nw \c_sixteen \@@_parse_expand:w + \@@_parse_operand:Nw \c_@@_prec_funcii_int \@@_parse_expand:w } % \end{macrocode} % \end{macro} @@ -2713,7 +2735,7 @@ \__int_value:w #3 \exp_after:wN ; \exp_after:wN } \exp:w - \@@_parse_operand:Nw \c_sixteen \@@_parse_expand:w + \@@_parse_operand:Nw \c_@@_prec_funcii_int \@@_parse_expand:w } \cs_new:Npn #2 #4 {#5} } |