3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

Answer architecture round 2: every builder joins its pieces through one bounded join, the readers take the engine guard, every refusal stands at the document's path, and a portable list's refusal names its own place

This commit is contained in:
2026-10-12 17:42:24 +02:00
committed by Lillem4n
parent 2b5d22cbc6
commit 3414c8690a
25 changed files with 379 additions and 249 deletions
+24 -4
View File
@@ -112,9 +112,18 @@ export function slotFault(type: string, text: string): ConvertFault | undefined
}
export function spellAttributes(pairs: readonly (readonly [string, string])[]): string {
if (pairs.length === 0) return ''
const spelled = [...pairs].sort(([left], [right]) => keyOrder(left, right)).map(([key, value]) => `${key}=${value}`)
return `{${spelled.join(' ')}}`
return [...attributePieces(pairs)].join('')
}
export function* attributePieces(pairs: readonly (readonly [string, string])[]): Generator<string> {
if (pairs.length === 0) return
yield '{'
for (const [index, [key, value]] of [...pairs].sort(([left], [right]) => keyOrder(left, right)).entries()) {
if (index > 0) yield ' '
yield `${key}=`
yield value
}
yield '}'
}
export function spellDirectiveCloser(name: string): string {
@@ -122,7 +131,18 @@ export function spellDirectiveCloser(name: string): string {
}
export function spellDirectiveOpener(name: string, argument: string | undefined, attributes: string): string {
return `${directivePrefix}${name}${argument === undefined ? '' : ` ${argument}`}${attributes === '' ? '' : ` ${attributes}`}`
return [...directiveOpenerPieces(name, argument, attributes === '' ? [] : [attributes])].join('')
}
export function* directiveOpenerPieces(name: string, argument: string | undefined, attributes: Iterable<string>): Generator<string> {
yield `${directivePrefix}${name}`
if (argument !== undefined) yield ` ${argument}`
let first = true
for (const piece of attributes) {
if (first) yield ' '
first = false
yield piece
}
}
export function spellJsonAttribute(value: JsonValue): string {