diff --git a/cli/src/repl.rs b/cli/src/repl.rs index 6d3c9db..1ce5cff 100644 --- a/cli/src/repl.rs +++ b/cli/src/repl.rs @@ -97,6 +97,7 @@ impl Highlighter for LineHighlighter { let reg = Regex::new( r"(?x) (?P([+\-/*%^!×÷]|if|otherwise)) | + (?P0[box][a-zA-Z0-9]+) | (?P[^!-@\s_|^⌊⌋⌈⌉\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)", ) .unwrap(); diff --git a/web/src/KalkCalculator.svelte b/web/src/KalkCalculator.svelte index a786474..fde3f6d 100644 --- a/web/src/KalkCalculator.svelte +++ b/web/src/KalkCalculator.svelte @@ -127,7 +127,7 @@ const [result, success] = calculate(kalk, input); output = success - ? highlight(result)[0] + ? highlight(result, true)[0] : `${result}`; } @@ -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( - /(?(!=|[<>]=?))|(?[<>&]|(\n\s*\}?|\s+))|(?([+\-/*%^!≈×÷]|if|otherwise)|(?[^!-@\s_|^⌊⌋⌈⌉≈\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)\(?)/g, - (substring, _, comparison, _2, html, _3, op, identifier) => { + /(?0[box][a-zA-Z0-9]+)|(?(!=|[<>]=?))|(?[<>&]|(\n\s*\}?|\s+))|(?([+\-/*%^!≈×÷]|if|otherwise)|(?[^!-@\s_|^⌊⌋⌈⌉≈\[\]\{\}≠≥≤⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎]+(_\d+)?)\(?)/g, + ( + substring, + _radix, + _, + comparison, + _2, + html, + _3, + op, + identifier + ) => { if (comparison) { if (substring == "<=") return "≤"; if (substring == ">=") return "≥"; @@ -296,7 +309,7 @@ return "
}"; } else { if (!substring.match(/\n\s\s/)) offset += 2; - return "
  "; + return isOutput ? "
" : "
  "; } } if (substring.match(/\s+/)) {