@fugood/llama.node 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/CMakeLists.txt +5 -2
  2. package/bin/darwin/arm64/llama-node.node +0 -0
  3. package/bin/darwin/x64/llama-node.node +0 -0
  4. package/bin/linux/arm64/llama-node.node +0 -0
  5. package/bin/linux/x64/llama-node.node +0 -0
  6. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  7. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  8. package/bin/win32/arm64/llama-node.node +0 -0
  9. package/bin/win32/arm64/node.lib +0 -0
  10. package/bin/win32/x64/llama-node.node +0 -0
  11. package/bin/win32/x64/node.lib +0 -0
  12. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  13. package/bin/win32-vulkan/arm64/node.lib +0 -0
  14. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  15. package/bin/win32-vulkan/x64/node.lib +0 -0
  16. package/lib/binding.ts +8 -1
  17. package/package.json +1 -1
  18. package/patches/llama.patch +12 -12
  19. package/src/DetokenizeWorker.cpp +1 -1
  20. package/src/LlamaContext.cpp +33 -1
  21. package/src/LlamaContext.h +1 -0
  22. package/src/LoadSessionWorker.cpp +1 -0
  23. package/src/llama.cpp/.github/workflows/bench.yml +310 -0
  24. package/src/llama.cpp/.github/workflows/build.yml +1315 -0
  25. package/src/llama.cpp/.github/workflows/close-issue.yml +23 -0
  26. package/src/llama.cpp/.github/workflows/docker.yml +116 -0
  27. package/src/llama.cpp/.github/workflows/editorconfig.yml +27 -0
  28. package/src/llama.cpp/.github/workflows/gguf-publish.yml +44 -0
  29. package/src/llama.cpp/.github/workflows/labeler.yml +17 -0
  30. package/src/llama.cpp/.github/workflows/nix-ci-aarch64.yml +65 -0
  31. package/src/llama.cpp/.github/workflows/nix-ci.yml +72 -0
  32. package/src/llama.cpp/.github/workflows/nix-flake-update.yml +22 -0
  33. package/src/llama.cpp/.github/workflows/nix-publish-flake.yml +36 -0
  34. package/src/llama.cpp/.github/workflows/python-check-requirements.yml +35 -0
  35. package/src/llama.cpp/.github/workflows/python-lint.yml +23 -0
  36. package/src/llama.cpp/.github/workflows/python-type-check.yml +38 -0
  37. package/src/llama.cpp/.github/workflows/server.yml +183 -0
  38. package/src/llama.cpp/CMakeLists.txt +91 -1245
  39. package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +1 -1
  40. package/src/llama.cpp/cmake/build-info.cmake +58 -0
  41. package/src/llama.cpp/cmake/git-vars.cmake +22 -0
  42. package/src/llama.cpp/common/CMakeLists.txt +4 -3
  43. package/src/llama.cpp/common/build-info.cpp.in +4 -0
  44. package/src/llama.cpp/common/common.cpp +1116 -877
  45. package/src/llama.cpp/common/common.h +191 -77
  46. package/src/llama.cpp/common/grammar-parser.cpp +118 -31
  47. package/src/llama.cpp/common/json-schema-to-grammar.cpp +346 -65
  48. package/src/llama.cpp/common/log.h +1 -1
  49. package/src/llama.cpp/common/ngram-cache.h +10 -3
  50. package/src/llama.cpp/common/sampling.cpp +19 -10
  51. package/src/llama.cpp/docs/build.md +353 -0
  52. package/src/llama.cpp/examples/CMakeLists.txt +22 -22
  53. package/src/llama.cpp/examples/baby-llama/CMakeLists.txt +1 -1
  54. package/src/llama.cpp/examples/baby-llama/baby-llama.cpp +6 -6
  55. package/src/llama.cpp/examples/batched/CMakeLists.txt +1 -1
  56. package/src/llama.cpp/examples/batched/batched.cpp +52 -55
  57. package/src/llama.cpp/examples/batched-bench/CMakeLists.txt +1 -1
  58. package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +20 -72
  59. package/src/llama.cpp/examples/benchmark/CMakeLists.txt +1 -1
  60. package/src/llama.cpp/examples/chat-13B.bat +57 -0
  61. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +1 -1
  62. package/src/llama.cpp/examples/{finetune → cvector-generator}/CMakeLists.txt +2 -2
  63. package/src/llama.cpp/examples/cvector-generator/completions.txt +582 -0
  64. package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +503 -0
  65. package/src/llama.cpp/examples/cvector-generator/mean.hpp +48 -0
  66. package/src/llama.cpp/examples/cvector-generator/negative.txt +4 -0
  67. package/src/llama.cpp/examples/cvector-generator/pca.hpp +325 -0
  68. package/src/llama.cpp/examples/cvector-generator/positive.txt +4 -0
  69. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +35 -0
  70. package/src/llama.cpp/examples/embedding/CMakeLists.txt +1 -1
  71. package/src/llama.cpp/examples/embedding/embedding.cpp +94 -46
  72. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +2 -2
  73. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +4 -6
  74. package/src/llama.cpp/examples/export-lora/CMakeLists.txt +1 -1
  75. package/src/llama.cpp/examples/export-lora/export-lora.cpp +344 -386
  76. package/src/llama.cpp/examples/gbnf-validator/CMakeLists.txt +2 -2
  77. package/src/llama.cpp/examples/gbnf-validator/gbnf-validator.cpp +30 -25
  78. package/src/llama.cpp/examples/gguf/CMakeLists.txt +1 -1
  79. package/src/llama.cpp/examples/gguf/gguf.cpp +5 -0
  80. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +15 -0
  81. package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +46 -0
  82. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +295 -0
  83. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +52 -0
  84. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +221 -0
  85. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +24 -0
  86. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +42 -0
  87. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +7093 -0
  88. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +693 -0
  89. package/src/llama.cpp/examples/gguf-split/CMakeLists.txt +1 -1
  90. package/src/llama.cpp/examples/gguf-split/gguf-split.cpp +3 -3
  91. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +1 -1
  92. package/src/llama.cpp/examples/gritlm/gritlm.cpp +6 -2
  93. package/src/llama.cpp/examples/imatrix/CMakeLists.txt +1 -1
  94. package/src/llama.cpp/examples/imatrix/imatrix.cpp +137 -176
  95. package/src/llama.cpp/examples/infill/CMakeLists.txt +1 -1
  96. package/src/llama.cpp/examples/infill/infill.cpp +38 -153
  97. package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +175 -94
  98. package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +65 -0
  99. package/src/llama.cpp/examples/llama.android/build.gradle.kts +6 -0
  100. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +68 -0
  101. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +11 -7
  102. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +2 -2
  103. package/src/llama.cpp/examples/llama.android/settings.gradle.kts +18 -0
  104. package/src/llama.cpp/examples/llava/CMakeLists.txt +6 -5
  105. package/src/llama.cpp/examples/llava/android/build_64.sh +8 -0
  106. package/src/llama.cpp/examples/llava/clip.cpp +23 -14
  107. package/src/llama.cpp/examples/llava/llava-cli.cpp +8 -6
  108. package/src/llama.cpp/examples/llava/requirements.txt +3 -2
  109. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +1 -1
  110. package/src/llama.cpp/examples/lookahead/lookahead.cpp +2 -1
  111. package/src/llama.cpp/examples/lookup/CMakeLists.txt +4 -4
  112. package/src/llama.cpp/examples/lookup/lookup-create.cpp +2 -0
  113. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +4 -4
  114. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +2 -2
  115. package/src/llama.cpp/examples/lookup/lookup.cpp +1 -1
  116. package/src/llama.cpp/examples/main/CMakeLists.txt +1 -1
  117. package/src/llama.cpp/examples/main/main.cpp +98 -75
  118. package/src/llama.cpp/examples/main-cmake-pkg/CMakeLists.txt +4 -5
  119. package/src/llama.cpp/examples/parallel/CMakeLists.txt +1 -1
  120. package/src/llama.cpp/examples/parallel/parallel.cpp +2 -1
  121. package/src/llama.cpp/examples/passkey/CMakeLists.txt +1 -1
  122. package/src/llama.cpp/examples/passkey/passkey.cpp +23 -43
  123. package/src/llama.cpp/examples/perplexity/CMakeLists.txt +1 -1
  124. package/src/llama.cpp/examples/perplexity/perplexity.cpp +13 -10
  125. package/src/llama.cpp/examples/quantize/CMakeLists.txt +1 -1
  126. package/src/llama.cpp/examples/quantize/quantize.cpp +37 -34
  127. package/src/llama.cpp/examples/quantize-stats/CMakeLists.txt +1 -1
  128. package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +1 -1
  129. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +1 -1
  130. package/src/llama.cpp/examples/retrieval/retrieval.cpp +26 -77
  131. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +1 -1
  132. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +14 -7
  133. package/src/llama.cpp/examples/server/CMakeLists.txt +26 -2
  134. package/src/llama.cpp/examples/server/server.cpp +274 -671
  135. package/src/llama.cpp/examples/server/tests/requirements.txt +2 -2
  136. package/src/llama.cpp/examples/server/utils.hpp +28 -29
  137. package/src/llama.cpp/examples/simple/CMakeLists.txt +1 -1
  138. package/src/llama.cpp/examples/simple/simple.cpp +21 -29
  139. package/src/llama.cpp/examples/speculative/CMakeLists.txt +1 -1
  140. package/src/llama.cpp/examples/speculative/speculative.cpp +2 -1
  141. package/src/llama.cpp/examples/sycl/CMakeLists.txt +1 -1
  142. package/src/llama.cpp/examples/sycl/build.sh +23 -0
  143. package/src/llama.cpp/examples/sycl/run-llama2.sh +36 -0
  144. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +33 -0
  145. package/src/llama.cpp/examples/sycl/win-run-llama2.bat +9 -0
  146. package/src/llama.cpp/examples/tokenize/CMakeLists.txt +1 -1
  147. package/src/llama.cpp/examples/tokenize/tokenize.cpp +16 -2
  148. package/src/llama.cpp/ggml/CMakeLists.txt +253 -0
  149. package/src/llama.cpp/{cmake → ggml/cmake}/FindSIMD.cmake +6 -6
  150. package/src/llama.cpp/{ggml-backend.h → ggml/include/ggml-backend.h} +22 -17
  151. package/src/llama.cpp/ggml/include/ggml-blas.h +23 -0
  152. package/src/llama.cpp/ggml/include/ggml-cann.h +125 -0
  153. package/src/llama.cpp/{ggml-cuda.h → ggml/include/ggml-cuda.h} +3 -0
  154. package/src/llama.cpp/{ggml-metal.h → ggml/include/ggml-metal.h} +1 -2
  155. package/src/llama.cpp/{ggml-sycl.h → ggml/include/ggml-sycl.h} +3 -10
  156. package/src/llama.cpp/{ggml.h → ggml/include/ggml.h} +80 -85
  157. package/src/llama.cpp/ggml/src/CMakeLists.txt +1329 -0
  158. package/src/llama.cpp/ggml/src/ggml-aarch64.c +2193 -0
  159. package/src/llama.cpp/ggml/src/ggml-aarch64.h +39 -0
  160. package/src/llama.cpp/{ggml-alloc.c → ggml/src/ggml-alloc.c} +100 -49
  161. package/src/llama.cpp/{ggml-backend-impl.h → ggml/src/ggml-backend-impl.h} +20 -8
  162. package/src/llama.cpp/{ggml-backend.c → ggml/src/ggml-backend.c} +307 -167
  163. package/src/llama.cpp/ggml/src/ggml-blas.cpp +367 -0
  164. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +198 -0
  165. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +230 -0
  166. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +2944 -0
  167. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +592 -0
  168. package/src/llama.cpp/ggml/src/ggml-cann/common.h +282 -0
  169. package/src/llama.cpp/ggml/src/ggml-cann/kernels/CMakeLists.txt +32 -0
  170. package/src/llama.cpp/ggml/src/ggml-cann/kernels/ascendc_kernels.h +17 -0
  171. package/src/llama.cpp/ggml/src/ggml-cann/kernels/dup.cpp +223 -0
  172. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f16.cpp +186 -0
  173. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f32.cpp +180 -0
  174. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +193 -0
  175. package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +191 -0
  176. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +208 -0
  177. package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +206 -0
  178. package/src/llama.cpp/ggml/src/ggml-cann.cpp +2023 -0
  179. package/src/llama.cpp/{ggml-common.h → ggml/src/ggml-common.h} +41 -7
  180. package/src/llama.cpp/{ggml-impl.h → ggml/src/ggml-impl.h} +113 -9
  181. package/src/llama.cpp/{ggml-kompute.cpp → ggml/src/ggml-kompute.cpp} +33 -18
  182. package/src/llama.cpp/{ggml-quants.c → ggml/src/ggml-quants.c} +1460 -940
  183. package/src/llama.cpp/{ggml-quants.h → ggml/src/ggml-quants.h} +19 -20
  184. package/src/llama.cpp/{ggml-rpc.cpp → ggml/src/ggml-rpc.cpp} +95 -72
  185. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +27 -0
  186. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +53 -0
  187. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +355 -0
  188. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +195 -0
  189. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +21 -0
  190. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +547 -0
  191. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +27 -0
  192. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +698 -0
  193. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +1023 -0
  194. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +27 -0
  195. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +3011 -0
  196. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +3031 -0
  197. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +33 -0
  198. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +1027 -0
  199. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +27 -0
  200. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +374 -0
  201. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +35 -0
  202. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +66 -0
  203. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +275 -0
  204. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +22 -0
  205. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +251 -0
  206. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +24 -0
  207. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +1140 -0
  208. package/src/llama.cpp/ggml/src/ggml-sycl.cpp +5314 -0
  209. package/src/llama.cpp/{ggml-vulkan.cpp → ggml/src/ggml-vulkan.cpp} +1781 -1868
  210. package/src/llama.cpp/{ggml.c → ggml/src/ggml.c} +1245 -2087
  211. package/src/llama.cpp/{sgemm.cpp → ggml/src/llamafile/sgemm.cpp} +21 -24
  212. package/src/llama.cpp/{sgemm.h → ggml/src/llamafile/sgemm.h} +1 -1
  213. package/src/llama.cpp/ggml/src/vulkan-shaders/CMakeLists.txt +5 -0
  214. package/src/llama.cpp/ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp +552 -0
  215. package/src/llama.cpp/{llama.h → include/llama.h} +175 -100
  216. package/src/llama.cpp/models/.editorconfig +1 -0
  217. package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  218. package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  219. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  220. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +112 -0
  221. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +46 -0
  222. package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  223. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +112 -0
  224. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +46 -0
  225. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  226. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +112 -0
  227. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +46 -0
  228. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  229. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +112 -0
  230. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +46 -0
  231. package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  232. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +112 -0
  233. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +46 -0
  234. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  235. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +112 -0
  236. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +46 -0
  237. package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  238. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  239. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +112 -0
  240. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +46 -0
  241. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  242. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +112 -0
  243. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +46 -0
  244. package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  245. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +112 -0
  246. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +46 -0
  247. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  248. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +112 -0
  249. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +46 -0
  250. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  251. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +112 -0
  252. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +46 -0
  253. package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  254. package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +112 -0
  255. package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +46 -0
  256. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  257. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +112 -0
  258. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +46 -0
  259. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +2 -2
  260. package/src/llama.cpp/requirements/requirements-all.txt +12 -0
  261. package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +2 -0
  262. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +3 -0
  263. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +3 -0
  264. package/src/llama.cpp/requirements/{requirements-convert.txt → requirements-convert_legacy_llama.txt} +1 -1
  265. package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +1 -0
  266. package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +2 -0
  267. package/src/llama.cpp/requirements/requirements-pydantic.txt +3 -0
  268. package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +1 -0
  269. package/src/llama.cpp/requirements.txt +5 -4
  270. package/src/llama.cpp/scripts/build-info.sh +30 -0
  271. package/src/llama.cpp/scripts/install-oneapi.bat +19 -0
  272. package/src/llama.cpp/src/CMakeLists.txt +33 -0
  273. package/src/llama.cpp/src/llama-grammar.cpp +539 -0
  274. package/src/llama.cpp/src/llama-grammar.h +39 -0
  275. package/src/llama.cpp/src/llama-impl.h +26 -0
  276. package/src/llama.cpp/src/llama-sampling.cpp +635 -0
  277. package/src/llama.cpp/src/llama-sampling.h +56 -0
  278. package/src/llama.cpp/src/llama-vocab.cpp +1721 -0
  279. package/src/llama.cpp/src/llama-vocab.h +130 -0
  280. package/src/llama.cpp/{llama.cpp → src/llama.cpp} +5979 -5260
  281. package/src/llama.cpp/{unicode-data.cpp → src/unicode-data.cpp} +851 -802
  282. package/src/llama.cpp/{unicode.cpp → src/unicode.cpp} +52 -30
  283. package/src/llama.cpp/{unicode.h → src/unicode.h} +5 -1
  284. package/src/llama.cpp/tests/CMakeLists.txt +19 -20
  285. package/src/llama.cpp/tests/test-backend-ops.cpp +245 -67
  286. package/src/llama.cpp/tests/test-chat-template.cpp +57 -3
  287. package/src/llama.cpp/tests/test-double-float.cpp +2 -2
  288. package/src/llama.cpp/tests/test-grad0.cpp +2 -2
  289. package/src/llama.cpp/tests/test-grammar-integration.cpp +978 -31
  290. package/src/llama.cpp/tests/test-grammar-parser.cpp +423 -158
  291. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +508 -135
  292. package/src/llama.cpp/tests/test-llama-grammar.cpp +15 -9
  293. package/src/llama.cpp/tests/test-quantize-fns.cpp +1 -1
  294. package/src/llama.cpp/tests/test-quantize-perf.cpp +1 -1
  295. package/src/llama.cpp/tests/test-rope.cpp +3 -4
  296. package/src/llama.cpp/tests/test-sampling.cpp +5 -5
  297. package/src/llama.cpp/tests/test-tokenizer-0.cpp +6 -6
  298. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +20 -15
  299. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +22 -11
  300. package/bin/darwin/arm64/default.metallib +0 -0
  301. package/bin/darwin/x64/default.metallib +0 -0
  302. package/src/llama.cpp/examples/beam-search/CMakeLists.txt +0 -5
  303. package/src/llama.cpp/examples/beam-search/beam-search.cpp +0 -188
  304. package/src/llama.cpp/examples/finetune/finetune.cpp +0 -1862
  305. package/src/llama.cpp/examples/llama.android/llama/CMakeLists.txt +0 -55
  306. package/src/llama.cpp/examples/train-text-from-scratch/CMakeLists.txt +0 -5
  307. package/src/llama.cpp/examples/train-text-from-scratch/train-text-from-scratch.cpp +0 -1253
  308. package/src/llama.cpp/ggml-opencl.cpp +0 -2305
  309. package/src/llama.cpp/ggml-opencl.h +0 -36
  310. package/src/llama.cpp/ggml-sycl.cpp +0 -17340
  311. package/src/llama.cpp/ggml-vulkan-shaders.hpp +0 -81211
  312. package/src/llama.cpp/requirements/requirements-convert-hf-to-gguf-update.txt +0 -2
  313. package/src/llama.cpp/requirements/requirements-convert-hf-to-gguf.txt +0 -2
  314. package/src/llama.cpp/requirements/requirements-convert-llama-ggml-to-gguf.txt +0 -1
  315. package/src/llama.cpp/scripts/gen-build-info-cpp.cmake +0 -24
  316. /package/src/llama.cpp/{ggml-alloc.h → ggml/include/ggml-alloc.h} +0 -0
  317. /package/src/llama.cpp/{ggml-kompute.h → ggml/include/ggml-kompute.h} +0 -0
  318. /package/src/llama.cpp/{ggml-rpc.h → ggml/include/ggml-rpc.h} +0 -0
  319. /package/src/llama.cpp/{ggml-vulkan.h → ggml/include/ggml-vulkan.h} +0 -0
  320. /package/src/llama.cpp/{unicode-data.h → src/unicode-data.h} +0 -0
@@ -80,6 +80,232 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
80
80
  runner(tc);
81
81
  };
82
82
 
83
+ test({
84
+ SUCCESS,
85
+ "min 0",
86
+ R"""({
87
+ "type": "integer",
88
+ "minimum": 0
89
+ })""",
90
+ R"""(
91
+ root ::= ([0] | [1-9] [0-9]{0,15}) space
92
+ space ::= | " " | "\n" [ \t]{0,20}
93
+ )"""
94
+ });
95
+
96
+ test({
97
+ SUCCESS,
98
+ "min 1",
99
+ R"""({
100
+ "type": "integer",
101
+ "minimum": 1
102
+ })""",
103
+ R"""(
104
+ root ::= ([1-9] [0-9]{0,15}) space
105
+ space ::= | " " | "\n" [ \t]{0,20}
106
+ )"""
107
+ });
108
+
109
+ test({
110
+ SUCCESS,
111
+ "min 3",
112
+ R"""({
113
+ "type": "integer",
114
+ "minimum": 3
115
+ })""",
116
+ R"""(
117
+ root ::= ([1-2] [0-9]{1,15} | [3-9] [0-9]{0,15}) space
118
+ space ::= | " " | "\n" [ \t]{0,20}
119
+ )"""
120
+ });
121
+
122
+ test({
123
+ SUCCESS,
124
+ "min 9",
125
+ R"""({
126
+ "type": "integer",
127
+ "minimum": 9
128
+ })""",
129
+ R"""(
130
+ root ::= ([1-8] [0-9]{1,15} | [9] [0-9]{0,15}) space
131
+ space ::= | " " | "\n" [ \t]{0,20}
132
+ )"""
133
+ });
134
+
135
+ test({
136
+ SUCCESS,
137
+ "min 10",
138
+ R"""({
139
+ "type": "integer",
140
+ "minimum": 10
141
+ })""",
142
+ R"""(
143
+ root ::= ([1] ([0-9]{1,15}) | [2-9] [0-9]{1,15}) space
144
+ space ::= | " " | "\n" [ \t]{0,20}
145
+ )"""
146
+ });
147
+
148
+ test({
149
+ SUCCESS,
150
+ "min 25",
151
+ R"""({
152
+ "type": "integer",
153
+ "minimum": 25
154
+ })""",
155
+ R"""(
156
+ root ::= ([1] [0-9]{2,15} | [2] ([0-4] [0-9]{1,14} | [5-9] [0-9]{0,14}) | [3-9] [0-9]{1,15}) space
157
+ space ::= | " " | "\n" [ \t]{0,20}
158
+ )"""
159
+ });
160
+
161
+ test({
162
+ SUCCESS,
163
+ "max 30",
164
+ R"""({
165
+ "type": "integer",
166
+ "maximum": 30
167
+ })""",
168
+ R"""(
169
+ root ::= ("-" [1-9] [0-9]{0,15} | [0-9] | ([1-2] [0-9] | [3] "0")) space
170
+ space ::= | " " | "\n" [ \t]{0,20}
171
+ )"""
172
+ });
173
+
174
+ test({
175
+ SUCCESS,
176
+ "min -5",
177
+ R"""({
178
+ "type": "integer",
179
+ "minimum": -5
180
+ })""",
181
+ R"""(
182
+ root ::= ("-" ([0-5]) | [0] | [1-9] [0-9]{0,15}) space
183
+ space ::= | " " | "\n" [ \t]{0,20}
184
+ )"""
185
+ });
186
+
187
+ test({
188
+ SUCCESS,
189
+ "min -123",
190
+ R"""({
191
+ "type": "integer",
192
+ "minimum": -123
193
+ })""",
194
+ R"""(
195
+ root ::= ("-" ([0-9] | ([1-8] [0-9] | [9] [0-9]) | "1" ([0-1] [0-9] | [2] [0-3])) | [0] | [1-9] [0-9]{0,15}) space
196
+ space ::= | " " | "\n" [ \t]{0,20}
197
+ )"""
198
+ });
199
+
200
+ test({
201
+ SUCCESS,
202
+ "max -5",
203
+ R"""({
204
+ "type": "integer",
205
+ "maximum": -5
206
+ })""",
207
+ R"""(
208
+ root ::= ("-" ([0-4] [0-9]{1,15} | [5-9] [0-9]{0,15})) space
209
+ space ::= | " " | "\n" [ \t]{0,20}
210
+ )"""
211
+ });
212
+
213
+ test({
214
+ SUCCESS,
215
+ "max 1",
216
+ R"""({
217
+ "type": "integer",
218
+ "maximum": 1
219
+ })""",
220
+ R"""(
221
+ root ::= ("-" [1-9] [0-9]{0,15} | [0-1]) space
222
+ space ::= | " " | "\n" [ \t]{0,20}
223
+ )"""
224
+ });
225
+
226
+ test({
227
+ SUCCESS,
228
+ "max 100",
229
+ R"""({
230
+ "type": "integer",
231
+ "maximum": 100
232
+ })""",
233
+ R"""(
234
+ root ::= ("-" [1-9] [0-9]{0,15} | [0-9] | ([1-8] [0-9] | [9] [0-9]) | "100") space
235
+ space ::= | " " | "\n" [ \t]{0,20}
236
+ )"""
237
+ });
238
+
239
+ test({
240
+ SUCCESS,
241
+ "min 0 max 23",
242
+ R"""({
243
+ "type": "integer",
244
+ "minimum": 0,
245
+ "maximum": 23
246
+ })""",
247
+ R"""(
248
+ root ::= ([0-9] | ([1] [0-9] | [2] [0-3])) space
249
+ space ::= | " " | "\n" [ \t]{0,20}
250
+ )"""
251
+ });
252
+
253
+ test({
254
+ SUCCESS,
255
+ "min 15 max 300",
256
+ R"""({
257
+ "type": "integer",
258
+ "minimum": 15,
259
+ "maximum": 300
260
+ })""",
261
+ R"""(
262
+ root ::= (([1] ([5-9]) | [2-9] [0-9]) | ([1-2] [0-9]{2} | [3] "00")) space
263
+ space ::= | " " | "\n" [ \t]{0,20}
264
+ )"""
265
+ });
266
+
267
+ test({
268
+ SUCCESS,
269
+ "min 5 max 30",
270
+ R"""({
271
+ "type": "integer",
272
+ "minimum": 5,
273
+ "maximum": 30
274
+ })""",
275
+ R"""(
276
+ root ::= ([5-9] | ([1-2] [0-9] | [3] "0")) space
277
+ space ::= | " " | "\n" [ \t]{0,20}
278
+ )"""
279
+ });
280
+
281
+ test({
282
+ SUCCESS,
283
+ "min -123 max 42",
284
+ R"""({
285
+ "type": "integer",
286
+ "minimum": -123,
287
+ "maximum": 42
288
+ })""",
289
+ R"""(
290
+ root ::= ("-" ([0-9] | ([1-8] [0-9] | [9] [0-9]) | "1" ([0-1] [0-9] | [2] [0-3])) | [0-9] | ([1-3] [0-9] | [4] [0-2])) space
291
+ space ::= | " " | "\n" [ \t]{0,20}
292
+ )"""
293
+ });
294
+
295
+ test({
296
+ SUCCESS,
297
+ "min -10 max 10",
298
+ R"""({
299
+ "type": "integer",
300
+ "minimum": -10,
301
+ "maximum": 10
302
+ })""",
303
+ R"""(
304
+ root ::= ("-" ([0-9] | "10") | [0-9] | "10") space
305
+ space ::= | " " | "\n" [ \t]{0,20}
306
+ )"""
307
+ });
308
+
83
309
  test({
84
310
  FAILURE,
85
311
  "unknown type",
@@ -105,14 +331,14 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
105
331
  R"""(
106
332
  array ::= "[" space ( value ("," space value)* )? "]" space
107
333
  boolean ::= ("true" | "false") space
108
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
109
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
110
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
334
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
335
+ decimal-part ::= [0-9]{1,16}
336
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
111
337
  null ::= "null" space
112
338
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
113
339
  object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
114
340
  root ::= object
115
- space ::= " "?
341
+ space ::= | " " | "\n" [ \t]{0,20}
116
342
  string ::= "\"" char* "\"" space
117
343
  value ::= object | array | string | number | boolean | null
118
344
  )"""
@@ -130,18 +356,18 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
130
356
  ]
131
357
  })""",
132
358
  R"""(
133
- date ::= [0-9] [0-9] [0-9] [0-9] "-" ( "0" [1-9] | "1" [0-2] ) "-" ( "0" [1-9] | [1-2] [0-9] | "3" [0-1] )
359
+ date ::= [0-9]{4} "-" ( "0" [1-9] | "1" [0-2] ) "-" ( "0" [1-9] | [1-2] [0-9] | "3" [0-1] )
134
360
  date-string ::= "\"" date "\"" space
135
361
  date-time ::= date "T" time
136
362
  date-time-string ::= "\"" date-time "\"" space
137
363
  root ::= "[" space tuple-0 "," space uuid "," space tuple-2 "," space tuple-3 "]" space
138
- space ::= " "?
139
- time ::= ([01] [0-9] | "2" [0-3]) ":" [0-5] [0-9] ":" [0-5] [0-9] ( "." [0-9] [0-9] [0-9] )? ( "Z" | ( "+" | "-" ) ( [01] [0-9] | "2" [0-3] ) ":" [0-5] [0-9] )
364
+ space ::= | " " | "\n" [ \t]{0,20}
365
+ time ::= ([01] [0-9] | "2" [0-3]) ":" [0-5] [0-9] ":" [0-5] [0-9] ( "." [0-9]{3} )? ( "Z" | ( "+" | "-" ) ( [01] [0-9] | "2" [0-3] ) ":" [0-5] [0-9] )
140
366
  time-string ::= "\"" time "\"" space
141
367
  tuple-0 ::= date-string
142
368
  tuple-2 ::= time-string
143
369
  tuple-3 ::= date-time-string
144
- uuid ::= "\"" [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F] "-" [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F] "-" [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F] "-" [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F] "-" [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F] "\"" space
370
+ uuid ::= "\"" [0-9a-fA-F]{8} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{12} "\"" space
145
371
  )"""
146
372
  });
147
373
 
@@ -152,9 +378,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
152
378
  "type": "string"
153
379
  })""",
154
380
  R"""(
155
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
381
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
156
382
  root ::= "\"" char* "\"" space
157
- space ::= " "?
383
+ space ::= | " " | "\n" [ \t]{0,20}
158
384
  )"""
159
385
  });
160
386
 
@@ -166,9 +392,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
166
392
  "minLength": 1
167
393
  })""",
168
394
  R"""(
169
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
395
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
170
396
  root ::= "\"" char+ "\"" space
171
- space ::= " "?
397
+ space ::= | " " | "\n" [ \t]{0,20}
172
398
  )"""
173
399
  });
174
400
 
@@ -180,9 +406,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
180
406
  "minLength": 3
181
407
  })""",
182
408
  R"""(
183
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
184
- root ::= "\"" char char char (char)* "\"" space
185
- space ::= " "?
409
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
410
+ root ::= "\"" char{3,} "\"" space
411
+ space ::= | " " | "\n" [ \t]{0,20}
186
412
  )"""
187
413
  });
188
414
 
@@ -194,9 +420,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
194
420
  "maxLength": 3
195
421
  })""",
196
422
  R"""(
197
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
198
- root ::= "\"" (char (char (char)?)?)? "\"" space
199
- space ::= " "?
423
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
424
+ root ::= "\"" char{0,3} "\"" space
425
+ space ::= | " " | "\n" [ \t]{0,20}
200
426
  )"""
201
427
  });
202
428
 
@@ -209,9 +435,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
209
435
  "maxLength": 4
210
436
  })""",
211
437
  R"""(
212
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
213
- root ::= "\"" char (char (char (char)?)?)? "\"" space
214
- space ::= " "?
438
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
439
+ root ::= "\"" char{1,4} "\"" space
440
+ space ::= | " " | "\n" [ \t]{0,20}
215
441
  )"""
216
442
  });
217
443
 
@@ -223,7 +449,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
223
449
  })""",
224
450
  R"""(
225
451
  root ::= ("true" | "false") space
226
- space ::= " "?
452
+ space ::= | " " | "\n" [ \t]{0,20}
227
453
  )"""
228
454
  });
229
455
 
@@ -234,9 +460,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
234
460
  "type": "integer"
235
461
  })""",
236
462
  R"""(
237
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
463
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
238
464
  root ::= ("-"? integral-part) space
239
- space ::= " "?
465
+ space ::= | " " | "\n" [ \t]{0,20}
240
466
  )"""
241
467
  });
242
468
 
@@ -247,8 +473,8 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
247
473
  "const": "foo"
248
474
  })""",
249
475
  R"""(
250
- root ::= "\"foo\""
251
- space ::= " "?
476
+ root ::= "\"foo\"" space
477
+ space ::= | " " | "\n" [ \t]{0,20}
252
478
  )"""
253
479
  });
254
480
 
@@ -259,8 +485,8 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
259
485
  "const": 123
260
486
  })""",
261
487
  R"""(
262
- root ::= "123"
263
- space ::= " "?
488
+ root ::= "123" space
489
+ space ::= | " " | "\n" [ \t]{0,20}
264
490
  )"""
265
491
  });
266
492
 
@@ -271,8 +497,40 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
271
497
  "enum": ["red", "amber", "green", null, 42, ["foo"]]
272
498
  })""",
273
499
  R"""(
274
- root ::= "\"red\"" | "\"amber\"" | "\"green\"" | "null" | "42" | "[\"foo\"]"
275
- space ::= " "?
500
+ root ::= ("\"red\"" | "\"amber\"" | "\"green\"" | "null" | "42" | "[\"foo\"]") space
501
+ space ::= | " " | "\n" [ \t]{0,20}
502
+ )"""
503
+ });
504
+
505
+ test({
506
+ SUCCESS,
507
+ "string array",
508
+ R"""({
509
+ "type": "array",
510
+ "prefixItems": { "type": "string" }
511
+ })""",
512
+ R"""(
513
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
514
+ root ::= "[" space (string ("," space string)*)? "]" space
515
+ space ::= | " " | "\n" [ \t]{0,20}
516
+ string ::= "\"" char* "\"" space
517
+ )"""
518
+ });
519
+
520
+ test({
521
+ SUCCESS,
522
+ "nullable string array",
523
+ R"""({
524
+ "type": ["array", "null"],
525
+ "prefixItems": { "type": "string" }
526
+ })""",
527
+ R"""(
528
+ alternative-0 ::= "[" space (string ("," space string)*)? "]" space
529
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
530
+ null ::= "null" space
531
+ root ::= alternative-0 | null
532
+ space ::= | " " | "\n" [ \t]{0,20}
533
+ string ::= "\"" char* "\"" space
276
534
  )"""
277
535
  });
278
536
 
@@ -283,9 +541,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
283
541
  "prefixItems": [{ "type": "string" }]
284
542
  })""",
285
543
  R"""(
286
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
544
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
287
545
  root ::= "[" space string "]" space
288
- space ::= " "?
546
+ space ::= | " " | "\n" [ \t]{0,20}
289
547
  string ::= "\"" char* "\"" space
290
548
  )"""
291
549
  });
@@ -297,12 +555,12 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
297
555
  "prefixItems": [{ "type": "string" }, { "type": "number" }]
298
556
  })""",
299
557
  R"""(
300
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
301
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
302
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
558
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
559
+ decimal-part ::= [0-9]{1,16}
560
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
303
561
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
304
562
  root ::= "[" space string "," space number "]" space
305
- space ::= " "?
563
+ space ::= | " " | "\n" [ \t]{0,20}
306
564
  string ::= "\"" char* "\"" space
307
565
  )"""
308
566
  });
@@ -314,10 +572,10 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
314
572
  "type": "number"
315
573
  })""",
316
574
  R"""(
317
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
318
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
575
+ decimal-part ::= [0-9]{1,16}
576
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
319
577
  root ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
320
- space ::= " "?
578
+ space ::= | " " | "\n" [ \t]{0,20}
321
579
  )"""
322
580
  });
323
581
 
@@ -332,8 +590,8 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
332
590
  })""",
333
591
  R"""(
334
592
  boolean ::= ("true" | "false") space
335
- root ::= "[" space boolean "," space boolean ("," space boolean)* "]" space
336
- space ::= " "?
593
+ root ::= "[" space boolean ("," space boolean)+ "]" space
594
+ space ::= | " " | "\n" [ \t]{0,20}
337
595
  )"""
338
596
  });
339
597
 
@@ -348,8 +606,8 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
348
606
  })""",
349
607
  R"""(
350
608
  boolean ::= ("true" | "false") space
351
- root ::= "[" space (boolean)? "]" space
352
- space ::= " "?
609
+ root ::= "[" space boolean? "]" space
610
+ space ::= | " " | "\n" [ \t]{0,20}
353
611
  )"""
354
612
  });
355
613
 
@@ -365,7 +623,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
365
623
  R"""(
366
624
  boolean ::= ("true" | "false") space
367
625
  root ::= "[" space (boolean ("," space boolean)?)? "]" space
368
- space ::= " "?
626
+ space ::= | " " | "\n" [ \t]{0,20}
369
627
  )"""
370
628
  });
371
629
 
@@ -380,13 +638,51 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
380
638
  "maxItems": 5
381
639
  })""",
382
640
  R"""(
383
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
641
+ decimal-part ::= [0-9]{1,16}
384
642
  integer ::= ("-"? integral-part) space
385
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
643
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
386
644
  item ::= number | integer
387
645
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
388
- root ::= "[" space item "," space item "," space item ("," space item ("," space item)?)? "]" space
389
- space ::= " "?
646
+ root ::= "[" space item ("," space item){2,4} "]" space
647
+ space ::= | " " | "\n" [ \t]{0,20}
648
+ )"""
649
+ });
650
+
651
+ test({
652
+ SUCCESS,
653
+ "min + max items with min + max values across zero",
654
+ R"""({
655
+ "items": {
656
+ "type": "integer",
657
+ "minimum": -12,
658
+ "maximum": 207
659
+ },
660
+ "minItems": 3,
661
+ "maxItems": 5
662
+ })""",
663
+ R"""(
664
+ item ::= ("-" ([0-9] | "1" [0-2]) | [0-9] | ([1-8] [0-9] | [9] [0-9]) | ([1] [0-9]{2} | [2] "0" [0-7])) space
665
+ root ::= "[" space item ("," space item){2,4} "]" space
666
+ space ::= | " " | "\n" [ \t]{0,20}
667
+ )"""
668
+ });
669
+
670
+ test({
671
+ SUCCESS,
672
+ "min + max items with min + max values",
673
+ R"""({
674
+ "items": {
675
+ "type": "integer",
676
+ "minimum": 12,
677
+ "maximum": 207
678
+ },
679
+ "minItems": 3,
680
+ "maxItems": 5
681
+ })""",
682
+ R"""(
683
+ item ::= (([1] ([2-9]) | [2-9] [0-9]) | ([1] [0-9]{2} | [2] "0" [0-7])) space
684
+ root ::= "[" space item ("," space item){2,4} "]" space
685
+ space ::= | " " | "\n" [ \t]{0,20}
390
686
  )"""
391
687
  });
392
688
 
@@ -399,7 +695,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
399
695
  })""",
400
696
  R"""(
401
697
  root ::= "\"" "ab" "c"? "d"* "ef" "g"+ ("hij")? "kl" "\"" space
402
- space ::= " "?
698
+ space ::= | " " | "\n" [ \t]{0,20}
403
699
  )"""
404
700
  });
405
701
 
@@ -412,7 +708,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
412
708
  })""",
413
709
  R"""(
414
710
  root ::= "\"" "[]{}()|+*?" "\"" space
415
- space ::= " "?
711
+ space ::= | " " | "\n" [ \t]{0,20}
416
712
  )"""
417
713
  });
418
714
 
@@ -425,7 +721,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
425
721
  })""",
426
722
  R"""(
427
723
  root ::= "\"" "\"" "\"" space
428
- space ::= " "?
724
+ space ::= | " " | "\n" [ \t]{0,20}
429
725
  )"""
430
726
  });
431
727
 
@@ -438,9 +734,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
438
734
  })""",
439
735
  R"""(
440
736
  dot ::= [^\x0A\x0D]
441
- root ::= "\"" ("(" root-1 (root-1 (root-1)?)? ")")? root-1 root-1 root-1 "-" root-1 root-1 root-1 root-1 " " "aaa" ("a" ("a")?)? "nd" dot dot dot "\"" space
737
+ root ::= "\"" ("(" root-1{1,3} ")")? root-1{3,3} "-" root-1{4,4} " " "a"{3,5} "nd" dot dot dot "\"" space
442
738
  root-1 ::= [0-9]
443
- space ::= " "?
739
+ space ::= | " " | "\n" [ \t]{0,20}
444
740
  )"""
445
741
  });
446
742
 
@@ -466,9 +762,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
466
762
  a-kv ::= "\"a\"" space ":" space string
467
763
  b-kv ::= "\"b\"" space ":" space string
468
764
  c-kv ::= "\"c\"" space ":" space string
469
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
765
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
470
766
  root ::= "{" space b-kv "," space c-kv "," space a-kv "}" space
471
- space ::= " "?
767
+ space ::= | " " | "\n" [ \t]{0,20}
472
768
  string ::= "\"" char* "\"" space
473
769
  )"""
474
770
  });
@@ -486,9 +782,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
486
782
  })""",
487
783
  R"""(
488
784
  a-kv ::= "\"a\"" space ":" space string
489
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
785
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
490
786
  root ::= "{" space (a-kv )? "}" space
491
- space ::= " "?
787
+ space ::= | " " | "\n" [ \t]{0,20}
492
788
  string ::= "\"" char* "\"" space
493
789
  )"""
494
790
  });
@@ -510,9 +806,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
510
806
  b-kv ::= "\"b\"" space ":" space string
511
807
  b-rest ::= ( "," space c-kv )?
512
808
  c-kv ::= "\"c\"" space ":" space string
513
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
809
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
514
810
  root ::= "{" space (a-kv a-rest | b-kv b-rest | c-kv )? "}" space
515
- space ::= " "?
811
+ space ::= | " " | "\n" [ \t]{0,20}
516
812
  string ::= "\"" char* "\"" space
517
813
  )"""
518
814
  });
@@ -534,11 +830,11 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
534
830
  a-kv ::= "\"a\"" space ":" space string
535
831
  b-kv ::= "\"b\"" space ":" space string
536
832
  c-kv ::= "\"c\"" space ":" space string
537
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
833
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
538
834
  d-kv ::= "\"d\"" space ":" space string
539
835
  d-rest ::= ( "," space c-kv )?
540
836
  root ::= "{" space b-kv "," space a-kv ( "," space ( d-kv d-rest | c-kv ) )? "}" space
541
- space ::= " "?
837
+ space ::= | " " | "\n" [ \t]{0,20}
542
838
  string ::= "\"" char* "\"" space
543
839
  )"""
544
840
  });
@@ -552,14 +848,13 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
552
848
  })""",
553
849
  R"""(
554
850
  additional-kv ::= string ":" space additional-value
555
- additional-kvs ::= additional-kv ( "," space additional-kv )*
556
851
  additional-value ::= "[" space (number ("," space number)*)? "]" space
557
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
558
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
559
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
852
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
853
+ decimal-part ::= [0-9]{1,16}
854
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
560
855
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
561
- root ::= "{" space (additional-kvs )? "}" space
562
- space ::= " "?
856
+ root ::= "{" space (additional-kv ( "," space additional-kv )* )? "}" space
857
+ space ::= | " " | "\n" [ \t]{0,20}
563
858
  string ::= "\"" char* "\"" space
564
859
  )"""
565
860
  });
@@ -574,14 +869,14 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
574
869
  R"""(
575
870
  array ::= "[" space ( value ("," space value)* )? "]" space
576
871
  boolean ::= ("true" | "false") space
577
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
578
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
579
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
872
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
873
+ decimal-part ::= [0-9]{1,16}
874
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
580
875
  null ::= "null" space
581
876
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
582
877
  object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
583
878
  root ::= object
584
- space ::= " "?
879
+ space ::= | " " | "\n" [ \t]{0,20}
585
880
  string ::= "\"" char* "\"" space
586
881
  value ::= object | array | string | number | boolean | null
587
882
  )"""
@@ -596,14 +891,14 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
596
891
  R"""(
597
892
  array ::= "[" space ( value ("," space value)* )? "]" space
598
893
  boolean ::= ("true" | "false") space
599
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
600
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
601
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
894
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
895
+ decimal-part ::= [0-9]{1,16}
896
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
602
897
  null ::= "null" space
603
898
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
604
899
  object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
605
900
  root ::= object
606
- space ::= " "?
901
+ space ::= | " " | "\n" [ \t]{0,20}
607
902
  string ::= "\"" char* "\"" space
608
903
  value ::= object | array | string | number | boolean | null
609
904
  )"""
@@ -618,7 +913,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
618
913
  })""",
619
914
  R"""(
620
915
  root ::= "{" space "}" space
621
- space ::= " "?
916
+ space ::= | " " | "\n" [ \t]{0,20}
622
917
  )"""
623
918
  });
624
919
 
@@ -635,14 +930,14 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
635
930
  })""",
636
931
  R"""(
637
932
  a-kv ::= "\"a\"" space ":" space number
638
- additional-kv ::= string ":" space string
639
- additional-kvs ::= additional-kv ( "," space additional-kv )*
640
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
641
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
642
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
933
+ additional-k ::= ["] ( [a] char+ | [^"a] char* )? ["] space
934
+ additional-kv ::= additional-k ":" space string
935
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
936
+ decimal-part ::= [0-9]{1,16}
937
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
643
938
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
644
- root ::= "{" space a-kv ( "," space ( additional-kvs ) )? "}" space
645
- space ::= " "?
939
+ root ::= "{" space a-kv ( "," space ( additional-kv ( "," space additional-kv )* ) )? "}" space
940
+ space ::= | " " | "\n" [ \t]{0,20}
646
941
  string ::= "\"" char* "\"" space
647
942
  )"""
648
943
  });
@@ -659,16 +954,15 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
659
954
  })""",
660
955
  R"""(
661
956
  a-kv ::= "\"a\"" space ":" space number
662
- a-rest ::= additional-kvs
663
- additional-kv ::= string ":" space number
664
- additional-kvs ::= additional-kv ( "," space additional-kv )*
665
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
666
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
667
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
957
+ a-rest ::= ( "," space additional-kv )*
958
+ additional-k ::= ["] ( [a] char+ | [^"a] char* )? ["] space
959
+ additional-kv ::= additional-k ":" space number
960
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
961
+ decimal-part ::= [0-9]{1,16}
962
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
668
963
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
669
- root ::= "{" space (a-kv a-rest | additional-kvs )? "}" space
670
- space ::= " "?
671
- string ::= "\"" char* "\"" space
964
+ root ::= "{" space (a-kv a-rest | additional-kv ( "," space additional-kv )* )? "}" space
965
+ space ::= | " " | "\n" [ \t]{0,20}
672
966
  )"""
673
967
  });
674
968
 
@@ -678,25 +972,100 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
678
972
  R"""({
679
973
  "type": "object",
680
974
  "properties": {
681
- "a": {"type": "number"},
682
- "b": {"type": "number"}
975
+ "and": {"type": "number"},
976
+ "also": {"type": "number"}
683
977
  },
684
- "required": ["a"],
978
+ "required": ["and"],
685
979
  "additionalProperties": {"type": "number"}
686
980
  })""",
687
981
  R"""(
688
- a-kv ::= "\"a\"" space ":" space number
689
- additional-kv ::= string ":" space number
690
- additional-kvs ::= additional-kv ( "," space additional-kv )*
691
- b-kv ::= "\"b\"" space ":" space number
692
- b-rest ::= additional-kvs
693
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
694
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
695
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
982
+ additional-k ::= ["] ( [a] ([l] ([s] ([o] char+ | [^"o] char*) | [^"s] char*) | [n] ([d] char+ | [^"d] char*) | [^"ln] char*) | [^"a] char* )? ["] space
983
+ additional-kv ::= additional-k ":" space number
984
+ also-kv ::= "\"also\"" space ":" space number
985
+ also-rest ::= ( "," space additional-kv )*
986
+ and-kv ::= "\"and\"" space ":" space number
987
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
988
+ decimal-part ::= [0-9]{1,16}
989
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
696
990
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
697
- root ::= "{" space a-kv ( "," space ( b-kv b-rest | additional-kvs ) )? "}" space
698
- space ::= " "?
699
- string ::= "\"" char* "\"" space
991
+ root ::= "{" space and-kv ( "," space ( also-kv also-rest | additional-kv ( "," space additional-kv )* ) )? "}" space
992
+ space ::= | " " | "\n" [ \t]{0,20}
993
+ )"""
994
+ });
995
+
996
+ test({
997
+ SUCCESS,
998
+ "optional props with empty name",
999
+ R"""({
1000
+ "properties": {
1001
+ "": {"type": "integer"},
1002
+ "a": {"type": "integer"}
1003
+ },
1004
+ "additionalProperties": {"type": "integer"}
1005
+ })""",
1006
+ R"""(
1007
+ -kv ::= "\"\"" space ":" space root
1008
+ -rest ::= ( "," space a-kv )? a-rest
1009
+ a-kv ::= "\"a\"" space ":" space integer
1010
+ a-rest ::= ( "," space additional-kv )*
1011
+ additional-k ::= ["] ( [a] char+ | [^"a] char* ) ["] space
1012
+ additional-kv ::= additional-k ":" space integer
1013
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
1014
+ integer ::= ("-"? integral-part) space
1015
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
1016
+ root ::= ("-"? integral-part) space
1017
+ root0 ::= "{" space (-kv -rest | a-kv a-rest | additional-kv ( "," space additional-kv )* )? "}" space
1018
+ space ::= | " " | "\n" [ \t]{0,20}
1019
+ )"""
1020
+ });
1021
+
1022
+ test({
1023
+ SUCCESS,
1024
+ "optional props with nested names",
1025
+ R"""({
1026
+ "properties": {
1027
+ "a": {"type": "integer"},
1028
+ "aa": {"type": "integer"}
1029
+ },
1030
+ "additionalProperties": {"type": "integer"}
1031
+ })""",
1032
+ R"""(
1033
+ a-kv ::= "\"a\"" space ":" space integer
1034
+ a-rest ::= ( "," space aa-kv )? aa-rest
1035
+ aa-kv ::= "\"aa\"" space ":" space integer
1036
+ aa-rest ::= ( "," space additional-kv )*
1037
+ additional-k ::= ["] ( [a] ([a] char+ | [^"a] char*) | [^"a] char* )? ["] space
1038
+ additional-kv ::= additional-k ":" space integer
1039
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
1040
+ integer ::= ("-"? integral-part) space
1041
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
1042
+ root ::= "{" space (a-kv a-rest | aa-kv aa-rest | additional-kv ( "," space additional-kv )* )? "}" space
1043
+ space ::= | " " | "\n" [ \t]{0,20}
1044
+ )"""
1045
+ });
1046
+
1047
+ test({
1048
+ SUCCESS,
1049
+ "optional props with common prefix",
1050
+ R"""({
1051
+ "properties": {
1052
+ "ab": {"type": "integer"},
1053
+ "ac": {"type": "integer"}
1054
+ },
1055
+ "additionalProperties": {"type": "integer"}
1056
+ })""",
1057
+ R"""(
1058
+ ab-kv ::= "\"ab\"" space ":" space integer
1059
+ ab-rest ::= ( "," space ac-kv )? ac-rest
1060
+ ac-kv ::= "\"ac\"" space ":" space integer
1061
+ ac-rest ::= ( "," space additional-kv )*
1062
+ additional-k ::= ["] ( [a] ([b] char+ | [c] char+ | [^"bc] char*) | [^"a] char* )? ["] space
1063
+ additional-kv ::= additional-k ":" space integer
1064
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
1065
+ integer ::= ("-"? integral-part) space
1066
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
1067
+ root ::= "{" space (ab-kv ab-rest | ac-kv ac-rest | additional-kv ( "," space additional-kv )* )? "}" space
1068
+ space ::= | " " | "\n" [ \t]{0,20}
700
1069
  )"""
701
1070
  });
702
1071
 
@@ -721,11 +1090,11 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
721
1090
  }
722
1091
  })""",
723
1092
  R"""(
724
- char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F])
1093
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
725
1094
  foo ::= "{" space foo-a-kv "}" space
726
1095
  foo-a-kv ::= "\"a\"" space ":" space string
727
1096
  root ::= foo
728
- space ::= " "?
1097
+ space ::= | " " | "\n" [ \t]{0,20}
729
1098
  string ::= "\"" char* "\"" space
730
1099
  )"""
731
1100
  });
@@ -753,13 +1122,13 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
753
1122
  alternative-1 ::= bar
754
1123
  bar ::= "{" space (bar-b-kv )? "}" space
755
1124
  bar-b-kv ::= "\"b\"" space ":" space number
756
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
1125
+ decimal-part ::= [0-9]{1,16}
757
1126
  foo ::= "{" space (foo-a-kv )? "}" space
758
1127
  foo-a-kv ::= "\"a\"" space ":" space number
759
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
1128
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
760
1129
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
761
1130
  root ::= alternative-0 | alternative-1
762
- space ::= " "?
1131
+ space ::= | " " | "\n" [ \t]{0,20}
763
1132
  )"""
764
1133
  });
765
1134
 
@@ -799,11 +1168,11 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
799
1168
  c-kv ::= "\"c\"" space ":" space number
800
1169
  d-kv ::= "\"d\"" space ":" space number
801
1170
  d-rest ::= ( "," space c-kv )?
802
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
803
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
1171
+ decimal-part ::= [0-9]{1,16}
1172
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
804
1173
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
805
1174
  root ::= "{" space a-kv "," space b-kv ( "," space ( d-kv d-rest | c-kv ) )? "}" space
806
- space ::= " "?
1175
+ space ::= | " " | "\n" [ \t]{0,20}
807
1176
  )"""
808
1177
  });
809
1178
 
@@ -842,8 +1211,8 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
842
1211
  "definitions": {}
843
1212
  })""",
844
1213
  R"""(
845
- decimal-part ::= [0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
846
- integral-part ::= [0-9] | [1-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9] ([0-9])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?
1214
+ decimal-part ::= [0-9]{1,16}
1215
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
847
1216
  number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
848
1217
  number- ::= "{" space number-number-kv "}" space
849
1218
  number-kv ::= "\"number\"" space ":" space number-
@@ -851,7 +1220,7 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
851
1220
  number-number-kv ::= "\"number\"" space ":" space number-number
852
1221
  number-number-root-kv ::= "\"root\"" space ":" space number
853
1222
  root ::= "{" space number-kv "}" space
854
- space ::= " "?
1223
+ space ::= | " " | "\n" [ \t]{0,20}
855
1224
  )"""
856
1225
  });
857
1226
  }
@@ -870,26 +1239,30 @@ int main() {
870
1239
  }
871
1240
  });
872
1241
 
873
- if (getenv("LLAMA_PYTHON_AVAILABLE") || (std::system("python --version") == 0)) {
874
- test_all("Python", [](const TestCase & tc) {
875
- write("test-json-schema-input.tmp", tc.schema);
876
- tc.verify_status(std::system(
877
- "python ./examples/json_schema_to_grammar.py test-json-schema-input.tmp > test-grammar-output.tmp") == 0 ? SUCCESS : FAILURE);
878
- tc.verify(read("test-grammar-output.tmp"));
879
- });
1242
+ if (getenv("LLAMA_SKIP_TESTS_SLOW_ON_EMULATOR")) {
1243
+ fprintf(stderr, "\033[33mWARNING: Skipping slow tests on emulator.\n\033[0m");
880
1244
  } else {
881
- fprintf(stderr, "\033[33mWARNING: Python not found, skipping Python JSON schema -> grammar tests.\n\033[0m");
882
- }
1245
+ if (getenv("LLAMA_PYTHON_AVAILABLE") || (std::system("python -c \"import sys; exit(1) if sys.version_info < (3, 8) else print('Python version is sufficient')\"") == 0)) {
1246
+ test_all("Python", [](const TestCase & tc) {
1247
+ write("test-json-schema-input.tmp", tc.schema);
1248
+ tc.verify_status(std::system(
1249
+ "python ./examples/json_schema_to_grammar.py test-json-schema-input.tmp > test-grammar-output.tmp") == 0 ? SUCCESS : FAILURE);
1250
+ tc.verify(read("test-grammar-output.tmp"));
1251
+ });
1252
+ } else {
1253
+ fprintf(stderr, "\033[33mWARNING: Python not found (min version required is 3.8), skipping Python JSON schema -> grammar tests.\n\033[0m");
1254
+ }
883
1255
 
884
- if (getenv("LLAMA_NODE_AVAILABLE") || (std::system("node --version") == 0)) {
885
- test_all("JavaScript", [](const TestCase & tc) {
886
- write("test-json-schema-input.tmp", tc.schema);
887
- tc.verify_status(std::system(
888
- "node ./tests/run-json-schema-to-grammar.mjs test-json-schema-input.tmp > test-grammar-output.tmp") == 0 ? SUCCESS : FAILURE);
889
- tc.verify(read("test-grammar-output.tmp"));
890
- });
891
- } else {
892
- fprintf(stderr, "\033[33mWARNING: Node not found, skipping JavaScript JSON schema -> grammar tests.\n\033[0m");
1256
+ if (getenv("LLAMA_NODE_AVAILABLE") || (std::system("node --version") == 0)) {
1257
+ test_all("JavaScript", [](const TestCase & tc) {
1258
+ write("test-json-schema-input.tmp", tc.schema);
1259
+ tc.verify_status(std::system(
1260
+ "node ./tests/run-json-schema-to-grammar.mjs test-json-schema-input.tmp > test-grammar-output.tmp") == 0 ? SUCCESS : FAILURE);
1261
+ tc.verify(read("test-grammar-output.tmp"));
1262
+ });
1263
+ } else {
1264
+ fprintf(stderr, "\033[33mWARNING: Node not found, skipping JavaScript JSON schema -> grammar tests.\n\033[0m");
1265
+ }
893
1266
  }
894
1267
 
895
1268
  test_all("Check Expectations Validity", [](const TestCase & tc) {