3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-18 22:25:44 +01:00

Answer stability round 1: 1 🔴, 3 🟡 (0 misread); stop each macro parameter at the next brace, read a code text's CRLF lines as line feeds and carry a code text holding a carriage return, and read the document carry whatever whitespace surrounds it

This commit is contained in:
2026-11-17 06:51:24 +01:00
committed by Lillem4n
parent 6f9e4ec3a8
commit 89639b84ef
11 changed files with 88 additions and 47 deletions
+4 -3
View File
@@ -8,16 +8,17 @@ export type AdfMacro = { end: number; inline: boolean; node: AdfNode }
const closer = '{adf}'
const holder = 'an {adf} macro'
const opener = /\{adf(?::([^}\n]*))?\}/y
const opener = /\{adf(?::([^{}\n]*))?\}/y
// spec/wiki.md, The carry: `undefined` where no `{adf}` macro opens at `at`. The macro closes before `end`.
// spec/wiki.md, The carry: `undefined` where no `{adf}` macro opens at `at`. A macro closing past `end` is refused.
export function readAdfMacro(wiki: string, at: number, end: number): Read<AdfMacro> | undefined {
opener.lastIndex = at
const opened = opener.exec(wiki)
if (opened === null) return undefined
const start = opener.lastIndex
const close = wiki.indexOf(closer, start)
if (close === -1 || close + closer.length > end) return { fault: refusal('closes with {adf}: this one is left open') }
if (close === -1) return { fault: refusal('closes with {adf}: this one is left open') }
if (close + closer.length > end) return { fault: refusal('inside a line closes on that line: this one closes on a later line') }
const value = carriedValue(wiki.slice(start, close), holder, refusal("holds one ADF node's JSON: this is no JSON"))
if (value.fault !== undefined) return value
const bounded = carriedNesting(value.value, largestNesting)