mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-13 10:00:51 +01:00
Fixed syntax highlighting for 0x-style literals
This commit is contained in:
parent
95a5718e38
commit
a922eb84d5
@ -97,6 +97,7 @@ impl Highlighter for LineHighlighter {
|
|||||||
let reg = Regex::new(
|
let reg = Regex::new(
|
||||||
r"(?x)
|
r"(?x)
|
||||||
(?P<op>([+\-/*%^!×÷]|if|otherwise)) |
|
(?P<op>([+\-/*%^!×÷]|if|otherwise)) |
|
||||||
|
(?P<radix>0[box][a-zA-Z0-9]+) |
|
||||||
(?P<identifier>[^!-@\s_|^⌊⌋⌈⌉\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)",
|
(?P<identifier>[^!-@\s_|^⌊⌋⌈⌉\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -127,7 +127,7 @@
|
|||||||
const [result, success] = calculate(kalk, input);
|
const [result, success] = calculate(kalk, input);
|
||||||
|
|
||||||
output = success
|
output = success
|
||||||
? highlight(result)[0]
|
? highlight(result, true)[0]
|
||||||
: `<span style="color: ${errorcolor}">${result}</span>`;
|
: `<span style="color: ${errorcolor}">${result}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,13 +274,26 @@
|
|||||||
if (autofocus) element.focus();
|
if (autofocus) element.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function highlight(input: string): [string, number] {
|
function highlight(
|
||||||
|
input: string,
|
||||||
|
isOutput: boolean = false
|
||||||
|
): [string, number] {
|
||||||
if (!input) return ["", 0];
|
if (!input) return ["", 0];
|
||||||
let result = input;
|
let result = input;
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
result = result.replace(
|
result = result.replace(
|
||||||
/(?<comparison>(!=|[<>]=?))|(?<html>[<>&]|(\n\s*\}?|\s+))|(?<op>([+\-/*%^!≈×÷]|if|otherwise)|(?<identifier>[^!-@\s_|^⌊⌋⌈⌉≈\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)\(?)/g,
|
/(?<radix>0[box][a-zA-Z0-9]+)|(?<comparison>(!=|[<>]=?))|(?<html>[<>&]|(\n\s*\}?|\s+))|(?<op>([+\-/*%^!≈×÷]|if|otherwise)|(?<identifier>[^!-@\s_|^⌊⌋⌈⌉≈\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)\(?)/g,
|
||||||
(substring, _, comparison, _2, html, _3, op, identifier) => {
|
(
|
||||||
|
substring,
|
||||||
|
_radix,
|
||||||
|
_,
|
||||||
|
comparison,
|
||||||
|
_2,
|
||||||
|
html,
|
||||||
|
_3,
|
||||||
|
op,
|
||||||
|
identifier
|
||||||
|
) => {
|
||||||
if (comparison) {
|
if (comparison) {
|
||||||
if (substring == "<=") return "≤";
|
if (substring == "<=") return "≤";
|
||||||
if (substring == ">=") return "≥";
|
if (substring == ">=") return "≥";
|
||||||
@ -296,7 +309,7 @@
|
|||||||
return "<br />}";
|
return "<br />}";
|
||||||
} else {
|
} else {
|
||||||
if (!substring.match(/\n\s\s/)) offset += 2;
|
if (!substring.match(/\n\s\s/)) offset += 2;
|
||||||
return "<br /> ";
|
return isOutput ? "<br />" : "<br /> ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (substring.match(/\s+/)) {
|
if (substring.match(/\s+/)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user