Repository navigation
fix: update cddl to 0.10.7 - #99
Open
Lightning00Blade wants to merge 5 commits into
Open
Lightning00Blade wants to merge 5 commits into
Lightning00Blade wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the cddl dependency to version 0.10.7 and introduces several utility functions in src/util.rs to collect group rules, identify literal member keys, and handle array group entries. These utilities are integrated into both the TypeScript and Zod engines to improve rule processing and member key normalization. The review feedback suggests an improvement to the member_key_literal_value helper in src/util.rs to remove the is_cut: false constraint, allowing both cut and non-cut literal keys to be correctly normalized as object properties.
cddl 0.10.7 switched to a Pest-based parser which altered four AST forms:
- Arrow map literal keys (? "key" => int) now parse as MemberKey::Type1 { is_cut: false } instead of MemberKey::Value.
- Bare type names and parenthesized types inside arrays now parse as GroupEntry::TypeGroupname and GroupEntry::InlineGroup.
- Top-level single-identifier parenthesized rules (Name = ( SingleIdent )) now parse as Rule::Type(ParenthesizedType).
Add AST normalization helpers in src/util.rs and wire them into both the TypeScript and Zod engines.
cddl 0.10.7 resolves escape sequences in text literals at parse time, so
a `\` in a text value is now a literal backslash. `escape_js_string`
kept anything that looked like a valid escape sequence, which turned
`.regexp "\\bword\\b"` into `new RegExp("\bword\b")`.
- `escape_js_string` now takes decoded text and escapes every `\`, `"`
and control character.
- `escape_js_raw_string` keeps the previous behavior for byte strings,
which the parser does not decode.
- Use `'content-type' => tstr` in the string literals example, because
cddl 0.10.7 rejects byte string keys in the colon form. Add `.regexp`
cases and update the snapshots; `\u00e9` is now emitted as `é`.
- Document the AST normalization helpers and make them `pub(crate)`.
- Replace the unreachable `MemberKey::Value` alternative in the Zod
engine with `unreachable!()`.
- Put the `type_is_group_ref` signature on one line, as rustfmt does.
- Add `byte_value_to_js_string` so `ByteValue::UTF8` uses raw escaping while `ByteValue::B16` re-encodes decoded bytes as `h'<HEX>'` without going through the fallible `Display` impl; align `member_key_literal_value` with `ByteValue::B64` handling. - Drop unnecessary `.to_string()` allocations at `escape_js_string` call sites in both engines. - Unwrap top-level `Name = ( SingleIdent )` rules in TypeScript's `visit_type_rule` so `NetworkResult` keeps single parentheses. - Expand `examples/string_literals.cddl` and unit tests for hex byte strings, escaped enums, numeric arrow keys, and `b64'...'` behavior.
Lightning00Blade
force-pushed
the
nvitkov/cddl-0.10.7
branch
from
November 10, 2026 16:05
50cc609 to
5b116aa
Compare
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.
Closes #86.
cddl0.10.7 replaced its handwritten two-pass parser with a Pest-based PEG parser, which changed four AST forms. This PR adds AST normalization helpers insrc/util.rsand updates the TypeScript and Zod engines to handle the new AST shapes.Changes
? "optional-key" => int):cddl0.10.7 parses arrow literal keys without^asMemberKey::Type1 { is_cut: false }instead ofMemberKey::Value. Addedmember_key_literal_valueandis_non_cut_type1_member_keyso literal keys stay formatted as normal object properties rather than index signatures /z.record.[* CapabilityRequest],[*(js-uint / text)]):cddl0.10.7 parses these asGroupEntry::TypeGroupnameandGroupEntry::InlineGroup. Addedarray_group_entry_as_type_entryto convert non-group array entries back toValueMemberKeyEntry.BrowserCommand = ( browser.Close ),LogEvent = ( log.EntryAdded )):cddl0.10.7 parses( SingleIdent )asRule::Type(ParenthesizedType). Addedcollect_group_rulesandtype_rule_as_group_ruleso aliases to group rules keep group semantics.NetworkResult = ( network.AddInterceptResult )wraps a type rule ({ ... }), whichcddl0.10.1 had previously treated as a group rule. Updated the single line intypescript__it_works-2.snapandzod__it_works-2.snapso it matchesSessionResult.src/util.rscovering each normalization helper.Verification
cargo testpasses all unit and snapshot tests.cargo check --features vector_groupscompiles cleanly.