3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 22:55: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
+7 -3
View File
@@ -88,8 +88,9 @@ export function readDirectiveLine(line: string): Read<DirectiveLine> | undefined
return line.charAt(directivePrefix.length) === '/' ? readCloserLine(line) : readOpenerLine(line)
}
export function readInlineDirective(text: string, index: number): Read<DirectiveSpan> | undefined {
return readNestedDirective(text, index, 1)
// Reads the directive an `!adf:` at `index` claims.
export function readInlineDirective(text: string, index: number): Read<DirectiveSpan> {
return readClaimedDirective(text, index, 1)
}
export function readSoleStringAttribute(span: DirectiveSpan, key: string): Read<string> {
@@ -211,7 +212,10 @@ function readOpenerAttributes(rest: string, index: number): Read<Attributes> {
}
function readNestedDirective(text: string, index: number, depth: number): Read<DirectiveSpan> | undefined {
if (!claimsDirectivePrefix(text, index)) return undefined
return claimsDirectivePrefix(text, index) ? readClaimedDirective(text, index, depth) : undefined
}
function readClaimedDirective(text: string, index: number, depth: number): Read<DirectiveSpan> {
const name = inlineDirectiveName(text, index)
if (name === undefined) return { fault: malformedDirective(prefixFault) }
if (depth > largestNesting) {