Skip to content

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaM314 committed Oct 15, 2024
1 parent 09ffc61 commit 21bb8ae
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 103 deletions.
50 changes: 25 additions & 25 deletions build/builtin_functions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ type PreprocesssedBuiltinFunctionData<TArgs extends BuiltinFunctionArg[], TRetur
};
export declare const getBuiltinFunctions: () => Record<keyof typeof preprocessedBuiltinFunctions, BuiltinFunctionData> & Partial<Record<string, BuiltinFunctionData>>;
export declare const preprocessedBuiltinFunctions: {
LEFT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
RIGHT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
MID: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
LENGTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
TO_UPPER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
TO_LOWER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
UCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
LCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
NUM_TO_STR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
STR_TO_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
IS_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
ASC: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
CHR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
INT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
RAND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
DAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
MONTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
YEAR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
DAYINDEX: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
SETDATE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
TODAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
EOF: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
ROUND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
POW: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
EXP: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
LEFT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
RIGHT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
MID: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
LENGTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
TO_UPPER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
TO_LOWER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
UCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
LCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
NUM_TO_STR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
STR_TO_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
IS_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
ASC: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
CHR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
INT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
RAND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
DAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
MONTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
YEAR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
DAYINDEX: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
SETDATE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
TODAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
EOF: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
ROUND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
POW: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
EXP: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
};
export {};
2 changes: 1 addition & 1 deletion build/lexer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export declare const tokenNameTypeData: {
readonly ".": "punctuation.period";
readonly "\n": "newline";
};
export declare const tokenTextMapping: Record<"brace.open" | "brace.close" | "bracket.open" | "bracket.close" | "parentheses.open" | "parentheses.close" | "punctuation.colon" | "punctuation.semicolon" | "punctuation.comma" | "punctuation.period" | "boolean.true" | "boolean.false" | "keyword.declare" | "keyword.define" | "keyword.constant" | "keyword.output" | "keyword.input" | "keyword.call" | "keyword.if" | "keyword.then" | "keyword.else" | "keyword.if_end" | "keyword.for" | "keyword.to" | "keyword.for_end" | "keyword.step" | "keyword.while" | "keyword.while_end" | "keyword.dowhile" | "keyword.dowhile_end" | "keyword.function" | "keyword.function_end" | "keyword.procedure" | "keyword.procedure_end" | "keyword.return" | "keyword.returns" | "keyword.pass_mode.by_reference" | "keyword.pass_mode.by_value" | "keyword.type" | "keyword.type_end" | "keyword.open_file" | "keyword.read_file" | "keyword.write_file" | "keyword.close_file" | "keyword.get_record" | "keyword.put_record" | "keyword.seek" | "keyword.file_mode.read" | "keyword.file_mode.write" | "keyword.file_mode.append" | "keyword.file_mode.random" | "keyword.case" | "keyword.of" | "keyword.case_end" | "keyword.otherwise" | "keyword.class" | "keyword.class_end" | "keyword.new" | "keyword.super" | "keyword.inherits" | "keyword.class_modifier.private" | "keyword.class_modifier.public" | "keyword.array" | "keyword.set" | "keyword.end" | "newline" | "operator.add" | "operator.minus" | "operator.multiply" | "operator.divide" | "operator.mod" | "operator.integer_divide" | "operator.and" | "operator.or" | "operator.not" | "operator.equal_to" | "operator.not_equal_to" | "operator.less_than" | "operator.greater_than" | "operator.less_than_equal" | "operator.greater_than_equal" | "operator.assignment" | "operator.pointer" | "operator.string_concatenate" | "operator.range", "." | "AND" | "APPEND" | "ARRAY" | "BYREF" | "BYVAL" | "CALL" | "CASE" | "CLASS" | "CLOSEFILE" | "CONSTANT" | "DECLARE" | "DEFINE" | "DIV" | "ELSE" | "END" | "ENDCASE" | "ENDCLASS" | "ENDFUNCTION" | "ENDIF" | "ENDPROCEDURE" | "ENDTYPE" | "ENDWHILE" | "FALSE" | "FOR" | "FUNCTION" | "GETRECORD" | "IF" | "INHERITS" | "INPUT" | "MOD" | "NEW" | "NEXT" | "NOT" | "OF" | "OPENFILE" | "OR" | "OTHERWISE" | "OUTPUT" | "PRIVATE" | "PROCEDURE" | "PUBLIC" | "PUTRECORD" | "RANDOM" | "READ" | "READFILE" | "REPEAT" | "RETURN" | "RETURNS" | "SEEK" | "SET" | "STEP" | "SUPER" | "THEN" | "TO" | "TRUE" | "TYPE" | "UNTIL" | "WHILE" | "WRITE" | "WRITEFILE" | "<-" | ">=" | "<=" | "<>" | ".." | "=" | ">" | "<" | "+" | "-" | "*" | "/" | "^" | "&" | "(" | ")" | "[" | "]" | "{" | "}" | ":" | ";" | "," | "\n">;
export declare const tokenTextMapping: Record<"brace.open" | "brace.close" | "bracket.open" | "bracket.close" | "parentheses.open" | "parentheses.close" | "punctuation.colon" | "punctuation.semicolon" | "punctuation.comma" | "punctuation.period" | "boolean.true" | "boolean.false" | "keyword.declare" | "keyword.define" | "keyword.constant" | "keyword.output" | "keyword.input" | "keyword.call" | "keyword.if" | "keyword.then" | "keyword.else" | "keyword.if_end" | "keyword.for" | "keyword.to" | "keyword.for_end" | "keyword.step" | "keyword.while" | "keyword.while_end" | "keyword.dowhile" | "keyword.dowhile_end" | "keyword.function" | "keyword.function_end" | "keyword.procedure" | "keyword.procedure_end" | "keyword.return" | "keyword.returns" | "keyword.pass_mode.by_reference" | "keyword.pass_mode.by_value" | "keyword.type" | "keyword.type_end" | "keyword.open_file" | "keyword.read_file" | "keyword.write_file" | "keyword.close_file" | "keyword.get_record" | "keyword.put_record" | "keyword.seek" | "keyword.file_mode.read" | "keyword.file_mode.write" | "keyword.file_mode.append" | "keyword.file_mode.random" | "keyword.case" | "keyword.of" | "keyword.case_end" | "keyword.otherwise" | "keyword.class" | "keyword.class_end" | "keyword.new" | "keyword.super" | "keyword.inherits" | "keyword.class_modifier.private" | "keyword.class_modifier.public" | "keyword.array" | "keyword.set" | "keyword.end" | "newline" | "operator.add" | "operator.minus" | "operator.multiply" | "operator.divide" | "operator.mod" | "operator.integer_divide" | "operator.and" | "operator.or" | "operator.not" | "operator.equal_to" | "operator.not_equal_to" | "operator.less_than" | "operator.greater_than" | "operator.less_than_equal" | "operator.greater_than_equal" | "operator.assignment" | "operator.pointer" | "operator.string_concatenate" | "operator.range", "\n" | "." | "DECLARE" | "DEFINE" | "CONSTANT" | "OUTPUT" | "INPUT" | "RETURN" | "CALL" | "ENDTYPE" | "IF" | "ENDIF" | "ELSE" | "ENDCASE" | "FOR" | "NEXT" | "WHILE" | "ENDWHILE" | "REPEAT" | "UNTIL" | "FUNCTION" | "ENDFUNCTION" | "PROCEDURE" | "ENDPROCEDURE" | "OPENFILE" | "READFILE" | "WRITEFILE" | "CLOSEFILE" | "SEEK" | "GETRECORD" | "PUTRECORD" | "CLASS" | "ENDCLASS" | "END" | "READ" | "WRITE" | "APPEND" | "RANDOM" | "NEW" | "AND" | "ARRAY" | "BYREF" | "BYVAL" | "CASE" | "DIV" | "FALSE" | "INHERITS" | "MOD" | "NOT" | "OF" | "OR" | "OTHERWISE" | "PRIVATE" | "PUBLIC" | "RETURNS" | "SET" | "STEP" | "SUPER" | "THEN" | "TO" | "TRUE" | "TYPE" | "<-" | ">=" | "<=" | "<>" | ".." | "=" | ">" | "<" | "+" | "-" | "*" | "/" | "^" | "&" | "(" | ")" | "[" | "]" | "{" | "}" | ":" | ";" | ",">;
type SymbolSpecifierFuncName = "isAlphanumeric" | "isNumber";
export declare function symbolize(input: string): SymbolizedProgram;
export declare function tokenize(input: SymbolizedProgram): TokenizedProgram;
Expand Down
6 changes: 3 additions & 3 deletions build/runtime-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ExpressionAST, ExpressionASTArrayTypeNode, ExpressionASTNode, Expr
import { Runtime } from "./runtime.js";
import type { AssignmentStatement, BuiltinFunctionArguments, ClassPropertyStatement, ClassStatement, ConstantStatement, DeclareStatement, DefineStatement, ForStatement, FunctionStatement, ProcedureStatement, Statement } from "./statements.js";
import { ClassFunctionStatement, ClassProcedureStatement } from "./statements.js";
import type { BoxPrimitive, IFormattable, RangeAttached, TextRange } from "./types.js";
import type { BoxPrimitive, IFormattable, RangeAttached, TextRange, TextRangeLike } from "./types.js";
import { ConfigSuggestion, RangeArray } from "./utils.js";
export type VariableTypeMapping<T> = T extends PrimitiveVariableType<infer U> ? (U extends "INTEGER" ? number : U extends "REAL" ? number : U extends "STRING" ? string : U extends "CHAR" ? string : U extends "BOOLEAN" ? boolean : U extends "DATE" ? Date : never) : T extends ArrayVariableType ? (Array<VariableTypeMapping<ArrayElementVariableType> | null> | Int32Array | Float64Array) : T extends IntegerRangeVariableType ? number : T extends RecordVariableType ? {
[index: string]: VariableTypeMapping<any> | null;
Expand Down Expand Up @@ -187,13 +187,13 @@ export declare class SetVariableType<Init extends boolean = true> extends BaseVa
export declare class ClassVariableType<Init extends boolean = true> extends BaseVariableType {
initialized: Init;
statement: ClassStatement;
properties: Record<string, [(Init extends true ? never : UnresolvedVariableType) | VariableType, ClassPropertyStatement]>;
properties: Record<string, [(Init extends true ? never : UnresolvedVariableType) | VariableType, ClassPropertyStatement, TextRangeLike]>;
ownMethods: Record<string, ClassMethodData>;
allMethods: Record<string, [source: ClassVariableType<Init extends true ? true : boolean>, data: ClassMethodData]>;
propertyStatements: ClassPropertyStatement[];
name: string;
baseClass: ClassVariableType<Init extends true ? true : boolean> | null;
constructor(initialized: Init, statement: ClassStatement, properties?: Record<string, [(Init extends true ? never : UnresolvedVariableType) | VariableType, ClassPropertyStatement]>, ownMethods?: Record<string, ClassMethodData>, allMethods?: Record<string, [source: ClassVariableType<Init extends true ? true : boolean>, data: ClassMethodData]>, propertyStatements?: ClassPropertyStatement[]);
constructor(initialized: Init, statement: ClassStatement, properties?: Record<string, [(Init extends true ? never : UnresolvedVariableType) | VariableType, ClassPropertyStatement, TextRangeLike]>, ownMethods?: Record<string, ClassMethodData>, allMethods?: Record<string, [source: ClassVariableType<Init extends true ? true : boolean>, data: ClassMethodData]>, propertyStatements?: ClassPropertyStatement[]);
init(runtime: Runtime): void;
fmtText(): string;
fmtShort(): string;
Expand Down
4 changes: 2 additions & 2 deletions build/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export declare class Runtime {
evaluateUntyped(expr: UntypedNodeValue): TypedValue;
evaluateUntyped<Type extends VariableType>(expr: UntypedNodeValue, type: Type): TypedValue<Type>;
resolveVariableType(type: UnresolvedVariableType): VariableType;
handleNonexistentClass(name: string, range: TextRangeLike): never;
handleNonexistentClass(name: string, range: TextRangeLike, gRange: TextRangeLike): never;
handleNonexistentType(name: string, range: TextRangeLike): never;
handleNonexistentFunction(name: string, range: TextRangeLike): never;
handleNonexistentVariable(name: string, range: TextRangeLike): never;
Expand All @@ -70,7 +70,7 @@ export declare class Runtime {
defineVariable(name: string, data: VariableData | ConstantData, range: TextRangeLike): void;
defineFunction(name: string, data: FunctionData, range: TextRange): void;
getFunction({ text, range }: Token): FunctionData | BuiltinFunctionData | ClassMethodCallInformation;
getClass(name: string, range: TextRange): ClassVariableType<boolean>;
getClass(name: string, range: TextRangeLike, gRange: TextRangeLike): ClassVariableType<boolean>;
getCurrentFunction(): FunctionData | ClassMethodStatement | null;
cloneValue<T extends VariableType>(type: T, value: VariableTypeMapping<T> | null): VariableTypeMapping<T> | null;
assembleScope(func: ProcedureStatement | FunctionStatement, args: RangeArray<ExpressionAST>): VariableScope;
Expand Down
Loading

0 comments on commit 21bb8ae

Please sign in to comment.