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

Escape a line against the inline reader's own tokens, in time linear in a run

This commit is contained in:
2026-10-09 16:39:13 +02:00
committed by Lillem4n
parent f5a296797e
commit 59ead3e8e9
9 changed files with 212 additions and 268 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ import test from 'node:test'
import type { DirectiveAttributes, DirectiveLine } from './directive-syntax.ts'
import { largestNesting } from '../nesting.ts'
import { readDirectiveLine, readInlineDirective } from './directive-syntax.ts'
import { claimsDirectivePrefix, readDirectiveLine, readInlineDirective } from './directive-syntax.ts'
// A pair the input spells bare decodes to itself; a quoted one names its spelling beside the decoding.
type Pair = [string, string, string?]
@@ -22,8 +22,8 @@ function fault(line: string): string {
}
function inline(text: string): unknown {
if (!claimsDirectivePrefix(text, 0)) return 'unclaimed'
const read = readInlineDirective(text, 0)
if (read === undefined) return 'unclaimed'
if (read.fault !== undefined) return read.fault.message
return { attributes: read.value.attributes, content: read.value.content, length: read.value.length, name: read.value.name }
}