https://gitlab.synchro.net/main/sbbs/-/commit/276df51b30f7181fdaf356f3
Added Files:
src/syncterm/wren_bind_wom.c wren_bind_wom.h
Modified Files:
src/syncterm/CMakeLists.txt GNUmakefile Wren.adoc src/syncterm/scripts/syncterm.wren wrentest.wren src/syncterm/wren_bind.c
Log Message:
SyncTERM: add WOM serialization to the Wren scripting host
WOM (Wren Object Model) round-trips Wren values through a literal
text format that's a strict subset of valid Wren syntax. Supports
Null, Bool, Num, String, List, Map; coerces Range / other Sequence
to List on serialize. Cycles abort the fiber. Pretty-print supported
via an indent-string second argument.
scripts/syncterm.wren: new class WOM with four serialize entry points (serialize / serializeLossy, each with optional indent String) plus
a foreign deserialize. Strict serialize aborts on unsupported types,
NaN, or Infinity; lossy silently omits unsupported list items / map
entries and maps a top-level unsupported value to "null". Both modes
abort on cycles. String escapes match Wren's compiler so output
pastes into Wren source — every literal % is escaped to \% so the
output never starts an interpolation.
wren_bind_wom.c: hand-written recursive-descent literal parser for
deserialize. No use of the Wren compiler — input never reaches eval,
so untrusted text is safe. Bounded recursion (256 levels), trailing
commas allowed inside [...] / {...}, arbitrary whitespace between
tokens, escape set matches Wren's readString exactly (accepting any
escape Wren itself rejects would break the "output is valid Wren
source" property). Input is copied at entry so a GC during the parse
can't invalidate the slot pointer. Errors abort the fiber with a
message that includes the byte offset.
scripts/wrentest.wren: 14 new inline test methods covering primitive round-trip, all string escapes, container compact + pretty form,
Range coercion, whitespace and trailing-comma tolerance, hex
literals, deeply nested round-trip, lossy mode (list + map),
strict-mode aborts, cycle detection, and parse errors. Tests that
involve multi-key Maps assert structurally rather than against a
pinned literal, since Wren Map iteration order is hash-bucket order.
Wren.adoc: new === WOM section under == Object Model with the type
table, member table, and a worked example. String-escape entry in
=== Literals expanded to list \%, \a, \b, \e, \f, \v. New
==== Strings and % subsection (cross-referenced from a new pitfalls
list entry) covering the basic rule that every literal % needs \%,
with a footnote on the rare \\\% case that comes up when generating
escape sequences.
Co-Authored-By: Claude Opus 4.7 (1M context) <
noreply@anthropic.com>
---
■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net