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