Skip to content

Add DataJS parser/serializer restructuring design document - #1764

Merged
sergey-shandar merged 15 commits into
mainfrom
claude/parser-serializer-restructure-fn8oz2
Aug 28, 2026
Merged

Add DataJS parser/serializer restructuring design document#1764
sergey-shandar merged 15 commits into
mainfrom
claude/parser-serializer-restructure-fn8oz2

Conversation

@sergey-shandar

Copy link
Copy Markdown
Contributor

Summary

This PR adds a comprehensive design document outlining the restructuring of JSON, DataJS, and FunctionalScript parsers and serializers across the codebase. The document serves as a coordinating issue that records design decisions, sequences implementation stages, and maps dependencies between existing issues.

Key Changes

  • Added todo/parser-serializer-restructure.md — A detailed design document that:
    • Identifies structural problems with the current parser/serializer architecture spread across fjs/media/json, fjs/djs, fjs/fsc, and fjs/bnf
    • Proposes a three-tier architecture with frozen spec layers and evolving language layers
    • Defines the DataJS format as a minimal JSON extension for DAG support with decision records covering data model, syntax, serialization, and file extensions
    • Establishes FunctionalScript consequences including semicolon requirements and reserved words
    • Sequences seven implementation stages from spec writing through cleanup
    • Maps required edits to seven existing issues that will be affected by the restructuring

Notable Details

  • The document establishes clear dependency boundaries: media codecs depend only on spec-frozen layers, preventing runtime dependencies on evolving code like fjs/bnf
  • DataJS is defined as a proper subset of FunctionalScript, which is a subset of JavaScript, with proof obligations for subset law compliance
  • The restructuring enables JSON to become self-contained (no longer dependent on fjs/js/tokenizer), while the compiler front end moves to fjs/fsc and continues evolving
  • Includes detailed syntax specification for DataJS with rationale for design choices (e.g., mandatory semicolons for minifiability and streaming support)
  • Provides a task checklist and cross-references to related documentation and existing issues

https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

A coordinating issue for restructuring the parser/serializer stack into
three tiers: a self-contained JSON codec, a new spec'd DataJS interchange
format (JSON extended from tree to DAG, nothing else) in fjs/media/datajs,
and the current fjs/djs front end moving to fjs/fsc to grow with the
language. Records the design decision log (';'-terminated consts, JSON
whitespace, JS-derived duplicate-key semantics, special-number round-trips,
ASCII const names, subset laws DataJS < FJS < JS), the staged migration
sequence, and the edits owed to the five existing issues it supersedes or
rebases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
functionalscript a8b421a Commit Preview URL

Branch Preview URL
Aug 28 2026, 10:01 PM

@sergey-shandar
sergey-shandar marked this pull request as ready for review August 28, 2026 21:09
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f33189618

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md Outdated
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-28T22:24:10.161347Z a8b421a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Three review findings on the DataJS decision record, each a subset-law
hole: const names must also exclude JavaScript's reserved words in module
code (const class = 1 is a JS syntax error); the JSON-to-DataJS textual
conversion must rewrite a bare "__proto__" key to the computed spelling
rather than claiming plain concatenation is always valid; and bigint is
its own digits-only production, not an 'n' suffix on the JSON number
grammar (JS rejects 1.5n and 1e2n).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1cbbb0e720

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Review follow-up: eval and arguments are not reserved words, but module
code is strict and rejects binding them, so the exclusion set is "every
name JS rejects as a binding identifier in module code", not "reserved
words" alone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 083f6cf9e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md Outdated

@o2alexanderfedin o2alexanderfedin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved. Checked the claims against the tree and against a JS engine rather than reading for plausibility, since a design note gets implemented later on trust.

Verified against the code: the fjs/media/json tokenizer really is a ~100-line adapter over fjs/js/tokenizer's 747; the NumberPolicy seam is in that README verbatim; fjs/djs's pipeline and the compile command wire up as described; fjs/fsc is a classifier plus an orphaned third JSON grammar, which its own todo independently confirms; and no exports map exists, which you account for. Nothing in the plan violates the .f.mjs rules. All links resolve, P2/open are valid, no changelog needed.

The newest commits' claims hold too, and I ran them: 1.5n and 1e2n are both SyntaxError, so "number + n" really would over-accept and making bigint its own production is right; 01n is rejected, matching the no-leading-zeros wording. const eval = 1 in strict mode is a SyntaxError while const undefined = 5 is accepted — so the two exclusion sets are genuinely different in kind, exactly as the note now says. That last one was on my could-not-verify list before; it checks out.

One gap still open, cheap to close now:

Stage 5 never says where fjs/djs/serializer/ lands — nor examples/, nor the top-level module.f.mjs/proof.f.mjs/types.ts carrying compile(). It is inferable (serializer into stage 4's fjs/media/datajs, compile() into stage 6's normalizer) but unstated, and it becomes a wrong instruction later: "Edits owed to existing issues" tells compile-modules-to-edag.md that "its paths move djsfsc in stage 5", while that todo's cited path is ../serializer/module.f.mjs, which by your own staging goes to media/datajs. Your next clause already says as much. One line naming the serializer's destination fixes both.

Minor: line 28 still lists "EOF encoding change" among what is still evolving, but EOF = -1 shipped in #1516 on 2026-08-13, some fifty fjs/bnf commits back.

claude added 2 commits August 28, 2026 21:22
Three review findings: normalized-form const hoisting is restricted to
objects/arrays counted by reference identity, so a value-equality ref
counter can never merge 0 with -0 or mishandle NaN; stage 5 gains the
front-end work for NaN/Infinity/-Infinity/-0 (unresolved identifiers in
today's parser), without which the stage-6 subset proofs reject DataJS
accept vectors; and stage 5's syntax change carries its own BREAKING
CHANGES changelog entry rather than deferring it to stage 7.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho
Review follow-ups from the human approval: stage 5 now states where the
rest of fjs/djs lands (serializer and value-tree types into stage 4's
fjs/media/datajs, examples and the top-level compile() module with the
front end to fsc), and the compile-modules-to-edag edit note distinguishes
its front-end paths (djs -> fsc) from its serializer citation (-> media/
datajs). The bnf EOF-encoding change is cited as shipped (#1516) rather
than listed as still pending.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4182601cc1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
claude added 2 commits August 28, 2026 21:29
Review finding: the normalizer's JSON output needs a representability
rule. DataJS output is total; JSON output is permitted only when every
leaf has a JSON spelling and no graph sharing is lost, and otherwise the
value is rejected as an error rather than substituted or dropped,
matching json-bigint-serialization's validation policy. Rejection proofs
cover each unrepresentable leaf and the shared-node case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho
…ault

Resolves the deferred canonical-layout decision: normalized form is the
fully minified one-line spelling, leaving normalization zero layout
freedom for byte-determinism; tooling defaults to a human-readable
layout, which is one of the many valid non-normalized spellings. The
media type remains the spec stage's one deferred detail.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6975376142

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Review finding: "position from the first occurrence" alone lets a non-JS
implementation preserve {"2":0,"1":0} as written, while every JS engine
observably enumerates "1" before "2" - array-index keys come first in
ascending numeric order, then other keys in first-occurrence order. The
data model now states JS own-property ordering explicitly and normalized
output emits keys in that observable order.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd68a5542a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md Outdated
Two review findings: "first-emission order" was underdetermined for
nested shared nodes, so normalization now emits consts in post-order of
one depth-first traversal (arrays in element order, objects in observable
key order, shared nodes descended on first encounter), which also makes
declaration-before-use automatic; and the normalizer's ordinary JSON
output rejects bigint alongside the other unrepresentable leaves, since
emitting 1n as the JSON text 1 silently changes the value's type for the
standard reader - extended-codec output stays an explicit, labeled
caller choice.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3015f9d232

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md
Two review findings: "shortest round-trip spelling" does not select
unique bytes (1e3 vs 1E3), so the canonical number spelling is exactly
ECMAScript's deterministic ToString(Number) algorithm, restated in the
spec, with -0 as the one stated exception (ToString spells it 0,
canonical DataJS spells it -0); and the serializer's input is a live
unfrozen value that may be cyclic, so cycle detection and a proved
rejection are required - a DataJS document can only represent a DAG.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd4d6d2dcc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md Outdated
claude added 2 commits August 28, 2026 21:50
Design change: one uniform terminator rule instead of a rule plus an
export-default exception - simpler to spec and implement, still a JS
subset since export default value; is valid JS. The grammar, the
one-line example, and the JSON-to-DataJS conversion (now
"export default " + json + ";") follow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho
Two review findings: serializer input validation generalizes beyond
cycles - any value outside the DataJS data model is rejected rather than
approximated (foreign leaves, sparse-array holes, symbol-keyed and
accessor properties, cycles), each with a rejection proof; and stage 5
no longer directs reimplementing exact -0, which the current front end
already parses correctly (lexeme pinned in the tokenizer proof,
parseFloat preserves signed zero) - it gets a regression proof instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ee9e89e3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Comment thread todo/parser-serializer-restructure.md Outdated
Two review findings on implementation feasibility: stage 4 now states
that today's JSON parser seam is too narrow for DataJS (NumberPolicy
sees number tokens only, no identifier/bigint tokens, string keys only)
and makes generalizing it - token vocabulary, leaf/identifier policy
hook, key-form hook, with JSON behavior pinned unchanged by proofs -
explicit prerequisite work; and minus folding becomes a parameterized
helper whose strict JSON instantiation folds a number only, while
DataJS's adds -Infinity and negative bigint, so the extra sign forms
never enter the JSON tokenizer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ff9dd8b89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread todo/parser-serializer-restructure.md Outdated
Review finding: "fixed string escaping" left \n-vs-
 and
slash-escaping divergence open. The canonical spelling is exactly
ECMAScript's QuoteJSONString (what JSON.stringify emits for a string),
restated in the spec, matching how canonical numbers anchor to
ToString(Number).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PfpYZSMQKCJvViyebNyLho

@o2alexanderfedin o2alexanderfedin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved. The gap I raised is closed — stage 4 now names the serializer explicitly (fjs/media/datajs — parser and serializer), so the instruction to the sibling todo no longer points it at fsc, and the EOF wording is corrected.

The later commits add real content rather than polish: the seam generalization, minus-folding as a parameter, -0 parsing, statement termination, and canonical escaping. I did not re-verify each against a JS engine the way I checked the bigint and const-name claims earlier; those held, which is some evidence for the rest, but not the same thing as having checked them.

@sergey-shandar

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: a8b421a8cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sergey-shandar
sergey-shandar added this pull request to the merge queue Aug 28, 2026
Merged via the queue into main with commit a9f9774 Aug 28, 2026
19 checks passed
@sergey-shandar
sergey-shandar deleted the claude/parser-serializer-restructure-fn8oz2 branch August 28, 2026 22:46
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.

3 participants