Conversation
This was referenced Jul 27, 2026
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Grammar::FromJSONSchemaoutput directly in the grammar AST instead of generating and reparsing one large EBNF stringGrammarBuilderwith nestable expression specs for strings, regexes, character classes, references, sequences, choices, repeats, dispatches, and token expressionsJSONSchemaToEBNFavailable for testing, debugging, and format-specific compatibility pathsImplementation
The schema parser and
SchemaSpecmodel stay shared with the existing converter. The newJSONSchemaASTConvertermirrors the established JSON behavior for whitespace, arrays, object-property cardinality,any_order, refs/cycles, unions, constants/enums, numeric ranges, string patterns, and additional/pattern properties, then normalizes the completed grammar.print_converted_ebnf=Trueprints the generated normalized grammar directly, so it no longer invokes the legacy converter for debugging output. Regex constructs whose FSM representation does not yet preserve the existing converter semantics use the mature regex frontend for that fragment only; the generated JSON grammar is no longer reparsed as a whole.Benchmark
Compared
origin/main(ff923ddf) with this branch using RelWithDebInfo builds in separate processes. Results are medians of 5 runs after 1 warmup.legacy parseris the EBNF parser portion of the old conversion path. Real schemas come from JSONSchemaBench; synthetic cases were generated by an out-of-tree benchmark harness. Benchmark-only artifacts are not part of this PR.Testing
pre-commit runruff check python/xgrammar/grammar.pyctest --test-dir build-cxx --output-on-failure -j 4(65 passed)pytest tests/python/test_json_schema_converter.py tests/python/test_grammar_regex_macro.py(592 passed)tests/pythonwith-m 'not hf_token_required'(2788 passed, 1 skipped, 622 remote-token tests deselected)