atdml: add support for any JSON-like input formats via atd-jsonlike library#485
Merged
atdml: add support for any JSON-like input formats via atd-jsonlike library#485
Conversation
New opam package with an empty library. The JSON-like AST type will be defined next. The library will serve as a runtime dependency for code generated by atdml that reads generic tree data (JSON, YAML, TOML, etc.). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename package, folder, library name - Pos.ml, Loc.ml: record type definitions matching the mli - Number.ml: of_int, of_float, of_string_opt with JSON number validation - AST.ml: tree type + loc_msg for human-readable location strings Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generate foo_of_jsonlike functions (consuming Atd_jsonlike.AST.t) alongside the existing foo_of_yojson functions. Error messages from of_jsonlike include the source location carried by every AST node. Implementation uses a mode record to parametrize the reader codegen, sharing all logic between the two input tree types. The inlined Atdml_runtime module is split into Atdml_runtime.Yojson and Atdml_runtime.Jsonlike submodules. Two new CLI flags let users opt out of either flavour: --no-jsonlike skip of_jsonlike readers (no atd-jsonlike dependency) --no-yojson skip of_yojson readers, writers, and I/O functions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- README.md documents the AST type, Number.t field semantics (with a table), and Loc/Pos conventions - tests/test.ml covers Number.of_int, Number.of_float, Number.of_string_opt (valid and invalid inputs), and AST.loc_msg - Makefile and test script follow the same pattern as atdml/atdcat - dune-project: add re and testo :with-test deps for atd-jsonlike; remove mistakenly added re dep from atdgen-codec-runtime - root Makefile: run atd-jsonlike tests as part of test-common Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e tests Each test_e2e test now also silently verifies that: yojson_in -> of_jsonlike -> yojson_of -> yojson_out2 == yojson_out A yojson_to_jsonlike_ helper (with dummy locations) is injected into the generated Main.ml. Tests for abstract types and JSON adapters opt out via ~test_jsonlike:false since those features are intentionally not supported by the jsonlike path. Also fixes Yojson.Safe.t compatibility: v3.0.0 removed `Floatlit, `Tuple, and `Variant constructors, so the match is now exhaustive with 8 cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ames Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When <json adapter.ocaml="M"> is used, of_jsonlike now calls M.normalize_jsonlike before deserialization, mirroring the M.normalize call in of_yojson. The function name is intentionally different to avoid conflicts with the Yojson adapter interface. Only module-based adapters are supported for jsonlike; inline adapters (adapter.to_ocaml / adapter.from_ocaml) are not supported and continue to be silently skipped for the jsonlike path. Implementation: the mode record's supports_json_adapters:bool field is replaced with normalize_of_adapter:(json_adapter -> string option), so each mode knows how to derive its normalize expression from an adapter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
atd-jsonlike: new
atd-jsonlikelibrary providing a generic JSON-like AST (Atd_jsonlike.AST.t) with source location on every node, aNumber.ttype that stores int/float/literal representations simultaneously, and helpers for building error messages with file/line/column context.atdml: generates
foo_of_jsonlikereaders (consumingAtd_jsonlike.AST.t) alongside the existingfoo_of_yojsonreaders. Reader codegen is mode-parametrized to avoid duplication. The inlinedAtdml_runtimeis split intoAtdml_runtime.YojsonandAtdml_runtime.Jsonlikesubmodules.atdml
--no-jsonlike/--no-yojson: opt-out flags to suppress either flavour of generated code, reducing output size and runtime dependencies.atd-jsonlike tests and README: 15 unit tests for
Numberarithmetic andAST.loc_msgformatting; README documenting the module API andNumber.tfield semantics.Test plan
make -C atdml test— all 46 atdml snapshot tests passmake -C atd-jsonlike test— all 15 unit tests passatdml --no-jsonlike foo.atdproduces noof_jsonlikefunctionsatdml --no-yojson foo.atdproduces noof_yojson/yojson_of/of_json/to_jsonfunctions🤖 Generated with Claude Code
Closes #453