mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
Merge 594cbb82bb into 37cfd2144b
This commit is contained in:
commit
b226e45ebf
1 changed files with 23 additions and 2 deletions
|
|
@ -18,7 +18,7 @@ interface SheetExports {
|
||||||
results: LineResult[];
|
results: LineResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const XREF_SCAN_RE = /@(?:\[([^\]]+)\]|([\p{L}_][\p{L}\d_]*))\./gu;
|
const XREF_BARE_RE_STICKY = /@([\p{L}_][\p{L}\d_]*)\./guy;
|
||||||
|
|
||||||
function escapeRegExp(s: string): string {
|
function escapeRegExp(s: string): string {
|
||||||
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
|
|
@ -104,7 +104,28 @@ export class Workspace {
|
||||||
if (cached && cached.text === text) return cached.refs;
|
if (cached && cached.text === text) return cached.refs;
|
||||||
}
|
}
|
||||||
const out: string[] = [];
|
const out: string[] = [];
|
||||||
for (const m of text.matchAll(XREF_SCAN_RE)) out.push((m[1] ?? m[2]).trim());
|
let i = 0;
|
||||||
|
while ((i = text.indexOf("@", i)) !== -1) {
|
||||||
|
if (i + 1 >= text.length) break;
|
||||||
|
|
||||||
|
if (text[i + 1] === "[") {
|
||||||
|
const endBracket = text.indexOf("]", i + 2);
|
||||||
|
if (endBracket !== -1 && endBracket + 1 < text.length && text[endBracket + 1] === ".") {
|
||||||
|
out.push(text.substring(i + 2, endBracket).trim());
|
||||||
|
i = endBracket + 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
XREF_BARE_RE_STICKY.lastIndex = i;
|
||||||
|
const m = XREF_BARE_RE_STICKY.exec(text);
|
||||||
|
if (m !== null) {
|
||||||
|
out.push(m[1]); // no trim needed for bare identifier regex match
|
||||||
|
i = XREF_BARE_RE_STICKY.lastIndex;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
if (id) {
|
if (id) {
|
||||||
this.parsedRefsCache.set(id, { text, refs: out });
|
this.parsedRefsCache.set(id, { text, refs: out });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue