Modularize UI, make it a bit more Lisp independent

This commit is contained in:
Yura Dupyn 2026-04-25 16:20:25 +02:00
parent e1e1b90579
commit c3edf193c4
19 changed files with 973 additions and 884 deletions

View file

@ -0,0 +1,45 @@
import type { FoundSyntax, ParseError } from '../../../languages/lisp';
import { spanLabel } from '../../format';
export function errorTitle(error: ParseError): string {
switch (error.tag) {
case "expected-expression":
return "Expected expression";
case "expected-close-delimiter":
return "Expected closing delimiter";
case "unexpected-close-delimiter":
return "Unexpected closing delimiter";
case "expected-list-separator":
return "Expected list separator";
case "unexpected-code-point":
return "Unexpected code point";
case "invalid-number":
return "Invalid number";
}
}
export function errorDetail(error: ParseError): string {
switch (error.tag) {
case "expected-expression":
return `found ${foundLabel(error.found)}`;
case "expected-close-delimiter":
return `expected ${error.expected}, opened at ${spanLabel(error.open)}, found ${foundLabel(error.found)}`;
case "unexpected-close-delimiter":
return `${error.delimiter} ${spanLabel(error.span)}`;
case "expected-list-separator":
return `found ${foundLabel(error.found)}`;
case "unexpected-code-point":
return `found ${foundLabel(error.found)}`;
case "invalid-number":
return `${error.reason}: ${error.text}`;
}
}
function foundLabel(found: FoundSyntax): string {
switch (found.tag) {
case "eof":
return `EOF ${spanLabel(found.span)}`;
case "code-point":
return `${String.fromCodePoint(found.value)} ${spanLabel(found.span)}`;
}
}