llguidance 0.7.17__tar.gz → 0.7.18__tar.gz
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.
- {llguidance-0.7.17 → llguidance-0.7.18}/CHANGELOG.md +5 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/Cargo.lock +5 -5
- {llguidance-0.7.17 → llguidance-0.7.18}/PKG-INFO +1 -1
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/Cargo.toml +1 -1
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/llguidance.h +4 -7
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/from_guidance.rs +2 -8
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/ffi.rs +27 -14
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/compiler.rs +15 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lark/compiler.rs +3 -5
- {llguidance-0.7.17 → llguidance-0.7.18}/pyproject.toml +1 -1
- {llguidance-0.7.17 → llguidance-0.7.18}/python_ext/Cargo.toml +1 -1
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/tests/test_lark.rs +14 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/tests/test_raw_parser.rs +15 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/Cargo.toml +1 -1
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie_hf_downloader/Cargo.toml +1 -1
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie_hf_tokenizers/Cargo.toml +1 -1
- {llguidance-0.7.17 → llguidance-0.7.18}/.github/workflows/rust.yml +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/.github/workflows/wheels.yml +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/.gitignore +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/CODE_OF_CONDUCT.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/Cargo.toml +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/LICENSE +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/SECURITY.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/SUPPORT.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/c_sample/Makefile +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/c_sample/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/c_sample/c_sample.cpp +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/docs/fast_forward.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/docs/json_schema.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/docs/mask_plot.png +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/docs/optimizations.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/docs/special_tokens.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/docs/syntax.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/docs/toktrie.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/Cargo.toml +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/expected_maskbench.json +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/jstats.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/scripts/split-stats.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/scripts/split_plot.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/src/json_stats.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/src/lib.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/json_stats/src/stats.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/LICENSE +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/build.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/cbindgen.toml +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/grammars/character.json +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/grammars/json.json +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/api.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/constraint.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/grammar.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/lexer.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/lexerspec.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/mod.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/parser.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/perf.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/regexvec.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/earley/slicer.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/factory.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/ffi_par.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/grammar_builder.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/context_ref.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/context_simple/context.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/context_simple/draft.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/context_simple/mod.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/formats.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/mod.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/numeric.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/schema.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json/shared_context.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/json_validation.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lark/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lark/ast.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lark/common.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lark/lexer.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lark/mod.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lark/parser.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/lib.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/logging.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/matcher.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/output.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/panic_utils.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/regex_rewrite.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/stop_controller.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/substring.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/tokenizer_json.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/parser/src/tokenparser.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/plan.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/__init__.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/_grammar_from.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/_lib.pyi +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/_struct_tag.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/_tokenizer.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/_util.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/cli.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/gbnf_to_lark.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/hf.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/mlx.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/numpy.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/py.typed +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/llguidance/torch.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/mypy.ini +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/torch_tests/__init__.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/torch_tests/test_bitmask.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/torch_tests/test_hf.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python/torch_tests/test_matcher.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python_ext/src/lib.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python_ext/src/llinterpreter.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python_ext/src/llmatcher.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python_ext/src/parserlimits.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python_ext/src/py.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/python_ext/src/pyjson.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/Cargo.toml +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/cli.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/blog.sample.json +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/blog.schema.json +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/blog.schema.ll.json +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/arithmetic.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/c.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/chess.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/english.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/japanese.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/json.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/json_arr.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/list.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/from-llama.cpp/vllm-sql.gbnf +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/lark.lark +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/rfc.lark +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/rfc.xml +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/data/ulysses.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/gtest.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/lark.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/run.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/src/lib.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/src/minimal.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/src/sample_parser.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/tests/test_ll.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/sample_parser/tests/test_stop.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/annotate_asm.js +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/bump.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/cbindgen.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/checklinks.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/checklinks.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/ci-publish.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/disasm.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/gbnf_to_lark.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/gen-testcase.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/git-version.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/install-deps.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/jsonschema-stats.js +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/remote-guidance-test.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/rust-size.js +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/rust_size.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/test-guidance.sh +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/tokenizer_test.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/scripts/update-git.py +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/LICENSE +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/README.md +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/src/bytes.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/src/lib.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/src/recognizer.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/src/rng.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/src/svob.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/src/tokenv.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/src/toktree.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie/tests/test_svob.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie_hf_downloader/LICENSE +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie_hf_downloader/src/lib.rs +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie_hf_tokenizers/LICENSE +0 -0
- {llguidance-0.7.17 → llguidance-0.7.18}/toktrie_hf_tokenizers/src/lib.rs +0 -0
|
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
If a release doesn't introduce any interesting changes (build fixes etc.), it's skipped.
|
|
6
6
|
|
|
7
|
+
#### [0.7.18](https://github.com/guidance-ai/llguidance/compare/v0.7.17...0.7.18) 2025-04-22
|
|
8
|
+
|
|
9
|
+
- apply x-guidance also in %json{} [`2627891`](https://github.com/guidance-ai/llguidance/commit/2627891c72c7e38062cd3e052f1de146d2e21635)
|
|
10
|
+
- more sensible llg_validate_grammar() signature [`41928c0`](https://github.com/guidance-ai/llguidance/commit/41928c07298e69e3c8adc4a3c1f43ef9b1cc1c6b)
|
|
11
|
+
|
|
7
12
|
#### [0.7.17](https://github.com/guidance-ai/llguidance/compare/v0.7.16...0.7.17) 2025-04-22
|
|
8
13
|
|
|
9
14
|
- support for min/maxProperties in JSON Schema [`#168`](https://github.com/guidance-ai/llguidance/issues/168)
|
|
@@ -1178,7 +1178,7 @@ checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856"
|
|
|
1178
1178
|
|
|
1179
1179
|
[[package]]
|
|
1180
1180
|
name = "llguidance"
|
|
1181
|
-
version = "0.7.
|
|
1181
|
+
version = "0.7.18"
|
|
1182
1182
|
dependencies = [
|
|
1183
1183
|
"anyhow",
|
|
1184
1184
|
"derivre",
|
|
@@ -1197,7 +1197,7 @@ dependencies = [
|
|
|
1197
1197
|
|
|
1198
1198
|
[[package]]
|
|
1199
1199
|
name = "llguidance_py"
|
|
1200
|
-
version = "0.7.
|
|
1200
|
+
version = "0.7.18"
|
|
1201
1201
|
dependencies = [
|
|
1202
1202
|
"anyhow",
|
|
1203
1203
|
"bytemuck",
|
|
@@ -2362,7 +2362,7 @@ dependencies = [
|
|
|
2362
2362
|
|
|
2363
2363
|
[[package]]
|
|
2364
2364
|
name = "toktrie"
|
|
2365
|
-
version = "0.7.
|
|
2365
|
+
version = "0.7.18"
|
|
2366
2366
|
dependencies = [
|
|
2367
2367
|
"anyhow",
|
|
2368
2368
|
"bytemuck",
|
|
@@ -2373,7 +2373,7 @@ dependencies = [
|
|
|
2373
2373
|
|
|
2374
2374
|
[[package]]
|
|
2375
2375
|
name = "toktrie_hf_downloader"
|
|
2376
|
-
version = "0.7.
|
|
2376
|
+
version = "0.7.18"
|
|
2377
2377
|
dependencies = [
|
|
2378
2378
|
"anyhow",
|
|
2379
2379
|
"hf-hub",
|
|
@@ -2384,7 +2384,7 @@ dependencies = [
|
|
|
2384
2384
|
|
|
2385
2385
|
[[package]]
|
|
2386
2386
|
name = "toktrie_hf_tokenizers"
|
|
2387
|
-
version = "0.7.
|
|
2387
|
+
version = "0.7.18"
|
|
2388
2388
|
dependencies = [
|
|
2389
2389
|
"anyhow",
|
|
2390
2390
|
"log",
|
|
@@ -462,17 +462,14 @@ struct LlgMatcher *llg_new_matcher(const struct LlgConstraintInit *init,
|
|
|
462
462
|
* This about twice as fast as creating a matcher (which also validates).
|
|
463
463
|
* See llg_new_matcher() for the grammar format.
|
|
464
464
|
* Returns 0 on success and -1 on error and 1 on warning.
|
|
465
|
-
* The error message is written to
|
|
466
|
-
*
|
|
467
|
-
* Same for warning_string.
|
|
465
|
+
* The error message or warning is written to message, which is message_len bytes long.
|
|
466
|
+
* It's always NUL-terminated.
|
|
468
467
|
*/
|
|
469
468
|
int32_t llg_validate_grammar(const struct LlgConstraintInit *init,
|
|
470
469
|
const char *constraint_type,
|
|
471
470
|
const char *data,
|
|
472
|
-
char *
|
|
473
|
-
size_t
|
|
474
|
-
char *warning_string,
|
|
475
|
-
size_t warning_string_len);
|
|
471
|
+
char *message,
|
|
472
|
+
size_t message_len);
|
|
476
473
|
|
|
477
474
|
/**
|
|
478
475
|
* Compute the set of allowed tokens for the current state.
|
|
@@ -37,14 +37,8 @@ impl CompileCtx {
|
|
|
37
37
|
let _ = lark;
|
|
38
38
|
bail!("lark_grammar is not supported in this build")
|
|
39
39
|
}
|
|
40
|
-
} else if let Some(
|
|
41
|
-
|
|
42
|
-
if let Some(x_guidance) = json_schema.get("x-guidance") {
|
|
43
|
-
opts = serde_json::from_value(x_guidance.clone())?;
|
|
44
|
-
// TODO not removing it causes oneOf to be handled as anyOf in Github_medium---o61004.json
|
|
45
|
-
json_schema.as_object_mut().unwrap().remove("x-guidance");
|
|
46
|
-
}
|
|
47
|
-
opts.json_to_llg(builder, json_schema)?
|
|
40
|
+
} else if let Some(json_schema) = input.json_schema {
|
|
41
|
+
JsonCompileOptions::default().json_to_llg_with_overrides(builder, json_schema)?
|
|
48
42
|
} else {
|
|
49
43
|
bail!("grammar must have either lark_grammar or json_schema");
|
|
50
44
|
};
|
|
@@ -170,17 +170,21 @@ impl LlgTokenizer {
|
|
|
170
170
|
})
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
fn to_env(&self) -> TokEnv {
|
|
173
|
+
pub fn to_env(&self) -> TokEnv {
|
|
174
174
|
self.factory.tok_env().clone()
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
fn tok_env(&self) -> &TokEnv {
|
|
177
|
+
pub fn tok_env(&self) -> &TokEnv {
|
|
178
178
|
self.factory.tok_env()
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
fn tok_trie(&self) -> &TokTrie {
|
|
181
|
+
pub fn tok_trie(&self) -> &TokTrie {
|
|
182
182
|
self.factory.tok_env().tok_trie()
|
|
183
183
|
}
|
|
184
|
+
|
|
185
|
+
pub fn factory(&self) -> &ParserFactory {
|
|
186
|
+
&self.factory
|
|
187
|
+
}
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
pub type LlgToken = u32;
|
|
@@ -644,8 +648,10 @@ pub extern "C" fn llg_clone_constraint(cc: &LlgConstraint) -> *mut LlgConstraint
|
|
|
644
648
|
}
|
|
645
649
|
|
|
646
650
|
/// Construct a new tokenizer from the given TokenizerInit
|
|
651
|
+
/// # Safety
|
|
652
|
+
/// This function should only be called from C code.
|
|
647
653
|
#[no_mangle]
|
|
648
|
-
pub extern "C" fn llg_new_tokenizer(
|
|
654
|
+
pub unsafe extern "C" fn llg_new_tokenizer(
|
|
649
655
|
tok_init: &LlgTokenizerInit,
|
|
650
656
|
error_string: *mut c_char,
|
|
651
657
|
error_string_len: usize,
|
|
@@ -849,7 +855,16 @@ fn build_stop_controller(
|
|
|
849
855
|
StopController::new(tokenizer.to_env(), stop_tokens.to_vec(), stop_rx, vec![])
|
|
850
856
|
}
|
|
851
857
|
|
|
852
|
-
|
|
858
|
+
/// Save the error string to the given pointer.
|
|
859
|
+
/// The string is NUL-terminated.
|
|
860
|
+
/// The function will write at most error_string_len bytes (including the NUL).
|
|
861
|
+
/// # Safety
|
|
862
|
+
/// This function should only when interacting with pointers passed from C.
|
|
863
|
+
pub unsafe fn save_error_string(
|
|
864
|
+
e: impl Display,
|
|
865
|
+
error_string: *mut c_char,
|
|
866
|
+
error_string_len: usize,
|
|
867
|
+
) {
|
|
853
868
|
if !error_string.is_null() && error_string_len > 0 {
|
|
854
869
|
let e = e.to_string();
|
|
855
870
|
let e = e.as_bytes();
|
|
@@ -999,9 +1014,8 @@ fn validate_grammar(
|
|
|
999
1014
|
/// This about twice as fast as creating a matcher (which also validates).
|
|
1000
1015
|
/// See llg_new_matcher() for the grammar format.
|
|
1001
1016
|
/// Returns 0 on success and -1 on error and 1 on warning.
|
|
1002
|
-
/// The error message is written to
|
|
1003
|
-
///
|
|
1004
|
-
/// Same for warning_string.
|
|
1017
|
+
/// The error message or warning is written to message, which is message_len bytes long.
|
|
1018
|
+
/// It's always NUL-terminated.
|
|
1005
1019
|
/// # Safety
|
|
1006
1020
|
/// This function should only be called from C code.
|
|
1007
1021
|
#[no_mangle]
|
|
@@ -1009,21 +1023,20 @@ pub unsafe extern "C" fn llg_validate_grammar(
|
|
|
1009
1023
|
init: &LlgConstraintInit,
|
|
1010
1024
|
constraint_type: *const c_char,
|
|
1011
1025
|
data: *const c_char,
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
warning_string: *mut c_char,
|
|
1015
|
-
warning_string_len: usize,
|
|
1026
|
+
message: *mut c_char,
|
|
1027
|
+
message_len: usize,
|
|
1016
1028
|
) -> i32 {
|
|
1017
1029
|
match validate_grammar(init, constraint_type, data) {
|
|
1018
1030
|
Err(e) => {
|
|
1019
|
-
save_error_string(e,
|
|
1031
|
+
save_error_string(e, message, message_len);
|
|
1020
1032
|
-1
|
|
1021
1033
|
}
|
|
1022
1034
|
Ok(s) => {
|
|
1023
1035
|
if !s.is_empty() {
|
|
1024
|
-
save_error_string(s,
|
|
1036
|
+
save_error_string(s, message, message_len);
|
|
1025
1037
|
1
|
|
1026
1038
|
} else {
|
|
1039
|
+
save_error_string("", message, message_len);
|
|
1027
1040
|
0
|
|
1028
1041
|
}
|
|
1029
1042
|
}
|
|
@@ -84,6 +84,21 @@ impl Default for JsonCompileOptions {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
impl JsonCompileOptions {
|
|
87
|
+
pub fn json_to_llg_with_overrides(
|
|
88
|
+
&self,
|
|
89
|
+
builder: GrammarBuilder,
|
|
90
|
+
mut schema: Value,
|
|
91
|
+
) -> Result<GrammarResult> {
|
|
92
|
+
if let Some(x_guidance) = schema.get("x-guidance") {
|
|
93
|
+
let opts: Self = serde_json::from_value(x_guidance.clone())?;
|
|
94
|
+
// TODO: figure out why not removing this still causes problems in maskbench
|
|
95
|
+
schema.as_object_mut().unwrap().remove("x-guidance");
|
|
96
|
+
opts.json_to_llg(builder, schema)
|
|
97
|
+
} else {
|
|
98
|
+
self.json_to_llg(builder, schema)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
87
102
|
pub fn json_to_llg(&self, builder: GrammarBuilder, schema: Value) -> Result<GrammarResult> {
|
|
88
103
|
let compiler = Compiler::new(self.clone(), builder);
|
|
89
104
|
#[cfg(feature = "jsonschema_validation")]
|
|
@@ -552,11 +552,9 @@ impl Compiler {
|
|
|
552
552
|
let mut builder = self.builder;
|
|
553
553
|
for (gg, loc, grm) in self.pending_grammars {
|
|
554
554
|
let res = match grm {
|
|
555
|
-
PendingGrammar::Json(json_schema) =>
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
.map_err(|e| loc.augment(anyhow!("failed to compile JSON schema: {}", e)))?
|
|
559
|
-
}
|
|
555
|
+
PendingGrammar::Json(json_schema) => JsonCompileOptions::default()
|
|
556
|
+
.json_to_llg_with_overrides(builder, json_schema)
|
|
557
|
+
.map_err(|e| loc.augment(anyhow!("failed to compile JSON schema: {}", e)))?,
|
|
560
558
|
PendingGrammar::Lark(items) => compile_lark(builder, ParsedLark { items })?,
|
|
561
559
|
};
|
|
562
560
|
builder = res.builder;
|
|
@@ -409,6 +409,20 @@ fn test_lark_syntax_attributes() {
|
|
|
409
409
|
"#,
|
|
410
410
|
);
|
|
411
411
|
|
|
412
|
+
lark_ok(
|
|
413
|
+
r#"
|
|
414
|
+
start: %json {
|
|
415
|
+
"x-guidance": {
|
|
416
|
+
"lenient": true
|
|
417
|
+
},
|
|
418
|
+
"oneOf": [
|
|
419
|
+
{ "type": "object", "properties": { "foo": { "type": "string" } } },
|
|
420
|
+
{ "type": "object", "properties": { "bar": { "type": "string" } } }
|
|
421
|
+
]
|
|
422
|
+
}
|
|
423
|
+
"#,
|
|
424
|
+
);
|
|
425
|
+
|
|
412
426
|
lark_err_test(
|
|
413
427
|
r#" start: foo
|
|
414
428
|
foo[foobar=12]: /.*/ "#,
|
|
@@ -192,3 +192,18 @@ fn test_ff_json4() {
|
|
|
192
192
|
json_fwd_test(schema.clone(), json!({ "foo": 123, "baz": "hello" }));
|
|
193
193
|
json_fwd_test(schema.clone(), json!({ "bar": 123 }));
|
|
194
194
|
}
|
|
195
|
+
|
|
196
|
+
#[test]
|
|
197
|
+
fn test_ff_early() {
|
|
198
|
+
let lark = r#"
|
|
199
|
+
start: lst
|
|
200
|
+
lst: "," lst | ""
|
|
201
|
+
"#;
|
|
202
|
+
|
|
203
|
+
let mut parser = make_parser(lark);
|
|
204
|
+
let tokens = get_tok_env().tokenize(",,,,,,,");
|
|
205
|
+
|
|
206
|
+
for tok in tokens.iter() {
|
|
207
|
+
parser.consume_token(*tok).unwrap();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|