diff options
Diffstat (limited to 'macros/latex/contrib/jsonparse')
-rw-r--r-- | macros/latex/contrib/jsonparse/README.md | 7 | ||||
-rw-r--r-- | macros/latex/contrib/jsonparse/jason/jason.pdf | bin | 214713 -> 3965 bytes | |||
-rw-r--r-- | macros/latex/contrib/jsonparse/jason/jason.svg | 87 | ||||
-rw-r--r-- | macros/latex/contrib/jsonparse/jason/jason.tex | 293 | ||||
-rw-r--r-- | macros/latex/contrib/jsonparse/jsonparse-doc.pdf | bin | 578489 -> 488017 bytes | |||
-rw-r--r-- | macros/latex/contrib/jsonparse/jsonparse-doc.tex | 237 | ||||
-rw-r--r-- | macros/latex/contrib/jsonparse/jsonparse.sty | 1015 |
7 files changed, 1226 insertions, 413 deletions
diff --git a/macros/latex/contrib/jsonparse/README.md b/macros/latex/contrib/jsonparse/README.md index 69258570db..4b4843424e 100644 --- a/macros/latex/contrib/jsonparse/README.md +++ b/macros/latex/contrib/jsonparse/README.md @@ -1,6 +1,6 @@ -![Version 0.8.3](https://img.shields.io/badge/version-0.8.3-blue) +![Version 0.9.7](https://img.shields.io/badge/version-0.9.7-blue) -![Jason, the JSON parsing horse](https://github.com/jasperhabicht/jsonparse/assets/6378801/d6abde3a-fa12-4b63-a213-ad8332e32199) +![Jason, the JSON parsing horse](https://github.com/jasperhabicht/jsonparse/assets/6378801/ddfddc70-bf5f-4121-ba45-4b9128875d85) # The `jsonparse` package @@ -46,5 +46,4 @@ We can store it in the token variable `\myJSONdata` using the command `\JSONPars This package including all files is subject to the LPPL 1.3c license. Copyright 2024 Jasper Habicht (mail(at)jasperhabicht.de). -Jason, the JSON parseing horse: Copyright 2024 Hannah Klöber. - +Jason, the JSON parsing horse: Copyright 2024 Hannah Klöber. diff --git a/macros/latex/contrib/jsonparse/jason/jason.pdf b/macros/latex/contrib/jsonparse/jason/jason.pdf Binary files differindex 324458e684..cb44f20d12 100644 --- a/macros/latex/contrib/jsonparse/jason/jason.pdf +++ b/macros/latex/contrib/jsonparse/jason/jason.pdf diff --git a/macros/latex/contrib/jsonparse/jason/jason.svg b/macros/latex/contrib/jsonparse/jason/jason.svg index fe8793dfa8..8499344783 100644 --- a/macros/latex/contrib/jsonparse/jason/jason.svg +++ b/macros/latex/contrib/jsonparse/jason/jason.svg @@ -1,67 +1,24 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Generator: Adobe Illustrator 16.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" - width="250px" height="250px" viewBox="0 0 450 450" enable-background="new 0 0 449.5 435" xml:space="preserve"> -<circle fill="#3FA9F5" cx="239" cy="226" r="206.166"/> -<g> - <defs> - <circle id="SVGID_1_" cx="239" cy="226" r="206.166"/> - </defs> - <clipPath id="SVGID_2_"> - <use xlink:href="#SVGID_1_" overflow="visible"/> - </clipPath> - <path clip-path="url(#SVGID_2_)" fill="#C69C6D" d="M418.334,389.667c0,0-10.334-12.333-36-86.667S344,189.333,333.667,163 - c-5.552-14.149-12.545-22.326-17.83-26.869c7.769-5.957,15.778-13.185,19.83-20.131c6.902-11.834,11.667-24.5,15.667-38.5 - C353.731,69.108,361,63.333,361,63.333s-55-13-78.666,29.5c-1.534,2.754-3.036,5.383-4.538,7.892l-125.587,25.33 - C141.705,137.165,130.648,151.436,126,166c-4.127,12.93-11.333,16-26.333,28s-47.398,43.774-47.398,43.774l12.106,48.851 - l56.113,69.247c13.436-9.009,28.206-20.065,46.512-27.122c13.874-5.348,33.133-8.479,51.113-12.082 - c2.555,6.323,8.828,23.014,11.387,40.332c3.25,22,4.5,91.5,4.5,91.5L418.334,389.667z"/> - <path clip-path="url(#SVGID_2_)" fill="#F7931E" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M465.5,307.334 - c0,0-9.667-14.833-21.667-21c-11.409-5.863-24.5-7.167-24.5-7.167s2.853-11.646,11.167-22.833C439.667,244,456,233.667,456,233.667 - l-51.499-17.5c0,0,17.166-6.5,25.166-13.833c9.095-8.336,13.333-30,13.333-30s-47.621,2.806-54.333-15.167 - C383.501,143.333,402.001,114,402.001,114s-27.334-6.333-41.167-6.167c-7.572,0.091-15.827,0.876-22.104,2.556 - c-0.978,1.889-1.986,3.764-3.063,5.611c-4.052,6.946-12.062,14.174-19.83,20.131c5.285,4.543,12.278,12.72,17.83,26.869 - c10.333,26.333,23.001,65.666,48.667,140s36,86.667,36,86.667l32.5-36.5c-15.167-3-22.334-20.5-22.334-20.5L465.5,307.334z"/> - <path clip-path="url(#SVGID_2_)" fill="none" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M234,448.5 - c0,0-1.25-69.5-4.5-91.5c-2.559-17.318-8.832-34.009-11.387-40.332c-0.185,0.037-0.369,0.074-0.554,0.111"/> +<?xml version='1.0' encoding='UTF-8'?> +<!-- This file was generated by dvisvgm 3.2.2 --> +<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width="250px" height="250px" viewBox='-70.503905 -70.50391 452.105105 441.67801'> +<defs> +<clipPath id='clip'> +<path d='M361.3402 148.0117C361.3402 261.4457 269.3832 353.4067 155.9452 353.4067C42.5082 353.4067-49.4531 261.4457-49.4531 148.0117C-49.4531 34.5747 42.5082-57.3867 155.9452-57.3867C269.3832-57.3867 361.3402 34.5747 361.3402 148.0117Z'/> +</clipPath> +</defs> +<g id='page1'> +<path d='M361.3402 148.0117C361.3402 261.4457 269.3832 353.4067 155.9452 353.4067C42.5082 353.4067-49.4531 261.4457-49.4531 148.0117C-49.4531 34.5747 42.5082-57.3867 155.9452-57.3867C269.3832-57.3867 361.3402 34.5747 361.3402 148.0117Z' fill='#5ba3de'/> +<path d='M334.6092 311.0627C334.6092 311.0627 324.3162 298.7777 298.7422 224.7227C273.1762 150.6637 260.5542 111.4807 250.2582 85.2457C244.7262 71.1487 237.7622 62.9997 232.4962 58.4767C240.2342 52.5387 248.2152 45.3397 252.2502 38.4217C259.1252 26.6289 263.8752 14.0117 267.8592 .0664C270.2462-8.2969 277.4922-14.0508 277.4922-14.0508S222.6952-27 199.1172 15.3398C197.5862 18.0859 196.0942 20.7031 194.5942 23.2031L69.4762 48.4377C59.0122 59.5077 48.0002 73.7227 43.3672 88.2347C39.2542 101.1167 32.0742 104.1757 17.1289 116.1287C2.1875 128.0857-30.0898 159.7387-30.0898 159.7387L-18.0273 208.4097L37.8752 277.3987C51.2622 268.4177 65.9722 257.4067 84.2152 250.3787C98.0352 245.0467 117.2222 241.9297 135.1372 238.3397C137.6832 244.6367 143.9332 261.2657 146.4802 278.5237C149.7192 300.4377 150.9652 369.6797 150.9652 369.6797Z' fill='#ba8d5d' clip-path='url(#clip)'/> +<path d='M381.6012 229.0387C381.6012 229.0387 371.9692 214.2617 360.0122 208.1167C348.6442 202.2777 335.6052 200.9767 335.6052 200.9767S338.4452 189.3747 346.7302 178.2307C355.8592 165.9457 372.1372 155.6447 372.1372 155.6447L320.8282 138.2107C320.8282 138.2107 337.9292 131.7347 345.8982 124.4297C354.9612 116.1247 359.1832 94.5427 359.1832 94.5427S311.7422 97.3397 305.0512 79.4337C299.9062 65.6527 318.3362 36.4297 318.3362 36.4297S291.1012 30.1167 277.3242 30.2847C269.7812 30.3747 261.5542 31.1567 255.3042 32.8277C254.3282 34.7107 253.3242 36.5817 252.2502 38.4217C248.2152 45.3397 240.2342 52.5387 232.4962 58.4767C237.7622 62.9997 244.7262 71.1487 250.2582 85.2457C260.5542 111.4807 273.1762 150.6637 298.7422 224.7227C324.3162 298.7777 334.6092 311.0627 334.6092 311.0627L366.9882 274.6997C351.8752 271.7107 344.7382 254.2777 344.7382 254.2777Z' fill='#f68623' stroke='#512c15' stroke-width='2.9888' stroke-miterlimit='10' clip-path='url(#clip)'/> +<path d='M37.8712 277.3987C51.2622 268.4177 65.9722 257.4067 84.2152 250.3787C108.1682 241.1407 148.2502 238.5427 169.8632 228.6327C191.4762 218.7307 194.1792 185.4067 194.1792 185.4067M150.9652 369.6797C150.9652 369.6797 149.7192 300.4377 146.4802 278.5237C143.9332 261.2657 137.6832 244.6367 135.1332 238.3397C134.9492 238.3747 134.7692 238.4097 134.5862 238.4497M212.7342 71.7967C212.7342 71.7967 242.9532 54.3637 252.2502 38.4217C259.1252 26.6289 263.8752 14.0117 267.8592 .0664C270.2462-8.2969 277.4922-14.0508 277.4922-14.0508S222.6952-27 199.1172 15.3398C197.5862 18.0859 196.0942 20.7031 194.5942 23.2031M69.4762 48.4377C59.0122 59.5077 47.9962 73.7227 43.3672 88.2347C39.2542 101.1167 32.0742 104.1757 17.1289 116.1287C2.1875 128.0857-30.0898 159.7387-30.0898 159.7387' stroke='#512c15' fill='none' stroke-width='2.9888' stroke-miterlimit='10' clip-path='url(#clip)'/> +<path d='M106.4652 1.2266C106.4652 1.2266 105.9652-3.918 96.3322-13.8828C94.6292-15.6484 92.7692-17.0078 90.8672-18.0586C91.1792-11.9961 91.7852-6.9063 92.1642-4.1016C98.3012-4.2969 103.4262-2.5938 106.4652 1.2266Z M96.1722-32.6484C106.4652-33.4766 119.5822-30.9844 125.7222-21.6875C128.7112-24.8398 128.7112-39.9531 128.7112-39.9531S136.2112-20.1836 148.1132-14.75C143.5472-30.8398 127.1132-45.75 120.3282-51.2422C113.3552-56.8906 103.7652-70.50391 103.7652-70.50391S94.8202-59.2109 91.8322-41.6133C91.2892-38.4297 90.9722-35.0938 90.8042-31.7695C92.5002-32.1836 94.2892-32.4961 96.1722-32.6484Z' fill='#ba8d5d' stroke='#512c15' stroke-width='2.9888' stroke-miterlimit='10'/> +<path d='M184.1722-2.2617C173.5472-11.8906 162.4222-13.0547 153.6172-13.3828C138.5702-13.9531 128.7112-39.9531 128.7112-39.9531S128.7112-24.8398 125.7222-21.6875C119.5822-30.9844 106.4652-33.4766 96.1722-32.6484C81.6252-31.4727 72.2622-21.0234 72.2622-21.0234S86.7072-23.8438 96.3322-13.8828C105.9652-3.918 106.4652 1.2266 106.4652 1.2266C99.3242-7.7422 80.7262-5.082 64.4532 6.543C48.1832 18.1602 52.9962 49.3787 52.9962 49.3787S56.6522 36.5937 73.5862 28.7887C80.1332 25.7734 97.4962 25.1367 97.4962 25.1367S72.7582 25.9687 67.9412 54.8597C65.0472 72.2457 71.5942 87.0707 71.5942 87.0707S73.0902 71.6287 87.8672 62.4957C98.1402 56.1487 109.6212 53.1997 109.6212 53.1997C104.4722 57.0157 106.4652 67.9767 106.4652 67.9767S115.4292 52.8667 139.1722 54.3637C169.5392 56.2737 182.0352 44.1877 194.5942 23.2031C194.0432 17.1289 191.9692 4.8008 184.1722-2.2617Z' fill='#f68623' stroke='#512c15' stroke-width='2.9888' stroke-miterlimit='10'/> +<path d='M37.8712 277.3987C46.1912 267.0387 57.7072 251.8637 60.5542 243.9027C68.0272 222.9807 59.3082 213.2657 54.5782 206.0427C49.8442 198.8207 57.8122 194.5857 44.6132 181.8827S-8.9336 190.1017-14.4141 187.6137C-19.8945 185.1207-19.3945 181.8827-20.8906 170.9257C-22.3867 159.9647-28.0469 158.7847-37.3281 159.9647C-49.9297 161.5627-55.7617 184.3747-58.9961 200.0667C-62.23437 215.7577-70.503905 215.5117-68.71094 228.9567C-67.86328 235.3317-64.28125 241.8907-52.8711 244.2927C-53.5937 250.0317-53.8047 257.0317-52.5898 264.6597C-49.4414 284.4727-17.918 294.3787 5.5 292.1247C16.2148 291.0977 26.5742 284.9727 37.8712 277.3987Z' fill='#976d46' stroke='#512c15' stroke-width='2.9888' stroke-miterlimit='10'/> +<path d='M159.6012 113.0977C159.6012 122.6597 150.8982 130.4097 140.1722 130.4097C129.4412 130.4097 120.7462 122.6597 120.7462 113.0977C120.7462 103.5347 129.4412 95.7887 140.1722 95.7887C150.8982 95.7887 159.6012 103.5347 159.6012 113.0977Z' fill='#fff' stroke='#512c15' stroke-width='2.9888' stroke-miterlimit='10'/> +<path d='M146.6482 115.1327C146.6482 118.9847 143.1172 122.1097 138.7622 122.1097C134.4062 122.1097 130.8712 118.9847 130.8712 115.1327C130.8712 111.2817 134.4062 108.1597 138.7622 108.1597C143.1172 108.1597 146.6482 111.2817 146.6482 115.1327Z' fill='#341a13'/> +<path d='M-1.9453 215.2187C-1.9453 215.2187 .4883 211.0157 4.1406 206.1677C8.5508 200.3047 16.4766 195.1837 20.4531 194.8357C27.5508 194.2107 32.6052 195.9337 29.7152 201.4997C26.8281 207.0707 17.3984 212.9567 10.4922 213.8907C3.5781 214.8167-1.9453 215.2187-1.9453 215.2187Z' fill='#341a13'/> +<path d='M-43.0742 245.1407C-43.793 249.6797-44.1641 256.3747-41.0664 260.0897C-36.082 266.0667-26.6211 275.0347-5.1992 262.0817C12.7813 251.2107 35.8402 229.8127 42.7892 223.2227C38.7772 226.3637 28.1367 232.1247 4.0156 231.9457C-22.5469 231.7417-28.8125 244.2577-43.0742 245.1407Z' fill='#fff' stroke='#512c15' stroke-width='2.9888' stroke-miterlimit='10'/> +<path d='M-52.8711 244.2927C-50.918 244.7027-48.7383 244.9997-46.2969 245.1487C-45.1719 245.2107-44.1055 245.2067-43.0742 245.1407' stroke='#512c15' fill='none' stroke-width='2.9888' stroke-miterlimit='10'/> +<path d='M25.7773 230.1017C9.6211 238.6997-18.1562 252.9177-25.7695 253.2777C-33.0273 253.6167-39.2852 248.5467-42.6719 245.1057C-42.8047 245.1167-42.9375 245.1287-43.0742 245.1407' stroke='#512c15' fill='none' stroke-width='2.9888' stroke-miterlimit='10'/> </g> -<path fill="#F7931E" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M267.334,75.167 - C256.668,65.5,245.5,64.333,236.667,64c-15.107-0.57-25-26.667-25-26.667s0,15.167-3,18.333c-6.167-9.333-19.333-11.833-29.667-11 - c-14.596,1.177-24,11.667-24,11.667s14.5-2.833,24.167,7.167c9.667,10,10.167,15.167,10.167,15.167 - c-7.167-9-25.834-6.334-42.167,5.333s-11.5,43-11.5,43s3.667-12.833,20.667-20.667c6.572-3.028,24-3.667,24-3.667 - S155.5,103.5,150.667,132.5c-2.909,17.455,3.667,32.333,3.667,32.333s1.5-15.5,16.333-24.667c10.31-6.371,21.833-9.333,21.833-9.333 - c-5.167,3.833-3.166,14.833-3.166,14.833s9-15.167,32.833-13.667c30.479,1.918,43.022-10.208,55.629-31.275 - C277.24,94.63,275.157,82.257,267.334,75.167z"/> -<path fill="#A67C52" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M120.487,355.872 - c8.348-10.395,19.908-25.626,22.763-33.622c7.5-21-1.25-30.75-6-38s3.25-11.5-10-24.25S73.5,268.25,68,265.75S63,260,61.5,249 - s-7.183-12.182-16.5-11c-12.646,1.604-18.5,24.5-21.75,40.25s-11.549,15.507-9.75,29c0.854,6.402,4.447,12.983,15.898,15.396 - c-0.721,5.758-0.935,12.787,0.283,20.442c3.164,19.888,34.804,29.832,58.308,27.572C98.749,369.626,109.143,363.479,120.487,355.872 - z"/> -<path fill="#C69C6D" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M189.334,78.667c0,0-0.5-5.167-10.167-15.167 - c-1.713-1.772-3.58-3.135-5.489-4.188c0.317,6.082,0.921,11.189,1.303,14.006C181.138,73.124,186.281,74.833,189.334,78.667z"/> -<path fill="#C69C6D" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M179,44.667c10.334-0.833,23.5,1.667,29.667,11 - c3-3.167,3-18.333,3-18.333s7.525,19.843,19.471,25.298c-4.58-16.15-21.08-31.12-27.888-36.632 - c-7-5.667-16.625-19.333-16.625-19.333s-8.979,11.333-11.979,29c-0.542,3.195-0.864,6.542-1.031,9.882 - C175.318,45.129,177.115,44.819,179,44.667z"/> -<ellipse fill="#FFFFFF" stroke="#603813" stroke-width="3" stroke-miterlimit="10" cx="223.167" cy="190.959" rx="19.5" ry="17.375"/> -<ellipse fill="#42210B" cx="221.751" cy="193" rx="7.917" ry="7"/> -<path fill="#603813" d="M80.519,293.464c0,0,2.443-4.219,6.106-9.089C91.052,278.49,99.007,273.351,103,273 - c7.125-0.625,12.198,1.105,9.299,6.695S99.936,291.193,93,292.125S80.519,293.464,80.519,293.464z"/> -<path fill="none" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M296,149.5c0,0,30.334-17.5,39.667-33.5 - c6.902-11.834,11.667-24.5,15.667-38.5C353.731,69.108,361,63.333,361,63.333s-55-13-78.666,29.5 - c-1.534,2.754-3.036,5.383-4.538,7.892"/> -<path fill="none" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M120.488,355.872 - c13.437-9.009,28.207-20.065,46.512-27.122c24.045-9.269,64.273-11.878,85.969-21.821s24.408-43.392,24.408-43.392"/> -<path fill="#FFFFFF" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M127.5,299.5c0,0-0.749,0.729-2.083,1.995 - C126.919,300.316,127.5,299.5,127.5,299.5z"/> -<path fill="#FFFFFF" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M39.236,323.495 - c-0.724,4.556-1.093,11.276,2.014,15.005c5,6,14.5,15,36,2c18.048-10.912,41.196-32.388,48.167-39.005 - c-4.023,3.157-14.707,8.937-38.917,8.755C59.839,310.05,53.549,322.611,39.236,323.495z"/> -<path fill="none" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M29.398,322.646c1.963,0.413,4.15,0.708,6.602,0.854 - c1.129,0.067,2.202,0.06,3.236-0.005"/> -<path fill="none" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M108.345,308.401 - c-16.22,8.63-44.097,22.899-51.74,23.26c-7.288,0.344-13.568-4.744-16.966-8.201c-0.135,0.01-0.266,0.026-0.403,0.035"/> -<path fill="none" stroke="#603813" stroke-width="3" stroke-miterlimit="10" d="M152.209,126.056 - C141.705,137.165,130.648,151.436,126,166c-4.126,12.93-11.333,16-26.333,28s-47.398,43.774-47.398,43.774"/> </svg> diff --git a/macros/latex/contrib/jsonparse/jason/jason.tex b/macros/latex/contrib/jsonparse/jason/jason.tex new file mode 100644 index 0000000000..c3eaa6294d --- /dev/null +++ b/macros/latex/contrib/jsonparse/jason/jason.tex @@ -0,0 +1,293 @@ +% File: jason/jason.tex +% Copyright 2024 Jasper Habicht (mail(at)jasperhabicht.de). +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License version 1.3c, +% available at http://www.latex-project.org/lppl/. +% +% This file is part of the `jsonparse' package (The Work in LPPL) +% and all files in that bundle must be distributed together. +% +% This work has the LPPL maintenance status `maintained'. +% +\documentclass{standalone} +\usepackage{l3draw} + +\begin{document} +\ExplSyntaxOn + +\color_set:nnn { color_i } { rgb } { 0.356863 , 0.639216 , 0.870588 } +\color_set:nnn { color_ii } { rgb } { 0.729412 , 0.552941 , 0.364706 } +\color_set:nnn { color_iii } { rgb } { 0.964706 , 0.52549 , 0.137255 } +\color_set:nnn { color_iv } { rgb } { 0.592157 , 0.427451 , 0.27451 } +\color_set:nnn { color_v } { rgb } { 0.317647 , 0.172549 , 0.0823529 } +\color_set:nnn { color_vi } { rgb } { 0.203922 , 0.101961 , 0.0745098 } +\color_set:nnn { color_vii } { rgb } { 1 , 1 , 1 } + +\draw_begin: + +% sky +\cs_new:Npn \__jsonparse_jason_path_i: { + \draw_path_moveto:n { 433.418 , 221.836 } + \draw_path_curveto:nnn { 433.418 , 335.695 } { 341.117 , 428 } { 227.254 , 428 } + \draw_path_curveto:nnn { 113.391 , 428 } { 21.086 , 335.695 } { 21.086 , 221.836 } + \draw_path_curveto:nnn { 21.086 , 107.973 } { 113.391 , 15.668 } { 227.254 , 15.668 } + \draw_path_curveto:nnn { 341.117 , 15.668 } { 433.418 , 107.973 } { 433.418 , 221.836 } + \draw_path_close: +} + +% head +\cs_new:Npn \__jsonparse_jason_path_ii: { + \draw_path_moveto:n { 406.586 , 385.5 } + \draw_path_curveto:nnn { 406.586 , 385.5 } { 396.254 , 373.168 } { 370.586 , 298.836 } + \draw_path_curveto:nnn { 344.922 , 224.5 } { 332.254 , 185.168 } { 321.918 , 158.836 } + \draw_path_curveto:nnn { 316.367 , 144.684 } { 309.375 , 136.508 } { 304.09 , 131.965 } + \draw_path_curveto:nnn { 311.859 , 126.008 } { 319.867 , 118.781 } { 323.918 , 111.836 } + \draw_path_curveto:nnn { 330.82 , 100 } { 335.586 , 87.336 } { 339.586 , 73.336 } + \draw_path_curveto:nnn { 341.984 , 64.941 } { 349.254 , 59.168 } { 349.254 , 59.168 } + \draw_path_curveto:nnn { 349.254 , 59.168 } { 294.254 , 46.168 } { 270.586 , 88.668 } + \draw_path_curveto:nnn { 269.051 , 91.422 } { 267.551 , 94.051 } { 266.047 , 96.559 } + \draw_path_lineto:n { 140.461 , 121.891 } + \draw_path_curveto:nnn { 129.957 , 133 } { 118.902 , 147.27 } { 114.254 , 161.836 } + \draw_path_curveto:nnn { 110.125 , 174.766 } { 102.918 , 177.836 } { 87.918 , 189.836 } + \draw_path_curveto:nnn { 72.918 , 201.836 } { 40.52 , 233.609 } { 40.52 , 233.609 } + \draw_path_lineto:n { 52.629 , 282.461 } + \draw_path_lineto:n { 108.742 , 351.707 } + \draw_path_curveto:nnn { 122.176 , 342.695 } { 136.945 , 331.641 } { 155.254 , 324.586 } + \draw_path_curveto:nnn { 169.125 , 319.234 } { 188.387 , 316.105 } { 206.367 , 312.504 } + \draw_path_curveto:nnn { 208.922 , 318.824 } { 215.195 , 335.516 } { 217.754 , 352.836 } + \draw_path_curveto:nnn { 221.004 , 374.836 } { 222.254 , 444.336 } { 222.254 , 444.336 } + \draw_path_close: +} + +% mane +\cs_new:Npn \__jsonparse_jason_path_iii: { + \draw_path_moveto:n { 453.754 , 303.168 } + \draw_path_curveto:nnn { 453.754 , 303.168 } { 444.086 , 288.336 } { 432.086 , 282.168 } + \draw_path_curveto:nnn { 420.676 , 276.305 } { 407.586 , 275 } { 407.586 , 275 } + \draw_path_curveto:nnn { 407.586 , 275 } { 410.438 , 263.355 } { 418.754 , 252.168 } + \draw_path_curveto:nnn { 427.918 , 239.836 } { 444.254 , 229.5 } { 444.254 , 229.5 } + \draw_path_lineto:n { 392.754 , 212 } + \draw_path_curveto:nnn { 392.754 , 212 } { 409.918 , 205.5 } { 417.918 , 198.168 } + \draw_path_curveto:nnn { 427.016 , 189.832 } { 431.254 , 168.168 } { 431.254 , 168.168 } + \draw_path_curveto:nnn { 431.254 , 168.168 } { 383.633 , 170.973 } { 376.918 , 153 } + \draw_path_curveto:nnn { 371.754 , 139.168 } { 390.254 , 109.836 } { 390.254 , 109.836 } + \draw_path_curveto:nnn { 390.254 , 109.836 } { 362.918 , 103.5 } { 349.086 , 103.668 } + \draw_path_curveto:nnn { 341.516 , 103.758 } { 333.258 , 104.543 } { 326.984 , 106.223 } + \draw_path_curveto:nnn { 326.004 , 108.113 } { 324.996 , 109.988 } { 323.918 , 111.836 } + \draw_path_curveto:nnn { 319.867 , 118.781 } { 311.859 , 126.008 } { 304.09 , 131.965 } + \draw_path_curveto:nnn { 309.375 , 136.508 } { 316.367 , 144.684 } { 321.918 , 158.836 } + \draw_path_curveto:nnn { 332.254 , 185.168 } { 344.922 , 224.5 } { 370.586 , 298.836 } + \draw_path_curveto:nnn { 396.254 , 373.168 } { 406.586 , 385.5 } { 406.586 , 385.5 } + \draw_path_lineto:n { 439.086 , 349 } + \draw_path_curveto:nnn { 423.918 , 346 } { 416.754 , 328.5 } { 416.754 , 328.5 } + \draw_path_close: +} + +% bangs +\cs_new:Npn \__jsonparse_jason_path_iv: { + \draw_path_moveto:n { 255.586 , 71 } + \draw_path_curveto:nnn { 244.922 , 61.336 } { 233.754 , 60.168 } { 224.918 , 59.836 } + \draw_path_curveto:nnn { 209.812 , 59.266 } { 199.918 , 33.168 } { 199.918 , 33.168 } + \draw_path_curveto:nnn { 199.918 , 33.168 } { 199.918 , 48.336 } { 196.918 , 51.5 } + \draw_path_curveto:nnn { 190.754 , 42.168 } { 177.586 , 39.668 } { 167.254 , 40.5 } + \draw_path_curveto:nnn { 152.656 , 41.68 } { 143.254 , 52.168 } { 143.254 , 52.168 } + \draw_path_curveto:nnn { 143.254 , 52.168 } { 157.754 , 49.336 } { 167.418 , 59.336 } + \draw_path_curveto:nnn { 177.086 , 69.336 } { 177.586 , 74.5 } { 177.586 , 74.5 } + \draw_path_curveto:nnn { 170.418 , 65.5 } { 151.754 , 68.168 } { 135.418 , 79.836 } + \draw_path_curveto:nnn { 119.086 , 91.5 } { 123.918 , 122.836 } { 123.918 , 122.836 } + \draw_path_curveto:nnn { 123.918 , 122.836 } { 127.586 , 110 } { 144.586 , 102.168 } + \draw_path_curveto:nnn { 151.156 , 99.141 } { 168.586 , 98.5 } { 168.586 , 98.5 } + \draw_path_curveto:nnn { 168.586 , 98.5 } { 143.754 , 99.336 } { 138.918 , 128.336 } + \draw_path_curveto:nnn { 136.012 , 145.789 } { 142.586 , 160.668 } { 142.586 , 160.668 } + \draw_path_curveto:nnn { 142.586 , 160.668 } { 144.086 , 145.168 } { 158.918 , 136 } + \draw_path_curveto:nnn { 169.23 , 129.629 } { 180.754 , 126.668 } { 180.754 , 126.668 } + \draw_path_curveto:nnn { 175.586 , 130.5 } { 177.586 , 141.5 } { 177.586 , 141.5 } + \draw_path_curveto:nnn { 177.586 , 141.5 } { 186.586 , 126.336 } { 210.418 , 127.836 } + \draw_path_curveto:nnn { 240.898 , 129.754 } { 253.441 , 117.625 } { 266.047 , 96.559 } + \draw_path_curveto:nnn { 265.492 , 90.465 } { 263.41 , 78.09 } { 255.586 , 71 } + \draw_path_close: +} + +% muzzle +\cs_new:Npn \__jsonparse_jason_path_v: { + \draw_path_moveto:n { 108.738 , 351.707 } + \draw_path_curveto:nnn { 117.086 , 341.312 } { 128.648 , 326.078 } { 131.504 , 318.086 } + \draw_path_curveto:nnn { 139.004 , 297.086 } { 130.254 , 287.336 } { 125.504 , 280.086 } + \draw_path_curveto:nnn { 120.754 , 272.836 } { 128.754 , 268.586 } { 115.504 , 255.836 } + \draw_path_curveto:nnn { 102.254 , 243.086 } { 61.754 , 264.086 } { 56.254 , 261.586 } + \draw_path_curveto:nnn { 50.754 , 259.086 } { 51.254 , 255.836 } { 49.754 , 244.836 } + \draw_path_curveto:nnn { 48.254 , 233.836 } { 42.57 , 232.652 } { 33.254 , 233.836 } + \draw_path_curveto:nnn { 20.605 , 235.438 } { 14.754 , 258.336 } { 11.504 , 274.086 } + \draw_path_curveto:nnn { 8.254 , 289.836 } { -0.047 , 289.59 } { 1.754 , 303.086 } + \draw_path_curveto:nnn { 2.605 , 309.484 } { 6.199 , 316.066 } { 17.652 , 318.48 } + \draw_path_curveto:nnn { 16.93 , 324.238 } { 16.715 , 331.266 } { 17.934 , 338.922 } + \draw_path_curveto:nnn { 21.098 , 358.809 } { 52.738 , 368.754 } { 76.242 , 366.492 } + \draw_path_curveto:nnn { 87 , 365.461 } { 97.395 , 359.312 } { 108.738 , 351.707 } + \draw_path_close: +} + +% head outline +\cs_new:Npn \__jsonparse_jason_path_vi: { + \draw_path_moveto:n { 108.738 , 351.707 } + \draw_path_curveto:nnn { 122.176 , 342.695 } { 136.945 , 331.641 } { 155.254 , 324.586 } + \draw_path_curveto:nnn { 179.297 , 315.316 } { 219.527 , 312.707 } { 241.223 , 302.762 } + \draw_path_curveto:nnn { 262.918 , 292.82 } { 265.629 , 259.371 } { 265.629 , 259.371 } + + \draw_path_moveto:n { 222.254 , 444.336 } + \draw_path_curveto:nnn { 222.254 , 444.336 } { 221.004 , 374.836 } { 217.754 , 352.836 } + \draw_path_curveto:nnn { 215.195 , 335.516 } { 208.922 , 318.824 } { 206.363 , 312.504 } + \draw_path_curveto:nnn { 206.18 , 312.539 } { 205.996 , 312.574 } { 205.812 , 312.613 } + + \draw_path_moveto:n { 284.254 , 145.336 } + \draw_path_curveto:nnn { 284.254 , 145.336 } { 314.586 , 127.836 } { 323.918 , 111.836 } + \draw_path_curveto:nnn { 330.82 , 100 } { 335.586 , 87.336 } { 339.586 , 73.336 } + \draw_path_curveto:nnn { 341.984 , 64.941 } { 349.254 , 59.168 } { 349.254 , 59.168 } + \draw_path_curveto:nnn { 349.254 , 59.168 } { 294.254 , 46.168 } { 270.586 , 88.668 } + \draw_path_curveto:nnn { 269.051 , 91.422 } { 267.551 , 94.051 } { 266.047 , 96.559 } + + \draw_path_moveto:n { 140.461 , 121.891 } + \draw_path_curveto:nnn { 129.957 , 133 } { 118.898 , 147.27 } { 114.254 , 161.836 } + \draw_path_curveto:nnn { 110.125 , 174.766 } { 102.918 , 177.836 } { 87.918 , 189.836 } + \draw_path_curveto:nnn { 72.918 , 201.836 } { 40.52 , 233.609 } { 40.52 , 233.609 } +} + +% ear +\cs_new:Npn \__jsonparse_jason_path_vii: { + \draw_path_moveto:n { 177.586 , 74.5 } + \draw_path_curveto:nnn { 177.586 , 74.5 } { 177.086 , 69.336 } { 167.418 , 59.336 } + \draw_path_curveto:nnn { 165.707 , 57.562 } { 163.84 , 56.199 } { 161.93 , 55.145 } + \draw_path_curveto:nnn { 162.246 , 61.227 } { 162.852 , 66.336 } { 163.234 , 69.152 } + \draw_path_curveto:nnn { 169.391 , 68.957 } { 174.535 , 70.668 } { 177.586 , 74.5 } + \draw_path_close: + + \draw_path_moveto:n { 167.254 , 40.5 } + \draw_path_curveto:nnn { 177.586 , 39.668 } { 190.754 , 42.168 } { 196.918 , 51.5 } + \draw_path_curveto:nnn { 199.918 , 48.336 } { 199.918 , 33.168 } { 199.918 , 33.168 } + \draw_path_curveto:nnn { 199.918 , 33.168 } { 207.445 , 53.012 } { 219.391 , 58.465 } + \draw_path_curveto:nnn { 214.809 , 42.316 } { 198.312 , 27.348 } { 191.504 , 21.836 } + \draw_path_curveto:nnn { 184.504 , 16.168 } { 174.879 , 2.5 } { 174.879 , 2.5 } + \draw_path_curveto:nnn { 174.879 , 2.5 } { 165.898 , 13.836 } { 162.898 , 31.5 } + \draw_path_curveto:nnn { 162.355 , 34.695 } { 162.035 , 38.043 } { 161.867 , 41.383 } + \draw_path_curveto:nnn { 163.57 , 40.965 } { 165.367 , 40.652 } { 167.254 , 40.5 } + \draw_path_close: +} + +% eye +\cs_new:Npn \__jsonparse_jason_path_viii: { + \draw_path_moveto:n { 230.922 , 186.793 } + \draw_path_curveto:nnn { 230.922 , 196.391 } { 222.188 , 204.168 } { 211.422 , 204.168 } + \draw_path_curveto:nnn { 200.648 , 204.168 } { 191.922 , 196.391 } { 191.922 , 186.793 } + \draw_path_curveto:nnn { 191.922 , 177.195 } { 200.648 , 169.418 } { 211.422 , 169.418 } + \draw_path_curveto:nnn { 222.188 , 169.418 } { 230.922 , 177.195 } { 230.922 , 186.793 } + \draw_path_close: +} + +% pupil +\cs_new:Npn \__jsonparse_jason_path_ix: { + \draw_path_moveto:n { 217.922 , 188.836 } + \draw_path_curveto:nnn { 217.922 , 192.699 } { 214.375 , 195.836 } { 210.004 , 195.836 } + \draw_path_curveto:nnn { 205.633 , 195.836 } { 202.086 , 192.699 } { 202.086 , 188.836 } + \draw_path_curveto:nnn { 202.086 , 184.969 } { 205.633 , 181.836 } { 210.004 , 181.836 } + \draw_path_curveto:nnn { 214.375 , 181.836 } { 217.922 , 184.969 } { 217.922 , 188.836 } + \draw_path_close: +} + +% nostril +\cs_new:Npn \__jsonparse_jason_path_x: { + \draw_path_moveto:n { 68.77 , 289.297 } + \draw_path_curveto:nnn { 68.77 , 289.297 } { 71.215 , 285.078 } { 74.879 , 280.211 } + \draw_path_curveto:nnn { 79.305 , 274.324 } { 87.262 , 269.184 } { 91.254 , 268.836 } + \draw_path_curveto:nnn { 98.379 , 268.211 } { 103.449 , 269.938 } { 100.551 , 275.527 } + \draw_path_curveto:nnn { 97.652 , 281.117 } { 88.188 , 287.027 } { 81.254 , 287.961 } + \draw_path_curveto:nnn { 74.316 , 288.891 } { 68.77 , 289.297 } { 68.77 , 289.297 } + \draw_path_close: +} + +% mouth +\cs_new:Npn \__jsonparse_jason_path_xi: { + \draw_path_moveto:n { 27.488 , 319.328 } + \draw_path_curveto:nnn { 26.766 , 323.887 } { 26.395 , 330.605 } { 29.504 , 334.336 } + \draw_path_curveto:nnn { 34.504 , 340.336 } { 44.004 , 349.336 } { 65.504 , 336.336 } + \draw_path_curveto:nnn { 83.551 , 325.422 } { 106.699 , 303.945 } { 113.672 , 297.328 } + \draw_path_curveto:nnn { 109.645 , 300.484 } { 98.965 , 306.266 } { 74.754 , 306.086 } + \draw_path_curveto:nnn { 48.09 , 305.883 } { 41.801 , 318.445 } { 27.488 , 319.328 } + \draw_path_close: +} + +% mouth outline +\cs_new:Npn \__jsonparse_jason_path_xii: { + \draw_path_moveto:n { 17.652 , 318.48 } + \draw_path_curveto:nnn { 19.613 , 318.891 } { 21.801 , 319.188 } { 24.254 , 319.336 } + \draw_path_curveto:nnn { 25.383 , 319.402 } { 26.453 , 319.395 } { 27.488 , 319.328 } +} + +% teeth +\cs_new:Npn \__jsonparse_jason_path_xiii: { + \draw_path_moveto:n { 96.598 , 304.234 } + \draw_path_curveto:nnn { 80.379 , 312.863 } { 52.5 , 327.137 } { 44.855 , 327.496 } + \draw_path_curveto:nnn { 37.57 , 327.84 } { 31.289 , 322.75 } { 27.891 , 319.293 } + \draw_path_curveto:nnn { 27.758 , 319.305 } { 27.625 , 319.32 } { 27.488 , 319.328 } +} + +\draw_transform_yscale:n { -1 } +\draw_linewidth:n { 3pt } +\draw_miterlimit:n { 10 } +\color_stroke:n { color_v } + +\draw_scope_begin: + + \color_fill:n { color_i } + \__jsonparse_jason_path_i: + \draw_path_use_clear:n { fill , clip } + + \color_fill:n { color_ii } + \__jsonparse_jason_path_ii: + \draw_path_use_clear:n { fill } + + \color_fill:n { color_iii } + \__jsonparse_jason_path_iii: + \draw_path_use_clear:n { fill , draw } + + \__jsonparse_jason_path_vi: + \draw_path_use_clear:n { draw } + +\draw_scope_end: + +\color_fill:n { color_ii } +\__jsonparse_jason_path_vii: +\draw_path_use_clear:n { fill , draw } + +\color_fill:n { color_iii } +\__jsonparse_jason_path_iv: +\draw_path_use_clear:n { fill , draw } + +\color_fill:n { color_iv } +\__jsonparse_jason_path_v: +\draw_path_use_clear:n { fill , draw } + +\color_fill:n { color_vii } +\__jsonparse_jason_path_viii: +\draw_path_use_clear:n { fill , draw } + +\color_fill:n { color_vi } +\__jsonparse_jason_path_ix: +\draw_path_use_clear:n { fill } + +\__jsonparse_jason_path_x: +\draw_path_use_clear:n { fill } + +\color_fill:n { color_vii } +\__jsonparse_jason_path_xi: +\draw_path_use_clear:n { fill , draw } + +\__jsonparse_jason_path_xii: +\draw_path_use_clear:n { draw } + +\__jsonparse_jason_path_xiii: +\draw_path_use_clear:n { draw } + +\draw_end: + +\ExplSyntaxOff +\end{document}
\ No newline at end of file diff --git a/macros/latex/contrib/jsonparse/jsonparse-doc.pdf b/macros/latex/contrib/jsonparse/jsonparse-doc.pdf Binary files differindex ed7a1dded6..703bb870ea 100644 --- a/macros/latex/contrib/jsonparse/jsonparse-doc.pdf +++ b/macros/latex/contrib/jsonparse/jsonparse-doc.pdf diff --git a/macros/latex/contrib/jsonparse/jsonparse-doc.tex b/macros/latex/contrib/jsonparse/jsonparse-doc.tex index 1cfcde1e18..a700978416 100644 --- a/macros/latex/contrib/jsonparse/jsonparse-doc.tex +++ b/macros/latex/contrib/jsonparse/jsonparse-doc.tex @@ -11,8 +11,8 @@ % This work has the LPPL maintenance status `maintained'. % \documentclass[a4paper]{article} -\def\jsonparsefileversion{0.8.3} -\def\jsonparsefiledate{28 April 2024} +\def\jsonparsefileversion{0.9.7} +\def\jsonparsefiledate{5 November 2024} \usepackage[T1]{fontenc} \usepackage{Alegreya} @@ -193,10 +193,19 @@ \changes{v0.5.7}{2024/04/14}{Bug fixes, key-value option setting added.} \changes{v0.6.0}{2024/04/15}{Bug fixes, renaming of several commands.} \changes{v0.7.0}{2024/04/18}{Renaming and rearranging of keys, escaping of special JSON escape sequences added.} -\changes{v0.7.1}{2024/04/20}{Access to first-level keys of object added.} +\changes{v0.7.1}{2024/04/20}{Access to top-level keys of object added.} \changes{v0.8.0}{2024/04/24}{Internal rewrite, escaping procedures changed.} \changes{v0.8.2}{2024/04/26}{Bug fixes, externalizing parsed data.} \changes{v0.8.3}{2024/04/28}{Escaping of characters with special meaning in TeX.} +\changes{v0.8.5}{2024/05/05}{Enhanced key management.} +\changes{v0.8.6}{2024/05/09}{Bug fix in nesting function.} +\changes{v0.8.7}{2024/08/08}{Corrections in documentation, error messages.} +\changes{v0.9.0}{2024/08/27}{Adaption to updated verbatim tokenization.} +\changes{v0.9.1}{2024/09/21}{Added functions to test for valid JSON numbers.} +\changes{v0.9.3}{2024/10/24}{Fixed a bug that prevented tabs in source from being parsed properly.} +\changes{v0.9.5}{2024/10/27}{Streamlining of code, clarification of explanations in documentation.} +\changes{v0.9.6}{2024/10/31}{Allowing for multiple return values when mapping over arrays.} +\changes{v0.9.7}{2024/11/05}{Streamlining of code, ensuring backward compatibility.} \begin{document} \vspace*{-1cm} @@ -225,20 +234,24 @@ The package does not load any dependencies. \end{macrodef} The package can be loaded with the option \macro{debug}. It will then output to the log file every instance of a string, a boolean (true or false) value, a null value, a number as well as the start and end of every object and the start and end of every array that is found while parsing the JSON string or JSON file. -\section{Escaping and special treatment of the input}\label{sec:escaping} +This key can be set either as package option or using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. + +\section{General remarks of the parsing procedure} -In general, the package reads the JSON source as string, which means that all characters have category code 12 (other), except for spaces which have category code 10 (space). The \macro{\endlinechar} value is set to $-1$. Furthermore, if PDFLaTeX is used, the upper-half of the 8-bit range is set to ``active''. JSON, however, defines a small set of escape sequences and in order to be able to process these, the category code of the backslash is set to 0 (escpape). +In general, the package will read and store the JSON source and data as string, which means that all characters have category code 12 (``other''), except for spaces and (horizontal) tabs which have category code 10 (``space''). The \macro{\endlinechar} value is set to $-1$ which means that linefeeds and carriage returns are ignored by TeX. These settings are in line with the JSON specification of handling whitespace. Furthermore, if PDFLaTeX is used, the upper-half of the 8-bit range is set to ``active''. Additionally, JSON defines a small set of escape sequences and in order to be able to process these, the category code of the backslash is set to 0 (``escape''). -JSON strings cannot contain the two characters \macro{"} and \macro{\}. These two characters need to be escaped with a preceding backslash (\macro{\}). This package therefore redefines locally the TeX control symbols \macro{\"}, \macro{\/}, \macro{\\}, \macro{\b}, \macro{\f}, \macro{\n}, \macro{\r}, \macro{\t} and \macro{\u}. These control symbols are prevented from expanding during parsing. For example, \macro{\"} is first defined as \macro{\exp_not:N \"} and only hen typeset, \macro{\"} is expanded to \macro{"}, which ensures that strings are parsed properly. +\section{Escaping and special treatment of the input}\label{sec:escaping} -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 eventually expands to \macro{\char"} followed by the relevant four hex digits. The JSON escape sequences \macro{\b}, \macro{\f}, \macro{\n}, \macro{\r}, \macro{\t} or \macro{\u} (followed by a hex value) eventually expand to token variables of which the contents can be set using the relevant \macro{replacement} key. See more on setting keys below in section \ref{sec:settings}. +JSON strings cannot contain the two characters \macro{"} and \macro{\}. These two characters need to be escaped with a preceding backslash (\macro{\}). This package therefore redefines locally the TeX control symbols \macro{\"}, \macro{\/}, \macro{\\}, \macro{\b}, \macro{\f}, \macro{\n}, \macro{\r}, \macro{\t} and \macro{\u}. These control symbols are prevented from expanding during parsing. For example, \macro{\"} is first defined as \macro{\exp_not:N \"} and only when typeset, \macro{\"} is expanded to \macro{"}, which ensures that strings are parsed properly. -It is possible to insert TeX macros to the JSON source that will eventually be parsed when typesetting. Backslashes of TeX macros need to be escaped by another backslash. The TeX macros \macro{\"} and \macro{\\} must be escaped twice in the JSON source, so that they become \macro{\\\"} and \macro{\\\\} respectively. +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{\char"} followed by the relevant four hex digits. 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}. + +It is possible to insert TeX macros to the JSON source that will eventually be parsed when typesetting. Backslashes of TeX macros need to be escaped by another backslash. The TeX macros \macro{\"} and \macro{\\} must be escaped twice in the JSON source so that they become \macro{\\\"} and \macro{\\\\} respectively. \begin{macrodef} -|\x|[<token variable name>][<key>] +|\x|{<token variable name>}{<key>} \end{macrodef} -Using the control sequence \macro{\x}, it is possible to nest JSON strings into each other. The control sequence takes two arguments delimited by square brackets. The first argument represents the name of the token variable that holds the parsed JSON data where the inserted JSON string should be taken from. The second argument sets the key that should be selected. The following example shows a simple use case: +Using the control sequence \macro{\x}, it is possible to nest JSON strings into each other. The control sequence takes two arguments delimited by curly braces. The first argument represents the name of the token variable that holds the parsed JSON data where the inserted JSON string should be taken from. The second argument sets the key that should be selected. The following example shows a simple use case: \begin{codeexamplecolumns} \JSONParse{\myJSONdataA}{ @@ -246,49 +259,52 @@ Using the control sequence \macro{\x}, it is possible to nest JSON strings into } \JSONParse{\myJSONdataB}{ - { "d" : \x[myJSONdataA][a] } + { "d" : \x{myJSONdataA}{a} } } \JSONParseValue{\myJSONdataB}{d.b} \end{codeexamplecolumns} +Note that the control sequence \macro{\x} is replaced by the value exactly. Therefore, if the value happens to be a string, the control sequence \macro{\x} should be placed between quotation marks (\macro{"}) in order for the resulting string to be valid JSON. The control sequence \macro{\x} is only available inside the \macro{\JSONParse} command, but not inside the \macro{\JSONParseFromFile} command. + \begin{macrodef} -|escape|={<all>} -|escape|={<none>} -|escape|={<number sign>} -|escape|={<dollar sign>} -|escape|={<percent sign>} -|escape|={<ampersand>} -|escape|={<circumflex accent>} -|escape|={<low line>} -|escape|={<tilde>} +|escape|={all} +|escape|={none} +|escape|={number sign} +|escape|={dollar sign} +|escape|={percent sign} +|escape|={ampersand} +|escape|={circumflex accent} +|escape|={low line} +|escape|={tilde} \end{macrodef} -The key \macro{escape} can be used to convert characters that don't require escaping in JSON but in TeX into their relevant TeX escape sequences. Apart from the backslash and curly braces that need to be escaped anyways, these are the number sign, the dollar sign, the percent sign, the ampersand, the circumflex accent, the low line and the tilde. The characters can be selected individually separated by a comma (for example \macro{escape={dollar sign, circumflex accent, low line}}. With \macro{escape={all}}, all escaping sequences are selected, with \macro{escape={none}}, none is selected. +The key \macro{escape} can be used to convert characters that don't require escaping in JSON but in TeX into the relevant TeX escape sequences. Apart from the backslash and curly braces that need to be escaped anyways, these are the number sign, the dollar sign, the percent sign, the ampersand, the circumflex accent, the low line and the tilde. The characters can be selected individually separated by a comma (for example \macro{escape={dollar sign, circumflex accent, low line}}. With \macro{escape={all}}, all escaping sequences are selected, with \macro{escape={none}}, none is selected. The naming of the relevant characters follows their Unicode names. However, \macro{hash} exists as alias for \macro{number sign}, \macro{dollar} as alias for \macro{dollar sign}, \macro{percent} for \macro{percent sign}, \macro{circumflex} for \macro{circumflex accent} and \macro{underscore} for \macro{low line}. +This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayValues} and \macro{\JSONParseArrayValuesMap}. + \begin{macrodef} -replacement/|backspace|={<string>} -replacement/|formfeed|={<string>} -replacement/|linefeed|={<string>} -replacement/|carriage return|={<string>} -replacement/|horizontal tab|={<string>} +|rescan| +|rescan|={<boolean>} \end{macrodef} -These keys can be used to set the replacement text for the JSON escape sequences \macro{\b} (backspace), \macro{\f} (formfeed), \macro{\n} (linefeed), \macro{\r} (carriage return) and \macro{\t} (horizontal tab). The default replacement string is a space. Only strings can be used as replacement. +The key \macro{rescan} can be used to activate and deactivate rescanning of the output. This key is active per default. Rescanning converts all tokens to their default category codes and TeX control sequences are expanded before typesetting. Further, during the rescanning process, JSON escape sequences are replaced and characters that don't require escaping in JSON but in TeX are replaced by the relevant TeX escape sequences. + +This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayValues} and \macro{\JSONParseArrayValuesMap}. \section{Main user commands} \begin{macrodef} -|\JSONParse|[<file name>]{<token variable>}{<JSON string>} +|\JSONParse|[<options>]{<token variable>}{<JSON string>} \end{macrodef} The command \macro{\JSONParse} is used to parse a JSON string and store the parsed result in a token variable (a property list). The second argument takes the name of the token variable that is created by the command. The third argument takes the JSON string to be parsed. For example, using \macro{\JSONParse{\myJSONdata}{ { "key" : "value" } }}, the relevant JSON string will be parsed and the result stored in the token variable \macro{\myJSONdata} as property list. In this case, the property list only consists of one entry with the key \macro{key} and the value \macro{value}. The command \macro{\JSONParseValue{\myJSONdata}{key}}, for example, can then be used to extract the relevant value from this property list (see the description below). -The first optinal argument can be used to externalize the parsed JSON data to a file. See more on externalization in section \ref{sec:externalizing} below. +The first optional argument can be used to pass options to the command that are then applied locally. \begin{macrodef} -|\JSONParseFromFile|[<file name>]{<token variable>}{<JSON file>} +|\JSONParseFromFile|[<options>]{<token variable>}{<JSON file>} \end{macrodef} The command \macro{\JSONParseFromFile} is used to parse a JSON file and store the parsed result in a token variable (a property list). It works the same way as \macro{\JSONParse}, but instead of a JSON string, it takes as third argument the path to the JSON file relative to the working directory. @@ -298,9 +314,7 @@ The command \macro{\JSONParseFromFile} is used to parse a JSON file and store th The command \macro{\JSONParseKeys} is used to store all top-level keys of a parsed JSON object as array into a token variable. The command takes as first argument the token variable that holds the parsed JSON data. The second argument takes the token variable that is assigned a JSON array containing the top-level keys of the object represented by the token variable in the first argument. The token variable to store the keys as array is created if it does not exist. \begin{macrodef} -|\JSONParseValue|{<token variable>}{<key>} -|\JSONParseValue*|{<token variable>}{<key>} -|\JSONParseExpandableValue|{<token variable>}{<key>} +|\JSONParseValue|[<options>]{<token variable>}{<key>} \end{macrodef} The command \macro{\JSONParseValue} is used to select values from the token variable (property list) that has been created using the commands \macro{\JSONParse} or \macro{\JSONParseFromFile}. The first argument takes the token variable that holds the parsed JSON data. The second argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. @@ -308,15 +322,21 @@ If the JSON string \macro{{ "key" : "value" }} is parsed into the token variable Nested objects and arrays are assigned keys that adhere to JavaScript syntax. For example, if the JSON string \macro{{ "outer_key" : { "inner_key" : "value" } }} is parsed into the token variable \macro{\myJSONdata}, to select the value associated with the key \macro{inner_key}, the command \macro{\JSONParseValue{\myJSONdata}{outer_key.inner_key}} can be used. To give an example for an array, the command \macro{\JSONParseValue{\myJSONdata}{key[0]}} selects the first value of the array associated with the key \macro{key} in the JSON string \macro{{ "key" : [ "one" , "two" ] }}. -The non-starred variant of this command, \macro{\JSONParseValue}, rescans the token list before it is typeset (which means that all category codes that may have been changed before are set to the default values). The starred variant, \macro{\JSONParseValue*}, does not rescan the ouput. The non-starred variants of this and similar commands should therefore not be placed in a \macro{\JSONParse} command. +The first optional argument can be used to pass options to the command, such as \macro{escape} or \macro{rescan}, that are then applied locally. When the option \macro{rescan} is used, the token list is rescanned before it is typeset (which means that all category codes that may have been changed before are set to the default values). This is the default behaviour. If rescanning is not desired, pass the option \macro{rescan=false} to the command. When a key is associated with an object or array, the whole object or array is output as JSON string. The special key \macro{.} (or the string defined using the key \macro{child sep}) returns the whole JSON object as string. -Whole objects or arrays can also be output as JSON string for further use in other macros using the expandable command \macro{\JSONParseExpandableValue}. +The command \macro{\JSONParseValue} is not expandable and can therefore not be used as argument of certain other arguments where expansion is needed. In such cases, the expandable command \macro{\JSONParseExpandableValue} should be used. \begin{macrodef} -|\JSONParseArrayValues|{<token variable>}{<key>}[<subkey>]{<string>} -|\JSONParseArrayValues*|{<token variable>}{<key>}[<subkey>]{<string>} +|\JSONParseExpandableValue|{<token variable>}{<key>} +\end{macrodef} +Whole objects or arrays can be output as JSON string for further use in other macros using the expandable command \macro{\JSONParseExpandableValue}. The value that is returned by this command is typically a string variable where all characters have category code 12 (``other''), except for spaces and (horizontal) tabs that have category code 10 (``space''). This should be kept in mind if string comparisons should be made. A comparison against a token list with the default category codes used by TeX won't work, since letters will have category code 11 (``letter''), but it is possible to use \macro{\detokenize} to set the category codes of the token list in such a way that the comparison works. + +For example, if the JSON string \macro{{ "key" : "value" }} has been parsed into the token variable \macro{\myJSONdata}, the command \macro{\JSONParseExpandableValue{\myJSONdata}{key}} will expand to the exact same token list as \macro{\detokenize{value}} with all characters having category code 12 (``other''). + +\begin{macrodef} +|\JSONParseArrayValues|[<options>]{<token variable>}{<key>}[<subkey>]{<string>} \end{macrodef} The command \macro{\JSONParseArrayValues} is used to select all values from an array from a parsed JSON string or JSON file. The first argument takes the token variable that holds the parsed JSON data. The second argument takes the key to select the relevant entry from the parsed JSON data using JavaScript syntax. The third argument is optional and can be used to pass a subkey, i.\,e. a key that is used to select a value for every item. The last argument takes a string that is inserted between all values when they are typeset. @@ -336,21 +356,20 @@ For example, let us assume the following JSON data structure is parsed into the ] } \end{codeexample} +\JSONParse{\myJSONdata}{ { "array" : [ { "key_a" : "one" , "key_b" : "two" } , { "key_a" : "three" , "key_b" : "four" } ] } } -Then, when using \macro{\JSONParseArrayValues{\myJSONdata}{array}[key_a]{, }}, `one, three' is typeset to the document. +Then, when using \macro{\JSONParseArrayValues{\myJSONdata}{array}[key_a]{, }}, `\JSONParseArrayValues{\myJSONdata}{array}[key_a]{, }' is typeset to the document. -The starred variant, \macro{\JSONParseArrayValues*}, does not rescan the token lists before they are typeset. +The first optional argument can be used to pass options to the command, such as \macro{escape} or \macro{rescan}, that are then applied locally. \begin{macrodef} -|\JSONParseArrayValuesMap|{<token variable>}{<key>}[<subkey>]{<command name>} -|\JSONParseArrayValuesMap*|{<token variable>}{<key>}[<subkey>]{<command name>} +|\JSONParseArrayValuesMap|[<options>]{<token variable>}{<key>}[<subkey>] + {<command name>}[<before code>][<after code>] \end{macrodef} -The command \macro{\JSONParseArrayValuesMap} takes the same first three arguments as the command \macro{\JSONParseArrayValues} and works in a similar way. However, instead of a string that is added between the array items, it takes a command name as fourth argument. This command can be defined beforehand and will be called for every array item. Inside its definition, the commands \macro{\JSONParseArrayIndex}, \macro{\JSONParseArrayKey} and \macro{\JSONParseArrayValue} can be used which are updated for each item and output the index, the key and the value of the current item respectively. +The command \macro{\JSONParseArrayValuesMap} takes the same first three arguments as the command \macro{\JSONParseArrayValues} and works in a similar way. However, instead of a string that is added between the array items, it takes a command name as fourth argument. This command can be defined beforehand and will be called for every array item. Inside its definition, the commands \macro{\JSONParseArrayIndex}, \macro{\JSONParseArrayKey} and \macro{\JSONParseArrayValue} can be used which are updated for each item and output the index, the key and the value of the current item respectively. Note that these commands are defined globally to make accessing them as easy as possible. For example, let us assume the same JSON data structure as defined above parsed into the token variable \macro{\myJSONdata}. Then, the following can be done: -\JSONParse{\myJSONdata}{ { "array" : [ { "key_a" : "one" , "key_b" : "two" } , { "key_a" : "three" , "key_b" : "four" } ] } } - \begin{codeexamplecolumns} \newcommand{\myJSONitem}{ \item \emph{\JSONParseArrayValue} @@ -362,7 +381,41 @@ For example, let us assume the same JSON data structure as defined above parsed \end{itemize} \end{codeexamplecolumns} -The starred variant, \macro{\JSONParseArrayValuesMap*}, does not rescan the token lists before they are typeset. +It is possible to make use of multiple subkeys by passing them as a comma separated list as third argument to the command. Inside the command that is called for every array item, the different keys and values can be access via commands numbered with uppercase Roman numerals such as \macro{\JSONParseArrayKeyI}, \macro{\JSONParseArrayKeyII}, \macro{\JSONParseArrayKeyIII} etc.\ and \macro{\JSONParseArrayValueI}, \macro{\JSONParseArrayValueII}, \macro{\JSONParseArrayValueIII} etc. + +We can extend the above example in the following way: + +\begin{codeexamplecolumns} +\newcommand{\myJSONitem}{ + \item \emph{\JSONParseArrayValueI :} + \JSONParseArrayValueII +} + +\begin{itemize} + \JSONParseArrayValuesMap{\myJSONdata} + {array}[key_a,key_b]{myJSONitem} +\end{itemize} +\end{codeexamplecolumns} + +The command additionally takes two optional arguments at sixth and seventh position. These arguments can be used to place code before and after the output that is generated by the command called for every array item, for example for typesetting tabular contents. + +Typesetting the above example in a tabular way can be achieved as follows: + +\begin{codeexamplecolumns} +\newcommand{\myJSONitem}{ + \JSONParseArrayValueI & + \JSONParseArrayValueII \\ +} + +\JSONParseArrayValuesMap{\myJSONdata} + {array}[key_a,key_b]{myJSONitem} + [\begin{tabular}{ c c } + \textbf{key a} & + \textbf{key b} \\ \hline] + [\hline \end{tabular}] +\end{codeexamplecolumns} + +Finally, the first optional argument of the command can be used to pass options to the command, such as \macro{escape} or \macro{rescan}, that are then applied locally. \begin{macrodef} |\JSONParseArrayCount|{<token variable>}{<key>} @@ -371,46 +424,97 @@ The command \macro{\JSONParseArrayCount} takes as first argument a token variabl \subsection{Externalising parsed JSON data}\label{sec:externalizing} -Parsing large JSON files can take quite a while. In order to speed up follow-up compilation runs, this package provides a way to store parsed JSON data for future use. The first opional argument of the commands \macro{\JSONParse} and \macro{\JSONParseFromFile} can be used to provide the name of a file (without file extension) that will be created in the working directory and which stores the relevant information. The file name will have the extension \macro{.jsonparse}. If a file with the same name and file extension already exists, an error will be issued. Once the file has been created, the package will try to load the data from this file instead of parsing the JSON data again. +Parsing large JSON files can take quite a while. In order to speed up follow-up compilation runs, this package provides a way to store parsed JSON data for future use. Once a file for externalization has been created, the package will try to load the data from this file instead of parsing the JSON data again. + +\begin{macrodef} +|externalize| +|externalize|={<boolean>} +\end{macrodef} +With the key \macro{externalize} set (or set to true), a file will be created in the working directory that stores the externalization of the parsed JSON data. The file name gets the extension \macro{.jsonparse}. The file name is created automatically and consists of the name of the current file followed by an underscore and the name of the token variable where the JSON data is stored into. If a file with the same name and file extension already exists, an error will be issued. + +This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. + +\begin{macrodef} +|externalize prefix|={<string>} +\end{macrodef} +With the key \macro{externalize prefix}, a prefix can be defined that is added to the file name. Per default this is an empty string. + +This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. + +\begin{macrodef} +|externalize file name|={<token list>} +\end{macrodef} +The key \macro{externalize file name} sets the schema for the file name. The default schema is as follows: + +\begin{codeexample} +\l_jsonparse_externalize_prefix_str \c_sys_jobname_str + \c_underscore_str \l_jsonparse_current_prop_str +\end{codeexample} + +The token variable \macro{\l_jsonparse_externalize_prefix_str} contains the prefix that is set using the key \macro{externalize prefix}. \macro{\c_sys_jobname_str} holds the name of the current file (the current job name), \macro{\c_underscore_str} is an underscore and the token variable \macro{\l_jsonparse_current_prop_str} contains the name of the property list where the relevant JSON data is stored into. + +This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. \begin{macrodef} |\JSONParsePut|{<token variable>}{<key>}[<JSON string>] \end{macrodef} The command \macro{\JSONParsePut} is used by the externalization procedure to re-read already parsed JSON data to the main file. It just adds a key-value pair to the property list (where the value part is read as string). Hence, it can also be used to append more entries to an already existing property list containing parsed JSON data. -\subsection{Changing separators, output and other settings}\label{sec:settings} +\subsection{Changing separators, output and other options}\label{sec:options} The package provides a set of keys can be set to change the separators used to select the relevant value in the JSON structure, the output that is generated from the JSON data as well as other things. \begin{macrodef} -|\JSONParseSet|{<key-value list>} +|\JSONParseSet|{<options>} \end{macrodef} -The commands \macro{\JSONParseSet} can be used to specify settings via key-value pairs (separated by commas). Keys that are presented here as a subkey (i.\,e. preceded by another key and a slash) can also be set using the syntax \macro{key={subkey}} and multiple subkeys belonging to one key can be combined using a comma as separator. The following keys are available: +The commands \macro{\JSONParseSet} can be used to specify options via key-value pairs (separated by commas). Keys that are presented here as a subkey (i.\,e. preceded by another key and a slash) can also be set using the syntax \macro{key={subkey}} and multiple subkeys belonging to one key can be combined using a comma as separator. Several user commands allow to pass keys directly which are then applied locally. The following keys are available: \begin{macrodef} separator/|child|={<string>} +separator/|array left|={<string>} +separator/|array right|={<string>} \end{macrodef} -With the key \macro{child sep}, the separator for child objects that is used in the syntax to select a specific value in the JSON data structure can be changed. Per default, the child separator is a dot (\macro{.}). Changing the separator can be useful if keys in the JSON structure already use these characters. +With the key \macro{separator/child}, the separator for child objects that is used in the syntax to select a specific value in the JSON data structure can be changed. Per default, the child separator is a dot (\macro{.}). Changing the separator can be useful if keys in the JSON structure already use these characters. + +With the keys \macro{separator/array left} and \macro{separator/array right}, the separators for arrays that are used in the syntax to select a specific value in the JSON data structure can be changed. Per default, the separators are square brackets (\macro{[} and \macro{]}). Changing the separators can be useful if keys in the JSON structure already use these characters. Changing these separators to curly braces (\macro{{}}) is not supported due to their grouping function in TeX. + +These keys can be set using \macro{\JSONParseSet}. They can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. \begin{macrodef} -separator/|array left|={<string>} -separator/|array right|={<string>} +|zero-based| +|zero-based|={<boolean>} \end{macrodef} -With the keys \macro{array sep left} and \macro{array sep right}, the separators for arrays that are used in the syntax to select a specific value in the JSON data structure can be changed. Per default, the separators are square brackets (\macro{[} and \macro{]}). Changing the separators can be useful if keys in the JSON structure already use these characters. +If set (or explicitly set to \macro{true}), the key \macro{zero-based} sets the numbering of the index of array items to zero-based. If set to false, the indexing starts with one instead. Per default, the package uses zero-based indexing to resemble JavaScript notation. + +This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. \begin{macrodef} -replacement/|true|={<string>} -replacement/|false|={<string>} -replacement/|null|={<string>} +replace/|true|={<string>} +replace/|false|={<string>} +replace/|null|={<string>} \end{macrodef} -With the keys \macro{true}, \macro{false} and \macro{null}, the string that is typeset for true, false and null values can be changed. The default strings that are typeset are \macro{true}, \macro{false} and \macro{null} respectively. Only strings can be used as replacement. +With the keys \macro{replace/true}, \macro{replace/false} and \macro{replace/null}, the string that is typeset for true, false and null values can be changed. The default strings that are typeset are \macro{true}, \macro{false} and \macro{null} respectively. Only strings can be used as replacement. These replacements take place already during parsing. + +These keys can be set using \macro{\JSONParseSet}. They can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. \begin{macrodef} -|array index zero-based| -|array index zero-based|={<boolean>} +replace/|backspace|={<string>} +replace/|formfeed|={<string>} +replace/|linefeed|={<string>} +replace/|carriage return|={<string>} +replace/|horizontal tab|={<string>} \end{macrodef} -If set (or explicitly set to \macro{true}), the key \macro{array index zero-based} sets the numbering of the index of array items to zero-based. If set to false, the indexing starts with one instead. Per default, the package uses zero-based indexing to resemble JavaScript notation. +These keys can be used to set the replacement text for the JSON escape sequences \macro{\b} (backspace), \macro{\f} (formfeed), \macro{\n} (linefeed), \macro{\r} (carriage return) and \macro{\t} (horizontal tab). The default replacement string is a space. Only strings can be used as replacement. These replacements take place only during typesetting. +These keys can be set using \macro{\JSONParseSet}. They can also be set locally as option to the commands \macro{\JSONParseValue}, \macro{\JSONParseArrayValues} and \macro{\JSONParseArrayValuesMap}. +\begin{macrodef} +|check num| +|check num|={<boolean>} +\end{macrodef} +If set to \macro{false}, the key \macro{check num} omits an internal check of numerical expressions against the JSON specification for numbers. Turning off this feature can increase the parsing speed. + +This key can be set using \macro{\JSONParseSet}. It can also be set locally as option to the commands \macro{\JSONParse} and \macro{\JSONParseFromFile}. + \subsection{L3 commands} \begin{macrodef} @@ -428,6 +532,19 @@ The command \macro{\jsonparse_parse_to_prop:Nn} creates the token variable given \end{macrodef} The command \macro{\jsonparse_parse_to_prop:Nn} processes the token variable given as the first arguments as property list and filters it according to the key given as second argument. Filtering means that for every entry in the property list, the key of this entry is compared against the key given to the command. If the key in the property list starts with the given key, the matching part is removed from the key in the property list. If the keys do not match, the entry is completely removed from the property list. +\begin{macrodef} +|\jsonparse_array_count:NN| <token variable> <integer variable> +\end{macrodef} +The command \macro{\jsonparse_array_count:NN} processes the token variable given as the first arguments as property list and, assuming that it is an array, counts its items and stores the result in the integer variable. If the token variable does not expand to a key that represents an array item, that is if the key does not start with the character defined by \macro{separator/array left}, the command will return an error. The command \macro{\JSONParseArrayCount} serves as a wrapper of this command. + +\begin{macrodef} +|\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_p:n} returns a boolean true or false. + % ===== \printchanges diff --git a/macros/latex/contrib/jsonparse/jsonparse.sty b/macros/latex/contrib/jsonparse/jsonparse.sty index 680e89bfca..a477d1d35f 100644 --- a/macros/latex/contrib/jsonparse/jsonparse.sty +++ b/macros/latex/contrib/jsonparse/jsonparse.sty @@ -1,24 +1,25 @@ -% File: jsonparse.sty +% File: jsonparse.sty % Copyright 2024 Jasper Habicht (mail(at)jasperhabicht.de). -% +% % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License version 1.3c, % available at http://www.latex-project.org/lppl/. -% +% % This file is part of the `jsonparse' package (The Work in LPPL) % and all files in that bundle must be distributed together. -% +% % This work has the LPPL maintenance status `maintained'. -% -\ProvidesExplPackage {jsonparse} {2024-04-28} {0.8.3} - {JSON Parse} +% +\ProvidesExplPackage {jsonparse} {2024-11-05} {0.9.7} + {A handy way to parse, store and access JSON data from files or strings in LaTeX documents} \bool_new:N \l__jsonparse_debug_mode_bool -\keys_define:nn { jsonparse } { +\keys_define:nn { jsonparse / global } { debug .bool_set:N = \l__jsonparse_debug_mode_bool , debug .default:n = { true } , + debug .initial:n = { false } } -\ProcessKeyOptions [ jsonparse ] +\ProcessKeyOptions [ jsonparse / global ] \msg_new:nnn { jsonparse } { debug-info } { #1 @@ -27,13 +28,13 @@ \msg_new:nnn { jsonparse } { parsing-error } { \msg_error_text:n { jsonparse } \iow_newline: Could ~ not ~ parse ~ JSON. \iow_newline: - Parsing ~ error ~ at ~ key ~ `#1` ~ with ~ value ~ `#2`. + Parsing ~ error ~ at ~ key ~ `#1` ~ with ~ value ~ `#2`. } \msg_new:nnn { jsonparse } { nested-non-expandable } { \msg_error_text:n { jsonparse } \iow_newline: Nested ~ use ~ of ~ \token_to_str:N \JSONParseValue \c_space_tl not ~ allowed. \iow_newline: - Use ~ \token_to_str:N \JSONParseExpandableValue \c_space_tl instead. + Use ~ \token_to_str:N \JSONParseExpandableValue \c_space_tl instead. } \msg_new:nnn { jsonparse } { file-not-found } { @@ -56,9 +57,14 @@ Escape ~ character ~ #1 ~ not ~ found. } +\msg_new:nnn { jsonparse } { unknown-key } { + \msg_warning_text:n { jsonparse } \iow_newline: + Ignoring ~ unknown ~ key: ~ #1. +} + \msg_new:nnn { jsonparse } { saving-external } { \msg_info_text:n { jsonparse } \iow_newline: - Saving ~ external ~ file: ~ #1. + Saving ~ to ~ external ~ file: ~ #1. } \msg_new:nnn { jsonparse } { loading-external } { @@ -66,15 +72,29 @@ Loading ~ from ~ external ~ file: ~ #1. } +\msg_new:nnn { jsonparse } { not-array-item } { + \msg_info_text:n { jsonparse } \iow_newline: + Key ~ does ~ not ~ represent ~ an ~ array ~ item: ~ #1 +} + % === - + +\str_new:N \l_jsonparse_externalize_prefix_str +\str_new:N \l_jsonparse_current_prop_str + +\tl_new:N \l__jsonparse_externalize_file_name_tl +\tl_new:N \l__jsonparse_externalize_file_data_tl + \str_new:N \l__jsonparse_child_sep_str \str_new:N \l__jsonparse_array_sep_left_str \str_new:N \l__jsonparse_array_sep_right_str \str_new:N \l__jsonparse_true_str \str_new:N \l__jsonparse_false_str \str_new:N \l__jsonparse_null_str -\bool_new:N \l__jsonparse_array_index_zero_based_bool +\bool_new:N \l__jsonparse_zero_based_bool +\bool_new:N \l__jsonparse_check_num_bool +\bool_new:N \l__jsonparse_rescan_bool +\bool_new:N \l__jsonparse_externalize_bool \str_new:N \l__jsonparse_backspace_str \str_new:N \l__jsonparse_formfeed_str @@ -82,59 +102,76 @@ \str_new:N \l__jsonparse_carriage_return_str \str_new:N \l__jsonparse_horizontal_tab_str -\clist_new:N \l__jsonparse_escape_tex_chars_clist -\clist_set:Nn \l__jsonparse_escape_tex_chars_clist { +\clist_new:N \l__jsonparse_unused_keys_clist + +\clist_const:Nn \c__jsonparse_escape_tex_chars_clist { number_sign , - dollar_sign , + dollar_sign , percent_sign , ampersand , - circumflex_accent , - low_line , - tilde + circumflex_accent , + low_line , + tilde } \str_new:N \l__jsonparse_escape_temp_str -\clist_map_inline:Nn \l__jsonparse_escape_tex_chars_clist { +\clist_map_inline:Nn \c__jsonparse_escape_tex_chars_clist { \bool_new:c { l__jsonparse_escape_ #1 _bool } } -\keys_define:nn { jsonparse } { - array ~ index ~ zero-based .bool_set:N = \l__jsonparse_array_index_zero_based_bool , - array ~ index ~ zero-based .default:n = { true } , - array ~ index ~ zero-based .initial:n = { true } , - separator .code:n = { \keys_set:nn { jsonparse / separator } {#1} }, - separator / child .str_set:N = \l__jsonparse_child_sep_str , - separator / child .initial:n = { . } , - separator / array ~ left .str_set:N = \l__jsonparse_array_sep_left_str , - separator / array ~ left .initial:n = { [ } , - separator / array ~ right .str_set:N = \l__jsonparse_array_sep_right_str , - separator / array ~ right .initial:n = { ] } , - replacement .code:n = { \keys_set:nn { jsonparse / replacement } {#1} }, - replacement / true .str_set:N = \l__jsonparse_true_str , - replacement / true .initial:n = { true } , - replacement / false .str_set:N = \l__jsonparse_false_str , - replacement / false .initial:n = { false } , - replacement / null .str_set:N = \l__jsonparse_null_str , - replacement / null .initial:n = { null } , - replacement / backspace .str_set:N = \l__jsonparse_backspace_str , - replacement / backspace .initial:n = { ~ } , - replacement / formfeed .str_set:N = \l__jsonparse_formfeed_str , - replacement / formfeed .initial:n = { ~ } , - replacement / linefeed .str_set:N = \l__jsonparse_linefeed_str , - replacement / linefeed .initial:n = { ~ } , - replacement / carriage ~ return .str_set:N = \l__jsonparse_carriage_return_str , - replacement / carriage ~ return .initial:n = { ~ } , - replacement / horizontal ~ tab .str_set:N = \l__jsonparse_horizontal_tab_str , - replacement / horizontal ~ tab .initial:n = { ~ } , - escape .code:n = { - \str_case:nnF {#1} { +\keys_define:nn { jsonparse / parse } { + externalize .bool_set:N = \l__jsonparse_externalize_bool , + externalize .default:n = { true } , + externalize .initial:n = { false } , + externalize ~ prefix .str_set:N = \l_jsonparse_externalize_prefix_str , + externalize ~ prefix .initial:n = { } , + externalize ~ file ~ name .tl_set:N = \l__jsonparse_externalize_file_name_tl , + externalize ~ file ~ name .initial:n = { + \l_jsonparse_externalize_prefix_str \c_sys_jobname_str \c_underscore_str \l_jsonparse_current_prop_str + } , + separator .code:n = { \keys_set:nn { jsonparse / parse / separator } {#1} } , + separator / child .str_set:N = \l__jsonparse_child_sep_str , + separator / child .initial:n = { . } , + separator / array ~ left .str_set:N = \l__jsonparse_array_sep_left_str , + separator / array ~ left .initial:n = { [ } , + separator / array ~ right .str_set:N = \l__jsonparse_array_sep_right_str , + separator / array ~ right .initial:n = { ] } , + zero-based .bool_set:N = \l__jsonparse_zero_based_bool , + zero-based .default:n = { true } , + zero-based .initial:n = { true } , + check ~ num .bool_set:N = \l__jsonparse_check_num_bool , + check ~ num .default:n = { true } , + check ~ num .initial:n = { true } , + replace .code:n = { \keys_set:nn { jsonparse / parse / replace } {#1} } , + replace / true .str_set:N = \l__jsonparse_true_str , + replace / true .initial:n = { true } , + replace / false .str_set:N = \l__jsonparse_false_str , + replace / false .initial:n = { false } , + replace / null .str_set:N = \l__jsonparse_null_str , + replace / null .initial:n = { null } +} + +\keys_define:nn { jsonparse / typeset } { + replace .code:n = { \keys_set:nn { jsonparse / typeset / replace } {#1} } , + replace / backspace .str_set:N = \l__jsonparse_backspace_str , + replace / backspace .initial:n = { ~ } , + replace / formfeed .str_set:N = \l__jsonparse_formfeed_str , + replace / formfeed .initial:n = { ~ } , + replace / linefeed .str_set:N = \l__jsonparse_linefeed_str , + replace / linefeed .initial:n = { ~ } , + replace / carriage ~ return .str_set:N = \l__jsonparse_carriage_return_str , + replace / carriage ~ return .initial:n = { ~ } , + replace / horizontal ~ tab .str_set:N = \l__jsonparse_horizontal_tab_str , + replace / horizontal ~ tab .initial:n = { ~ } , + escape .code:n = { + \str_case:nnF {#1} { { all } { - \clist_map_inline:Nn \l__jsonparse_escape_tex_chars_clist { + \clist_map_inline:Nn \c__jsonparse_escape_tex_chars_clist { \bool_set_true:c { l__jsonparse_escape_ ##1 _bool } } - } + } { none } { - \clist_map_inline:Nn \l__jsonparse_escape_tex_chars_clist { + \clist_map_inline:Nn \c__jsonparse_escape_tex_chars_clist { \bool_set_false:c { l__jsonparse_escape_ ##1 _bool } } } @@ -145,7 +182,7 @@ \bool_if_exist:cTF { l__jsonparse_escape_ \l__jsonparse_escape_temp_str _bool } { \bool_set_true:c { l__jsonparse_escape_ \l__jsonparse_escape_temp_str _bool } } { - \str_case:nnF {##1} { + \str_case:nnF {##1} { { hash } { \bool_set_true:c { l__jsonparse_escape_number_sign_bool } } @@ -168,19 +205,37 @@ } } } + } , + escape .groups:n = { output } , + rescan .bool_set:N = \l__jsonparse_rescan_bool , + rescan .default:n = { true } , + rescan .initial:n = { true } , + rescan .groups:n = { output } +} + +\cs_new:Npn \__jsonparse_warning_unused_keys: { + \clist_map_inline:Nn \l__jsonparse_unused_keys_clist { + \msg_warning:nne { jsonparse } { unknown-key } { + ##1 + } } } \NewDocumentCommand { \JSONParseSet } { m } { - \keys_set:nn { jsonparse } {#1} + \keys_set_known:nnN { jsonparse / global } {#1} \l__jsonparse_unused_keys_clist + \keys_set_known:noN { jsonparse / parse } { \l__jsonparse_unused_keys_clist } \l__jsonparse_unused_keys_clist + \keys_set_known:noN { jsonparse / typeset } { \l__jsonparse_unused_keys_clist } \l__jsonparse_unused_keys_clist + \__jsonparse_warning_unused_keys: } % === -\cs_if_exist:NF \str_casefold:n { +\cs_if_exist:NF \str_casefold:n { \cs_new:Npn \str_casefold:n { \str_foldcase:n } } +\cs_generate_variant:Nn \file_input:n { e } +\cs_generate_variant:Nn \tl_gset:Nn { Ne , ce } \cs_generate_variant:Nn \tl_gset_rescan:Nnn { Nne } \cs_generate_variant:Nn \tl_range:nnn { nne , nen } \cs_generate_variant:Nn \tl_range:Nnn { Nne , Nen } @@ -193,18 +248,27 @@ \cs_generate_variant:Nn \str_case_e:nn { en } \cs_generate_variant:Nn \str_casefold:n { o } \cs_generate_variant:Nn \str_head_ignore_spaces:n { o } +\cs_generate_variant:Nn \str_set:Nn { Ne } +\cs_generate_variant:Nn \clist_const:Nn { Ne } +\cs_generate_variant:Nn \seq_put_right:Nn { Ne } \cs_generate_variant:Nn \prop_gput:Nnn { Nee } \cs_generate_variant:Nn \prop_item:Nn { Ne , ce } \cs_generate_variant:Nn \prop_put:Nnn { Nen , Nee } +\cs_generate_variant:Nn \keys_set_known:nnN { noN } \cs_generate_variant:Nn \iow_now:Nn { Ne } +\cs_generate_variant:Nn \iow_open:Nn { Ne } \cs_generate_variant:Nn \msg_error:nnn { nno } \cs_generate_variant:Nn \msg_error:nnnn { nnoo } +\cs_generate_variant:Nn \msg_info:nnn { nne } \cs_generate_variant:Nn \msg_log:nnn { nne } +\cs_generate_variant:Nn \msg_warning:nnn { nne } -\prg_generate_conditional_variant:Nnn \tl_if_eq:nn { en } { T } +\prg_generate_conditional_variant:Nnn \file_if_exist:n { e } { T , TF } \prg_generate_conditional_variant:Nnn \tl_if_head_eq_charcode:nN { oN } { T , TF } \prg_generate_conditional_variant:Nnn \tl_if_in:nn { nV } { F } -\prg_generate_conditional_variant:Nnn \str_if_eq:nn { en , eV } { T , TF } +\prg_generate_conditional_variant:Nnn \seq_if_in:Nn { Ne } { F } +\prg_generate_conditional_variant:Nnn \str_if_eq:nn { en , eV } { T , F , TF } +\prg_generate_conditional_variant:Nnn \str_if_eq:nn { Vn } { p } \prop_new:N \g_jsonparse_entries_prop \prop_new:N \l__jsonparse_temp_prop @@ -221,18 +285,30 @@ \int_new:N \l__jsonparse_array_index_int \int_new:N \l__jsonparse_array_count_int -\int_new:N \l__jsonparse_array_count_last_int +\int_new:N \l__jsonparse_array_count_aux_int +\seq_new:N \l__jsonparse_array_count_last_seq + +\str_new:N \l__jsonparse_filter_key_str + +\int_new:N \l__jsonparse_array_keys_index_int +\tl_new:N \l__jsonparse_array_keys_index_roman_tl + +\str_new:N \l__jsonparse_array_values_key_str +\tl_new:N \l__jsonparse_array_values_insert_tl + +\clist_new:N \l__jsonparse_array_map_keys_clist +\str_new:N \l__jsonparse_array_map_function_str \bool_new:N \l__jsonparse_prop_map_first_bool -\bool_new:N \l__jsonparse_load_external_bool +\bool_new:N \l__jsonparse_externalize_load_bool -\ior_new:N \l__jsonparse_json_ior \iow_new:N \g__jsonparse_externalize_iow % === \cctab_const:Nn \c__jsonparse_json_escape_cctab { \cctab_select:N \c_str_cctab + \char_set_catcode_space:n { 9 } \char_set_catcode_escape:n { 92 } \bool_lazy_or:nnF { \sys_if_engine_xetex_p: } { \sys_if_engine_luatex_p: } @@ -241,72 +317,258 @@ % === +\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:Ne \c__jsonparse_num_others_clist { + \tl_to_str:n { + } , + \tl_to_str:n { - } , + \tl_to_str:n { . } , + \tl_to_str:n { e } , + \tl_to_str:n { E } +} + +\prg_new_conditional:Npnn \jsonparse_if_num:n #1 { p , 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 + } { + \__jsonparse_parse_num:n {#1} + } + \clist_if_in:NVT \c__jsonparse_num_others_clist \l__jsonparse_num_input_last_tl { + \bool_set_false:N \l__jsonparse_num_bool + } + \bool_if:NTF \l__jsonparse_num_bool { + \prg_return_true: + } { + \prg_return_false: + } +} + +\cs_new: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 + } { + \exp_last_unbraced:No + \__jsonparse_parse_num_other:w \l__jsonparse_num_input_tl \q_stop + } + } +} + +\cs_new:cpn { __jsonparse_parse_num_ + :w } #1 \q_stop { + \exp_last_unbraced:No + \__jsonparse_parse_num_plus_minus:w #1 \q_stop +} + +\cs_new:cpn { __jsonparse_parse_num_ - :w } #1 \q_stop { + \exp_last_unbraced:No + \__jsonparse_parse_num_plus_minus:w #1 \q_stop +} + +\cs_new:cpn { __jsonparse_parse_num_ . :w } #1 \q_stop { + \exp_last_unbraced:No + \__jsonparse_parse_num_fraction:w #1 \q_stop +} + +\cs_new: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_ E :w } #1 \q_stop { + \exp_last_unbraced:No + \__jsonparse_parse_num_exponent:w #1 \q_stop +} + +\clist_map_inline:Nn \c__jsonparse_num_digits_clist { + \cs_new:cpn { __jsonparse_parse_num_ #1 :w } ##1 \q_stop { + \exp_last_unbraced:No + \__jsonparse_parse_num_digit:w ##1 \q_stop + } +} + +\cs_new: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 + } { + \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 + } + } { + \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 + } + } + } + \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: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 + } { + \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 + } { + \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 + } + } + } + \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: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 + } { + \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 + } { + \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 + } + } + } + \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: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 } } + } + } { + \str_if_eq:enT { \tl_head:n {#1} } { 0 } { + \bool_set_true:N \l__jsonparse_num_zero_seen_bool + } + } { + \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 + } + } + \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: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_protected:Npn \jsonparse_parse_to_prop:Nn #1#2 { \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { - \iow_newline: - Parsing ~ JSON ~ ... - } + \iow_newline: + Parsing ~ JSON ~ ... + } } \prop_gclear:N \g_jsonparse_entries_prop \jsonparse_parse:n {#2} - \prop_gset_eq:NN #1 \g_jsonparse_entries_prop + \prop_gset_eq:NN #1 \g_jsonparse_entries_prop \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { - JSON ~ parsing ~ done. \iow_newline: - } + JSON ~ parsing ~ done. \iow_newline: + } } } \cs_new_protected:Npn \jsonparse_parse:n #1 { \tl_set:Ne \l__jsonparse_input_tl { \tl_trim_spaces:e {#1} } - \cs_if_exist_use:cTF { __jsonparse_parse_ \str_head_ignore_spaces:o { \l__jsonparse_input_tl } :w } { + \cs_if_exist_use:cTF { __jsonparse_parse_ \str_head_ignore_spaces:o { \l__jsonparse_input_tl } :w } { \l__jsonparse_input_tl \q_stop } { % other - \exp_last_unbraced:No - \__jsonparse_parse_other:w \l__jsonparse_input_tl \q_stop + \exp_last_unbraced:No + \__jsonparse_parse_other:w \l__jsonparse_input_tl \q_stop } } % === \cs_new:cpn { __jsonparse_parse_ \c_left_brace_str :w } #1 \q_stop { - \exp_last_unbraced:No + \exp_last_unbraced:No \__jsonparse_parse_object_begin:w #1 \q_stop } \cs_new:cpn { __jsonparse_parse_ \c_right_brace_str :w } #1 \q_stop { - \exp_last_unbraced:No + \exp_last_unbraced:No \__jsonparse_parse_object_end:w #1 \q_stop } \cs_new:cpn { __jsonparse_parse_ [ :w } #1 \q_stop { - \exp_last_unbraced:No + \exp_last_unbraced:No \__jsonparse_parse_array_begin:w #1 \q_stop } \cs_new:cpn { __jsonparse_parse_ ] :w } #1 \q_stop { - \exp_last_unbraced:No + \exp_last_unbraced:No \__jsonparse_parse_array_end:w #1 \q_stop } \cs_new:cpn { __jsonparse_parse_ " :w } #1 \q_stop { - \exp_last_unbraced:No + \exp_last_unbraced:No \__jsonparse_parse_string_key:w #1 \q_stop } \cs_new:Npn \__jsonparse_array_key_set: { - \str_if_eq:eVT { - \tl_range:Nen \l__jsonparse_prefix_tl { - \int_eval:n { - -1 * \tl_count:N \l__jsonparse_array_sep_left_str - } + \str_if_eq:eVT { + \tl_range:Nen \l__jsonparse_prefix_tl { + \int_eval:n { + -1 * \tl_count:N \l__jsonparse_array_sep_left_str + } } { -1 } } \l__jsonparse_array_sep_left_str { \int_incr:N \l__jsonparse_array_index_int - \tl_set:Ne \l__jsonparse_key_tl { - \l__jsonparse_prefix_tl \int_use:N \l__jsonparse_array_index_int \l__jsonparse_array_sep_right_str + \tl_set:Ne \l__jsonparse_key_tl { + \l__jsonparse_prefix_tl \int_use:N \l__jsonparse_array_index_int \l__jsonparse_array_sep_right_str } } } @@ -318,11 +580,11 @@ % object begin \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nnn { jsonparse } { debug-info } { - (obj ~ begin) - } + (obj ~ begin) + } } \tl_if_empty:NTF \l__jsonparse_key_tl { - \tl_set_eq:NN \l__jsonparse_object_array_key_tl \l__jsonparse_child_sep_str + \tl_set_eq:NN \l__jsonparse_object_array_key_tl \l__jsonparse_child_sep_str } { \tl_set_eq:NN \l__jsonparse_object_array_key_tl \l__jsonparse_key_tl \tl_set:Ne \l__jsonparse_prefix_tl { \l__jsonparse_key_tl \l__jsonparse_child_sep_str } @@ -332,27 +594,27 @@ } \exp_last_unbraced:NNo \cs_new:Npn \__jsonparse_parse_object_end:w \c_right_brace_str #1 \q_stop { - \tl_set:Ne \l__jsonparse_object_array_val_tl { + \tl_set:Ne \l__jsonparse_object_array_val_tl { \tl_range:Nne \l__jsonparse_object_array_val_tl { 1 } { \int_eval:n { -1 * \tl_count:n {#1} - 1 } } } - \prop_gput:Nee \g_jsonparse_entries_prop + \prop_gput:Nee \g_jsonparse_entries_prop { \l__jsonparse_object_array_key_tl } { \l__jsonparse_object_array_val_tl } \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { (key) ~ \str_use:N \l__jsonparse_object_array_key_tl : \iow_newline: - \iow_char:N \ \iow_char:N \ (obj) ~ \str_use:N \l__jsonparse_object_array_val_tl - } - } + \iow_char:N \ \iow_char:N \ (obj) ~ \str_use:N \l__jsonparse_object_array_val_tl + } + } \group_end: % object end \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nnn { jsonparse } { debug-info } { - (obj ~ end) - } + (obj ~ end) + } } \tl_set:Nn \l__jsonparse_remainder_tl {#1} \__jsonparse_parse_remainder: @@ -365,11 +627,11 @@ % array begin \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nnn { jsonparse } { debug-info } { - (arr ~ begin) - } + (arr ~ begin) + } } \int_zero:N \l__jsonparse_array_index_int - \bool_if:NT \l__jsonparse_array_index_zero_based_bool { + \bool_if:NT \l__jsonparse_zero_based_bool { \int_decr:N \l__jsonparse_array_index_int } \tl_set_eq:NN \l__jsonparse_object_array_key_tl \l__jsonparse_key_tl @@ -379,27 +641,27 @@ } \cs_new:Npn \__jsonparse_parse_array_end:w ] #1 \q_stop { - \tl_set:Ne \l__jsonparse_object_array_val_tl { + \tl_set:Ne \l__jsonparse_object_array_val_tl { \tl_range:Nne \l__jsonparse_object_array_val_tl { 1 } { \int_eval:n { -1 * \tl_count:n {#1} - 1 } } } - \prop_gput:Nee \g_jsonparse_entries_prop + \prop_gput:Nee \g_jsonparse_entries_prop { \l__jsonparse_object_array_key_tl } { \l__jsonparse_object_array_val_tl } \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { (key) ~ \str_use:N \l__jsonparse_object_array_key_tl : \iow_newline: \iow_char:N \ \iow_char:N \ (arr) ~ \str_use:N \l__jsonparse_object_array_val_tl - } - } + } + } \group_end: % array end \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nnn { jsonparse } { debug-info } { - (arr ~ end) - } + (arr ~ end) + } } \tl_set:Nn \l__jsonparse_remainder_tl {#1} \__jsonparse_parse_remainder: @@ -410,18 +672,18 @@ \tl_set:Ne \l__jsonparse_remainder_tl { \tl_trim_spaces:n {#2} } % key or string? \tl_if_head_eq_charcode:oNTF { \l__jsonparse_remainder_tl } : { - \tl_remove_once:NV \l__jsonparse_remainder_tl \c_colon_str + \tl_remove_once:NV \l__jsonparse_remainder_tl \c_colon_str \tl_set:Ne \l__jsonparse_key_tl { \l__jsonparse_prefix_tl #1 } - } { + } { \tl_set:Nn \l__jsonparse_val_tl {#1} - \prop_gput:Nee \g_jsonparse_entries_prop + \prop_gput:Nee \g_jsonparse_entries_prop { \l__jsonparse_key_tl } { \l__jsonparse_val_tl } % string \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { (key) ~ \str_use:N \l__jsonparse_key_tl : \iow_newline: \iow_char:N \ \iow_char:N \ (str) ~ \str_use:N \l__jsonparse_val_tl - } + } } } \__jsonparse_parse_remainder: @@ -440,28 +702,41 @@ \cs_new:Npn \__jsonparse_parse_other_aux:w #1 , #2 \q_stop { \tl_set:Ne \l__jsonparse_temp_tl { \tl_trim_spaces:n {#1} } \cs_if_exist_use:cF { __jsonparse_parse_ \str_casefold:o { \l__jsonparse_temp_tl } : } { - \fp_if_nan:nTF {#1} { - % nan - \msg_error:nnoo { jsonparse } { parsing-error } - { \l__jsonparse_key_tl } {#1} - } { + \bool_if:NTF \l__jsonparse_check_num_bool { + \jsonparse_if_num:nTF {#1} { + \tl_set:Nn \l__jsonparse_val_tl {#1} + \prop_gput:Nee \g_jsonparse_entries_prop + { \l__jsonparse_key_tl } { \l__jsonparse_val_tl } + % number + \bool_if:NT \l__jsonparse_debug_mode_bool { + \msg_log:nne { jsonparse } { debug-info } { + (key) ~ \str_use:N \l__jsonparse_key_tl : \iow_newline: + \iow_char:N \ \iow_char:N \ (num) ~ \str_use:N \l__jsonparse_val_tl + } + } + } { + % not a valid JSON fp + \msg_error:nnoo { jsonparse } { parsing-error } + { \l__jsonparse_key_tl } {#1} + } + } { \tl_set:Nn \l__jsonparse_val_tl {#1} - \prop_gput:Nee \g_jsonparse_entries_prop + \prop_gput:Nee \g_jsonparse_entries_prop { \l__jsonparse_key_tl } { \l__jsonparse_val_tl } % number \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { (key) ~ \str_use:N \l__jsonparse_key_tl : \iow_newline: \iow_char:N \ \iow_char:N \ (num) ~ \str_use:N \l__jsonparse_val_tl - } + } } } } \tl_set:Ne \l__jsonparse_remainder_tl { \tl_trim_spaces:e { \l__jsonparse_remainder_tl } } - \tl_set:Ne \l__jsonparse_remainder_tl { - \tl_range:Nen \l__jsonparse_remainder_tl { + \tl_set:Ne \l__jsonparse_remainder_tl { + \tl_range:Nen \l__jsonparse_remainder_tl { \int_eval:n { - \tl_count:n {#1} + 1 + \tl_count:n {#1} + 1 } } { -1 } } @@ -469,41 +744,41 @@ } \cs_new:Npn \__jsonparse_parse_true: { - \tl_set_eq:NN \l__jsonparse_val_tl \l__jsonparse_true_str - \prop_gput:Nee \g_jsonparse_entries_prop + \tl_set_eq:NN \l__jsonparse_val_tl \l__jsonparse_true_str + \prop_gput:Nee \g_jsonparse_entries_prop { \l__jsonparse_key_tl } { \l__jsonparse_val_tl } % true \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { (key) ~ \str_use:N \l__jsonparse_key_tl : \iow_newline: \iow_char:N \ \iow_char:N \ (tru) ~ \str_use:N \l__jsonparse_val_tl - } + } } } \cs_new:Npn \__jsonparse_parse_false: { - \tl_set_eq:NN \l__jsonparse_val_tl \l__jsonparse_false_str - \prop_gput:Nee \g_jsonparse_entries_prop + \tl_set_eq:NN \l__jsonparse_val_tl \l__jsonparse_false_str + \prop_gput:Nee \g_jsonparse_entries_prop { \l__jsonparse_key_tl } { \l__jsonparse_val_tl } % false \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { (key) ~ \str_use:N \l__jsonparse_key_tl : \iow_newline: \iow_char:N \ \iow_char:N \ (fal) ~ \str_use:N \l__jsonparse_val_tl - } + } } } \cs_new:Npn \__jsonparse_parse_null: { \tl_set_eq:NN \l__jsonparse_val_tl \l__jsonparse_null_str - \prop_gput:Nee \g_jsonparse_entries_prop + \prop_gput:Nee \g_jsonparse_entries_prop { \l__jsonparse_key_tl } { \l__jsonparse_val_tl } % null \bool_if:NT \l__jsonparse_debug_mode_bool { \msg_log:nne { jsonparse } { debug-info } { (key) ~ \str_use:N \l__jsonparse_key_tl : \iow_newline: \iow_char:N \ \iow_char:N \ (nul) ~ \str_use:N \l__jsonparse_val_tl - } + } } } @@ -515,24 +790,33 @@ \tl_if_empty:NF \l__jsonparse_remainder_tl { \exp_args:No \jsonparse_parse:n { \l__jsonparse_remainder_tl } } -} +} -\cs_new_protected:Npn \jsonparse_filter:Nn #1#2 { - \prop_clear:N \l__jsonparse_temp_prop - \prop_map_inline:Nn #1 { - \str_case_e:en { - \tl_range:nne {##1} { 1 } { \int_eval:n { \tl_count:n {#2} + 1 } } - } { - { #2 \l__jsonparse_child_sep_str } { - \prop_put:Nen \l__jsonparse_temp_prop - { \tl_range:nen {##1} { \int_eval:n { \tl_count:n {#2} + 2 } } { -1 } } {##2} - } - { #2 \l__jsonparse_array_sep_left_str } { - \prop_put:Nen \l__jsonparse_temp_prop - { \tl_range:nen {##1} { \int_eval:n { \tl_count:n {#2} + 1 } } { -1 } } {##2} - } +\cs_new:Npn \__jsonparse_filter:nn #1#2 { + \str_case_e:en { + \tl_range:nne {#1} { 1 } { \int_eval:n { + \tl_count:o { \l__jsonparse_filter_key_str } + 1 + } } + } { + { \l__jsonparse_filter_key_str \l__jsonparse_child_sep_str } { + \prop_put:Nen \l__jsonparse_temp_prop + { \tl_range:nen {#1} { \int_eval:n { + \tl_count:o { \l__jsonparse_filter_key_str } + 2 + } } { -1 } } {#2} + } + { \l__jsonparse_filter_key_str \l__jsonparse_array_sep_left_str } { + \prop_put:Nen \l__jsonparse_temp_prop + { \tl_range:nen {#1} { \int_eval:n { + \tl_count:o { \l__jsonparse_filter_key_str } + 1 + } } { -1 } } {#2} } } +} + +\cs_new_protected:Npn \jsonparse_filter:Nn #1#2 { + \prop_clear:N \l__jsonparse_temp_prop + \str_set:Nn \l__jsonparse_filter_key_str {#2} + \prop_map_function:NN #1 \__jsonparse_filter:nn \prop_set_eq:NN #1 \l__jsonparse_temp_prop } @@ -540,108 +824,132 @@ \NewDocumentCommand { \JSONParsePut } { m m +v } { \prop_if_exist:NF #1 { - \prop_new:N #1 - } - \prop_gput:Nnn #1 { #2 } { #3 } + \prop_new:N #1 + } + \prop_gput:Nnn #1 {#2} {#3} } \cs_new:Npn \__jsonparse_externalize:Nn #1#2 { - \file_if_exist:nTF {#2} { - \msg_error:nnn { jsonparse } { file-exists } + \file_if_exist:eTF {#2} { + \msg_error:nne { jsonparse } { file-exists } {#2} } { - \iow_open:Nn \g__jsonparse_externalize_iow {#2} + \iow_open:Ne \g__jsonparse_externalize_iow {#2} \prop_map_inline:Nn #1 { \iow_now:Nn \g__jsonparse_externalize_iow { \JSONParsePut {#1} {##1} {##2} } } \iow_close:N \g__jsonparse_externalize_iow - \msg_info:nnn { jsonparse } { saving-external } + \msg_info:nne { jsonparse } { saving-external } {#2} } } % === -\NewDocumentCommand { \JSONParse } { o m +v } { - \bool_set_false:N \l__jsonparse_load_external_bool - \tl_if_novalue:nF {#1} { - \file_if_exist:nT { #1 .jsonparse } { - \bool_set_true:N \l__jsonparse_load_external_bool - } +\cs_new:Npn \__json_nested_construct_cs:Nnn #1#2#3 { + \cs_set:Npn #1 #2 ##1 #3 #2 ##2 #3 { + \prop_item:ce {##1} {##2} } - \bool_if:NTF \l__jsonparse_load_external_bool { - \msg_info:nnn { jsonparse } { loading-external } - { #1 .jsonparse } - \file_input:n { #1 .jsonparse } - } { - \prop_new:N #2 - \tl_gclear:N \g__jsonparse_json_tl - \group_begin: - \cs_set:Npn \" { \exp_not:N \" } - \cs_set:Npn \/ { \exp_not:N \/ } - \cs_set:Npn \\ { \exp_not:N \\ } - \cs_set:Npn \b { \exp_not:N \b } - \cs_set:Npn \f { \exp_not:N \f } - \cs_set:Npn \n { \exp_not:N \n } - \cs_set:Npn \r { \exp_not:N \r } - \cs_set:Npn \t { \exp_not:N \t } - \cs_set:Npn \u { \exp_not:N \u } - \cs_set:Npn \x [ ##1 ] [ ##2 ] { \prop_item:ce {##1} {##2} } - \tl_gset_rescan:Nne \g__jsonparse_json_tl { \cctab_select:N \c__jsonparse_json_escape_cctab } {#3} - \exp_args:NNe \jsonparse_parse_to_prop:Nn #2 { \g__jsonparse_json_tl } - \group_end: - \tl_if_novalue:nF {#1} { - \__jsonparse_externalize:Nn #2 { #1 .jsonparse } - } - } -} - -\NewDocumentCommand { \JSONParseFromFile } { o m m } { +} +\cs_generate_variant:Nn \__json_nested_construct_cs:Nnn { Noo } + +\NewDocumentCommand { \JSONParse } { O{} m +v } { + \group_begin: + \str_set:Ne \l_jsonparse_current_prop_str { \cs_to_str:N #2 } + \keys_set_known:nnN { jsonparse / global } {#1} \l__jsonparse_unused_keys_clist + \keys_set_known:noN { jsonparse / parse } { \l__jsonparse_unused_keys_clist } \l__jsonparse_unused_keys_clist + \__jsonparse_warning_unused_keys: + \bool_set_false:N \l__jsonparse_externalize_load_bool + \bool_if:NT \l__jsonparse_externalize_bool { + \file_if_exist:eT { \l__jsonparse_externalize_file_name_tl .jsonparse } { + \bool_set_true:N \l__jsonparse_externalize_load_bool + } + } + \bool_if:NTF \l__jsonparse_externalize_load_bool { + \msg_info:nne { jsonparse } { loading-external } + { \l__jsonparse_externalize_file_name_tl .jsonparse } + \file_input:e { \l__jsonparse_externalize_file_name_tl .jsonparse } + } { + \prop_new:N #2 + \tl_gclear:N \g__jsonparse_json_tl + \group_begin: + \cs_set:Npn \" { \exp_not:N \" } + \cs_set:Npn \/ { \exp_not:N \/ } + \cs_set:Npn \\ { \exp_not:N \\ } + \cs_set:Npn \b { \exp_not:N \b } + \cs_set:Npn \f { \exp_not:N \f } + \cs_set:Npn \n { \exp_not:N \n } + \cs_set:Npn \r { \exp_not:N \r } + \cs_set:Npn \t { \exp_not:N \t } + \cs_set:Npn \u { \exp_not:N \u } + \__json_nested_construct_cs:Noo \x \c_left_brace_str \c_right_brace_str + \tl_set:Nn \obeyedline { ~ } + \tl_gset_rescan:Nne \g__jsonparse_json_tl { \cctab_select:N \c__jsonparse_json_escape_cctab } {#3} + \exp_args:NNe \jsonparse_parse_to_prop:Nn #2 { \g__jsonparse_json_tl } + \group_end: + \bool_if:NT \l__jsonparse_externalize_bool { + \__jsonparse_externalize:Nn #2 { \l__jsonparse_externalize_file_name_tl .jsonparse } + } + } + \group_end: +} + +\NewDocumentCommand { \JSONParseFromFile } { O{} m m } { \file_if_exist:nF {#3} { \msg_error:nnn { jsonparse } { file-not-found } {#3} } - \bool_set_false:N \l__jsonparse_load_external_bool - \tl_if_novalue:nF {#1} { - \file_if_exist:nT { #1 .jsonparse } { - \bool_set_true:N \l__jsonparse_load_external_bool + \group_begin: + \str_set:Ne \l_jsonparse_current_prop_str { \cs_to_str:N #2 } + \keys_set_known:nnN { jsonparse / global } {#1} \l__jsonparse_unused_keys_clist + \keys_set_known:noN { jsonparse / parse } { \l__jsonparse_unused_keys_clist } \l__jsonparse_unused_keys_clist + \__jsonparse_warning_unused_keys: + \bool_set_false:N \l__jsonparse_externalize_load_bool + \bool_if:NT \l__jsonparse_externalize_bool { + \file_if_exist:eT { \l__jsonparse_externalize_file_name_tl .jsonparse } { + \bool_set_true:N \l__jsonparse_externalize_load_bool + } } - } - \bool_if:NTF \l__jsonparse_load_external_bool { - \msg_info:nnn { jsonparse } { loading-external } - { #1 .jsonparse } - \file_input:n { #1 .jsonparse } - } { - \prop_new:N #2 - \tl_gclear:N \g__jsonparse_json_tl - \group_begin: - \cs_set:Npn \" { \exp_not:N \" } - \cs_set:Npn \/ { \exp_not:N \/ } - \cs_set:Npn \\ { \exp_not:N \\ } - \cs_set:Npn \b { \exp_not:N \b } - \cs_set:Npn \f { \exp_not:N \f } - \cs_set:Npn \n { \exp_not:N \n } - \cs_set:Npn \r { \exp_not:N \r } - \cs_set:Npn \t { \exp_not:N \t } - \cs_set:Npn \u { \exp_not:N \u } - \cs_set:Npn \x [ ##1 ] [ ##2 ] { \prop_item:ce {##1} {##2} } - \file_get:nnN {#3} { \cctab_select:N \c__jsonparse_json_escape_cctab } \g__jsonparse_json_tl - \exp_args:NNe \jsonparse_parse_to_prop:Nn #2 { \g__jsonparse_json_tl } - \group_end: - \tl_if_novalue:nF {#1} { - \__jsonparse_externalize:Nn #2 { #1 .jsonparse } + \bool_if:NTF \l__jsonparse_externalize_load_bool { + \msg_info:nne { jsonparse } { loading-external } + { \l__jsonparse_externalize_file_name_tl .jsonparse } + \file_input:e { \l__jsonparse_externalize_file_name_tl .jsonparse } + } { + \prop_new:N #2 + \tl_gclear:N \g__jsonparse_json_tl + \group_begin: + \cs_set:Npn \" { \exp_not:N \" } + \cs_set:Npn \/ { \exp_not:N \/ } + \cs_set:Npn \\ { \exp_not:N \\ } + \cs_set:Npn \b { \exp_not:N \b } + \cs_set:Npn \f { \exp_not:N \f } + \cs_set:Npn \n { \exp_not:N \n } + \cs_set:Npn \r { \exp_not:N \r } + \cs_set:Npn \t { \exp_not:N \t } + \cs_set:Npn \u { \exp_not:N \u } + \file_get:nnN {#3} { \cctab_select:N \c__jsonparse_json_escape_cctab } \l__jsonparse_externalize_file_data_tl + \tl_gset_eq:NN \g__jsonparse_json_tl \l__jsonparse_externalize_file_data_tl + \exp_args:NNe \jsonparse_parse_to_prop:Nn #2 { \g__jsonparse_json_tl } + \group_end: + \bool_if:NT \l__jsonparse_externalize_bool { + \__jsonparse_externalize:Nn #2 { \l__jsonparse_externalize_file_name_tl .jsonparse } + } } - } + \group_end: } \NewExpandableDocumentCommand { \JSONParseExpandableValue } { m m } { - \prop_item:Ne #1 {#2} + \prop_item:Ne #1 {#2} } -\cs_set_eq:NN \__jsonparse_tex_quote \" -\cs_set_eq:NN \__jsonparse_tex_backslash \\ +\cs_set_eq:NN \__jsonparse_tex_quote: \" +\cs_set_eq:NN \__jsonparse_tex_backslash: \\ + +\cs_new:Npn \__jsonparse_unicode_char:NNNN #1#2#3#4 { + \symbol{ " \str_uppercase:n { #1 #2 #3 #4 } } { } +} \cs_new:Npn \__jsonparse_rescan:n #1 { \group_begin: @@ -653,10 +961,10 @@ \cs_set:Npn \n { \l__jsonparse_linefeed_str } \cs_set:Npn \r { \l__jsonparse_carriage_return_str } \cs_set:Npn \t { \l__jsonparse_horizontal_tab_str } - \cs_set:Npn \u { \char" } + \cs_set_eq:NN \u \__jsonparse_unicode_char:NNNN \tl_set:Ne \l__jsonparse_temp_tl {#1} - \cs_set_eq:NN \" \__jsonparse_tex_quote - \cs_set_eq:NN \\ \__jsonparse_tex_backslash + \cs_set_eq:NN \" \__jsonparse_tex_quote: + \cs_set_eq:NN \\ \__jsonparse_tex_backslash: \bool_if:NT \l__jsonparse_escape_number_sign_bool { \tl_replace_all:Noe \l__jsonparse_temp_tl { \c_hash_str } { \c_backslash_str \c_hash_str } } @@ -682,11 +990,26 @@ \group_end: } -\NewDocumentCommand { \JSONParseValue } { s m m } { - \bool_if:NTF #1 { - \prop_item:Ne #2 {#3} - } { - \exp_args:Ne \__jsonparse_rescan:n { \prop_item:Ne #2 {#3} } +\NewDocumentCommand { \JSONParseValue } { O{} m m } { + \group_begin: + \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist + \__jsonparse_warning_unused_keys: + \bool_if:NTF \l__jsonparse_rescan_bool { + \exp_args:Ne \__jsonparse_rescan:n { \prop_item:Ne #2 {#3} } + } { + \prop_item:Ne #2 {#3} + } + \group_end: +} + +\cs_new:Npn \__jsonparse_keys:n #1 { + \tl_if_in:nVF {#1} \l__jsonparse_child_sep_str { + \bool_if:NTF \l__jsonparse_prop_map_first_bool { + \bool_set_false:N \l__jsonparse_prop_map_first_bool + } { + \tl_put_right:Nn \l__jsonparse_temp_tl { , } + } + \tl_put_right:Nn \l__jsonparse_temp_tl { " #1 " } } } @@ -696,89 +1019,213 @@ } \bool_set_true:N \l__jsonparse_prop_map_first_bool \tl_set:Nn \l__jsonparse_temp_tl { [ } - \prop_map_inline:Nn #1 { - \tl_if_in:nVF {##1} \l__jsonparse_child_sep_str { - \bool_if:NTF \l__jsonparse_prop_map_first_bool { - \bool_set_false:N \l__jsonparse_prop_map_first_bool - } { - \tl_put_right:Nn \l__jsonparse_temp_tl { , } + \prop_map_function:NN #1 \__jsonparse_keys:n + \tl_put_right:Nn \l__jsonparse_temp_tl { ] } + \tl_set_eq:NN #2 \l__jsonparse_temp_tl +} + +\cs_new:Npn \__jsonparse_get_array_index:w [ #1 ] #2 \q_stop { + #1 +} + +\cs_new:Npn \__jsonparse_array_count:nn #1#2 { + \str_if_eq:eVF { \tl_head:n {#1} } \l__jsonparse_array_sep_left_str { + \msg_error:nnn { jsonparse } { not-array-item } + {#1} + } + \seq_if_in:NeF \l__jsonparse_array_count_last_seq { + \__jsonparse_get_array_index:w #1 \q_stop + } { + \int_incr:N \l__jsonparse_array_count_aux_int + \seq_put_right:Ne \l__jsonparse_array_count_last_seq { + \__jsonparse_get_array_index:w #1 \q_stop + } + } +} + +\cs_new_protected:Npn \jsonparse_array_count:NN #1#2 { + \int_zero:N \l__jsonparse_array_count_aux_int + \seq_clear:N \l__jsonparse_array_count_last_seq + \prop_map_function:NN #1 \__jsonparse_array_count:nn + \int_set_eq:NN #2 \l__jsonparse_array_count_aux_int +} + +\NewDocumentCommand { \JSONParseArrayCount } { m m } { + \group_begin: + \tl_set_eq:NN \l__jsonparse_temp_tl #1 + \jsonparse_filter:Nn \l__jsonparse_temp_tl {#2} + \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int + \int_use:N \l__jsonparse_array_count_int + \group_end: +} + +\cs_new:Npn \__jsonparse_array_values:n #1 { + \bool_if:NTF \l__jsonparse_prop_map_first_bool { + \bool_set_false:N \l__jsonparse_prop_map_first_bool + } { + \l__jsonparse_array_values_insert_tl + } + \bool_if:NTF \l__jsonparse_rescan_bool { + \exp_args:Ne \__jsonparse_rescan:n { + \prop_item:Ne \l__jsonparse_temp_tl { + \l__jsonparse_array_sep_left_str + \bool_if:NTF \l__jsonparse_zero_based_bool { + \int_eval:n { #1 - 1 } + } { + #1 + } + \l__jsonparse_array_sep_right_str + \str_if_empty:NF \l__jsonparse_array_values_key_str { + \l__jsonparse_child_sep_str + \l__jsonparse_array_values_key_str } - \tl_put_right:Nn \l__jsonparse_temp_tl { " ##1 " } } } - \tl_put_right:Nn \l__jsonparse_temp_tl { ] } - \tl_set_eq:NN #2 \l__jsonparse_temp_tl + } { + \prop_item:Ne \l__jsonparse_temp_tl { + \l__jsonparse_array_sep_left_str + \bool_if:NTF \l__jsonparse_zero_based_bool { + \int_eval:n { #1 - 1 } + } { + #1 + } + \l__jsonparse_array_sep_right_str + \str_if_empty:NF \l__jsonparse_array_values_key_str { + \l__jsonparse_child_sep_str + \l__jsonparse_array_values_key_str + } + } + } } -\NewDocumentCommand { \JSONParseArrayValues } { s m m O{} m } { +\NewDocumentCommand { \JSONParseArrayValues } { O{} m m O{} m } { \group_begin: - \tl_set:Nn \l__jsonparse_temp_tl {#2} + \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist + \__jsonparse_warning_unused_keys: + \tl_set_eq:NN \l__jsonparse_temp_tl #2 \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3} + \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int + \str_set:Nn \l__jsonparse_array_values_key_str {#4} + \tl_set:Nn \l__jsonparse_array_values_insert_tl {#5} \bool_set_true:N \l__jsonparse_prop_map_first_bool - \prop_map_inline:Nn \l__jsonparse_temp_tl { - \str_if_eq:enT { - \tl_range:nen {##1} { \int_eval:n { -1 * \tl_count:n {#4} } } { -1 } - } {#4} { - \bool_if:NTF \l__jsonparse_prop_map_first_bool { - \bool_set_false:N \l__jsonparse_prop_map_first_bool - } { - #5 - } - \bool_if:NTF #1 { - ##2 - } { - \__jsonparse_rescan:n {##2} - } - } - } + \int_step_function:nN { \l__jsonparse_array_count_int } + \__jsonparse_array_values:n \group_end: } -\cs_new:Npn \__jsonparse_get_array_index:w [ #1 ] #2 \q_stop { - #1 +\tl_new:N \JSONParseArrayIndex +\tl_new:N \JSONParseArrayKey +\tl_new:N \JSONParseArrayValue + +\cs_new:Npn \__jsonparse_array_values_map_keys:n #1 { + \int_incr:N \l__jsonparse_array_keys_index_int + \tl_set:Ne \l__jsonparse_array_keys_index_roman_tl { + \int_to_Roman:n { \l__jsonparse_array_keys_index_int } + } + \tl_gset:ce { JSONParseArrayKey \l__jsonparse_array_keys_index_roman_tl } { + \l__jsonparse_array_sep_left_str + \JSONParseArrayIndex + \l__jsonparse_array_sep_right_str + \l__jsonparse_child_sep_str + #1 + } + \bool_if:NTF \l__jsonparse_rescan_bool { + \tl_gset:cn { JSONParseArrayValue \l__jsonparse_array_keys_index_roman_tl } { + \exp_args:Ne \__jsonparse_rescan:n { + \prop_item:Ne \l__jsonparse_temp_tl { + \l__jsonparse_array_sep_left_str + \JSONParseArrayIndex + \l__jsonparse_array_sep_right_str + \l__jsonparse_child_sep_str + #1 + } + } + } + } { + \tl_gset:ce { JSONParseArrayValue \l__jsonparse_array_keys_index_roman_tl } { + \prop_item:Ne \l__jsonparse_temp_tl { + \l__jsonparse_array_sep_left_str + \JSONParseArrayIndex + \l__jsonparse_array_sep_right_str + \l__jsonparse_child_sep_str + #1 + } + } + } } -\NewDocumentCommand { \JSONParseArrayCount } { m m } { - \group_begin: - \jsonparse_filter:Nn #1 {#2} - \int_zero:N \l__jsonparse_array_count_int - \int_set:Nn \l__jsonparse_array_count_last_int { -1 } - \prop_map_inline:Nn #1 { - \int_compare:nNnF { - \__jsonparse_get_array_index:w ##1 \q_stop - } = { \l__jsonparse_array_count_last_int } { - \int_incr:N \l__jsonparse_array_count_int +\cs_new:Npn \__jsonparse_array_values_map:n #1 { + \bool_if:NTF \l__jsonparse_zero_based_bool { + \tl_gset:Nn \JSONParseArrayIndex { \int_eval:n { #1 - 1 } } + } { + \tl_gset:Nn \JSONParseArrayIndex {#1} + } + \clist_if_empty:NTF \l__jsonparse_array_map_keys_clist { + \tl_gset:Ne \JSONParseArrayKey { + \l__jsonparse_array_sep_left_str + \JSONParseArrayIndex + \l__jsonparse_array_sep_right_str + } + \bool_if:NTF \l__jsonparse_rescan_bool { + \tl_gset:Nn \JSONParseArrayValue { + \exp_args:Ne \__jsonparse_rescan:n { + \prop_item:Ne \l__jsonparse_temp_tl { + \l__jsonparse_array_sep_left_str + \JSONParseArrayIndex + \l__jsonparse_array_sep_right_str + } + } } - \int_set:Nn \l__jsonparse_array_count_last_int { - \__jsonparse_get_array_index:w ##1 \q_stop + } { + \tl_gset:Ne \JSONParseArrayValue { + \prop_item:Ne \l__jsonparse_temp_tl { + \l__jsonparse_array_sep_left_str + \JSONParseArrayIndex + \l__jsonparse_array_sep_right_str + } } - } - \int_use:N \l__jsonparse_array_count_int - \group_end: + } + } { + \int_zero:N \l__jsonparse_array_keys_index_int + \clist_map_function:NN \l__jsonparse_array_map_keys_clist + \__jsonparse_array_values_map_keys:n + \tl_gset_eq:NN \JSONParseArrayKey \JSONParseArrayKeyI + \tl_gset_eq:NN \JSONParseArrayValue \JSONParseArrayValueI + } + \use:c { \l__jsonparse_array_map_function_str } } -\tl_new:N \JSONParseArrayIndex -\tl_new:N \JSONParseArrayKey -\tl_new:N \JSONParseArrayValue +\cs_set:Npn \__jsonparse_array_map_create_cs:n #1 { + \int_incr:N \l__jsonparse_array_keys_index_int + \tl_set:Ne \l__jsonparse_array_keys_index_roman_tl { + \int_to_Roman:n { \l__jsonparse_array_keys_index_int } + } + \tl_if_exist:cF { JSONParseArrayKey \l__jsonparse_array_keys_index_roman_tl } { + \tl_new:c { JSONParseArrayKey \l__jsonparse_array_keys_index_roman_tl } + } + \tl_if_exist:cF { JSONParseArrayValue \l__jsonparse_array_keys_index_roman_tl } { + \tl_new:c { JSONParseArrayValue \l__jsonparse_array_keys_index_roman_tl } + } +} -\NewDocumentCommand { \JSONParseArrayValuesMap } { s m m O{} m } { +\NewDocumentCommand { \JSONParseArrayValuesMap } { O{} m m O{} m O{} O{} } { \group_begin: - \jsonparse_filter:Nn #2 {#3} - \prop_map_inline:Nn #2 { - \str_if_eq:enT { - \tl_range:nen {##1} { \int_eval:n { -1 * \tl_count:n {#4} } } { -1 } - } {#4} { - \int_incr:N \l__jsonparse_array_index_int - \tl_set:Ne \JSONParseArrayIndex { \__jsonparse_get_array_index:w ##1 \q_stop } - \tl_set:Nn \JSONParseArrayKey {##1} - \bool_if:NTF #1 { - \tl_set:Nn \JSONParseArrayValue { \prop_item:Nn #2 {##1} } - } { - \tl_set:Nn \JSONParseArrayValue { \exp_args:Ne \__jsonparse_rescan:n { \prop_item:Nn #2 {##1} } } - } - \use:c {#5} - } - } + \keys_set_known:nn { jsonparse / typeset } {#1} \l__jsonparse_unused_keys_clist + \__jsonparse_warning_unused_keys: + \tl_set_eq:NN \l__jsonparse_temp_tl #2 + \jsonparse_filter:Nn \l__jsonparse_temp_tl {#3} + \jsonparse_array_count:NN \l__jsonparse_temp_tl \l__jsonparse_array_count_int + \clist_set:Nn \l__jsonparse_array_map_keys_clist {#4} + \str_set:Nn \l__jsonparse_array_map_function_str {#5} + \clist_if_empty:NF \l__jsonparse_array_map_keys_clist { + \int_zero:N \l__jsonparse_array_keys_index_int + \clist_map_function:NN \l__jsonparse_array_map_keys_clist + \__jsonparse_array_map_create_cs:n + } + #6 + \int_step_function:nN { \l__jsonparse_array_count_int } + \__jsonparse_array_values_map:n + #7 \group_end: } |