Make basic Signal Digith work

This commit is contained in:
Yura Dupyn 2026-02-16 19:11:57 +01:00
parent bf5eb54932
commit c0198d419f
15 changed files with 464 additions and 73 deletions

View file

@ -4,12 +4,6 @@ import { DisplayLineViews } from "./LineView";
export function formatErrorMesage(err: ParseError): string {
switch (err.tag) {
case "UnexpectedToken":
return `Unexpected token. Expected: ${err.expected}`;
case "UnexpectedTokenWhileParsingSequence":
return `Unexpected token in sequence. Expected delimiter ${formatChar(err.expectedDelimiter)} or terminator ${formatChar(err.expectedTerminator)}, but found ${formatChar(err.received)}.`;
case "UnexpectedCharacter":
return `Unexpected character: ${formatChar(err.char)}`;
@ -20,13 +14,12 @@ export function formatErrorMesage(err: ParseError): string {
return "Expected a number here.";
case "InvalidNumber":
return err.reason === "NotFinite"
? "Number is too large or invalid."
: "Invalid number format (missing fractional digits?).";
case "InvalidIdentifier":
// Handle nested reasons if needed, e.g. "Keyword 'let' cannot be used as an identifier"
return `Invalid identifier '${err.text}': ${err.reason.tag}`;
switch (err.reason) {
case "NotFinite":
return "Number is too large or invalid.";
case "MissingFractionalDigits":
return "Invalid number format (missing fractional digits?).";
}
case "InvalidEscape":
switch (err.reason.tag) {
@ -37,8 +30,56 @@ export function formatErrorMesage(err: ParseError): string {
case "UnicodeOverflow": return `Unicode code point ${err.reason.value.toString(16)} is out of bounds.`;
}
case "InvalidIdentifier": {
let identifierKind = "";
switch (err.kind) {
case "variable_use":
identifierKind = "variable name";
break;
case "field_name":
identifierKind = "field name ";
break;
case "tag_construction":
identifierKind = "tag";
break;
case "function_call":
identifierKind = "function name";
break;
case "signal_read":
identifierKind = "signal name";
break;
case "pattern_binding":
identifierKind = "pattern variable";
break;
}
let reason = "";
switch (err.reason.tag) {
case "Empty":
reason = "It's empty";
break;
case "StartsWithDigit":
reason = "Can't start with a digit"
break;
case "IsKeyword":
reason = "I'ts a keyword";
break;
}
return `Invalid ${identifierKind} '${err.text}' ${reason}.`;
}
case "UnexpectedIdentifier":
return `Unexpected identifier encountered '${err.identifier}'`;
case "UnexpectedToken":
return `Unexpected token. Expected: ${err.expected}`;
case "UnexpectedTokenWhileParsingSequence":
return `Unexpected token in sequence. Expected delimiter ${formatChar(err.expectedDelimiter)} or terminator ${formatChar(err.expectedTerminator)}, but found ${formatChar(err.received)}.`;
// Context specific errors
case "ExpectedExpression": return "Expected an expression here.";
case "ExpectedSignalExpression": return "Expected a signal expression here.";
case "ExpectedFieldAssignmentSymbol": return "Expected '=' for field assignment.";
case "ExpectedPatternAssignmentSymbol": return "Expected '=' for pattern assignment.";
case "ExpectedPatternBindingSymbol": return "Expected '.' for pattern binding.";
@ -46,6 +87,8 @@ export function formatErrorMesage(err: ParseError): string {
case "ExpectedRecordOpen": return "Expected '(' to start record.";
case "ExpectedLetBlockOpen": return "Expected '{' to start let-block.";
case "ExpectedLetBlockClose": return "Expected '}' to close let-block.";
case "ExpectedLetSignalBlockOpen": return "Expected '{' to start let-signal-block.";
case "ExpectedLetSignalBlockClose": return "Expected '}' to close let-signal-block.";
case "ExpectedMatchBlockOpen": return "Expected '{' to start match-block.";
case "ExpectedMatchBlockClose": return "Expected '}' to close match-block.";
case "ExpectedLambdaBlockOpen": return "Expected '{' to start lambda body.";
@ -54,11 +97,8 @@ export function formatErrorMesage(err: ParseError): string {
case "ExpectedApplySeparator": return "Expected '!' inside 'apply'.";
case "UnexpectedTagPattern": return "Unexpected tag pattern (expected product pattern).";
case "ExpectedPattern": return "Expected a pattern here.";
case "ExpectedRecordPatternOpen": return "Expected '(' for record pattern.";
case "ExpectedRecordPatternOpen": return "Expected a ':(' at start of record pattern here.";
case "ExpectedRecordField": return "Expected a field name in record pattern.";
default:
return `Unknown error: ${(err as any).tag}`;
}
}