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)}`; } }