mirror of
https://github.com/remko/waforth
synced 2025-01-13 08:01:32 +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,37 +66,48 @@ export default class Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.codeEl.innerText = "";
|
this.codeEl.innerText = "";
|
||||||
const vs = v.split(/(\s+)/);
|
|
||||||
let nextIsDefinition = false;
|
let nextIsDefinition = false;
|
||||||
let inComment = false;
|
for (const vl of v.split("\n")) {
|
||||||
for (const v of vs) {
|
const vs = vl.split(/(\s+)/);
|
||||||
let parentEl: HTMLElement = this.codeEl;
|
let inComment = false;
|
||||||
let cls: string | undefined;
|
let inLineComment = false;
|
||||||
if (inComment || v === "(") {
|
for (const v of vs) {
|
||||||
cls = "c-com";
|
let parentEl: HTMLElement = this.codeEl;
|
||||||
} else if (!isNaN(v as any)) {
|
let cls: string | undefined;
|
||||||
cls = "c-num";
|
if (inComment || inLineComment || v === "(" || v === "\\") {
|
||||||
} else if (nextIsDefinition && v.trim().length > 0) {
|
cls = "c-com";
|
||||||
cls = "c-def";
|
} else if (!isNaN(v as any)) {
|
||||||
nextIsDefinition = false;
|
cls = "c-num";
|
||||||
} else {
|
} else if (nextIsDefinition && v.trim().length > 0) {
|
||||||
cls = highlightClass[v];
|
cls = "c-def";
|
||||||
}
|
nextIsDefinition = false;
|
||||||
if (cls != null) {
|
} else {
|
||||||
const spanEl = document.createElement("span");
|
cls = highlightClass[v];
|
||||||
spanEl.className = cls;
|
}
|
||||||
parentEl.appendChild(spanEl);
|
if (cls != null) {
|
||||||
parentEl = spanEl;
|
const spanEl = document.createElement("span");
|
||||||
}
|
spanEl.className = cls;
|
||||||
parentEl.appendChild(document.createTextNode(v));
|
parentEl.appendChild(spanEl);
|
||||||
|
parentEl = spanEl;
|
||||||
|
}
|
||||||
|
parentEl.appendChild(document.createTextNode(v));
|
||||||
|
|
||||||
if (v === ":" || v === "CONSTANT" || v === "VARIABLE" || v === "VALUE") {
|
if (
|
||||||
nextIsDefinition = true;
|
v === ":" ||
|
||||||
} else if (v === "(") {
|
v === "CONSTANT" ||
|
||||||
inComment = true;
|
v === "VARIABLE" ||
|
||||||
} else if (inComment && v === ")") {
|
v === "VALUE"
|
||||||
inComment = false;
|
) {
|
||||||
|
nextIsDefinition = true;
|
||||||
|
} else if (v === "(") {
|
||||||
|
inComment = true;
|
||||||
|
} else if (v === "\\") {
|
||||||
|
inLineComment = true;
|
||||||
|
} else if (inComment && v === ")") {
|
||||||
|
inComment = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this.codeEl.appendChild(document.createTextNode("\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue