mirror of
https://github.com/remko/waforth
synced 2025-01-14 08:01:34 +01:00
editor: Highlight line comments
This commit is contained in:
parent
e525044c39
commit
78ca0bf8ec
1 changed files with 39 additions and 28 deletions
|
@ -66,13 +66,15 @@ export default class Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.codeEl.innerText = "";
|
this.codeEl.innerText = "";
|
||||||
const vs = v.split(/(\s+)/);
|
|
||||||
let nextIsDefinition = false;
|
let nextIsDefinition = false;
|
||||||
|
for (const vl of v.split("\n")) {
|
||||||
|
const vs = vl.split(/(\s+)/);
|
||||||
let inComment = false;
|
let inComment = false;
|
||||||
|
let inLineComment = false;
|
||||||
for (const v of vs) {
|
for (const v of vs) {
|
||||||
let parentEl: HTMLElement = this.codeEl;
|
let parentEl: HTMLElement = this.codeEl;
|
||||||
let cls: string | undefined;
|
let cls: string | undefined;
|
||||||
if (inComment || v === "(") {
|
if (inComment || inLineComment || v === "(" || v === "\\") {
|
||||||
cls = "c-com";
|
cls = "c-com";
|
||||||
} else if (!isNaN(v as any)) {
|
} else if (!isNaN(v as any)) {
|
||||||
cls = "c-num";
|
cls = "c-num";
|
||||||
|
@ -90,14 +92,23 @@ export default class Editor {
|
||||||
}
|
}
|
||||||
parentEl.appendChild(document.createTextNode(v));
|
parentEl.appendChild(document.createTextNode(v));
|
||||||
|
|
||||||
if (v === ":" || v === "CONSTANT" || v === "VARIABLE" || v === "VALUE") {
|
if (
|
||||||
|
v === ":" ||
|
||||||
|
v === "CONSTANT" ||
|
||||||
|
v === "VARIABLE" ||
|
||||||
|
v === "VALUE"
|
||||||
|
) {
|
||||||
nextIsDefinition = true;
|
nextIsDefinition = true;
|
||||||
} else if (v === "(") {
|
} else if (v === "(") {
|
||||||
inComment = true;
|
inComment = true;
|
||||||
|
} else if (v === "\\") {
|
||||||
|
inLineComment = true;
|
||||||
} else if (inComment && v === ")") {
|
} else if (inComment && v === ")") {
|
||||||
inComment = false;
|
inComment = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.codeEl.appendChild(document.createTextNode("\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#updateScroll() {
|
#updateScroll() {
|
||||||
|
|
Loading…
Reference in a new issue