From f21ccb2c52d9ae7617b446db6a3c3244ffc75ff2 Mon Sep 17 00:00:00 2001 From: BalaM314 <71201189+BalaM314@users.noreply.github.com> Date: Fri, 3 May 2024 23:00:15 +0530 Subject: [PATCH] e --- build/lexer.d.ts | 2 +- build/parser-types.d.ts | 2 +- build/statements.d.ts | 4 ++-- build/statements.js | 2 +- src/parser.ts | 1 + src/statements.ts | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build/lexer.d.ts b/build/lexer.d.ts index aa81fa6..cd8eba7 100644 --- a/build/lexer.d.ts +++ b/build/lexer.d.ts @@ -88,7 +88,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" | "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", "." | "\n" | "+" | "-" | "*" | "/" | "(" | ")" | "[" | "]" | "<-" | "NEW" | "READ" | "WRITE" | "APPEND" | "RANDOM" | "AND" | "ARRAY" | "BYREF" | "BYVAL" | "CALL" | "CASE" | "CLASS" | "CLOSEFILE" | "CONSTANT" | "DECLARE" | "DEFINE" | "DIV" | "ELSE" | "ENDCASE" | "ENDCLASS" | "ENDFUNCTION" | "ENDIF" | "ENDPROCEDURE" | "ENDTYPE" | "ENDWHILE" | "FALSE" | "FOR" | "FUNCTION" | "GETRECORD" | "IF" | "INHERITS" | "INPUT" | "MOD" | "NEXT" | "NOT" | "OF" | "OPENFILE" | "OR" | "OTHERWISE" | "OUTPUT" | "PRIVATE" | "PROCEDURE" | "PUBLIC" | "PUTRECORD" | "READFILE" | "REPEAT" | "RETURN" | "RETURNS" | "SEEK" | "SET" | "STEP" | "SUPER" | "THEN" | "TO" | "TRUE" | "TYPE" | "UNTIL" | "WHILE" | "WRITEFILE" | ">=" | "<=" | "<>" | "=" | ">" | "<" | "^" | "&" | "{" | "}" | ":" | ";" | ",">; +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" | "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", "." | "ELSE" | "REPEAT" | "READ" | "WRITE" | "APPEND" | "RANDOM" | "\n" | "NEW" | "ENDPROCEDURE" | "ENDFUNCTION" | "+" | "-" | "*" | "/" | "(" | ")" | "[" | "]" | "<-" | "AND" | "ARRAY" | "BYREF" | "BYVAL" | "CALL" | "CASE" | "CLASS" | "CLOSEFILE" | "CONSTANT" | "DECLARE" | "DEFINE" | "DIV" | "ENDCASE" | "ENDCLASS" | "ENDIF" | "ENDTYPE" | "ENDWHILE" | "FALSE" | "FOR" | "FUNCTION" | "GETRECORD" | "IF" | "INHERITS" | "INPUT" | "MOD" | "NEXT" | "NOT" | "OF" | "OPENFILE" | "OR" | "OTHERWISE" | "OUTPUT" | "PRIVATE" | "PROCEDURE" | "PUBLIC" | "PUTRECORD" | "READFILE" | "RETURN" | "RETURNS" | "SEEK" | "SET" | "STEP" | "SUPER" | "THEN" | "TO" | "TRUE" | "TYPE" | "UNTIL" | "WHILE" | "WRITEFILE" | ">=" | "<=" | "<>" | "=" | ">" | "<" | "^" | "&" | "{" | "}" | ":" | ";" | ",">; type SymbolSpecifierFuncName = "isAlphanumeric" | "isNumber"; export declare function symbolize(input: string): SymbolizedProgram; export declare function tokenize(input: SymbolizedProgram): TokenizedProgram; diff --git a/build/parser-types.d.ts b/build/parser-types.d.ts index 23361e2..2fe93c8 100644 --- a/build/parser-types.d.ts +++ b/build/parser-types.d.ts @@ -69,7 +69,7 @@ export declare class Operator implements IFormattable { fmtDebug(): string; } export declare const operatorsByPriority: Operator[][]; -export declare const operators: Omit, "assignment" | "pointer">; +export declare const operators: Omit, "assignment" | "pointer">; export type TokenMatcher = TokenType | "." | "literal" | "literal|otherwise" | ".*" | ".+" | "expr+" | "type+" | "file_mode" | "class_modifier"; export type ProgramAST = { program: string; diff --git a/build/statements.d.ts b/build/statements.d.ts index 39e953f..ecbb554 100644 --- a/build/statements.d.ts +++ b/build/statements.d.ts @@ -9,7 +9,7 @@ export declare function StatementType(input: string): StatementType; export type StatementCategory = "normal" | "block" | "block_end" | "block_multi_split"; export declare const statements: { byStartKeyword: Partial>; - byType: Record<"function" | "type" | "assignment" | "if" | "for" | "for.step" | "while" | "dowhile" | "procedure" | "switch" | "class" | "class.inherits" | "class_function" | "class_procedure" | "input" | "output" | "declare" | "define" | "constant" | "return" | "call" | "type.pointer" | "type.enum" | "type.set" | "type.end" | "if.end" | "else" | "switch.end" | "case" | "case.range" | "for.end" | "while.end" | "dowhile.end" | "function.end" | "procedure.end" | "openfile" | "readfile" | "writefile" | "closefile" | "seek" | "getrecord" | "putrecord" | "class.end" | "class_property" | "class_procedure.end" | "class_function.end", typeof Statement>; + byType: Record<"function" | "declare" | "define" | "constant" | "assignment" | "output" | "input" | "return" | "call" | "type" | "type.pointer" | "type.enum" | "type.set" | "type.end" | "if" | "if.end" | "else" | "switch" | "switch.end" | "case" | "case.range" | "for" | "for.step" | "for.end" | "while" | "while.end" | "dowhile" | "dowhile.end" | "function.end" | "procedure" | "procedure.end" | "openfile" | "readfile" | "writefile" | "closefile" | "seek" | "getrecord" | "putrecord" | "class" | "class.inherits" | "class.end" | "class_property" | "class_procedure" | "class_procedure.end" | "class_function" | "class_function.end", typeof Statement>; irregular: (typeof Statement)[]; }; export type PassMode = "value" | "reference"; @@ -379,7 +379,7 @@ interface IClassMemberStatement { accessModifier: "public" | "private"; } export declare class ClassStatement extends Statement { - static allowOnly: Set<"function" | "type" | "assignment" | "if" | "for" | "for.step" | "while" | "dowhile" | "procedure" | "switch" | "class" | "class.inherits" | "class_function" | "class_procedure" | "input" | "output" | "declare" | "define" | "constant" | "return" | "call" | "type.pointer" | "type.enum" | "type.set" | "type.end" | "if.end" | "else" | "switch.end" | "case" | "case.range" | "for.end" | "while.end" | "dowhile.end" | "function.end" | "procedure.end" | "openfile" | "readfile" | "writefile" | "closefile" | "seek" | "getrecord" | "putrecord" | "class.end" | "class_property" | "class_procedure.end" | "class_function.end">; + static allowOnly: Set<"function" | "declare" | "define" | "constant" | "assignment" | "output" | "input" | "return" | "call" | "type" | "type.pointer" | "type.enum" | "type.set" | "type.end" | "if" | "if.end" | "else" | "switch" | "switch.end" | "case" | "case.range" | "for" | "for.step" | "for.end" | "while" | "while.end" | "dowhile" | "dowhile.end" | "function.end" | "procedure" | "procedure.end" | "openfile" | "readfile" | "writefile" | "closefile" | "seek" | "getrecord" | "putrecord" | "class" | "class.inherits" | "class.end" | "class_property" | "class_procedure" | "class_procedure.end" | "class_function" | "class_function.end">; name: Token; constructor(tokens: [Token, Token] | [Token, Token, Token, Token]); initializeClass(runtime: Runtime, branchNode: ProgramASTBranchNode): ClassVariableType; diff --git a/build/statements.js b/build/statements.js index fdefd51..f39fe46 100644 --- a/build/statements.js +++ b/build/statements.js @@ -496,7 +496,7 @@ let InputStatement = (() => { if (!variable) fail(`Undeclared variable ${this.name}`, this.tokens[1]); if (!variable.mutable) - fail(`Cannot INPUT ${this.name} because it is a constant`); + fail(`Cannot INPUT ${this.name} because it is a constant`, this.tokens[1]); const input = runtime._input(f.text `Enter the value for variable "${this.name}" (type: ${variable.type})`); switch (variable.type) { case PrimitiveVariableType.BOOLEAN: diff --git a/src/parser.ts b/src/parser.ts index 4136f3d..ad69c58 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -257,6 +257,7 @@ type StatementCheckFailResult = { message: string; priority: number; range: Text */ export const checkStatement = errorBoundary()((statement:typeof Statement, input:Token[]): StatementCheckFailResult | StatementCheckTokenRange[] => { + //TODO rewrite to use modified wagner-fischer for best detection if(input.length == 0) crash(`checkStatement() called with empty input`); if(statement.category == "block_multi_split" && !statement.blockType) crash(`block_multi_split statements must have a block type specified.`); diff --git a/src/statements.ts b/src/statements.ts index b3a630d..2675bd4 100644 --- a/src/statements.ts +++ b/src/statements.ts @@ -363,7 +363,7 @@ export class InputStatement extends Statement { run(runtime:Runtime){ const variable = runtime.getVariable(this.name); if(!variable) fail(`Undeclared variable ${this.name}`, this.tokens[1]); - if(!variable.mutable) fail(`Cannot INPUT ${this.name} because it is a constant`); + if(!variable.mutable) fail(`Cannot INPUT ${this.name} because it is a constant`, this.tokens[1]); const input = runtime._input(f.text`Enter the value for variable "${this.name}" (type: ${variable.type})`); switch(variable.type){ case PrimitiveVariableType.BOOLEAN: