mirror of
https://github.com/morluto/rea.git
synced 2026-11-06 23:06:18 +00:00
Project bounded JSON diagnostics using shared URI roles and source spans. Keep complete parser input unchanged and compute safe diagnostics lazily. Preserve byte facts, error classification, path data and cleanup ownership. Reuse JSON escape-coordinate mapping with IDA diagnostics. Fixes #7812 Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
32 lines
931 B
TypeScript
32 lines
931 B
TypeScript
/** Ordered, nonoverlapping UTF-16 spans in a decoded JSON string. */
|
|
export interface JsonStringSpan {
|
|
readonly start: number;
|
|
readonly end: number;
|
|
}
|
|
|
|
/** Map parsed string facts back to their original, validated JSON spelling.
|
|
* `encoded` excludes the quotes; callers own JSON decoding and span validity.
|
|
*/
|
|
export function* jsonStringSourceSpans(
|
|
encoded: string,
|
|
offset: number,
|
|
spans: Iterable<JsonStringSpan>,
|
|
): Generator<JsonStringSpan> {
|
|
let sourceCursor = 0;
|
|
let decodedCursor = 0;
|
|
const sourceOffset = (boundary: number): number => {
|
|
while (decodedCursor < boundary) {
|
|
sourceCursor +=
|
|
encoded[sourceCursor] === "\\"
|
|
? encoded[sourceCursor + 1] === "u"
|
|
? 6
|
|
: 2
|
|
: 1;
|
|
decodedCursor++;
|
|
}
|
|
return offset + sourceCursor;
|
|
};
|
|
for (const span of spans)
|
|
yield { start: sourceOffset(span.start), end: sourceOffset(span.end) };
|
|
}
|