texlive[73624] Master/texmf-dist: jsonparse (27jan25)

commits+karl at tug.org commits+karl at tug.org
Tue Jan 28 22:07:41 CET 2025


Revision: 73624
          https://tug.org/svn/texlive?view=revision&revision=73624
Author:   karl
Date:     2025-01-28 22:07:41 +0100 (Tue, 28 Jan 2025)
Log Message:
-----------
jsonparse (27jan25)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/jsonparse/README.md
    trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf
    trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex
    trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty

Modified: trunk/Master/texmf-dist/doc/latex/jsonparse/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/jsonparse/README.md	2025-01-28 21:07:31 UTC (rev 73623)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/README.md	2025-01-28 21:07:41 UTC (rev 73624)
@@ -1,4 +1,4 @@
-![Version 1.0.2](https://img.shields.io/badge/version-1.0.2-blue)
+![Version 1.0.3](https://img.shields.io/badge/version-1.0.3-blue)
 
 ![Jason, the JSON parsing horse](https://github.com/jasperhabicht/jsonparse/assets/6378801/ddfddc70-bf5f-4121-ba45-4b9128875d85)
 

Modified: trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex	2025-01-28 21:07:31 UTC (rev 73623)
+++ trunk/Master/texmf-dist/doc/latex/jsonparse/jsonparse-doc.tex	2025-01-28 21:07:41 UTC (rev 73624)
@@ -11,8 +11,8 @@
 % This work has the LPPL maintenance status `maintained'.
 %
 \documentclass[a4paper]{article}
-\def\jsonparsefileversion{1.0.2}
-\def\jsonparsefiledate{23 January 2025}
+\def\jsonparsefileversion{1.0.3}
+\def\jsonparsefiledate{26 January 2025}
 
 \usepackage[T1]{fontenc}
 \usepackage{Alegreya}
@@ -187,7 +187,7 @@
     [The jsonparse package]
     {The \titlemacro{jsonparse} package}
     {A handy way to parse, store and access JSON data from files or strings in LaTeX documents}
-    {Jasper Habicht}[E-mail: \href{mailto:mail at jasperhabicht.de}{mail at jasperhabicht.de}. I am grateful to Joseph Wright, Jonathan P. Spratte and David Carlisle who helped me navigating the peculiarities of TeX and optimizing the code. Jason, the JSON parsing horse: Copyright 2024 Hannah Klöber.]
+    {Jasper Habicht}[E-mail: \href{mailto:mail at jasperhabicht.de}{mail at jasperhabicht.de}. I am grateful to Joseph Wright, Jonathan P. Spratte and David Carlisle who helped me navigating the peculiarities of TeX and optimizing the code. Jason, the JSON parsing horse: \textcopyright{} 2024--2025 Hannah Klöber.]
     {Version \jsonparsefileversion, released on \jsonparsefiledate}
 
 \changes{v0.3.0}{2024/04/08}{First public beta release.}
@@ -217,6 +217,7 @@
 \changes{v1.0.0}{2025/01/20}{Streamlining of code, unification of command structure.}
 \changes{v1.0.1}{2025/01/21}{Fixes in documentation. Added user command for filtering.}
 \changes{v1.0.2}{2025/01/23}{Support for Unicode surrogate pairs.}
+\changes{v1.0.3}{2025/01/26}{Test for valid JSON numbers expandable.}
 
 \begin{document}
 \vspace*{-1cm}
@@ -232,7 +233,7 @@
 
 The \macro{jsonparse} package provides a handy way to read in JSON data from files or strings in LaTeX documents, parse the data and store it in a user-defined token variable. The package allows accessing the stored data via a JavaScript-flavored syntax.
 
-This package is still in a beta stage and not thoroughly tested. Bugs or improvements can be issued via GitHub at \url{https://github.com/jasperhabicht/jsonparse/issues}.
+The package has been tested, but not exhaustively. The author is grateful for reporting any bugs via GitHub at \url{https://github.com/jasperhabicht/jsonparse/issues}. A site for asking questions about how to use the package and for suggestions for improvement is available at \url{https://github.com/jasperhabicht/jsonparse/discussions}.  
 
 \section{Loading the package}
 
@@ -257,7 +258,7 @@
 
 Similarly, the control symbol \macro{\/} expands eventually to \macro{/} and \macro{\\} to \macro{\c_backslash_str} (i.\,e. a backslash with category code 12).
 
-The escape sequence \macro{\u} followed by a hex value consisting of four digits eventually expands to \macro{\codepoint_generate:nn} that creates the character represented by the relevant four hex digits with category code 12 (``other''). If two escape sequences \macro{\u} wit four hex digits each follow each other and together represent a Unicode surrogate pair, this surrogate pair is converted into the relevant Unicode codepoint.
+The escape sequence \macro{\u} followed by a hex value consisting of four digits eventually expands to \macro{\codepoint_generate:nn} that creates the character represented by the relevant four hex digits with category code 12 (``other''). If two escape sequences \macro{\u} with four hex digits each follow each other and together represent a Unicode surrogate pair, this surrogate pair is converted into the relevant Unicode codepoint.
 
 The JSON escape sequences \macro{\b}, \macro{\f}, \macro{\n}, \macro{\r} and \macro{\t} eventually expand to token variables of which the contents can be set using the relevant \macro{replacement} key. See more on setting options below in section \ref{sec:options}.
 
@@ -641,9 +642,12 @@
 |\jsonparse_if_num:nTF| {<string>} {<true code>} {<false code>}
 |\jsonparse_if_num:nT| {<string>} {<true code>}
 |\jsonparse_if_num:nF| {<string>} {<false code>}
+|\jsonparse_if_num_p:n| {<string>}
 \end{macrodef}
-The command \macro{\jsonparse_if_num:nTF} checks whether a string is a valid JSON number according the relevant specification. It executes the true code if the string is a valid JSON number and the false code if not. The variants \macro{\jsonparse_if_num:nT} and \macro{\jsonparse_if_num:nF} work accordingly.
+The command \macro{\jsonparse_if_num:nTF} checks whether a string is a valid JSON number according the relevant specification. It executes the true code if the string is a valid JSON number and the false code if not. The variants \macro{\jsonparse_if_num:nT} and \macro{\jsonparse_if_num:nF} work accordingly. The command \macro{\jsonparse_if_num_p:n} returns a boolean true or false (i.\,e. \macro{\c_true_bool} or \macro{\c_false_bool}).
 
+This conditional function is fully expandable.
+
 \begin{macrodef}
 |\jsonparse_unicode_if_high_surrogate:nTF| {<codepoint>}
   {<true code>} {<false code>}

Modified: trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2025-01-28 21:07:31 UTC (rev 73623)
+++ trunk/Master/texmf-dist/tex/latex/jsonparse/jsonparse.sty	2025-01-28 21:07:41 UTC (rev 73624)
@@ -10,7 +10,7 @@
 %
 % This work has the LPPL maintenance status `maintained'.
 %
-\ProvidesExplPackage {jsonparse} {2025-01-23} {1.0.2}
+\ProvidesExplPackage {jsonparse} {2025-01-26} {1.0.3}
   {A handy way to parse, store and access JSON data from files or strings in LaTeX documents}
 
 \msg_new:nnn { jsonparse } { old-kernel } {
@@ -364,23 +364,12 @@
 
 % ===
 
-\tl_new:N \l__jsonparse_num_input_tl
-\tl_new:N \l__jsonparse_num_remainder_tl
-\tl_new:N \l__jsonparse_num_input_last_tl
-\bool_new:N \l__jsonparse_num_bool
-\bool_new:N \l__jsonparse_num_zero_seen_bool
-\bool_new:N \l__jsonparse_num_plus_minus_seen_bool
-\bool_new:N \l__jsonparse_num_fraction_seen_bool
-\bool_new:N \l__jsonparse_num_exponent_seen_bool
-
-\clist_const:Nn \c__jsonparse_num_digits_clist {
-  0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
+\clist_const:Nn \c__jsonparse_num_nonzero_digits_clist {
+  1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
 }
 
-\clist_const:Ne \c__jsonparse_num_plus_minus_fraction_clist {
-  \tl_to_str:n { + } ,
-  \tl_to_str:n { - } ,
-  \tl_to_str:n { . }
+\clist_const:Ne \c__jsonparse_num_digits_clist {
+  0 , \c__jsonparse_num_nonzero_digits_clist
 }
 
 \clist_const:Ne \c__jsonparse_num_exponent_clist {
@@ -388,171 +377,190 @@
   \tl_to_str:n { E }
 }
 
-\clist_concat:NNN \c__jsonparse_num_others_clist
-  \c__jsonparse_num_plus_minus_fraction_clist
-  \c__jsonparse_num_exponent_clist
+\clist_const:Ne \c__jsonparse_num_plus_minus_clist {
+  \tl_to_str:n { + } ,
+  \tl_to_str:n { - }
+}
 
-\prg_new_protected_conditional:Npnn \jsonparse_if_num:n #1 { T , F , TF } {
-  \bool_set_true:N \l__jsonparse_num_bool
-  \bool_set_false:N \l__jsonparse_num_zero_seen_bool
-  \bool_set_false:N \l__jsonparse_num_plus_minus_seen_bool
-  \bool_set_false:N \l__jsonparse_num_fraction_seen_bool
-  \bool_set_false:N \l__jsonparse_num_exponent_seen_bool
-  \tl_set:Nn \l__jsonparse_num_remainder_tl { #1 }
-  \tl_if_empty:NTF \l__jsonparse_num_remainder_tl {
-    \bool_set_false:N \l__jsonparse_num_bool
+\prg_new_conditional:Npnn \jsonparse_if_num:n #1 { p , T , F , TF } {
+  \exp_last_unbraced:Ne
+    \__jsonparse_parse_num:w { \tl_to_str:e { \tl_trim_spaces:n {#1} } } \q_stop
+}
+
+\cs_new:Npn \__jsonparse_parse_num:w #1#2 \q_stop {
+  \cs_if_exist_use:cTF { __jsonparse_parse_num_first_ #1 :w } {
+    #2 \q_stop
   } {
-    \__jsonparse_parse_num:n {#1}
+    \prg_return_false:
   }
-  \clist_if_in:NVT \c__jsonparse_num_others_clist \l__jsonparse_num_input_last_tl {
-    \bool_set_false:N \l__jsonparse_num_bool
+}
+
+\cs_new:cpn { __jsonparse_parse_num_first_ - :w } #1 \q_stop {
+  \tl_if_blank:nTF {#1} {
+    \prg_return_false:
+  } {
+    \__jsonparse_parse_num_first_minus:w #1 \q_stop
   }
-  \bool_if:NTF \l__jsonparse_num_bool {
+}
+
+\cs_new:cpn { __jsonparse_parse_num_first_ 0 :w } #1 \q_stop {
+  \tl_if_blank:nTF {#1} {
     \prg_return_true:
   } {
-    \prg_return_false:
+    \__jsonparse_parse_num_first_zero:w #1 \q_stop
   }
 }
 
-\cs_new_protected:Npn \__jsonparse_parse_num:n #1 {
-  \tl_set:Ne \l__jsonparse_num_input_tl { \tl_trim_spaces:e {#1} }
-  \tl_if_empty:NF \l__jsonparse_num_input_tl {
-    \cs_if_exist_use:cTF { __jsonparse_parse_num_ \str_head_ignore_spaces:o { \l__jsonparse_num_input_tl } :w } {
-      \l__jsonparse_num_input_tl \q_stop
+\clist_map_inline:Nn \c__jsonparse_num_nonzero_digits_clist {
+  \cs_new:cpn { __jsonparse_parse_num_first_ #1 :w } ##1 \q_stop {
+    \tl_if_blank:nTF {##1} {
+      \prg_return_true:
     } {
-      \exp_last_unbraced:No
-      \__jsonparse_parse_num_other:w \l__jsonparse_num_input_tl \q_stop
+      \__jsonparse_parse_num_digit:w ##1 \q_stop
     }
   }
 }
 
-\cs_new_protected:cpn { __jsonparse_parse_num_ + :w } #1 \q_stop {
-  \exp_last_unbraced:No
-    \__jsonparse_parse_num_plus_minus:w #1 \q_stop
+\cs_new:Npn \__jsonparse_parse_num_first_minus:w #1#2 \q_stop {
+  \str_if_eq:nnTF {#1} { - } {
+    \prg_return_false:
+  } {
+    \cs_if_exist_use:cTF { __jsonparse_parse_num_first_ #1 :w } {
+      #2 \q_stop
+    } {
+      \prg_return_false:
+    }
+  }
 }
 
-\cs_new_protected:cpn { __jsonparse_parse_num_ - :w } #1 \q_stop {
-  \exp_last_unbraced:No
-    \__jsonparse_parse_num_plus_minus:w #1 \q_stop
+\cs_new:Npn \__jsonparse_parse_num_first_zero:w #1#2 \q_stop {
+  \clist_if_in:NnTF \c__jsonparse_num_digits_clist {#1} {
+    \prg_return_false:
+  } {
+    \cs_if_exist_use:cTF { __jsonparse_parse_num_ #1 :w } {
+      #2 \q_stop
+    } {
+      \prg_return_false:
+    }
+  }
 }
 
-\cs_new_protected:cpn { __jsonparse_parse_num_ . :w } #1 \q_stop {
-  \exp_last_unbraced:No
-    \__jsonparse_parse_num_fraction:w #1 \q_stop
+\cs_new:Npn \__jsonparse_parse_num_digit:w #1#2 \q_stop {
+  \cs_if_exist_use:cTF { __jsonparse_parse_num_ #1 :w } {
+    #2 \q_stop
+  } {
+    \prg_return_false:
+  }
 }
 
-\cs_new_protected:cpn { __jsonparse_parse_num_ e :w } #1 \q_stop {
-  \exp_last_unbraced:No
-    \__jsonparse_parse_num_exponent:w #1 \q_stop
+\cs_new:cpn { __jsonparse_parse_num_ . :w } #1 \q_stop {
+  \tl_if_blank:nTF {#1} {
+    \prg_return_false:
+  } {
+    \__jsonparse_parse_num_fraction:w #1 \q_stop
+  }
 }
 
-\cs_new_protected:cpn { __jsonparse_parse_num_ E :w } #1 \q_stop {
-  \exp_last_unbraced:No
-    \__jsonparse_parse_num_exponent:w #1 \q_stop
+\clist_map_inline:Nn \c__jsonparse_num_exponent_clist {
+  \cs_new:cpn { __jsonparse_parse_num_ #1 :w } ##1 \q_stop {
+    \tl_if_blank:nTF {##1} {
+      \prg_return_false:
+    } {
+      \__jsonparse_parse_num_exponent:w ##1 \q_stop
+    }
+  }
 }
 
 \clist_map_inline:Nn \c__jsonparse_num_digits_clist {
-  \cs_new_protected:cpn { __jsonparse_parse_num_ #1 :w } ##1 \q_stop {
-    \exp_last_unbraced:No
+  \cs_new:cpn { __jsonparse_parse_num_ #1 :w } ##1 \q_stop {
+    \tl_if_blank:nTF {##1} {
+      \prg_return_true:
+    } {
       \__jsonparse_parse_num_digit:w ##1 \q_stop
+    }
   }
 }
 
-\cs_new_protected:Npn \__jsonparse_parse_num_plus_minus:w #1 \q_stop {
-  \bool_if:NTF \l__jsonparse_num_plus_minus_seen_bool {
-    \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-    \bool_set_false:N \l__jsonparse_num_bool
+\cs_new:Npn \__jsonparse_parse_num_fraction:w #1#2 \q_stop {
+  \cs_if_exist_use:cTF { __jsonparse_parse_num_fraction_ #1 :w } {
+    #2 \q_stop
   } {
-    \tl_if_empty:NTF \l__jsonparse_num_input_last_tl {
-      \str_if_eq:enT { \tl_head:n {#1} } { + } {
-        \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-        \bool_set_false:N \l__jsonparse_num_bool
-      }
+    \prg_return_false:
+  }
+}
+
+\clist_map_inline:Nn \c__jsonparse_num_digits_clist {
+  \cs_new:cpn { __jsonparse_parse_num_fraction_ #1 :w } ##1 \q_stop {
+    \tl_if_blank:nTF {##1} {
+      \prg_return_true:
     } {
-      \clist_if_in:NVT \c__jsonparse_num_plus_minus_fraction_clist \l__jsonparse_num_input_last_tl {
-        \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-        \bool_set_false:N \l__jsonparse_num_bool
-      }
+      \__jsonparse_parse_num_fraction_digit:w ##1 \q_stop
     }
   }
-  \bool_set_true:N \l__jsonparse_num_plus_minus_seen_bool
-  \tl_set:Ne \l__jsonparse_num_input_last_tl { \tl_head:n {#1} }
-  \tl_set:Ne \l__jsonparse_num_remainder_tl { \tl_tail:n {#1} }
-  \__jsonparse_parse_num:n { \l__jsonparse_num_remainder_tl }
 }
 
-\cs_new_protected:Npn \__jsonparse_parse_num_fraction:w #1 \q_stop {
-  \bool_if:NTF \l__jsonparse_num_fraction_seen_bool {
-    \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-    \bool_set_false:N \l__jsonparse_num_bool
+\cs_new:Npn \__jsonparse_parse_num_fraction_digit:w #1#2 \q_stop {
+  \clist_if_in:NnTF \c__jsonparse_num_exponent_clist {#1} {
+    \__jsonparse_parse_num_exponent:w #2 \q_stop
   } {
-    \tl_if_empty:NTF \l__jsonparse_num_input_last_tl {
-      \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-      \bool_set_false:N \l__jsonparse_num_bool
+    \cs_if_exist_use:cTF { __jsonparse_parse_num_fraction_ #1 :w } {
+      #2 \q_stop
     } {
-      \clist_if_in:NVT \c__jsonparse_num_others_clist \l__jsonparse_num_input_last_tl {
-        \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-        \bool_set_false:N \l__jsonparse_num_bool
-      }
+      \prg_return_false:
     }
   }
-  \bool_set_false:N \l__jsonparse_num_zero_seen_bool
-  \bool_set_true:N \l__jsonparse_num_plus_minus_seen_bool
-  \bool_set_true:N \l__jsonparse_num_fraction_seen_bool
-  \tl_set:Ne \l__jsonparse_num_input_last_tl { \tl_head:n {#1} }
-  \tl_set:Ne \l__jsonparse_num_remainder_tl { \tl_tail:n {#1} }
-  \__jsonparse_parse_num:n { \l__jsonparse_num_remainder_tl }
 }
 
-\cs_new_protected:Npn \__jsonparse_parse_num_exponent:w #1 \q_stop {
-  \bool_if:NTF \l__jsonparse_num_exponent_seen_bool {
-    \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-    \bool_set_false:N \l__jsonparse_num_bool
+\cs_new:Npn \__jsonparse_parse_num_exponent:w #1#2 \q_stop {
+  \cs_if_exist_use:cTF { __jsonparse_parse_num_exponent_ #1 :w } {
+    #2 \q_stop
   } {
-    \tl_if_empty:NTF \l__jsonparse_num_input_last_tl {
-      \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-      \bool_set_false:N \l__jsonparse_num_bool
+    \prg_return_false:
+  }
+}
+
+\clist_map_inline:Nn \c__jsonparse_num_plus_minus_clist {
+  \cs_new:cpn { __jsonparse_parse_num_exponent_ #1 :w } ##1 \q_stop {
+    \tl_if_blank:nTF {##1} {
+      \prg_return_false:
     } {
-      \clist_if_in:NVT \c__jsonparse_num_others_clist \l__jsonparse_num_input_last_tl {
-        \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-        \bool_set_false:N \l__jsonparse_num_bool
-      }
+      \__jsonparse_parse_num_exponent_plus_minus:w ##1 \q_stop
     }
   }
-  \bool_set_false:N \l__jsonparse_num_zero_seen_bool
-  \bool_set_false:N \l__jsonparse_num_plus_minus_seen_bool
-  \bool_set_true:N \l__jsonparse_num_fraction_seen_bool
-  \bool_set_true:N \l__jsonparse_num_exponent_seen_bool
-  \tl_set:Ne \l__jsonparse_num_input_last_tl { \tl_head:n {#1} }
-  \tl_set:Ne \l__jsonparse_num_remainder_tl { \tl_tail:n {#1} }
-  \__jsonparse_parse_num:n { \l__jsonparse_num_remainder_tl }
 }
 
-\cs_new_protected:Npn \__jsonparse_parse_num_digit:w #1 \q_stop {
-  \bool_lazy_any:nTF {
-    { \tl_if_empty_p:N \l__jsonparse_num_input_last_tl }
-    { \bool_lazy_and_p:nn
-      { \str_if_eq_p:Vn \l__jsonparse_num_input_last_tl { - } }
-      { \bool_not_p:n { \l__jsonparse_num_exponent_seen_bool } }
-    }
+\cs_new:Npn \__jsonparse_parse_num_exponent_plus_minus:w #1#2 \q_stop {
+  \clist_if_in:NnTF \c__jsonparse_num_plus_minus_clist {#1} {
+    \prg_return_false:
   } {
-    \str_if_eq:enT { \tl_head:n {#1} } { 0 } {
-      \bool_set_true:N \l__jsonparse_num_zero_seen_bool
+    \cs_if_exist_use:cTF { __jsonparse_parse_num_exponent_ #1 :w } {
+      #2 \q_stop
+    } {
+      \prg_return_false:
     }
-  } {
-    \bool_if:NT \l__jsonparse_num_zero_seen_bool {
-      \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-      \bool_set_false:N \l__jsonparse_num_bool
+  }
+}
+
+\clist_map_inline:Nn \c__jsonparse_num_digits_clist {
+  \cs_new:cpn { __jsonparse_parse_num_exponent_ #1 :w } ##1 \q_stop {
+    \tl_if_blank:nTF {##1} {
+      \prg_return_true:
+    } {
+      \__jsonparse_parse_num_exponent_digit:w ##1 \q_stop
     }
   }
-  \tl_set:Ne \l__jsonparse_num_input_last_tl { \tl_head:n {#1} }
-  \tl_set:Ne \l__jsonparse_num_remainder_tl { \tl_tail:n {#1} }
-  \__jsonparse_parse_num:n { \l__jsonparse_num_remainder_tl }
 }
 
-\cs_new_protected:Npn \__jsonparse_parse_num_other:w #1 \q_stop {
-  \tl_set:Nn \l__jsonparse_num_remainder_tl { }
-  \bool_set_false:N \l__jsonparse_num_bool
+\cs_new:Npn \__jsonparse_parse_num_exponent_digit:w #1#2 \q_stop {
+  \clist_if_in:NnTF \c__jsonparse_num_plus_minus_clist {#1} {
+    \prg_return_false:
+  } {
+    \cs_if_exist_use:cTF { __jsonparse_parse_num_exponent_ #1 :w } {
+      #2 \q_stop
+    } {
+      \prg_return_false:
+    }
+  }
 }
 
 % ===



More information about the tex-live-commits mailing list.