import { For, Match, Show, Switch } from "solid-js"; import { ParseError } from "src/lang/parser/parser"; import { SourceRegion } from "source-region"; import { ShowParseError } from 'src/ui/Component/ParseError'; import { Program } from "src/lang/program"; export type DigithError = { payload: DigithError.Payload, ids: DigithError.Id[], tags: DigithError.Tag[], config: DigithError.Config, } export namespace DigithError { export type Payload = | { tag: "Parse", err: ParseError, src: SourceRegion } | { tag: "Program", err: Program.Error }; export type Id = string; export type Tag = string; export type Config = { title?: string, display?: "box" | "flat", } function findById(errors: DigithError[], id: Id): DigithError | undefined { return errors.find((e) => e.ids.includes(id)); } function allWithTag(errors: DigithError[], tag: Tag): DigithError[] { return errors.filter((e) => e.tags.includes(tag)); } export function All(props: { errors: DigithError[] }) { return (
{(error) => }
); } export function ById(props: { errors: DigithError[], id: Id }) { const error = () => findById(props.errors, props.id); return ( {(e) => } ); } export function ByTag(props: { errors: DigithError[], tag: Tag }) { const matched = () => allWithTag(props.errors, props.tag); return ( 0}> ); } function Single(props: { error: DigithError }) { const display = () => props.error.config.display ?? "box"; return (
{props.error.config.title}
{props.error.config.title}:
); } function PayloadView(props: { payload: Payload }) { return ( ) : undefined} > {(err) => } ) : undefined} > {(err) => } ); } } export function ProgramErrorDisplay(props: { error: Program.Error }) { const message = () => { switch (props.error.tag) { case "DuplicateFunctionName": return `A function named '${props.error.name}' already exists.`; case "PrimitiveFunctionAlreadyExists": return `Cannot overwrite the primitive function '${props.error.name}'.`; // TODO: handle other cases default: return `Runtime Error: ${props.error.tag}`; } }; return (
Registration Failed

{message()}

); }