Skip to content

fix: update cddl to 0.10.7 - #99

Open
Lightning00Blade wants to merge 5 commits into
mainfrom
nvitkov/cddl-0.10.7
Open

Lightning00Blade wants to merge 5 commits into
mainfrom
nvitkov/cddl-0.10.7

Conversation

@Lightning00Blade

@Lightning00Blade Lightning00Blade commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #86.

cddl 0.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 in src/util.rs and updates the TypeScript and Zod engines to handle the new AST shapes.

Changes

  • Arrow map literal keys (? "optional-key" => int): cddl 0.10.7 parses arrow literal keys without ^ as MemberKey::Type1 { is_cut: false } instead of MemberKey::Value. Added member_key_literal_value and is_non_cut_type1_member_key so literal keys stay formatted as normal object properties rather than index signatures / z.record.
  • Bare type names and parenthesized types in arrays ([* CapabilityRequest], [*(js-uint / text)]): cddl 0.10.7 parses these as GroupEntry::TypeGroupname and GroupEntry::InlineGroup. Added array_group_entry_as_type_entry to convert non-group array entries back to ValueMemberKeyEntry.
  • Top-level group aliases (BrowserCommand = ( browser.Close ), LogEvent = ( log.EntryAdded )): cddl 0.10.7 parses ( SingleIdent ) as Rule::Type(ParenthesizedType). Added collect_group_rules and type_rule_as_group_rule so aliases to group rules keep group semantics.
  • Snapshots: NetworkResult = ( network.AddInterceptResult ) wraps a type rule ({ ... }), which cddl 0.10.1 had previously treated as a group rule. Updated the single line in typescript__it_works-2.snap and zod__it_works-2.snap so it matches SessionResult.
  • Tests: Added unit tests in src/util.rs covering each normalization helper.

Verification

  • cargo test passes all unit and snapshot tests.
  • cargo check --features vector_groups compiles cleanly.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/util.rs Resolved

@sadym-chromium sadym-chromium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first AI review

Comment thread Cargo.toml Resolved
Comment thread src/util.rs Resolved
Comment thread src/util.rs Resolved
Comment thread src/engines/zod.rs Resolved
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants