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

Answer architecture round 3: the comprehension floor's decision names item 95, the directive read takes its index from the claimed prefix, and only the claimed prefix leaves directive-syntax.ts

This commit is contained in:
2026-10-09 18:46:56 +02:00
parent 47635be59b
commit 4153f29927
5 changed files with 13 additions and 13 deletions
+4 -4
View File
@@ -75,10 +75,6 @@ export function claimDirectivePrefix(text: string, index: number): ClaimedPrefix
return claimsDirectivePrefix(text, index) ? { [claimedPrefix]: true, index } : undefined
}
export function claimsDirectivePrefix(text: string, index: number): boolean {
return text.startsWith(directivePrefix, index)
}
export function holdsDirectivePrefix(text: string): boolean {
return text.includes(directivePrefix)
}
@@ -164,6 +160,10 @@ export function unsupportedNodeShape(message: string): ConvertFault {
return { code: 'unsupported-node-shape', message }
}
function claimsDirectivePrefix(text: string, index: number): boolean {
return text.startsWith(directivePrefix, index)
}
function keyOrder(left: string, right: string): number {
if (left < right) return -1
return left > right ? 1 : 0
+5 -5
View File
@@ -119,7 +119,7 @@ function scanInline(scan: Scan): Result<Scanned> {
}
function readToken(scan: Scan, index: number, token: InlineToken): Result<number> {
if (token.kind === 'directive') return readDirective(scan, index, token.prefix)
if (token.kind === 'directive') return readDirective(scan, token.prefix)
if (token.kind === 'html') return failure('unmappable-html', `no raw HTML converts at this version: ${token.construct}`, scan.path)
const end = index + token.width
switch (token.kind) {
@@ -168,12 +168,12 @@ function readLineEnding(scan: Scan, index: number): number {
return index + 1
}
function readDirective(scan: Scan, index: number, prefix: ClaimedPrefix): Result<number> {
const held = scan.spans.get(index)
if (held !== undefined) return pushDirective(scan, held, index)
function readDirective(scan: Scan, prefix: ClaimedPrefix): Result<number> {
const held = scan.spans.get(prefix.index)
if (held !== undefined) return pushDirective(scan, held, prefix.index)
const directive = readInlineDirective(scan.source, prefix)
if (directive.fault !== undefined) return faulted(directive.fault, scan.path)
return pushDirective(scan, directive.value, index)
return pushDirective(scan, directive.value, prefix.index)
}
function pushDirective(scan: Scan, span: DirectiveSpan, index: number): Result<number> {