@rsconcept/domain 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{analyzer-0kmNRqcr.d.ts → analyzer-A82AxKdS.d.ts} +2 -2
- package/dist/{ast-annotations-BnVekMjH.d.ts → ast-annotations-YzvwjoFW.d.ts} +2 -2
- package/dist/{calculator-OV-RNXre.d.ts → calculator-Cyy9eYyx.d.ts} +2 -2
- package/dist/{error-DYLkv4B3.d.ts → error-Cv4sntcy.d.ts} +6 -3
- package/dist/index.d.ts +4 -4
- package/dist/library/rsengine.d.ts +1 -1
- package/dist/library/rsform-api.d.ts +1 -1
- package/dist/library/rsform-api.js +2 -1
- package/dist/library/rsform-api.js.map +1 -1
- package/dist/library/rsform.d.ts +1 -1
- package/dist/rslang/ast-annotations.d.ts +1 -1
- package/dist/rslang/error.d.ts +1 -1
- package/dist/rslang/error.js +5 -2
- package/dist/rslang/error.js.map +1 -1
- package/dist/rslang/eval/calculator.d.ts +1 -1
- package/dist/rslang/eval/evaluator.d.ts +1 -1
- package/dist/rslang/index.d.ts +4 -4
- package/dist/rslang/parser/syntax-errors.d.ts +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +1 -1
- package/dist/rslang/semantic/analyzer.js +5 -2
- package/dist/rslang/semantic/analyzer.js.map +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +1 -1
- package/dist/rslang/semantic/type-auditor.js +32 -11
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +1 -1
- package/package.json +1 -1
- package/src/library/rsform-api.test.ts +30 -2
- package/src/library/rsform-api.ts +2 -1
- package/src/rslang/error.ts +5 -2
- package/src/rslang/semantic/analyzer.test.ts +56 -6
- package/src/rslang/semantic/analyzer.ts +5 -2
- package/src/rslang/semantic/type-auditor.test.ts +17 -7
- package/src/rslang/semantic/type-auditor.ts +31 -22
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
2
|
import { f as ExpressionType, g as TypeClass } from "./typification-Dk-fisgO.js";
|
|
3
|
-
import { i as RSErrorDescription } from "./error-
|
|
3
|
+
import { i as RSErrorDescription } from "./error-Cv4sntcy.js";
|
|
4
4
|
import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
|
|
5
5
|
|
|
6
6
|
//#region src/rslang/semantic/analyzer.d.ts
|
|
@@ -36,4 +36,4 @@ declare class RSLangAnalyzer {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
export { RSLangAnalyzer as a, AnalysisOptions as i, AnalysisFast as n, AnalysisFull as r, AnalysisBase as t };
|
|
39
|
-
//# sourceMappingURL=analyzer-
|
|
39
|
+
//# sourceMappingURL=analyzer-A82AxKdS.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
2
|
import { f as ExpressionType } from "./typification-Dk-fisgO.js";
|
|
3
|
-
import { a as RSErrorInfo, r as RSErrorCode } from "./error-
|
|
3
|
+
import { a as RSErrorInfo, r as RSErrorCode } from "./error-Cv4sntcy.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/ast-annotations.d.ts
|
|
6
6
|
/** Appends {@link ExpressionType} onto the node's `annotation.rsType`. */
|
|
@@ -13,4 +13,4 @@ declare function annotateError(node: AstNode, code: RSErrorCode, params?: readon
|
|
|
13
13
|
declare function readErrorAnnotation(node: AstNode): RSErrorInfo | null;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { readTypeAnnotation as i, annotateType as n, readErrorAnnotation as r, annotateError as t };
|
|
16
|
-
//# sourceMappingURL=ast-annotations-
|
|
16
|
+
//# sourceMappingURL=ast-annotations-YzvwjoFW.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
2
|
import { f as ExpressionType } from "./typification-Dk-fisgO.js";
|
|
3
|
-
import { i as RSErrorDescription } from "./error-
|
|
3
|
+
import { i as RSErrorDescription } from "./error-Cv4sntcy.js";
|
|
4
4
|
import { l as Value } from "./value-BduA_ZGp.js";
|
|
5
5
|
|
|
6
6
|
//#region src/rslang/eval/calculator.d.ts
|
|
@@ -36,4 +36,4 @@ declare class RSCalculator {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
export { CalculatorResult as n, RSCalculator as r, CalculatorEvaluateOptions as t };
|
|
39
|
-
//# sourceMappingURL=calculator-
|
|
39
|
+
//# sourceMappingURL=calculator-Cyy9eYyx.d.ts.map
|
|
@@ -47,9 +47,12 @@ declare const RSErrorCode: {
|
|
|
47
47
|
readonly invalidDebool: 34825;
|
|
48
48
|
readonly globalFuncWithoutArgs: 34827;
|
|
49
49
|
readonly invalidReduce: 34832;
|
|
50
|
-
readonly invalidProjectionTuple: 34833;
|
|
51
|
-
readonly invalidProjectionSet: 34834;
|
|
52
50
|
readonly invalidEnumeration: 34835;
|
|
51
|
+
readonly projectionSetArgumentNotSet: 34864;
|
|
52
|
+
readonly projectionSetArgumentNotTupleSet: 34865;
|
|
53
|
+
readonly projectionSetIndexOutOfRange: 34866;
|
|
54
|
+
readonly projectionTupleArgumentNotTuple: 34867;
|
|
55
|
+
readonly projectionTupleIndexOutOfRange: 34868;
|
|
53
56
|
readonly invalidCortegeDeclare: 34836;
|
|
54
57
|
readonly localOutOfScope: 34837;
|
|
55
58
|
readonly invalidElementPredicate: 34838;
|
|
@@ -93,4 +96,4 @@ declare function getRSErrorPrefix(code: RSErrorCode): string;
|
|
|
93
96
|
declare function isCritical(code: RSErrorCode): boolean;
|
|
94
97
|
//#endregion
|
|
95
98
|
export { RSErrorInfo as a, RSErrorDescription as i, RSErrorClass as n, getRSErrorPrefix as o, RSErrorCode as r, isCritical as s, ErrorReporter as t };
|
|
96
|
-
//# sourceMappingURL=error-
|
|
99
|
+
//# sourceMappingURL=error-Cv4sntcy.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -9,15 +9,15 @@ import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i a
|
|
|
9
9
|
import { t as Branded } from "./branded-ZlzIcxzu.js";
|
|
10
10
|
import { n as generateStub, t as applyHash_fnv1a } from "./hash-Y8I4c6Al.js";
|
|
11
11
|
import { O as makeTypePath, b as Typification, d as EmptySetT, f as ExpressionType, g as TypeClass, m as LogicT, t as AnyTypificationT, v as TypeID, y as TypePath } from "./typification-Dk-fisgO.js";
|
|
12
|
-
import { i as RSErrorDescription, r as RSErrorCode } from "./error-
|
|
13
|
-
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-
|
|
12
|
+
import { i as RSErrorDescription, r as RSErrorCode } from "./error-Cv4sntcy.js";
|
|
13
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-YzvwjoFW.js";
|
|
14
14
|
import { d as ValuePath, l as Value, o as TUPLE_ID, p as makeValuePath } from "./value-BduA_ZGp.js";
|
|
15
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-
|
|
15
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-Cyy9eYyx.js";
|
|
16
16
|
import { d as printValue } from "./value-api-B6T6f4Ia.js";
|
|
17
17
|
import { t as parser } from "./parser-Bwd8LxJ1.js";
|
|
18
18
|
import { t as TokenID } from "./token-DeXAmzwr.js";
|
|
19
19
|
import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
|
|
20
|
-
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-
|
|
20
|
+
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-A82AxKdS.js";
|
|
21
21
|
import { n as ArgumentsType } from "./arguments-extractor-1acwjQNc.js";
|
|
22
22
|
import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "./typification-parser-BBVx1RxP.js";
|
|
23
23
|
import { n as TypificationNodeData, t as TypificationGraph } from "./typification-graph-6HcZ-rKH.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "../ast-C8sIpKdL.js";
|
|
2
2
|
import { l as Value } from "../value-BduA_ZGp.js";
|
|
3
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-
|
|
3
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-Cyy9eYyx.js";
|
|
4
4
|
import { CstType, RSForm } from "./rsform.js";
|
|
5
5
|
import { BasicBinding, BasicsContext, EvalStatus, RSModel } from "./rsmodel.js";
|
|
6
6
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as LibraryItem } from "../library-CYun28Xz.js";
|
|
2
2
|
import { g as TypeClass, y as TypePath } from "../typification-Dk-fisgO.js";
|
|
3
3
|
import { t as ValueClass } from "../value-class-CNI-lqXJ.js";
|
|
4
|
-
import { r as AnalysisFull } from "../analyzer-
|
|
4
|
+
import { r as AnalysisFull } from "../analyzer-A82AxKdS.js";
|
|
5
5
|
import { ArgumentValue, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats } from "./rsform.js";
|
|
6
6
|
|
|
7
7
|
//#region src/library/rsform-api.d.ts
|
|
@@ -266,7 +266,8 @@ function getAnalysisFor(expression, cstType, schema, alias) {
|
|
|
266
266
|
errors: [{
|
|
267
267
|
code: RSErrorCode.definitionNotAllowed,
|
|
268
268
|
from: 0,
|
|
269
|
-
to: Math.max(
|
|
269
|
+
to: Math.max(expression.length, 1),
|
|
270
|
+
params: [cstType, alias ?? ""]
|
|
270
271
|
}],
|
|
271
272
|
ast: null
|
|
272
273
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsform-api.js","names":[],"sources":["../../src/library/rsform-api.ts"],"sourcesContent":["/**\n * Module: API for formal representation for systems of concepts.\n */\n\nimport {\n type AnalysisFull,\n RSErrorCode,\n TypeClass,\n TypeID,\n type TypePath,\n type Typification,\n ValueClass\n} from '../rslang';\nimport { basic, bool, constant, type EchelonFunctional, isTypification } from '../rslang/semantic/typification';\nimport { applyPath } from '../rslang/semantic/typification-api';\n\nimport { type LibraryItem } from './library';\nimport {\n type ArgumentValue,\n type Constituenta,\n CstClass,\n CstStatus,\n CstType,\n type RSForm,\n type RSFormStats\n} from './rsform';\n\n/** Record of {@link CstType} prefixes. */\nconst CST_TYPE_PREFIX: Record<CstType, string> = {\n [CstType.NOMINAL]: 'N',\n [CstType.BASE]: 'X',\n [CstType.CONSTANT]: 'C',\n [CstType.STRUCTURED]: 'S',\n [CstType.AXIOM]: 'A',\n [CstType.TERM]: 'D',\n [CstType.FUNCTION]: 'F',\n [CstType.PREDICATE]: 'P',\n [CstType.STATEMENT]: 'T'\n};\n\n/** Record of {@link CstType} to {@link CstClass} mapping. */\nconst CST_TYPE_TO_CLASS: Record<CstType, CstClass> = {\n [CstType.NOMINAL]: CstClass.NOMINAL,\n [CstType.BASE]: CstClass.BASIC,\n [CstType.CONSTANT]: CstClass.BASIC,\n [CstType.STRUCTURED]: CstClass.BASIC,\n [CstType.TERM]: CstClass.DERIVED,\n [CstType.FUNCTION]: CstClass.DERIVED,\n [CstType.AXIOM]: CstClass.STATEMENT,\n [CstType.PREDICATE]: CstClass.DERIVED,\n [CstType.STATEMENT]: CstClass.STATEMENT\n};\n\n/** Checks if {@link Constituenta} is a schema issue. */\nexport function isSchemaIssue(cst: Constituenta): boolean {\n if (\n cst.homonyms.length > 0 ||\n cst.formalDuplicates.length > 0 ||\n cst.status === CstStatus.INCORRECT ||\n cst.status === CstStatus.INCALCULABLE ||\n cst.is_type_mismatch\n ) {\n return true;\n }\n if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {\n if (!cst.convention || !cst.term_resolved) {\n return true;\n }\n }\n return false;\n}\n\n/** Infers the status of an expression based on parsing and value information. */\nexport function inferStatus(parse: boolean, value?: ValueClass | null): CstStatus {\n if (!parse) {\n return CstStatus.INCORRECT;\n }\n if (value === null) {\n return CstStatus.INCALCULABLE;\n }\n if (value === ValueClass.PROPERTY) {\n return CstStatus.PROPERTY;\n }\n return CstStatus.VERIFIED;\n}\n\n/** Infers type of constituent for a given template and arguments. */\nexport function inferTemplatedType(templateType: CstType, args: ArgumentValue[]): CstType {\n if (args.length === 0 || args.some(arg => !arg.value)) {\n return templateType;\n } else if (templateType === CstType.PREDICATE) {\n return CstType.AXIOM;\n } else {\n return CstType.TERM;\n }\n}\n\n/** Checks if given expression is a template. */\nexport function inferTemplate(expression: string): boolean {\n const match = expression.match(/R\\d+/g);\n return (match && match?.length > 0) ?? false;\n}\n\n/** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */\nexport function inferClass(type: CstType, isTemplate: boolean = false): CstClass {\n if (isTemplate) {\n return CstClass.TEMPLATE;\n }\n return CST_TYPE_TO_CLASS[type];\n}\n\n/** Check if {@link Constituenta} is a template or a category. */\nexport function isTemplateCst(cst: Constituenta): boolean {\n return cst.cst_type === CstType.FUNCTION || cst.cst_type === CstType.PREDICATE || cst.cst_type === CstType.STATEMENT;\n}\n\n/** Apply filter based on start {@link Constituenta} type. */\nexport function applyFilterCategory(start: Constituenta, items: Constituenta[]): Constituenta[] {\n const startIndex = items.indexOf(start);\n if (startIndex === -1) {\n return [];\n }\n const nextCategoryIndex = items.findIndex((cst, index) => index > startIndex && cst.cst_type === CstType.STATEMENT);\n\n return items.filter((_, index) => index >= startIndex && (nextCategoryIndex === -1 || index < nextCategoryIndex));\n}\n\n/** Prefix for alias indicating {@link CstType}. */\nexport function getCstTypePrefix(type: CstType): string {\n return CST_TYPE_PREFIX[type];\n}\n\n/** Guess {@link CstType} from user input hint. */\nexport function guessCstType(hint: string): CstType | null {\n if (hint.length !== 1) {\n return null;\n }\n for (const [type, prefix] of Object.entries(CST_TYPE_PREFIX)) {\n if (hint === prefix) {\n return type as CstType;\n }\n }\n return null;\n}\n\n/** Evaluate if {@link CstType} is basic concept. */\nexport function isBasicConcept(type: CstType): boolean {\n switch (type) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n return true;\n\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is base set or constant set. */\nexport function isBaseSet(type: CstType): boolean {\n switch (type) {\n case CstType.BASE:\n case CstType.CONSTANT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is a function. */\nexport function isFunctional(type: CstType): boolean {\n switch (type) {\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is logical. */\nexport function isLogical(type: CstType): boolean {\n switch (type) {\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return false;\n }\n}\n\n/** Evaluate if {@link Constituenta} can be used produce structure. */\nexport function canProduceStructure(cst: Constituenta): boolean {\n switch (cst.cst_type) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.AXIOM:\n case CstType.STATEMENT:\n case CstType.PREDICATE:\n return false;\n }\n if (!cst.effectiveType) {\n return false;\n }\n if (cst.cst_type === CstType.FUNCTION) {\n const result = (cst.effectiveType as EchelonFunctional).result;\n return typeCanProduceStructure(result);\n }\n if (!isTypification(cst.effectiveType)) {\n return false;\n }\n return typeCanProduceStructure(cst.effectiveType as Typification);\n}\n\n/** Evaluate if {@link CstType} can have manual typification. */\nexport function canHaveManualTypification(type: CstType): boolean {\n switch (type) {\n case CstType.STRUCTURED:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */\nexport function validateAliasFormat(alias: string, type: CstType): boolean {\n if (alias.length < 2) {\n return false;\n }\n const prefix = getCstTypePrefix(type);\n if (!alias.startsWith(prefix)) {\n return false;\n }\n if (!/^\\d+$/.exec(alias.substring(prefix.length))) {\n return false;\n }\n return true;\n}\n\n/** Validate new alias against {@link CstType} and {@link RSForm}. */\nexport function validateNewAlias(alias: string, type: CstType, schema: RSForm): boolean {\n if (!validateAliasFormat(alias, type)) {\n return false;\n }\n if (schema.cstByAlias.has(alias)) {\n return false;\n }\n return true;\n}\n\n/** Generate alias for new {@link Constituenta} of a given {@link CstType} for current {@link RSForm}. */\nexport function generateAlias(type: CstType, schema: RSForm, takenAliases: string[] = []): string {\n const prefix = getCstTypePrefix(type);\n if (schema.items.length <= 0) {\n return `${prefix}1`;\n }\n let index = schema.items.reduce((prev, cst, index) => {\n if (cst.cst_type !== type) {\n return prev;\n }\n index = Number(cst.alias.slice(1 - cst.alias.length)) + 1;\n return Math.max(prev, index);\n }, 1);\n let alias = `${prefix}${index}`;\n while (takenAliases.includes(alias)) {\n index = index + 1;\n alias = `${prefix}${index}`;\n }\n return alias;\n}\n\n/**\n * Id to pass as `insert_after` when creating a new {@link Constituenta} spawned by `targetId`:\n * after the last existing child of that spawner, or after the spawner itself if none.\n */\nexport function inferNewSpawnPosition(schema: RSForm, targetId: number): number {\n let last: number | null = null;\n for (const cst of schema.items) {\n if (cst.spawner === targetId) {\n last = cst.id;\n }\n }\n return last ?? targetId;\n}\n\n/** Sorts library items relevant for InlineSynthesis with specified {@link RSForm}. */\nexport function sortItemsForInlineSynthesis(receiver: RSForm, items: readonly LibraryItem[]): LibraryItem[] {\n const result = items.filter(item => item.location === receiver.location);\n for (const item of items) {\n if (item.visible && item.owner === item.owner && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (item.visible && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (!result.includes(item)) {\n result.push(item);\n }\n }\n return result;\n}\n\n/** Remove alias from expression. */\nexport function removeAliasReference(expression: string, alias: string): string {\n const result = expression.replaceAll(new RegExp(`\\\\b${alias}\\\\b`, 'g'), 'DEL');\n return result === 'DEL' ? '' : result;\n}\n\n/** Add alias to expression. */\nexport function addAliasReference(expression: string, alias: string): string {\n return expression + ' ' + alias;\n}\n\n/** Returns expected {@link TypeClass} of formal definition for {@link CstType}. */\nexport function typeClassForCstType(cstType: CstType): TypeClass {\n switch (cstType) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.TERM:\n return TypeClass.typification;\n case CstType.FUNCTION:\n return TypeClass.function;\n case CstType.PREDICATE:\n return TypeClass.predicate;\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return TypeClass.logic;\n }\n}\n\n/** Checks whether a constituenta type supports formal definitions. */\nexport function canHaveFormalDefinition(cstType: CstType): boolean {\n return cstType !== CstType.BASE && cstType !== CstType.CONSTANT;\n}\n\n/** Analyze expression for {@link RSForm}. */\nexport function getAnalysisFor(expression: string, cstType: CstType, schema: RSForm, alias?: string): AnalysisFull {\n if (!canHaveFormalDefinition(cstType)) {\n if (expression.trim().length === 0) {\n const fallbackAlias = alias && alias.length > 0 ? alias : 'X0';\n const type = cstType === CstType.BASE ? bool(basic(fallbackAlias)) : bool(constant(fallbackAlias));\n return {\n success: true,\n type,\n valueClass: ValueClass.VALUE,\n errors: [],\n ast: null\n };\n }\n return {\n success: false,\n type: null,\n valueClass: null,\n errors: [\n {\n code: RSErrorCode.definitionNotAllowed,\n from: 0,\n to: Math.max(0, expression.length - 1)\n }\n ],\n ast: null\n };\n }\n return schema.analyzer.checkFull(expression, {\n expected: typeClassForCstType(cstType),\n isDomain: cstType === CstType.STRUCTURED\n });\n}\n\n/** Calculate statistics for {@link RSForm}. */\nexport function calculateSchemaStats(target: RSForm): RSFormStats {\n const items = target.items;\n return {\n count_all: items.length,\n count_crucial: items.reduce((sum, cst) => sum + (cst.crucial ? 1 : 0), 0),\n\n step_complexity: items.reduce((sum, cst) => sum + calculateStepComplexity(cst), 0),\n\n count_problematic: items.reduce((sum, cst) => sum + (isSchemaIssue(cst) ? 1 : 0), 0),\n count_homonyms: items.reduce((sum, cst) => sum + (cst.homonyms.length > 0 ? 1 : 0), 0),\n count_formal_duplicates: items.reduce((sum, cst) => sum + (cst.formalDuplicates.length > 0 ? 1 : 0), 0),\n count_missing_convention: items.reduce((sum, cst) => sum + (isMissingConvention(cst) ? 1 : 0), 0),\n count_type_mismatch: items.reduce((sum, cst) => sum + (cst.is_type_mismatch ? 1 : 0), 0),\n\n count_incorrect: items.reduce((sum, cst) => sum + (cst.status === CstStatus.INCORRECT ? 1 : 0), 0),\n count_property: items.reduce((sum, cst) => sum + (cst.analysis?.valueClass === ValueClass.PROPERTY ? 1 : 0), 0),\n count_incalculable: items.reduce(\n (sum, cst) => sum + (cst.analysis?.success && cst.analysis.valueClass === null ? 1 : 0),\n 0\n ),\n count_inherited: items.reduce((sum, cst) => sum + (cst.is_inherited ? 1 : 0), 0),\n\n count_text_term: items.reduce((sum, cst) => sum + (cst.term_raw ? 1 : 0), 0),\n count_definition: items.reduce((sum, cst) => sum + (cst.definition_raw ? 1 : 0), 0),\n count_convention: items.reduce((sum, cst) => sum + (isBasicConcept(cst.cst_type) && cst.convention ? 1 : 0), 0),\n count_comment: items.reduce((sum, cst) => sum + (!isBasicConcept(cst.cst_type) && !cst.convention ? 1 : 0), 0),\n\n count_base: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.BASE ? 1 : 0), 0),\n count_constant: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.CONSTANT ? 1 : 0), 0),\n count_structured: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STRUCTURED ? 1 : 0), 0),\n count_axiom: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.AXIOM ? 1 : 0), 0),\n count_term: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.TERM ? 1 : 0), 0),\n count_function: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.FUNCTION ? 1 : 0), 0),\n count_predicate: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.PREDICATE ? 1 : 0), 0),\n count_statement: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STATEMENT ? 1 : 0), 0),\n count_nominal: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.NOMINAL ? 1 : 0), 0)\n };\n}\n\n/** Finds {@link Constituenta} by structure path. */\nexport function findCstByStructure(schema: RSForm, target: Constituenta, path: TypePath): Constituenta | null {\n for (const cst of schema.items) {\n if (cst.spawner === target.id && cst.spawner_path) {\n if (cst.spawner_path.length === path.length && cst.spawner_path.every((v, i) => v === path[i])) {\n return cst;\n }\n }\n }\n return null;\n}\n\n/** Retrieves name for piece of target {@link Constituenta} structure. */\nexport function getStructureName(schema: RSForm, target: Constituenta, path: TypePath): string {\n const representation = findCstByStructure(schema, target, path);\n if (representation) {\n return `${representation.alias}: ${representation.term_resolved}`;\n }\n if (!isTypification(target.effectiveType)) {\n return '';\n }\n const type = applyPath(target.effectiveType as Typification, path);\n if (type?.typeID === TypeID.basic) {\n const cst = schema.cstByAlias.get(type.baseID);\n if (cst?.term_resolved) {\n return `${cst.alias}: ${cst.term_resolved}`;\n }\n }\n return '';\n}\n\n// ========= Internals =====\nfunction calculateStepComplexity(cst: Constituenta): number {\n if (cst.cst_type === CstType.AXIOM || cst.cst_type === CstType.NOMINAL || !isBasicConcept(cst.cst_type)) {\n return 0;\n }\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT || !cst.effectiveType) {\n return 1;\n }\n\n const type = cst.effectiveType as Typification;\n return calculateTypificationComplexity(type) + 1;\n}\n\nfunction calculateTypificationComplexity(type: Typification): number {\n switch (type.typeID) {\n case TypeID.basic:\n case TypeID.integer:\n case TypeID.anyTypification:\n return 0;\n case TypeID.tuple:\n return (\n type.factors.length + type.factors.reduce((sum, factor) => sum + calculateTypificationComplexity(factor), 0)\n );\n case TypeID.collection:\n if (type.base.typeID === TypeID.tuple) {\n let sum = 0;\n type.base.factors.forEach(factor => {\n sum += calculateTypificationComplexity(factor);\n });\n return sum + type.base.factors.length;\n } else if (type.base.typeID === TypeID.collection) {\n return calculateTypificationComplexity(type.base) + 1;\n }\n return 0;\n }\n}\n\nfunction isMissingConvention(cst: Constituenta): boolean {\n if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {\n if (!cst.convention || !cst.term_resolved) {\n return true;\n }\n }\n return false;\n}\n\n/** Evaluate if {@link Typification} can be used to produce structure. */\nfunction typeCanProduceStructure(type: Typification): boolean {\n if (type.typeID === TypeID.basic || type.typeID === TypeID.integer || type.typeID === TypeID.anyTypification) {\n return false;\n } else if (type.typeID === TypeID.tuple) {\n return true;\n } else {\n return (\n type.base.typeID !== TypeID.basic &&\n type.base.typeID !== TypeID.integer &&\n type.base.typeID !== TypeID.anyTypification\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,kBAA2C;EAC9C,QAAQ,UAAU;EAClB,QAAQ,OAAO;EACf,QAAQ,WAAW;EACnB,QAAQ,aAAa;EACrB,QAAQ,QAAQ;EAChB,QAAQ,OAAO;EACf,QAAQ,WAAW;EACnB,QAAQ,YAAY;EACpB,QAAQ,YAAY;AACvB;;AAGA,MAAM,oBAA+C;EAClD,QAAQ,UAAU,SAAS;EAC3B,QAAQ,OAAO,SAAS;EACxB,QAAQ,WAA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AAI,KAAK,WAAW,OAAO,SAAS,KAAK,WAAW,OAAO,WAAW,KAAK,WAAW,OAAO,iBAC3F,OAAO;MACF,IAAI,KAAK,WAAW,OAAO,OAChC,OAAO;MAEP,OACE,KAAK,KAAK,WAAW,OAAO,SAC5B,KAAK,KAAK,WAAW,OAAO,WAC5B,KAAK,KAAK,WAAW,OAAO;AAGlC"}
|
|
1
|
+
{"version":3,"file":"rsform-api.js","names":[],"sources":["../../src/library/rsform-api.ts"],"sourcesContent":["/**\n * Module: API for formal representation for systems of concepts.\n */\n\nimport {\n type AnalysisFull,\n RSErrorCode,\n TypeClass,\n TypeID,\n type TypePath,\n type Typification,\n ValueClass\n} from '../rslang';\nimport { basic, bool, constant, type EchelonFunctional, isTypification } from '../rslang/semantic/typification';\nimport { applyPath } from '../rslang/semantic/typification-api';\n\nimport { type LibraryItem } from './library';\nimport {\n type ArgumentValue,\n type Constituenta,\n CstClass,\n CstStatus,\n CstType,\n type RSForm,\n type RSFormStats\n} from './rsform';\n\n/** Record of {@link CstType} prefixes. */\nconst CST_TYPE_PREFIX: Record<CstType, string> = {\n [CstType.NOMINAL]: 'N',\n [CstType.BASE]: 'X',\n [CstType.CONSTANT]: 'C',\n [CstType.STRUCTURED]: 'S',\n [CstType.AXIOM]: 'A',\n [CstType.TERM]: 'D',\n [CstType.FUNCTION]: 'F',\n [CstType.PREDICATE]: 'P',\n [CstType.STATEMENT]: 'T'\n};\n\n/** Record of {@link CstType} to {@link CstClass} mapping. */\nconst CST_TYPE_TO_CLASS: Record<CstType, CstClass> = {\n [CstType.NOMINAL]: CstClass.NOMINAL,\n [CstType.BASE]: CstClass.BASIC,\n [CstType.CONSTANT]: CstClass.BASIC,\n [CstType.STRUCTURED]: CstClass.BASIC,\n [CstType.TERM]: CstClass.DERIVED,\n [CstType.FUNCTION]: CstClass.DERIVED,\n [CstType.AXIOM]: CstClass.STATEMENT,\n [CstType.PREDICATE]: CstClass.DERIVED,\n [CstType.STATEMENT]: CstClass.STATEMENT\n};\n\n/** Checks if {@link Constituenta} is a schema issue. */\nexport function isSchemaIssue(cst: Constituenta): boolean {\n if (\n cst.homonyms.length > 0 ||\n cst.formalDuplicates.length > 0 ||\n cst.status === CstStatus.INCORRECT ||\n cst.status === CstStatus.INCALCULABLE ||\n cst.is_type_mismatch\n ) {\n return true;\n }\n if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {\n if (!cst.convention || !cst.term_resolved) {\n return true;\n }\n }\n return false;\n}\n\n/** Infers the status of an expression based on parsing and value information. */\nexport function inferStatus(parse: boolean, value?: ValueClass | null): CstStatus {\n if (!parse) {\n return CstStatus.INCORRECT;\n }\n if (value === null) {\n return CstStatus.INCALCULABLE;\n }\n if (value === ValueClass.PROPERTY) {\n return CstStatus.PROPERTY;\n }\n return CstStatus.VERIFIED;\n}\n\n/** Infers type of constituent for a given template and arguments. */\nexport function inferTemplatedType(templateType: CstType, args: ArgumentValue[]): CstType {\n if (args.length === 0 || args.some(arg => !arg.value)) {\n return templateType;\n } else if (templateType === CstType.PREDICATE) {\n return CstType.AXIOM;\n } else {\n return CstType.TERM;\n }\n}\n\n/** Checks if given expression is a template. */\nexport function inferTemplate(expression: string): boolean {\n const match = expression.match(/R\\d+/g);\n return (match && match?.length > 0) ?? false;\n}\n\n/** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */\nexport function inferClass(type: CstType, isTemplate: boolean = false): CstClass {\n if (isTemplate) {\n return CstClass.TEMPLATE;\n }\n return CST_TYPE_TO_CLASS[type];\n}\n\n/** Check if {@link Constituenta} is a template or a category. */\nexport function isTemplateCst(cst: Constituenta): boolean {\n return cst.cst_type === CstType.FUNCTION || cst.cst_type === CstType.PREDICATE || cst.cst_type === CstType.STATEMENT;\n}\n\n/** Apply filter based on start {@link Constituenta} type. */\nexport function applyFilterCategory(start: Constituenta, items: Constituenta[]): Constituenta[] {\n const startIndex = items.indexOf(start);\n if (startIndex === -1) {\n return [];\n }\n const nextCategoryIndex = items.findIndex((cst, index) => index > startIndex && cst.cst_type === CstType.STATEMENT);\n\n return items.filter((_, index) => index >= startIndex && (nextCategoryIndex === -1 || index < nextCategoryIndex));\n}\n\n/** Prefix for alias indicating {@link CstType}. */\nexport function getCstTypePrefix(type: CstType): string {\n return CST_TYPE_PREFIX[type];\n}\n\n/** Guess {@link CstType} from user input hint. */\nexport function guessCstType(hint: string): CstType | null {\n if (hint.length !== 1) {\n return null;\n }\n for (const [type, prefix] of Object.entries(CST_TYPE_PREFIX)) {\n if (hint === prefix) {\n return type as CstType;\n }\n }\n return null;\n}\n\n/** Evaluate if {@link CstType} is basic concept. */\nexport function isBasicConcept(type: CstType): boolean {\n switch (type) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n return true;\n\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is base set or constant set. */\nexport function isBaseSet(type: CstType): boolean {\n switch (type) {\n case CstType.BASE:\n case CstType.CONSTANT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is a function. */\nexport function isFunctional(type: CstType): boolean {\n switch (type) {\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is logical. */\nexport function isLogical(type: CstType): boolean {\n switch (type) {\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return false;\n }\n}\n\n/** Evaluate if {@link Constituenta} can be used produce structure. */\nexport function canProduceStructure(cst: Constituenta): boolean {\n switch (cst.cst_type) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.AXIOM:\n case CstType.STATEMENT:\n case CstType.PREDICATE:\n return false;\n }\n if (!cst.effectiveType) {\n return false;\n }\n if (cst.cst_type === CstType.FUNCTION) {\n const result = (cst.effectiveType as EchelonFunctional).result;\n return typeCanProduceStructure(result);\n }\n if (!isTypification(cst.effectiveType)) {\n return false;\n }\n return typeCanProduceStructure(cst.effectiveType as Typification);\n}\n\n/** Evaluate if {@link CstType} can have manual typification. */\nexport function canHaveManualTypification(type: CstType): boolean {\n switch (type) {\n case CstType.STRUCTURED:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */\nexport function validateAliasFormat(alias: string, type: CstType): boolean {\n if (alias.length < 2) {\n return false;\n }\n const prefix = getCstTypePrefix(type);\n if (!alias.startsWith(prefix)) {\n return false;\n }\n if (!/^\\d+$/.exec(alias.substring(prefix.length))) {\n return false;\n }\n return true;\n}\n\n/** Validate new alias against {@link CstType} and {@link RSForm}. */\nexport function validateNewAlias(alias: string, type: CstType, schema: RSForm): boolean {\n if (!validateAliasFormat(alias, type)) {\n return false;\n }\n if (schema.cstByAlias.has(alias)) {\n return false;\n }\n return true;\n}\n\n/** Generate alias for new {@link Constituenta} of a given {@link CstType} for current {@link RSForm}. */\nexport function generateAlias(type: CstType, schema: RSForm, takenAliases: string[] = []): string {\n const prefix = getCstTypePrefix(type);\n if (schema.items.length <= 0) {\n return `${prefix}1`;\n }\n let index = schema.items.reduce((prev, cst, index) => {\n if (cst.cst_type !== type) {\n return prev;\n }\n index = Number(cst.alias.slice(1 - cst.alias.length)) + 1;\n return Math.max(prev, index);\n }, 1);\n let alias = `${prefix}${index}`;\n while (takenAliases.includes(alias)) {\n index = index + 1;\n alias = `${prefix}${index}`;\n }\n return alias;\n}\n\n/**\n * Id to pass as `insert_after` when creating a new {@link Constituenta} spawned by `targetId`:\n * after the last existing child of that spawner, or after the spawner itself if none.\n */\nexport function inferNewSpawnPosition(schema: RSForm, targetId: number): number {\n let last: number | null = null;\n for (const cst of schema.items) {\n if (cst.spawner === targetId) {\n last = cst.id;\n }\n }\n return last ?? targetId;\n}\n\n/** Sorts library items relevant for InlineSynthesis with specified {@link RSForm}. */\nexport function sortItemsForInlineSynthesis(receiver: RSForm, items: readonly LibraryItem[]): LibraryItem[] {\n const result = items.filter(item => item.location === receiver.location);\n for (const item of items) {\n if (item.visible && item.owner === item.owner && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (item.visible && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (!result.includes(item)) {\n result.push(item);\n }\n }\n return result;\n}\n\n/** Remove alias from expression. */\nexport function removeAliasReference(expression: string, alias: string): string {\n const result = expression.replaceAll(new RegExp(`\\\\b${alias}\\\\b`, 'g'), 'DEL');\n return result === 'DEL' ? '' : result;\n}\n\n/** Add alias to expression. */\nexport function addAliasReference(expression: string, alias: string): string {\n return expression + ' ' + alias;\n}\n\n/** Returns expected {@link TypeClass} of formal definition for {@link CstType}. */\nexport function typeClassForCstType(cstType: CstType): TypeClass {\n switch (cstType) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.TERM:\n return TypeClass.typification;\n case CstType.FUNCTION:\n return TypeClass.function;\n case CstType.PREDICATE:\n return TypeClass.predicate;\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return TypeClass.logic;\n }\n}\n\n/** Checks whether a constituenta type supports formal definitions. */\nexport function canHaveFormalDefinition(cstType: CstType): boolean {\n return cstType !== CstType.BASE && cstType !== CstType.CONSTANT;\n}\n\n/** Analyze expression for {@link RSForm}. */\nexport function getAnalysisFor(expression: string, cstType: CstType, schema: RSForm, alias?: string): AnalysisFull {\n if (!canHaveFormalDefinition(cstType)) {\n if (expression.trim().length === 0) {\n const fallbackAlias = alias && alias.length > 0 ? alias : 'X0';\n const type = cstType === CstType.BASE ? bool(basic(fallbackAlias)) : bool(constant(fallbackAlias));\n return {\n success: true,\n type,\n valueClass: ValueClass.VALUE,\n errors: [],\n ast: null\n };\n }\n return {\n success: false,\n type: null,\n valueClass: null,\n errors: [\n {\n code: RSErrorCode.definitionNotAllowed,\n from: 0,\n to: Math.max(expression.length, 1),\n params: [cstType, alias ?? '']\n }\n ],\n ast: null\n };\n }\n return schema.analyzer.checkFull(expression, {\n expected: typeClassForCstType(cstType),\n isDomain: cstType === CstType.STRUCTURED\n });\n}\n\n/** Calculate statistics for {@link RSForm}. */\nexport function calculateSchemaStats(target: RSForm): RSFormStats {\n const items = target.items;\n return {\n count_all: items.length,\n count_crucial: items.reduce((sum, cst) => sum + (cst.crucial ? 1 : 0), 0),\n\n step_complexity: items.reduce((sum, cst) => sum + calculateStepComplexity(cst), 0),\n\n count_problematic: items.reduce((sum, cst) => sum + (isSchemaIssue(cst) ? 1 : 0), 0),\n count_homonyms: items.reduce((sum, cst) => sum + (cst.homonyms.length > 0 ? 1 : 0), 0),\n count_formal_duplicates: items.reduce((sum, cst) => sum + (cst.formalDuplicates.length > 0 ? 1 : 0), 0),\n count_missing_convention: items.reduce((sum, cst) => sum + (isMissingConvention(cst) ? 1 : 0), 0),\n count_type_mismatch: items.reduce((sum, cst) => sum + (cst.is_type_mismatch ? 1 : 0), 0),\n\n count_incorrect: items.reduce((sum, cst) => sum + (cst.status === CstStatus.INCORRECT ? 1 : 0), 0),\n count_property: items.reduce((sum, cst) => sum + (cst.analysis?.valueClass === ValueClass.PROPERTY ? 1 : 0), 0),\n count_incalculable: items.reduce(\n (sum, cst) => sum + (cst.analysis?.success && cst.analysis.valueClass === null ? 1 : 0),\n 0\n ),\n count_inherited: items.reduce((sum, cst) => sum + (cst.is_inherited ? 1 : 0), 0),\n\n count_text_term: items.reduce((sum, cst) => sum + (cst.term_raw ? 1 : 0), 0),\n count_definition: items.reduce((sum, cst) => sum + (cst.definition_raw ? 1 : 0), 0),\n count_convention: items.reduce((sum, cst) => sum + (isBasicConcept(cst.cst_type) && cst.convention ? 1 : 0), 0),\n count_comment: items.reduce((sum, cst) => sum + (!isBasicConcept(cst.cst_type) && !cst.convention ? 1 : 0), 0),\n\n count_base: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.BASE ? 1 : 0), 0),\n count_constant: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.CONSTANT ? 1 : 0), 0),\n count_structured: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STRUCTURED ? 1 : 0), 0),\n count_axiom: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.AXIOM ? 1 : 0), 0),\n count_term: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.TERM ? 1 : 0), 0),\n count_function: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.FUNCTION ? 1 : 0), 0),\n count_predicate: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.PREDICATE ? 1 : 0), 0),\n count_statement: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STATEMENT ? 1 : 0), 0),\n count_nominal: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.NOMINAL ? 1 : 0), 0)\n };\n}\n\n/** Finds {@link Constituenta} by structure path. */\nexport function findCstByStructure(schema: RSForm, target: Constituenta, path: TypePath): Constituenta | null {\n for (const cst of schema.items) {\n if (cst.spawner === target.id && cst.spawner_path) {\n if (cst.spawner_path.length === path.length && cst.spawner_path.every((v, i) => v === path[i])) {\n return cst;\n }\n }\n }\n return null;\n}\n\n/** Retrieves name for piece of target {@link Constituenta} structure. */\nexport function getStructureName(schema: RSForm, target: Constituenta, path: TypePath): string {\n const representation = findCstByStructure(schema, target, path);\n if (representation) {\n return `${representation.alias}: ${representation.term_resolved}`;\n }\n if (!isTypification(target.effectiveType)) {\n return '';\n }\n const type = applyPath(target.effectiveType as Typification, path);\n if (type?.typeID === TypeID.basic) {\n const cst = schema.cstByAlias.get(type.baseID);\n if (cst?.term_resolved) {\n return `${cst.alias}: ${cst.term_resolved}`;\n }\n }\n return '';\n}\n\n// ========= Internals =====\nfunction calculateStepComplexity(cst: Constituenta): number {\n if (cst.cst_type === CstType.AXIOM || cst.cst_type === CstType.NOMINAL || !isBasicConcept(cst.cst_type)) {\n return 0;\n }\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT || !cst.effectiveType) {\n return 1;\n }\n\n const type = cst.effectiveType as Typification;\n return calculateTypificationComplexity(type) + 1;\n}\n\nfunction calculateTypificationComplexity(type: Typification): number {\n switch (type.typeID) {\n case TypeID.basic:\n case TypeID.integer:\n case TypeID.anyTypification:\n return 0;\n case TypeID.tuple:\n return (\n type.factors.length + type.factors.reduce((sum, factor) => sum + calculateTypificationComplexity(factor), 0)\n );\n case TypeID.collection:\n if (type.base.typeID === TypeID.tuple) {\n let sum = 0;\n type.base.factors.forEach(factor => {\n sum += calculateTypificationComplexity(factor);\n });\n return sum + type.base.factors.length;\n } else if (type.base.typeID === TypeID.collection) {\n return calculateTypificationComplexity(type.base) + 1;\n }\n return 0;\n }\n}\n\nfunction isMissingConvention(cst: Constituenta): boolean {\n if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {\n if (!cst.convention || !cst.term_resolved) {\n return true;\n }\n }\n return false;\n}\n\n/** Evaluate if {@link Typification} can be used to produce structure. */\nfunction typeCanProduceStructure(type: Typification): boolean {\n if (type.typeID === TypeID.basic || type.typeID === TypeID.integer || type.typeID === TypeID.anyTypification) {\n return false;\n } else if (type.typeID === TypeID.tuple) {\n return true;\n } else {\n return (\n type.base.typeID !== TypeID.basic &&\n type.base.typeID !== TypeID.integer &&\n type.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C,OAAO,gCAAgC,MAAM;IAC/C,CAAC;IACD,OAAO,MAAM,KAAK,KAAK,QAAQ;GACjC,OAAO,IAAI,KAAK,KAAK,WAAW,OAAO,YACrC,OAAO,gCAAgC,KAAK,IAAI,IAAI;GAEtD,OAAO;CACX;AACF;AAEA,SAAS,oBAAoB,KAA4B;CACvD,IAAI,eAAe,IAAI,QAAQ,KAAK,CAAC,UAAU,IAAI,QAAQ,GACzD;MAAI,CAAC,IAAI,cAAc,CAAC,IAAI,eAC1B,OAAO;CACT;CAEF,OAAO;AACT;;AAGA,SAAS,wBAAwB,MAA6B;CAC5D,IAAI,KAAK,WAAW,OAAO,SAAS,KAAK,WAAW,OAAO,WAAW,KAAK,WAAW,OAAO,iBAC3F,OAAO;MACF,IAAI,KAAK,WAAW,OAAO,OAChC,OAAO;MAEP,OACE,KAAK,KAAK,WAAW,OAAO,SAC5B,KAAK,KAAK,WAAW,OAAO,WAC5B,KAAK,KAAK,WAAW,OAAO;AAGlC"}
|
package/dist/library/rsform.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Graph } from "../graph-DR8rL2o3.js";
|
|
2
2
|
import { i as LibraryItemReference, n as CurrentVersion, r as LibraryItem, s as VersionInfo } from "../library-CYun28Xz.js";
|
|
3
3
|
import { f as ExpressionType, y as TypePath } from "../typification-Dk-fisgO.js";
|
|
4
|
-
import { a as RSLangAnalyzer, t as AnalysisBase } from "../analyzer-
|
|
4
|
+
import { a as RSLangAnalyzer, t as AnalysisBase } from "../analyzer-A82AxKdS.js";
|
|
5
5
|
//#region src/library/rsform.d.ts
|
|
6
6
|
/** Represents {@link Constituenta} type. */
|
|
7
7
|
declare const CstType: {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-
|
|
1
|
+
import { i as readTypeAnnotation, n as annotateType, r as readErrorAnnotation, t as annotateError } from "../ast-annotations-YzvwjoFW.js";
|
|
2
2
|
export { annotateError, annotateType, readErrorAnnotation, readTypeAnnotation };
|
package/dist/rslang/error.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RSErrorInfo, i as RSErrorDescription, n as RSErrorClass, o as getRSErrorPrefix, r as RSErrorCode, s as isCritical, t as ErrorReporter } from "../error-
|
|
1
|
+
import { a as RSErrorInfo, i as RSErrorDescription, n as RSErrorClass, o as getRSErrorPrefix, r as RSErrorCode, s as isCritical, t as ErrorReporter } from "../error-Cv4sntcy.js";
|
|
2
2
|
export { ErrorReporter, RSErrorClass, RSErrorCode, RSErrorDescription, RSErrorInfo, getRSErrorPrefix, isCritical };
|
package/dist/rslang/error.js
CHANGED
|
@@ -34,9 +34,12 @@ const RSErrorCode = {
|
|
|
34
34
|
invalidDebool: 34825,
|
|
35
35
|
globalFuncWithoutArgs: 34827,
|
|
36
36
|
invalidReduce: 34832,
|
|
37
|
-
invalidProjectionTuple: 34833,
|
|
38
|
-
invalidProjectionSet: 34834,
|
|
39
37
|
invalidEnumeration: 34835,
|
|
38
|
+
projectionSetArgumentNotSet: 34864,
|
|
39
|
+
projectionSetArgumentNotTupleSet: 34865,
|
|
40
|
+
projectionSetIndexOutOfRange: 34866,
|
|
41
|
+
projectionTupleArgumentNotTuple: 34867,
|
|
42
|
+
projectionTupleIndexOutOfRange: 34868,
|
|
40
43
|
invalidCortegeDeclare: 34836,
|
|
41
44
|
localOutOfScope: 34837,
|
|
42
45
|
invalidElementPredicate: 34838,
|
package/dist/rslang/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":[],"sources":["../../src/rslang/error.ts"],"sourcesContent":["/** Module: Error types and functions. */\n\n/** Represents error class. */\nexport const RSErrorClass = {\n LEXER: 0,\n PARSER: 1,\n SEMANTIC: 2,\n EVALUATION: 3,\n UNKNOWN: 4\n} as const;\nexport type RSErrorClass = (typeof RSErrorClass)[keyof typeof RSErrorClass];\n\n/** Represents RSLang expression error information. */\nexport interface RSErrorInfo {\n code: RSErrorCode;\n params?: readonly string[];\n}\n\n/** Represents RSLang expression error description. */\nexport interface RSErrorDescription extends RSErrorInfo {\n from: number;\n to: number;\n}\n\n/** Error reporter function type. */\nexport type ErrorReporter = (error: RSErrorDescription) => void;\n\n/** Represents RSLang expression error types. */\nexport const RSErrorCode = {\n unknownSyntax: 0x8400, // 33792\n bracketMismatch: 0x8409, // 33801\n doubleParenthesis: 0x840a, // 33802\n missingOpenBracket: 0x840b, // 33803\n missingCloseBracket: 0x840c, // 33804\n invalidFilterSyntax: 0x8417, // 33815\n expectedFunctionBody: 0x8418, // 33816\n expectedExpressionBody: 0x8419, // 33817\n expectedLogicBody: 0x841a, // 33818\n expectedLocal: 0x8415, // 33813\n expectedType: 0x8416, // 33814\n\n localDoubleDeclare: 0x2801, // 10241\n localNotUsed: 0x2802, // 10242\n\n localUndeclared: 0x8801, // 34817\n localShadowing: 0x8802, // 34818\n\n typesNotEqual: 0x8803, // 34819\n globalNotTyped: 0x8804, // 34820\n invalidDecart: 0x8805, // 34821\n invalidBoolean: 0x8806, // 34822\n invalidTypeOperation: 0x8807, // 34823\n invalidCard: 0x8808, // 34824\n invalidDebool: 0x8809, // 34825\n globalFuncWithoutArgs: 0x880b, // 34827\n invalidReduce: 0x8810, // 34832\n
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../src/rslang/error.ts"],"sourcesContent":["/** Module: Error types and functions. */\n\n/** Represents error class. */\nexport const RSErrorClass = {\n LEXER: 0,\n PARSER: 1,\n SEMANTIC: 2,\n EVALUATION: 3,\n UNKNOWN: 4\n} as const;\nexport type RSErrorClass = (typeof RSErrorClass)[keyof typeof RSErrorClass];\n\n/** Represents RSLang expression error information. */\nexport interface RSErrorInfo {\n code: RSErrorCode;\n params?: readonly string[];\n}\n\n/** Represents RSLang expression error description. */\nexport interface RSErrorDescription extends RSErrorInfo {\n from: number;\n to: number;\n}\n\n/** Error reporter function type. */\nexport type ErrorReporter = (error: RSErrorDescription) => void;\n\n/** Represents RSLang expression error types. */\nexport const RSErrorCode = {\n unknownSyntax: 0x8400, // 33792\n bracketMismatch: 0x8409, // 33801\n doubleParenthesis: 0x840a, // 33802\n missingOpenBracket: 0x840b, // 33803\n missingCloseBracket: 0x840c, // 33804\n invalidFilterSyntax: 0x8417, // 33815\n expectedFunctionBody: 0x8418, // 33816\n expectedExpressionBody: 0x8419, // 33817\n expectedLogicBody: 0x841a, // 33818\n expectedLocal: 0x8415, // 33813\n expectedType: 0x8416, // 33814\n\n localDoubleDeclare: 0x2801, // 10241\n localNotUsed: 0x2802, // 10242\n\n localUndeclared: 0x8801, // 34817\n localShadowing: 0x8802, // 34818\n\n typesNotEqual: 0x8803, // 34819\n globalNotTyped: 0x8804, // 34820\n invalidDecart: 0x8805, // 34821\n invalidBoolean: 0x8806, // 34822\n invalidTypeOperation: 0x8807, // 34823\n invalidCard: 0x8808, // 34824\n invalidDebool: 0x8809, // 34825\n globalFuncWithoutArgs: 0x880b, // 34827\n invalidReduce: 0x8810, // 34832\n invalidEnumeration: 0x8813, // 34835\n projectionSetArgumentNotSet: 0x8830, // 34864\n projectionSetArgumentNotTupleSet: 0x8831, // 34865\n projectionSetIndexOutOfRange: 0x8832, // 34866\n projectionTupleArgumentNotTuple: 0x8833, // 34867\n projectionTupleIndexOutOfRange: 0x8834, // 34868\n invalidCortegeDeclare: 0x8814, // 34836\n localOutOfScope: 0x8815, // 34837\n invalidElementPredicate: 0x8816, // 34838\n invalidEmptySetUsage: 0x8817, // 34839\n invalidArgsArity: 0x8818, // 34840\n invalidArgumentType: 0x8819, // 34841\n globalStructure: 0x881c, // 34844\n radicalUsage: 0x8821, // 34849\n invalidFilterArgumentType: 0x8822, // 34850\n invalidFilterArity: 0x8823, // 34851\n arithmeticNotSupported: 0x8824, // 34852\n typesNotCompatible: 0x8825, // 34853\n orderingNotSupported: 0x8826, // 34854\n expectedLogic: 0x8827, // 34855\n expectedSetexpr: 0x8828, // 34856\n invalidArgumentCortegeDeclare: 0x8829, // 34857\n invalidQuantifierDomain: 0x882a, // 34858\n invalidFilterParameterType: 0x882b, // 34859\n invalidFilterIndex: 0x882c, // 34860\n invalidFilterBooleanEchelon: 0x882d, // 34861\n localOutOfScopeParentheses: 0x882e, // 34862\n localUndeclaredInSubexpr: 0x882f, // 34863\n\n globalNoValue: 0x8840, // 34880\n invalidPropertyUsage: 0x8841, // 34881\n\n // Value evaluation (runtime)\n calcUnknownError: 0x8100, // 35328\n setOverflow: 0x8101, // 35329\n booleanBaseLimit: 0x8102, // 35330\n calcGlobalMissing: 0x8103, // 35331\n iterationsLimit: 0x8104, // 35332\n calcInvalidDebool: 0x8105, // 35333\n iterateInfinity: 0x8106, // 35334\n calculationNotSupported: 0x8107, // 35335\n calcInvalidData: 0x8108, // 35336\n\n cstEmptyDerived: 0x8861, // 34913\n definitionNotAllowed: 0x8862 // 34914\n} as const;\nexport type RSErrorCode = (typeof RSErrorCode)[keyof typeof RSErrorCode];\n\nconst ERROR_EVALUATION_MASK = 0x0100;\nconst ERROR_LEXER_MASK = 0x0200;\nconst ERROR_PARSER_MASK = 0x0400;\nconst ERROR_SEMANTIC_MASK = 0x0800;\n\n/** Infers error class from error type (code). */\nfunction inferErrorClass(error: RSErrorCode): RSErrorClass {\n if ((error & ERROR_EVALUATION_MASK) !== 0) {\n return RSErrorClass.EVALUATION;\n } else if ((error & ERROR_LEXER_MASK) !== 0) {\n return RSErrorClass.LEXER;\n } else if ((error & ERROR_PARSER_MASK) !== 0) {\n return RSErrorClass.PARSER;\n } else if ((error & ERROR_SEMANTIC_MASK) !== 0) {\n return RSErrorClass.SEMANTIC;\n } else {\n return RSErrorClass.UNKNOWN;\n }\n}\n\n/** Generate ErrorID label. */\nexport function getRSErrorPrefix(code: RSErrorCode): string {\n const id = code.toString(16).toUpperCase();\n // prettier-ignore\n switch (inferErrorClass(code)) {\n case RSErrorClass.LEXER: return 'L' + id;\n case RSErrorClass.PARSER: return 'P' + id;\n case RSErrorClass.SEMANTIC: return 'S' + id;\n case RSErrorClass.EVALUATION: return 'E' + id;\n case RSErrorClass.UNKNOWN: return 'U' + id;\n }\n}\n\n/** Checks if error is critical. */\nexport function isCritical(code: RSErrorCode): boolean {\n return code !== RSErrorCode.localDoubleDeclare && code !== RSErrorCode.localNotUsed;\n}\n"],"mappings":";;;AAGA,MAAa,eAAe;CAC1B,OAAO;CACP,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;AACX;;AAmBA,MAAa,cAAc;CACzB,eAAe;CACf,iBAAiB;CACjB,mBAAmB;CACnB,oBAAoB;CACpB,qBAAqB;CACrB,qBAAqB;CACrB,sBAAsB;CACtB,wBAAwB;CACxB,mBAAmB;CACnB,eAAe;CACf,cAAc;CAEd,oBAAoB;CACpB,cAAc;CAEd,iBAAiB;CACjB,gBAAgB;CAEhB,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,aAAa;CACb,eAAe;CACf,uBAAuB;CACvB,eAAe;CACf,oBAAoB;CACpB,6BAA6B;CAC7B,kCAAkC;CAClC,8BAA8B;CAC9B,iCAAiC;CACjC,gCAAgC;CAChC,uBAAuB;CACvB,iBAAiB;CACjB,yBAAyB;CACzB,sBAAsB;CACtB,kBAAkB;CAClB,qBAAqB;CACrB,iBAAiB;CACjB,cAAc;CACd,2BAA2B;CAC3B,oBAAoB;CACpB,wBAAwB;CACxB,oBAAoB;CACpB,sBAAsB;CACtB,eAAe;CACf,iBAAiB;CACjB,+BAA+B;CAC/B,yBAAyB;CACzB,4BAA4B;CAC5B,oBAAoB;CACpB,6BAA6B;CAC7B,4BAA4B;CAC5B,0BAA0B;CAE1B,eAAe;CACf,sBAAsB;CAGtB,kBAAkB;CAClB,aAAa;CACb,kBAAkB;CAClB,mBAAmB;CACnB,iBAAiB;CACjB,mBAAmB;CACnB,iBAAiB;CACjB,yBAAyB;CACzB,iBAAiB;CAEjB,iBAAiB;CACjB,sBAAsB;AACxB;AAGA,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB;;AAG5B,SAAS,gBAAgB,OAAkC;CACzD,KAAK,QAAQ,2BAA2B,GACtC,OAAO,aAAa;MACf,KAAK,QAAQ,sBAAsB,GACxC,OAAO,aAAa;MACf,KAAK,QAAQ,uBAAuB,GACzC,OAAO,aAAa;MACf,KAAK,QAAQ,yBAAyB,GAC3C,OAAO,aAAa;MAEpB,OAAO,aAAa;AAExB;;AAGA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,KAAK,KAAK,SAAS,EAAE,CAAC,CAAC,YAAY;CAEzC,QAAQ,gBAAgB,IAAI,GAA5B;EACE,KAAK,aAAa,OAAO,OAAO,MAAM;EACtC,KAAK,aAAa,QAAQ,OAAO,MAAM;EACvC,KAAK,aAAa,UAAU,OAAO,MAAM;EACzC,KAAK,aAAa,YAAY,OAAO,MAAM;EAC3C,KAAK,aAAa,SAAS,OAAO,MAAM;CAC1C;AACF;;AAGA,SAAgB,WAAW,MAA4B;CACrD,OAAO,SAAS,YAAY,sBAAsB,SAAS,YAAY;AACzE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-
|
|
1
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../../calculator-Cyy9eYyx.js";
|
|
2
2
|
export { CalculatorEvaluateOptions, CalculatorResult, RSCalculator };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
|
-
import { t as ErrorReporter } from "../../error-
|
|
2
|
+
import { t as ErrorReporter } from "../../error-Cv4sntcy.js";
|
|
3
3
|
import { l as Value, u as ValueContext } from "../../value-BduA_ZGp.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/eval/evaluator.d.ts
|
package/dist/rslang/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { O as makeTypePath, b as Typification, d as EmptySetT, f as ExpressionType, g as TypeClass, m as LogicT, t as AnyTypificationT, v as TypeID, y as TypePath } from "../typification-Dk-fisgO.js";
|
|
2
|
-
import { i as RSErrorDescription, r as RSErrorCode } from "../error-
|
|
3
|
-
import { i as readTypeAnnotation, r as readErrorAnnotation } from "../ast-annotations-
|
|
2
|
+
import { i as RSErrorDescription, r as RSErrorCode } from "../error-Cv4sntcy.js";
|
|
3
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "../ast-annotations-YzvwjoFW.js";
|
|
4
4
|
import { d as ValuePath, l as Value, p as makeValuePath } from "../value-BduA_ZGp.js";
|
|
5
|
-
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-
|
|
5
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-Cyy9eYyx.js";
|
|
6
6
|
import { d as printValue } from "../value-api-B6T6f4Ia.js";
|
|
7
7
|
import { t as parser } from "../parser-Bwd8LxJ1.js";
|
|
8
8
|
import { t as TokenID } from "../token-DeXAmzwr.js";
|
|
9
9
|
import { t as ValueClass } from "../value-class-CNI-lqXJ.js";
|
|
10
|
-
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../analyzer-
|
|
10
|
+
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../analyzer-A82AxKdS.js";
|
|
11
11
|
import { n as ArgumentsType } from "../arguments-extractor-1acwjQNc.js";
|
|
12
12
|
import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "../typification-parser-BBVx1RxP.js";
|
|
13
13
|
import { n as TypificationNodeData, t as TypificationGraph } from "../typification-graph-6HcZ-rKH.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
2
|
import { g as TypeClass } from "../../typification-Dk-fisgO.js";
|
|
3
|
-
import { t as ErrorReporter } from "../../error-
|
|
3
|
+
import { t as ErrorReporter } from "../../error-Cv4sntcy.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/parser/syntax-errors.d.ts
|
|
6
6
|
/** Options for syntax error extraction. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RSLangAnalyzer, i as AnalysisOptions, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../../analyzer-
|
|
1
|
+
import { a as RSLangAnalyzer, i as AnalysisOptions, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "../../analyzer-A82AxKdS.js";
|
|
2
2
|
export { AnalysisBase, AnalysisFast, AnalysisFull, AnalysisOptions, RSLangAnalyzer };
|
|
@@ -4,6 +4,7 @@ import { buildTree } from "../../parsing/ast.js";
|
|
|
4
4
|
import "../../parsing/index.js";
|
|
5
5
|
import { TokenID } from "../parser/token.js";
|
|
6
6
|
import { TypeID, basic, bool, constant, debool } from "./typification.js";
|
|
7
|
+
import { labelType } from "../labels.js";
|
|
7
8
|
import { parser } from "../parser/parser.js";
|
|
8
9
|
import { normalizeAST } from "../parser/normalize.js";
|
|
9
10
|
import { extractSyntaxErrors } from "../parser/syntax-errors.js";
|
|
@@ -144,12 +145,14 @@ var RSLangAnalyzer = class {
|
|
|
144
145
|
};
|
|
145
146
|
}
|
|
146
147
|
if (options?.expected && getTypeClass(type.typeID) !== options.expected) {
|
|
148
|
+
const errorParams = [String(options.expected), labelType(type)];
|
|
147
149
|
reporter({
|
|
148
150
|
code: RSErrorCode.expectedType,
|
|
149
151
|
from: ast.from,
|
|
150
|
-
to: ast.to
|
|
152
|
+
to: ast.to,
|
|
153
|
+
params: errorParams
|
|
151
154
|
});
|
|
152
|
-
if (options?.annotateErrors) annotateError(ast, RSErrorCode.expectedType);
|
|
155
|
+
if (options?.annotateErrors) annotateError(ast, RSErrorCode.expectedType, errorParams);
|
|
153
156
|
return {
|
|
154
157
|
success: false,
|
|
155
158
|
type: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","names":["rslangParser"],"sources":["../../../src/rslang/semantic/analyzer.ts"],"sourcesContent":["import { type AstNode, buildTree } from '../../parsing';\nimport { annotateError } from '../ast-annotations';\nimport { RSErrorCode, type RSErrorDescription } from '../error';\nimport { normalizeAST } from '../parser/normalize';\nimport { parser as rslangParser } from '../parser/parser';\nimport { extractSyntaxErrors } from '../parser/syntax-errors';\nimport { TokenID } from '../parser/token';\n\nimport { TypeAuditor } from './type-auditor';\nimport {\n basic,\n bool,\n constant,\n debool,\n type ExpressionType,\n type TypeClass,\n type TypeContext,\n TypeID\n} from './typification';\nimport { getTypeClass } from './typification-api';\nimport { ValueAuditor } from './value-auditor';\nimport { ValueClass, type ValueClassContext } from './value-class';\n\nexport interface AnalysisBase {\n success: boolean;\n type: ExpressionType | null;\n valueClass: ValueClass | null;\n}\n\nexport interface AnalysisFast extends AnalysisBase {\n ast: AstNode | null;\n}\n\nexport interface AnalysisFull extends AnalysisBase {\n ast: AstNode | null;\n errors: RSErrorDescription[];\n}\n\nexport interface AnalysisOptions {\n expected?: TypeClass;\n isDomain?: boolean;\n annotateTypes?: boolean;\n annotateErrors?: boolean;\n}\n\nexport class RSLangAnalyzer {\n private typeContext: TypeContext = new Map<string, ExpressionType>();\n private valueContext: ValueClassContext = new Map<string, ValueClass>();\n private typeAuditor: TypeAuditor = new TypeAuditor(this.typeContext);\n private valueAuditor: ValueAuditor = new ValueAuditor(this.valueContext);\n\n public addBase(alias: string, isNumeric: boolean = false, valueClass: ValueClass = ValueClass.VALUE): void {\n if (isNumeric) {\n this.typeContext.set(alias, bool(constant(alias)));\n this.valueContext.set(alias, valueClass);\n } else {\n this.typeContext.set(alias, bool(basic(alias)));\n this.valueContext.set(alias, valueClass);\n }\n }\n\n public setGlobal(alias: string, type: ExpressionType | null, value: ValueClass | null): void {\n if (type) {\n this.typeContext.set(alias, type);\n }\n if (value) {\n this.valueContext.set(alias, value);\n }\n }\n\n public getType(alias: string): ExpressionType | null {\n return this.typeContext.get(alias) ?? null;\n }\n\n public checkFast(expression: string, options?: AnalysisOptions): AnalysisFast {\n if (expression.length === 0) {\n return { success: false, type: null, valueClass: null, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, ast: ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n return {\n success: true,\n type: type,\n valueClass: options?.isDomain ? ValueClass.VALUE : this.valueAuditor.run(ast),\n ast: ast\n };\n }\n\n public checkFull(expression: string, options?: AnalysisOptions): AnalysisFull {\n const errors: RSErrorDescription[] = [];\n const reporter = (error: RSErrorDescription) => {\n errors.push(error);\n };\n if (expression.length === 0) {\n reporter({ code: RSErrorCode.cstEmptyDerived, from: 0, to: 0 });\n return { success: false, type: null, valueClass: null, errors: errors, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false, {\n expected: options?.expected\n });\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false, reporter, options?.annotateErrors ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n reporter({ code: RSErrorCode.globalStructure, from: ast.from, to: ast.to });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.globalStructure);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, errors, ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n reporter({\n code: RSErrorCode.expectedType,\n from: ast.from,\n to: ast.to\n });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.expectedType);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n const valueClass = options?.isDomain\n ? ValueClass.VALUE\n : this.valueAuditor.run(ast, reporter, options?.annotateErrors ?? false);\n return { success: true, type, valueClass, errors, ast };\n }\n\n private parse(expression: string): AstNode {\n const tree = rslangParser.parse(expression);\n const ast = buildTree(tree.cursor());\n normalizeAST(ast, expression);\n return ast;\n }\n}\n\n// ======= Internals ========\nfunction isStructureDomain(node: AstNode): boolean {\n switch (node.typeID) {\n case TokenID.LIT_WHOLE_NUMBERS:\n case TokenID.ID_GLOBAL:\n case TokenID.BOOLEAN:\n case TokenID.DECART:\n case TokenID.NT_ENUMERATION:\n break;\n default:\n return false;\n }\n for (const child of node.children) {\n if (!isStructureDomain(child)) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"analyzer.js","names":["rslangParser"],"sources":["../../../src/rslang/semantic/analyzer.ts"],"sourcesContent":["import { type AstNode, buildTree } from '../../parsing';\nimport { annotateError } from '../ast-annotations';\nimport { RSErrorCode, type RSErrorDescription } from '../error';\nimport { labelType } from '../labels';\nimport { normalizeAST } from '../parser/normalize';\nimport { parser as rslangParser } from '../parser/parser';\nimport { extractSyntaxErrors } from '../parser/syntax-errors';\nimport { TokenID } from '../parser/token';\n\nimport { TypeAuditor } from './type-auditor';\nimport {\n basic,\n bool,\n constant,\n debool,\n type ExpressionType,\n type TypeClass,\n type TypeContext,\n TypeID\n} from './typification';\nimport { getTypeClass } from './typification-api';\nimport { ValueAuditor } from './value-auditor';\nimport { ValueClass, type ValueClassContext } from './value-class';\n\nexport interface AnalysisBase {\n success: boolean;\n type: ExpressionType | null;\n valueClass: ValueClass | null;\n}\n\nexport interface AnalysisFast extends AnalysisBase {\n ast: AstNode | null;\n}\n\nexport interface AnalysisFull extends AnalysisBase {\n ast: AstNode | null;\n errors: RSErrorDescription[];\n}\n\nexport interface AnalysisOptions {\n expected?: TypeClass;\n isDomain?: boolean;\n annotateTypes?: boolean;\n annotateErrors?: boolean;\n}\n\nexport class RSLangAnalyzer {\n private typeContext: TypeContext = new Map<string, ExpressionType>();\n private valueContext: ValueClassContext = new Map<string, ValueClass>();\n private typeAuditor: TypeAuditor = new TypeAuditor(this.typeContext);\n private valueAuditor: ValueAuditor = new ValueAuditor(this.valueContext);\n\n public addBase(alias: string, isNumeric: boolean = false, valueClass: ValueClass = ValueClass.VALUE): void {\n if (isNumeric) {\n this.typeContext.set(alias, bool(constant(alias)));\n this.valueContext.set(alias, valueClass);\n } else {\n this.typeContext.set(alias, bool(basic(alias)));\n this.valueContext.set(alias, valueClass);\n }\n }\n\n public setGlobal(alias: string, type: ExpressionType | null, value: ValueClass | null): void {\n if (type) {\n this.typeContext.set(alias, type);\n }\n if (value) {\n this.valueContext.set(alias, value);\n }\n }\n\n public getType(alias: string): ExpressionType | null {\n return this.typeContext.get(alias) ?? null;\n }\n\n public checkFast(expression: string, options?: AnalysisOptions): AnalysisFast {\n if (expression.length === 0) {\n return { success: false, type: null, valueClass: null, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, ast: ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n return { success: false, type: null, valueClass: null, ast: ast };\n }\n\n return {\n success: true,\n type: type,\n valueClass: options?.isDomain ? ValueClass.VALUE : this.valueAuditor.run(ast),\n ast: ast\n };\n }\n\n public checkFull(expression: string, options?: AnalysisOptions): AnalysisFull {\n const errors: RSErrorDescription[] = [];\n const reporter = (error: RSErrorDescription) => {\n errors.push(error);\n };\n if (expression.length === 0) {\n reporter({ code: RSErrorCode.cstEmptyDerived, from: 0, to: 0 });\n return { success: false, type: null, valueClass: null, errors: errors, ast: null };\n }\n const ast = this.parse(expression);\n if (ast.hasError) {\n extractSyntaxErrors(ast, expression, reporter, options?.annotateErrors ?? false, {\n expected: options?.expected\n });\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n const type = this.typeAuditor.run(ast, options?.annotateTypes ?? false, reporter, options?.annotateErrors ?? false);\n if (type === null) {\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n\n if (options?.isDomain) {\n if (!isStructureDomain(ast) || type.typeID !== TypeID.collection) {\n reporter({ code: RSErrorCode.globalStructure, from: ast.from, to: ast.to });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.globalStructure);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n return { success: true, type: debool(type), valueClass: ValueClass.VALUE, errors, ast };\n }\n if (options?.expected && getTypeClass(type.typeID) !== options.expected) {\n const errorParams = [String(options.expected), labelType(type)];\n reporter({\n code: RSErrorCode.expectedType,\n from: ast.from,\n to: ast.to,\n params: errorParams\n });\n if (options?.annotateErrors) {\n annotateError(ast, RSErrorCode.expectedType, errorParams);\n }\n return { success: false, type: null, valueClass: null, errors, ast };\n }\n const valueClass = options?.isDomain\n ? ValueClass.VALUE\n : this.valueAuditor.run(ast, reporter, options?.annotateErrors ?? false);\n return { success: true, type, valueClass, errors, ast };\n }\n\n private parse(expression: string): AstNode {\n const tree = rslangParser.parse(expression);\n const ast = buildTree(tree.cursor());\n normalizeAST(ast, expression);\n return ast;\n }\n}\n\n// ======= Internals ========\nfunction isStructureDomain(node: AstNode): boolean {\n switch (node.typeID) {\n case TokenID.LIT_WHOLE_NUMBERS:\n case TokenID.ID_GLOBAL:\n case TokenID.BOOLEAN:\n case TokenID.DECART:\n case TokenID.NT_ENUMERATION:\n break;\n default:\n return false;\n }\n for (const child of node.children) {\n if (!isStructureDomain(child)) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8CA,IAAa,iBAAb,MAA4B;CAC1B,8BAAmC,IAAI,IAA4B;CACnE,+BAA0C,IAAI,IAAwB;CACtE,cAAmC,IAAI,YAAY,KAAK,WAAW;CACnE,eAAqC,IAAI,aAAa,KAAK,YAAY;CAEvE,QAAe,OAAe,YAAqB,OAAO,aAAyB,WAAW,OAAa;EACzG,IAAI,WAAW;GACb,KAAK,YAAY,IAAI,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC;GACjD,KAAK,aAAa,IAAI,OAAO,UAAU;EACzC,OAAO;GACL,KAAK,YAAY,IAAI,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC;GAC9C,KAAK,aAAa,IAAI,OAAO,UAAU;EACzC;CACF;CAEA,UAAiB,OAAe,MAA6B,OAAgC;EAC3F,IAAI,MACF,KAAK,YAAY,IAAI,OAAO,IAAI;EAElC,IAAI,OACF,KAAK,aAAa,IAAI,OAAO,KAAK;CAEtC;CAEA,QAAe,OAAsC;EACnD,OAAO,KAAK,YAAY,IAAI,KAAK,KAAK;CACxC;CAEA,UAAiB,YAAoB,SAAyC;EAC5E,IAAI,WAAW,WAAW,GACxB,OAAO;GAAE,SAAS;GAAO,MAAM;GAAM,YAAY;GAAM,KAAK;EAAK;EAEnE,MAAM,MAAM,KAAK,MAAM,UAAU;EACjC,IAAI,IAAI,UACN,OAAO;GAAE,SAAS;GAAO,MAAM;GAAM,YAAY;GAAW;EAAI;EAElE,MAAM,OAAO,KAAK,YAAY,IAAI,KAAK,SAAS,iBAAiB,KAAK;EACtE,IAAI,SAAS,MACX,OAAO;GAAE,SAAS;GAAO,MAAM;GAAM,YAAY;GAAW;EAAI;EAGlE,IAAI,SAAS,UAAU;GACrB,IAA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../typification-Dk-fisgO.js";
|
|
3
|
-
import { t as ErrorReporter } from "../../error-
|
|
3
|
+
import { t as ErrorReporter } from "../../error-Cv4sntcy.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/semantic/type-auditor.d.ts
|
|
6
6
|
/** Type auditor for AST type checking. */
|
|
@@ -411,30 +411,46 @@ var TypeAuditor = class TypeAuditor {
|
|
|
411
411
|
return bool(result);
|
|
412
412
|
}
|
|
413
413
|
visitProjectSet(node) {
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (
|
|
414
|
+
const operator = labelRSLangNode(node);
|
|
415
|
+
const argNode = node.children[0];
|
|
416
|
+
const argType = this.childTypification(node, 0);
|
|
417
|
+
if (argType === null) return null;
|
|
418
|
+
if (argType.typeID === TypeID.anyTypification) return EmptySetT;
|
|
419
|
+
if (argType.typeID !== TypeID.collection) return this.onError(RSErrorCode.projectionSetArgumentNotSet, argNode, [operator, labelType(argType)]);
|
|
420
|
+
const argument = debool(argType);
|
|
421
|
+
if (argument.typeID !== TypeID.tuple) return this.onError(RSErrorCode.projectionSetArgumentNotTupleSet, argNode, [operator, labelType(bool(argument))]);
|
|
418
422
|
const indices = getNodeIndices(node);
|
|
419
423
|
const components = [];
|
|
420
424
|
for (const index of indices) {
|
|
421
425
|
const newComponent = component(argument, index);
|
|
422
|
-
if (newComponent === null) return this.onError(RSErrorCode.
|
|
426
|
+
if (newComponent === null) return this.onError(RSErrorCode.projectionSetIndexOutOfRange, argNode, [
|
|
427
|
+
operator,
|
|
428
|
+
String(index),
|
|
429
|
+
String(argument.factors.length),
|
|
430
|
+
labelType(bool(argument))
|
|
431
|
+
]);
|
|
423
432
|
else components.push(newComponent);
|
|
424
433
|
}
|
|
425
434
|
if (components.length === 1) return bool(components[0]);
|
|
426
435
|
else return bool(tuple(components));
|
|
427
436
|
}
|
|
428
437
|
visitProjectTuple(node) {
|
|
438
|
+
const operator = labelRSLangNode(node);
|
|
439
|
+
const argNode = node.children[0];
|
|
429
440
|
const argument = this.childTypification(node, 0);
|
|
430
441
|
if (argument === null) return null;
|
|
431
442
|
if (argument.typeID === TypeID.anyTypification) return argument;
|
|
432
|
-
if (argument.typeID !== TypeID.tuple) return this.onError(RSErrorCode.
|
|
443
|
+
if (argument.typeID !== TypeID.tuple) return this.onError(RSErrorCode.projectionTupleArgumentNotTuple, argNode, [operator, labelType(argument)]);
|
|
433
444
|
const indices = getNodeIndices(node);
|
|
434
445
|
const components = [];
|
|
435
446
|
for (const index of indices) {
|
|
436
447
|
const newComponent = component(argument, index);
|
|
437
|
-
if (newComponent === null) return this.onError(RSErrorCode.
|
|
448
|
+
if (newComponent === null) return this.onError(RSErrorCode.projectionTupleIndexOutOfRange, argNode, [
|
|
449
|
+
operator,
|
|
450
|
+
String(index),
|
|
451
|
+
String(argument.factors.length),
|
|
452
|
+
labelType(argument)
|
|
453
|
+
]);
|
|
438
454
|
else components.push(newComponent);
|
|
439
455
|
}
|
|
440
456
|
if (components.length === 1) return components[0];
|
|
@@ -629,9 +645,14 @@ function isLogicBinaryNode(typeID) {
|
|
|
629
645
|
function isQuantifierNode(typeID) {
|
|
630
646
|
return typeID === TokenID.QUANTOR_UNIVERSAL || typeID === TokenID.QUANTOR_EXISTS;
|
|
631
647
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
648
|
+
/** Quantifier on the path from `node` up through `stopAt` (inclusive). */
|
|
649
|
+
function pathContainsQuantifier(node, stopAt) {
|
|
650
|
+
let current = node;
|
|
651
|
+
while (current !== null) {
|
|
652
|
+
if (isQuantifierNode(current.typeID)) return true;
|
|
653
|
+
if (current === stopAt) return false;
|
|
654
|
+
current = current.parent;
|
|
655
|
+
}
|
|
635
656
|
return false;
|
|
636
657
|
}
|
|
637
658
|
/** Right operand subtree of the innermost logic binary containing `node`. */
|
|
@@ -693,7 +714,7 @@ var LocalContext = class {
|
|
|
693
714
|
} else if (local.level < 1) {
|
|
694
715
|
const subexprRoot = findRightLogicOperandRoot(node);
|
|
695
716
|
if (subexprRoot !== null) {
|
|
696
|
-
if (
|
|
717
|
+
if (pathContainsQuantifier(node, subexprRoot)) return this.onError(RSErrorCode.localUndeclaredInSubexpr, node, [alias, labelType(local.type)]);
|
|
697
718
|
return this.onError(RSErrorCode.localOutOfScopeParentheses, node, [alias]);
|
|
698
719
|
}
|
|
699
720
|
this.onError(RSErrorCode.localOutOfScope, node, [alias]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-auditor.js","names":[],"sources":["../../../src/rslang/semantic/type-auditor.ts"],"sourcesContent":["/**\n * Module: Type auditor for AST type checking.\n */\n\nimport { type AstNode, getNodeIndices, getNodeText } from '../../parsing';\nimport { annotateError, annotateType } from '../ast-annotations';\nimport { type ErrorReporter, RSErrorCode } from '../error';\nimport { labelRSLangNode, labelToken, labelType } from '../labels';\nimport { TokenID } from '../parser/token';\n\nimport {\n type Argument,\n bool,\n component,\n debool,\n type EchelonTuple,\n EmptySetT,\n type ExpressionType,\n IntegerT,\n isRadical,\n isTypification,\n LogicT,\n type Parametrized,\n tuple,\n type TypeContext,\n TypeID,\n type Typification\n} from './typification';\nimport {\n checkCompatibility,\n checkEquality,\n compareTemplated,\n hasGenerics,\n mergeTypifications,\n substituteBase\n} from './typification-api';\n\n/** Type auditor for AST type checking. */\nexport class TypeAuditor {\n private static readonly TYPE_DEDUCTION_DEPTH = 5;\n\n private context: TypeContext;\n private reporter?: ErrorReporter;\n private locals: LocalContext;\n private annotateTypes: boolean;\n private annotateErrors: boolean;\n\n constructor(context: TypeContext) {\n this.annotateTypes = false;\n this.annotateErrors = false;\n this.context = context;\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n public run(\n ast: AstNode,\n annotateTypes: boolean,\n reporter?: ErrorReporter,\n annotateErrors: boolean = false\n ): ExpressionType | null {\n if (ast.hasError) {\n return null;\n }\n this.annotateTypes = annotateTypes;\n this.annotateErrors = annotateErrors;\n this.reporter = reporter;\n this.clear();\n return this.dispatchVisit(ast);\n }\n\n private clear(): void {\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n private dispatchDeclare(node: AstNode, domain: Typification): boolean {\n const result = this.processDeclare(node, domain);\n if (result === true && this.annotateTypes) {\n annotateType(node, domain);\n }\n return result;\n }\n\n private processDeclare(node: AstNode, domain: Typification): boolean {\n switch (node.typeID) {\n case TokenID.ID_LOCAL:\n return this.declareLocal(node, domain);\n case TokenID.NT_TUPLE_DECL:\n return this.declareTuple(node, domain);\n case TokenID.NT_ENUM_DECL:\n return this.declareEnumeration(node, domain);\n }\n return false;\n }\n\n private declareLocal(node: AstNode, domain: Typification): boolean {\n return this.locals.pushLocal(node, domain);\n }\n\n private declareTuple(node: AstNode, domain: Typification): boolean {\n if (domain.typeID !== TypeID.tuple || domain.factors.length !== node.children.length) {\n this.onError(RSErrorCode.invalidCortegeDeclare, node.children[0]);\n return false;\n }\n for (let child = 0; child < node.children.length; child++) {\n if (!this.visitChildDeclaration(node, child, component(domain, child + 1)!)) {\n return false;\n }\n }\n return true;\n }\n\n private declareEnumeration(node: AstNode, domain: Typification): boolean {\n for (const child of node.children) {\n if (!this.dispatchDeclare(child, domain)) {\n return false;\n }\n }\n return true;\n }\n\n private dispatchVisit(node: AstNode): ExpressionType | null {\n const result = this.processVisit(node);\n if (result !== null && this.annotateTypes) {\n annotateType(node, result);\n }\n return result;\n }\n\n private processVisit(node: AstNode): ExpressionType | null {\n switch (node.typeID) {\n case TokenID.ID_GLOBAL:\n case TokenID.ID_FUNCTION:\n case TokenID.ID_PREDICATE:\n return this.visitGlobal(node);\n\n case TokenID.ID_LOCAL:\n return this.visitLocal(node);\n case TokenID.ID_RADICAL:\n return this.visitRadical(node);\n\n case TokenID.LIT_INTEGER:\n return IntegerT;\n case TokenID.LIT_WHOLE_NUMBERS:\n return bool(IntegerT);\n case TokenID.LIT_EMPTYSET:\n return this.visitEmptySet(node);\n\n case TokenID.NT_ARGUMENTS:\n return this.visitArgumentsEnum(node);\n case TokenID.NT_ARG_DECL:\n return this.visitArgument(node);\n\n case TokenID.PLUS:\n case TokenID.MINUS:\n case TokenID.MULTIPLY:\n return this.visitArithmetic(node);\n\n case TokenID.QUANTOR_UNIVERSAL:\n case TokenID.QUANTOR_EXISTS:\n return this.visitQuantifier(node);\n\n case TokenID.LOGIC_NOT:\n return this.visitNegation(node);\n\n case TokenID.LOGIC_AND:\n case TokenID.LOGIC_OR:\n case TokenID.LOGIC_IMPLICATION:\n case TokenID.LOGIC_EQUIVALENT:\n return this.visitLogicBinary(node);\n\n case TokenID.EQUAL:\n case TokenID.NOTEQUAL:\n return this.visitEquals(node);\n\n case TokenID.GREATER:\n case TokenID.LESSER:\n case TokenID.GREATER_OR_EQ:\n case TokenID.LESSER_OR_EQ:\n return this.visitIntegerPredicate(node);\n\n case TokenID.SET_IN:\n case TokenID.SET_NOT_IN:\n case TokenID.SUBSET:\n case TokenID.SUBSET_OR_EQ:\n case TokenID.NOT_SUBSET:\n return this.visitSetexprPredicate(node);\n\n case TokenID.DECART:\n return this.visitDecart(node);\n case TokenID.BOOLEAN:\n return this.visitBoolean(node);\n\n case TokenID.NT_TUPLE:\n return this.visitTuple(node);\n case TokenID.NT_ENUMERATION:\n return this.visitEnumeration(node);\n\n case TokenID.BIGPR:\n return this.visitProjectSet(node);\n case TokenID.SMALLPR:\n return this.visitProjectTuple(node);\n case TokenID.FILTER:\n return this.visitFilter(node);\n\n case TokenID.CARD:\n return this.visitCard(node);\n case TokenID.REDUCE:\n return this.visitReduce(node);\n case TokenID.BOOL:\n return this.visitBool(node);\n case TokenID.DEBOOL:\n return this.visitDebool(node);\n\n case TokenID.SET_UNION:\n case TokenID.SET_INTERSECTION:\n case TokenID.SET_MINUS:\n case TokenID.SET_SYMMETRIC_MINUS:\n return this.visitSetexprBinary(node);\n\n case TokenID.NT_FUNC_DEFINITION:\n return this.visitFunctionDefinition(node);\n\n case TokenID.NT_FUNC_CALL:\n return this.visitFunctionCall(node);\n\n case TokenID.ITERATE:\n return this.visitIterate(node);\n case TokenID.ASSIGN:\n return this.visitAssign(node);\n\n case TokenID.NT_DECLARATIVE_EXPR:\n return this.visitDeclarative(node);\n case TokenID.NT_IMPERATIVE_EXPR:\n return this.visitImperative(node);\n\n case TokenID.NT_RECURSIVE_FULL:\n case TokenID.NT_RECURSIVE_SHORT:\n return this.visitRecursion(node);\n }\n return null;\n }\n\n private onError(code: RSErrorCode, node: AstNode, params?: string[]): null {\n this.reporter?.({ code, from: node.from, to: node.to, params });\n if (this.annotateErrors) {\n annotateError(node, code, params);\n }\n return null;\n }\n\n private visitChild(node: AstNode, index: number): ExpressionType | null {\n if (index >= node.children.length) {\n return null;\n }\n return this.dispatchVisit(node.children[index]);\n }\n\n private visitChildDeclaration(node: AstNode, index: number, domain: Typification): boolean {\n if (index >= node.children.length) {\n return false;\n }\n if (!this.dispatchDeclare(node.children[index], domain)) {\n return false;\n }\n return true;\n }\n\n private visitAllAndReturn(node: AstNode, type: ExpressionType | null): ExpressionType | null {\n for (const child of node.children) {\n if (!this.dispatchVisit(child)) {\n return null;\n }\n }\n return type;\n }\n\n private childTypification(node: AstNode, index: number): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.expectedSetexpr, node.children[index], [labelType(result)]);\n return null;\n }\n return result as Typification;\n }\n\n private childLogic(node: AstNode, index: number): boolean {\n const result = this.visitChild(node, index);\n if (result === null) {\n return false;\n }\n if (result.typeID !== TypeID.logic) {\n this.onError(RSErrorCode.expectedLogic, node.children[index], [labelType(result)]);\n return false;\n }\n return true;\n }\n\n private childTypeDebool(\n node: AstNode,\n index: number,\n errorCode: RSErrorCode,\n operation?: string\n ): Typification | null {\n const result = this.childTypification(node, index);\n if (result === null) {\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n const params =\n errorCode === RSErrorCode.invalidTypeOperation && operation !== undefined\n ? [operation, labelType(result)]\n : [labelType(result)];\n this.onError(errorCode, node.children[index], params);\n return null;\n }\n return debool(result);\n }\n\n private childQuantifierDomain(node: AstNode, index: number, operator: string): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n return debool(result);\n }\n\n private visitLocal(node: AstNode): ExpressionType | null {\n return this.locals.getLocalType(node);\n }\n\n private visitGlobal(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n const type = this.context.get(alias);\n if (!type) {\n return this.onError(RSErrorCode.globalNotTyped, node, [alias]);\n }\n if (type.typeID === TypeID.function || type.typeID === TypeID.predicate) {\n return this.onError(RSErrorCode.globalFuncWithoutArgs, node, [alias]);\n }\n return type;\n }\n\n private visitFunctionDefinition(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n if (!this.visitChild(node, 0)) {\n return null;\n }\n\n const args: Argument[] = [];\n for (const local of this.locals.data) {\n if (local.level === 1) {\n args.push({ alias: local.alias, type: local.type });\n }\n }\n\n const result = this.visitChild(node, 1);\n if (result === null || result.typeID === TypeID.function || result.typeID === TypeID.predicate) {\n return null;\n }\n this.locals.endScope(node.children[1]);\n if (result.typeID === TypeID.logic) {\n return {\n typeID: TypeID.predicate,\n result: result,\n args: args\n };\n } else {\n return {\n typeID: TypeID.function,\n result: result,\n args: args\n };\n }\n }\n\n private visitFunctionCall(node: AstNode): ExpressionType | null {\n const funcName = getNodeText(node.children[0]);\n const funcType = this.context.get(funcName);\n if (funcType?.typeID !== TypeID.function && funcType?.typeID !== TypeID.predicate) {\n return this.onError(RSErrorCode.globalNotTyped, node.children[0], [funcName]);\n }\n if (this.annotateTypes) {\n annotateType(node.children[0], funcType);\n }\n\n const substitutes = this.checkFuncArguments(node, funcName, funcType);\n if (substitutes === null) {\n return null;\n }\n if (funcType.result.typeID === TypeID.logic) {\n return funcType.result;\n } else {\n const result = mangleRadicals(funcName, funcType.result);\n if (substitutes.size > 0) {\n substituteBase(result, substitutes);\n }\n return result;\n }\n }\n\n private visitRadical(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n if (!this.isInsideFuncArgument(node)) {\n return this.onError(RSErrorCode.radicalUsage, node, [alias]);\n }\n return bool({ typeID: TypeID.basic, baseID: alias });\n }\n\n private visitEmptySet(node: AstNode): ExpressionType | null {\n const invalidParents: TokenID[] = [\n TokenID.CARD,\n TokenID.DEBOOL,\n TokenID.SET_UNION,\n TokenID.SET_INTERSECTION,\n TokenID.SET_MINUS,\n TokenID.SET_SYMMETRIC_MINUS,\n TokenID.REDUCE,\n TokenID.BIGPR,\n TokenID.SMALLPR\n ];\n if (invalidParents.includes(node.parent?.typeID as TokenID)) {\n return this.onError(RSErrorCode.invalidEmptySetUsage, node);\n }\n return EmptySetT;\n }\n\n private visitArgument(node: AstNode): ExpressionType | null {\n const variable = node.children[0];\n if (variable.typeID === TokenID.NT_TUPLE_DECL) {\n return this.onError(RSErrorCode.invalidArgumentCortegeDeclare, variable);\n }\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return domain;\n }\n\n private visitCard(node: AstNode): ExpressionType | null {\n if (!this.childTypeDebool(node, 0, RSErrorCode.invalidCard)) {\n return null;\n }\n return IntegerT;\n }\n\n private visitArithmetic(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isArithmetic' in type1 && type1.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isArithmetic' in type2 && type2.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return result;\n }\n\n private visitIntegerPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isOrdered' in type1 && type1.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isOrdered' in type2 && type2.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitQuantifier(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const operator = labelRSLangNode(node);\n const domain = this.childQuantifierDomain(node, 1, operator);\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return LogicT;\n }\n\n private visitNegation(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0)) {\n return null;\n }\n return LogicT;\n }\n\n private visitLogicBinary(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0) || !this.childLogic(node, 1)) {\n return null;\n }\n return LogicT;\n }\n\n private visitEquals(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitSetexprPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n let type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n const isSubset = this.isSubset(node.typeID as TokenID);\n if (isSubset) {\n type2 = bool(type2);\n }\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n if (!checkCompatibility(type1, type2)) {\n if (isSubset) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(type1), labelType(type2), operator]);\n } else {\n return this.onError(RSErrorCode.invalidElementPredicate, node, [\n labelType(type1),\n operator,\n labelType(bool(type2))\n ]);\n }\n }\n return LogicT;\n }\n\n private visitDecart(node: AstNode): ExpressionType | null {\n const factors: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypeDebool(node, child, RSErrorCode.invalidDecart);\n if (type === null) {\n return null;\n } else {\n factors.push(type);\n }\n }\n return bool(tuple(factors));\n }\n\n private visitBoolean(node: AstNode): ExpressionType | null {\n const type = this.childTypeDebool(node, 0, RSErrorCode.invalidBoolean);\n if (type === null) {\n return null;\n }\n return bool(bool(type));\n }\n\n private visitTuple(node: AstNode): ExpressionType | null {\n const components: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypification(node, child);\n if (type === null) {\n return null;\n }\n components.push(type);\n }\n return tuple(components);\n }\n\n private visitEnumeration(node: AstNode): ExpressionType | null {\n let type: ExpressionType | null = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n\n const merge = mergeTypifications(type, childType);\n if (merge === null) {\n return this.onError(RSErrorCode.invalidEnumeration, node.children[child], [\n labelType(type),\n labelType(childType)\n ]);\n }\n type = merge;\n }\n return bool(type);\n }\n\n private visitBool(node: AstNode): ExpressionType | null {\n return this.visitEnumeration(node);\n }\n\n private visitDebool(node: AstNode): ExpressionType | null {\n return this.childTypeDebool(node, 0, RSErrorCode.invalidDebool);\n }\n\n private visitSetexprBinary(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypeDebool(node, 0, RSErrorCode.invalidTypeOperation, operator);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(bool(type1)), labelType(bool(type2)), operator]);\n }\n return bool(result);\n }\n\n private visitProjectSet(node: AstNode): ExpressionType | null {\n const argument = this.childTypeDebool(node, 0, RSErrorCode.invalidProjectionSet);\n if (argument === null) {\n return null;\n }\n if (argument.typeID === TypeID.anyTypification) {\n return EmptySetT;\n }\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidProjectionSet, node.children[0], [\n labelRSLangNode(node),\n labelType(bool(argument))\n ]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.invalidProjectionSet, node.children[0], [\n labelRSLangNode(node),\n labelType(bool(argument))\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return bool(components[0]);\n } else {\n return bool(tuple(components));\n }\n }\n\n private visitProjectTuple(node: AstNode): ExpressionType | null {\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (argument.typeID === TypeID.anyTypification) {\n return argument;\n }\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidProjectionTuple, node.children[0], [\n labelRSLangNode(node),\n labelType(argument)\n ]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.invalidProjectionTuple, node.children[0], [\n labelRSLangNode(node),\n labelType(argument)\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return components[0];\n } else {\n return tuple(components);\n }\n }\n\n private visitFilter(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const indices = getNodeIndices(node);\n const tupleParam = indices.length === node.children.length - 1;\n if (!tupleParam && node.children.length > 2) {\n const extraParam = node.children[indices.length];\n return this.onError(RSErrorCode.invalidFilterArity, extraParam ?? node, [\n String(indices.length),\n String(node.children.length - 1),\n operator\n ]);\n }\n\n const argument = this.childTypification(node, node.children.length - 1);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n const expectedArgument = this.expectedFilterArgumentLabel(indices);\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidFilterArgumentType, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n expectedArgument\n ]);\n }\n\n const argBase = debool(argument) as EchelonTuple;\n const bases: Typification[] = [];\n for (const index of indices) {\n const newBase = component(argBase, index);\n if (newBase === null) {\n return this.onError(RSErrorCode.invalidFilterIndex, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n String(index),\n String(argBase.factors.length)\n ]);\n }\n bases.push(newBase);\n }\n\n if (tupleParam) {\n for (let child = 0; child + 1 < node.children.length; child++) {\n const param = this.childTypification(node, child);\n if (param === null) {\n return null;\n }\n const expectedParam = bool(bases[child]);\n if (param.typeID !== TypeID.collection || !checkCompatibility(bases[child], debool(param))) {\n return this.reportFilterParameterError(node, child, param, expectedParam, operator);\n }\n }\n } else {\n const param = this.childTypification(node, 0);\n if (param === null) {\n return null;\n }\n const paramType = param;\n const expected = bool(tuple(bases));\n if (paramType.typeID !== TypeID.collection || !checkCompatibility(expected, paramType)) {\n return this.reportFilterParameterError(node, 0, paramType, expected, operator);\n }\n }\n return argument;\n }\n\n private expectedFilterArgumentLabel(indices: number[]): string {\n const maxIndex = Math.max(...indices, 0);\n if (maxIndex <= 1) {\n return labelType(bool({ typeID: TypeID.anyTypification }));\n }\n const factors: Typification[] = [];\n for (let index = 1; index <= maxIndex; index++) {\n factors.push({ typeID: TypeID.anyTypification });\n }\n return labelType(bool(tuple(factors)));\n }\n\n private reportFilterParameterError(\n node: AstNode,\n childIndex: number,\n param: Typification,\n expected: Typification,\n operator: string\n ): null {\n const wrapped = bool(param);\n if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) {\n return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [\n operator,\n labelType(param)\n ]);\n }\n return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [\n labelType(param),\n labelType(expected),\n operator\n ]);\n }\n\n private visitReduce(node: AstNode): ExpressionType | null {\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.collection) {\n return this.onError(RSErrorCode.invalidReduce, node.children[0], [labelType(argument)]);\n }\n return debool(argument);\n }\n\n private visitArgumentsEnum(node: AstNode): ExpressionType | null {\n return this.visitAllAndReturn(node, LogicT);\n }\n\n private visitDeclarative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const domain = this.childTypeDebool(\n node,\n 1,\n RSErrorCode.invalidTypeOperation,\n labelToken(TokenID.NT_DECLARATIVE_EXPR)\n );\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return bool(domain);\n }\n\n private visitImperative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n for (let child = 1; child < node.children.length; child++) {\n if (!this.childLogic(node, child)) {\n return null;\n }\n }\n\n const type = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n\n this.locals.endScope(node);\n return bool(type);\n }\n\n private visitIterate(node: AstNode): ExpressionType | null {\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitAssign(node: AstNode): ExpressionType | null {\n const domain = this.childTypification(node, 1);\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitRecursion(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const initType = this.childTypification(node, 1);\n if (initType === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, initType)) {\n return null;\n }\n\n const isFull = node.typeID === TokenID.NT_RECURSIVE_FULL;\n const iterationIndex = isFull ? 3 : 2;\n\n let iterationValue = this.childTypification(node, iterationIndex);\n if (iterationValue === null) {\n return null;\n }\n if (!checkCompatibility(iterationValue, initType)) {\n return this.onError(RSErrorCode.typesNotEqual, node.children[iterationIndex], [\n labelType(iterationValue),\n labelType(initType),\n labelToken(node.typeID as TokenID)\n ]);\n }\n\n if (hasGenerics(initType)) {\n for (let retries = TypeAuditor.TYPE_DEDUCTION_DEPTH; retries > 0; retries--) {\n this.locals.endScope(node);\n this.locals.clearUnused();\n this.locals.startScope();\n if (!this.visitChildDeclaration(node, 0, iterationValue)) {\n return null;\n }\n const newIteration = this.childTypification(node, iterationIndex);\n if (newIteration === null) {\n return null;\n }\n if (checkEquality(newIteration, iterationValue)) {\n break;\n }\n iterationValue = newIteration;\n }\n }\n\n if (isFull) {\n if (!this.childLogic(node, 2)) {\n return null;\n }\n }\n\n this.locals.endScope(node);\n return iterationValue;\n }\n\n private isSubset(token: TokenID): boolean {\n return token === TokenID.SUBSET || token === TokenID.SUBSET_OR_EQ || token === TokenID.NOT_SUBSET;\n }\n\n private isInsideFuncArgument(node: AstNode): boolean {\n while (node.parent && node.parent !== node) {\n if (node.typeID === TokenID.NT_ARGUMENTS) return true;\n node = node.parent;\n }\n return false;\n }\n\n private checkFuncArguments(node: AstNode, alias: string, type: Parametrized): Map<string, Typification> | null {\n if (node.children.length - 1 !== type.args.length) {\n return this.onError(RSErrorCode.invalidArgsArity, node, [\n String(type.args.length),\n String(node.children.length - 1)\n ]);\n }\n\n const substitutes = new Map<string, Typification>();\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n const argType = mangleRadicals(alias, type.args[child - 1].type);\n if (!compareTemplated(substitutes, argType, childType)) {\n this.onError(RSErrorCode.invalidArgumentType, node.children[child], [\n `${type.args[child - 1].alias}∈${labelType(argType)}`,\n labelType(childType)\n ]);\n return null;\n }\n }\n return substitutes;\n }\n}\n\n// ========= Internals ========\nfunction mangleRadicals(funcName: string, type: Typification): Typification {\n switch (type.typeID) {\n default:\n throw new Error(`Unexpected type for ${funcName}: ${JSON.stringify(type)}`);\n case TypeID.anyTypification:\n case TypeID.integer:\n return type;\n case TypeID.basic: {\n if (isRadical(type.baseID)) {\n return {\n typeID: type.typeID,\n baseID: type.baseID + funcName\n };\n }\n return type;\n }\n case TypeID.collection: {\n return {\n typeID: type.typeID,\n base: mangleRadicals(funcName, debool(type))\n };\n }\n case TypeID.tuple: {\n const factors: Typification[] = [];\n for (let index = 1; index <= type.factors.length; ++index) {\n factors.push(mangleRadicals(funcName, component(type, index)!));\n }\n return {\n typeID: type.typeID,\n factors: factors\n };\n }\n }\n}\n\n/** Local variable data. */\ninterface LocalData {\n alias: string;\n level: number;\n useCount: number;\n type: Typification;\n}\n\nfunction isLogicBinaryNode(typeID: number): boolean {\n return (\n typeID === TokenID.LOGIC_AND ||\n typeID === TokenID.LOGIC_OR ||\n typeID === TokenID.LOGIC_IMPLICATION ||\n typeID === TokenID.LOGIC_EQUIVALENT\n );\n}\n\nfunction isQuantifierNode(typeID: number): boolean {\n return typeID === TokenID.QUANTOR_UNIVERSAL || typeID === TokenID.QUANTOR_EXISTS;\n}\n\nfunction subtreeContainsQuantifier(node: AstNode): boolean {\n if (isQuantifierNode(node.typeID)) {\n return true;\n }\n for (const child of node.children) {\n if (subtreeContainsQuantifier(child)) {\n return true;\n }\n }\n return false;\n}\n\n/** Right operand subtree of the innermost logic binary containing `node`. */\nfunction findRightLogicOperandRoot(node: AstNode): AstNode | null {\n let current: AstNode | null = node;\n while (current !== null && current.parent !== null) {\n const parent: AstNode = current.parent;\n if (isLogicBinaryNode(parent.typeID)) {\n const childIndex = parent.children.indexOf(current);\n if (childIndex > 0) {\n return current;\n }\n }\n current = parent;\n }\n return null;\n}\n\n/** Local variables context. */\nclass LocalContext {\n private onError: (code: RSErrorCode, node: AstNode, params: string[]) => null;\n\n public data: LocalData[] = [];\n\n constructor(onError: (code: RSErrorCode, node: AstNode, params: string[]) => null) {\n this.onError = onError;\n }\n\n startScope(): void {\n for (const local of this.data) {\n if (local.level > 0) {\n local.level = local.level + 1;\n }\n }\n }\n\n endScope(node: AstNode, skipUnused: boolean = false): void {\n for (const local of this.data) {\n local.level--;\n if (!skipUnused && local.level === 0 && local.useCount === 0) {\n this.onError(RSErrorCode.localNotUsed, node, [local.alias]);\n }\n }\n }\n\n clearUnused(): void {\n this.data = this.data.filter(data => data.level > 0);\n }\n\n pushLocal(node: AstNode, type: Typification): boolean {\n const alias = getNodeText(node);\n const existing = this.data.find(data => data.alias === alias);\n if (existing) {\n if (existing.level > 0) {\n this.onError(RSErrorCode.localShadowing, node, [alias]);\n return false;\n } else {\n this.onError(RSErrorCode.localDoubleDeclare, node, [alias]);\n const index = this.data.indexOf(existing);\n if (index !== -1) {\n this.data.splice(index, 1);\n }\n }\n }\n this.data.push({ alias, type, level: 1, useCount: 0 });\n return true;\n }\n\n getLocalType(node: AstNode): Typification | null {\n const alias = getNodeText(node);\n const local = this.data.find(data => data.alias === alias);\n if (local === undefined) {\n this.onError(RSErrorCode.localUndeclared, node, [alias]);\n return null;\n } else if (local.level < 1) {\n const subexprRoot = findRightLogicOperandRoot(node);\n if (subexprRoot !== null) {\n if (subtreeContainsQuantifier(subexprRoot)) {\n return this.onError(RSErrorCode.localUndeclaredInSubexpr, node, [alias, labelType(local.type)]);\n }\n return this.onError(RSErrorCode.localOutOfScopeParentheses, node, [alias]);\n }\n this.onError(RSErrorCode.localOutOfScope, node, [alias]);\n return null;\n } else {\n local.useCount++;\n return local.type;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,IAAa,cAAb,MAAa,YAAY;CACvB,OAAwB,uBAAuB;CAE/C;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAsB;EAChC,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,KAAK,UAAU;EACf,KAAK,SAAS,IAAI,aAAa,KAAK,QAAQ,KAAK,IAAI,CAAC;CACxD;CAEA,IACE,KACA,eACA,UACA,iBAA0B,OACH;EACvB,IAAI,IAAI,UACN,OAAO;EAET,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,KAAK,WAAW;EAChB,KAAK,MAAM;EACX,OAAO,KAAK,cAAc,GAAG;CAC/B;CAEA,QAAsB;EACpB,KAAK,SAAS,IAAI,aAAa,KAAK,QAAQ,KAAK,IAAI,CAAC;CACxD;CAEA,gBAAwB,MAAe,QAA+B;EACpE,MAAM,SAAS,KAAK,eAAe,MAAM,MAAM;EAC/C,IAAI,WAAW,QAAQ,KAAK,eAC1B,aAAa,MAAM,MAAM;EAE3B,OAAO;CACT;CAEA,eAAuB,MAAe,QAA+B;EACnE,QAAQ,KAAK,QAAb;GACE,KAAK,QAAQ,UACX,OAAO,KAAK,aAAa,MAAM,MAAM;GACvC,KAAK,QAAQ,eACX,OAAO,KAAK,aAAa,MAAM,MAAM;GACvC,KAAK,QAAQ,cACX,OAAO,KAAK,mBAAmB,MAAM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AAoC;EAC/C,MAAM,QAAQ,YAAY,IAAI;EAC9B,MAAM,QAAQ,KAAK,KAAK,MAAK,SAAQ,KAAK,UAAU,KAAK;EACzD,IAAI,UAAU,QAAW;GACvB,KAAK,QAAQ,YAAY,iBAAiB,MAAM,CAAC,KAAK,CAAC;GACvD,OAAO;EACT,OAAO,IAAI,MAAM,QAAQ,GAAG;GAC1B,MAAM,cAAc,0BAA0B,IAAI;GAClD,IAAI,gBAAgB,MAAM;IACxB,IAAI,0BAA0B,WAAW,GACvC,OAAO,KAAK,QAAQ,YAAY,0BAA0B,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,CAAC,CAAC;IAEhG,OAAO,KAAK,QAAQ,YAAY,4BAA4B,MAAM,CAAC,KAAK,CAAC;GAC3E;GACA,KAAK,QAAQ,YAAY,iBAAiB,MAAM,CAAC,KAAK,CAAC;GACvD,OAAO;EACT,OAAO;GACL,MAAM;GACN,OAAO,MAAM;EACf;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"type-auditor.js","names":[],"sources":["../../../src/rslang/semantic/type-auditor.ts"],"sourcesContent":["/**\n * Module: Type auditor for AST type checking.\n */\n\nimport { type AstNode, getNodeIndices, getNodeText } from '../../parsing';\nimport { annotateError, annotateType } from '../ast-annotations';\nimport { type ErrorReporter, RSErrorCode } from '../error';\nimport { labelRSLangNode, labelToken, labelType } from '../labels';\nimport { TokenID } from '../parser/token';\n\nimport {\n type Argument,\n bool,\n component,\n debool,\n type EchelonTuple,\n EmptySetT,\n type ExpressionType,\n IntegerT,\n isRadical,\n isTypification,\n LogicT,\n type Parametrized,\n tuple,\n type TypeContext,\n TypeID,\n type Typification\n} from './typification';\nimport {\n checkCompatibility,\n checkEquality,\n compareTemplated,\n hasGenerics,\n mergeTypifications,\n substituteBase\n} from './typification-api';\n\n/** Type auditor for AST type checking. */\nexport class TypeAuditor {\n private static readonly TYPE_DEDUCTION_DEPTH = 5;\n\n private context: TypeContext;\n private reporter?: ErrorReporter;\n private locals: LocalContext;\n private annotateTypes: boolean;\n private annotateErrors: boolean;\n\n constructor(context: TypeContext) {\n this.annotateTypes = false;\n this.annotateErrors = false;\n this.context = context;\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n public run(\n ast: AstNode,\n annotateTypes: boolean,\n reporter?: ErrorReporter,\n annotateErrors: boolean = false\n ): ExpressionType | null {\n if (ast.hasError) {\n return null;\n }\n this.annotateTypes = annotateTypes;\n this.annotateErrors = annotateErrors;\n this.reporter = reporter;\n this.clear();\n return this.dispatchVisit(ast);\n }\n\n private clear(): void {\n this.locals = new LocalContext(this.onError.bind(this));\n }\n\n private dispatchDeclare(node: AstNode, domain: Typification): boolean {\n const result = this.processDeclare(node, domain);\n if (result === true && this.annotateTypes) {\n annotateType(node, domain);\n }\n return result;\n }\n\n private processDeclare(node: AstNode, domain: Typification): boolean {\n switch (node.typeID) {\n case TokenID.ID_LOCAL:\n return this.declareLocal(node, domain);\n case TokenID.NT_TUPLE_DECL:\n return this.declareTuple(node, domain);\n case TokenID.NT_ENUM_DECL:\n return this.declareEnumeration(node, domain);\n }\n return false;\n }\n\n private declareLocal(node: AstNode, domain: Typification): boolean {\n return this.locals.pushLocal(node, domain);\n }\n\n private declareTuple(node: AstNode, domain: Typification): boolean {\n if (domain.typeID !== TypeID.tuple || domain.factors.length !== node.children.length) {\n this.onError(RSErrorCode.invalidCortegeDeclare, node.children[0]);\n return false;\n }\n for (let child = 0; child < node.children.length; child++) {\n if (!this.visitChildDeclaration(node, child, component(domain, child + 1)!)) {\n return false;\n }\n }\n return true;\n }\n\n private declareEnumeration(node: AstNode, domain: Typification): boolean {\n for (const child of node.children) {\n if (!this.dispatchDeclare(child, domain)) {\n return false;\n }\n }\n return true;\n }\n\n private dispatchVisit(node: AstNode): ExpressionType | null {\n const result = this.processVisit(node);\n if (result !== null && this.annotateTypes) {\n annotateType(node, result);\n }\n return result;\n }\n\n private processVisit(node: AstNode): ExpressionType | null {\n switch (node.typeID) {\n case TokenID.ID_GLOBAL:\n case TokenID.ID_FUNCTION:\n case TokenID.ID_PREDICATE:\n return this.visitGlobal(node);\n\n case TokenID.ID_LOCAL:\n return this.visitLocal(node);\n case TokenID.ID_RADICAL:\n return this.visitRadical(node);\n\n case TokenID.LIT_INTEGER:\n return IntegerT;\n case TokenID.LIT_WHOLE_NUMBERS:\n return bool(IntegerT);\n case TokenID.LIT_EMPTYSET:\n return this.visitEmptySet(node);\n\n case TokenID.NT_ARGUMENTS:\n return this.visitArgumentsEnum(node);\n case TokenID.NT_ARG_DECL:\n return this.visitArgument(node);\n\n case TokenID.PLUS:\n case TokenID.MINUS:\n case TokenID.MULTIPLY:\n return this.visitArithmetic(node);\n\n case TokenID.QUANTOR_UNIVERSAL:\n case TokenID.QUANTOR_EXISTS:\n return this.visitQuantifier(node);\n\n case TokenID.LOGIC_NOT:\n return this.visitNegation(node);\n\n case TokenID.LOGIC_AND:\n case TokenID.LOGIC_OR:\n case TokenID.LOGIC_IMPLICATION:\n case TokenID.LOGIC_EQUIVALENT:\n return this.visitLogicBinary(node);\n\n case TokenID.EQUAL:\n case TokenID.NOTEQUAL:\n return this.visitEquals(node);\n\n case TokenID.GREATER:\n case TokenID.LESSER:\n case TokenID.GREATER_OR_EQ:\n case TokenID.LESSER_OR_EQ:\n return this.visitIntegerPredicate(node);\n\n case TokenID.SET_IN:\n case TokenID.SET_NOT_IN:\n case TokenID.SUBSET:\n case TokenID.SUBSET_OR_EQ:\n case TokenID.NOT_SUBSET:\n return this.visitSetexprPredicate(node);\n\n case TokenID.DECART:\n return this.visitDecart(node);\n case TokenID.BOOLEAN:\n return this.visitBoolean(node);\n\n case TokenID.NT_TUPLE:\n return this.visitTuple(node);\n case TokenID.NT_ENUMERATION:\n return this.visitEnumeration(node);\n\n case TokenID.BIGPR:\n return this.visitProjectSet(node);\n case TokenID.SMALLPR:\n return this.visitProjectTuple(node);\n case TokenID.FILTER:\n return this.visitFilter(node);\n\n case TokenID.CARD:\n return this.visitCard(node);\n case TokenID.REDUCE:\n return this.visitReduce(node);\n case TokenID.BOOL:\n return this.visitBool(node);\n case TokenID.DEBOOL:\n return this.visitDebool(node);\n\n case TokenID.SET_UNION:\n case TokenID.SET_INTERSECTION:\n case TokenID.SET_MINUS:\n case TokenID.SET_SYMMETRIC_MINUS:\n return this.visitSetexprBinary(node);\n\n case TokenID.NT_FUNC_DEFINITION:\n return this.visitFunctionDefinition(node);\n\n case TokenID.NT_FUNC_CALL:\n return this.visitFunctionCall(node);\n\n case TokenID.ITERATE:\n return this.visitIterate(node);\n case TokenID.ASSIGN:\n return this.visitAssign(node);\n\n case TokenID.NT_DECLARATIVE_EXPR:\n return this.visitDeclarative(node);\n case TokenID.NT_IMPERATIVE_EXPR:\n return this.visitImperative(node);\n\n case TokenID.NT_RECURSIVE_FULL:\n case TokenID.NT_RECURSIVE_SHORT:\n return this.visitRecursion(node);\n }\n return null;\n }\n\n private onError(code: RSErrorCode, node: AstNode, params?: string[]): null {\n this.reporter?.({ code, from: node.from, to: node.to, params });\n if (this.annotateErrors) {\n annotateError(node, code, params);\n }\n return null;\n }\n\n private visitChild(node: AstNode, index: number): ExpressionType | null {\n if (index >= node.children.length) {\n return null;\n }\n return this.dispatchVisit(node.children[index]);\n }\n\n private visitChildDeclaration(node: AstNode, index: number, domain: Typification): boolean {\n if (index >= node.children.length) {\n return false;\n }\n if (!this.dispatchDeclare(node.children[index], domain)) {\n return false;\n }\n return true;\n }\n\n private visitAllAndReturn(node: AstNode, type: ExpressionType | null): ExpressionType | null {\n for (const child of node.children) {\n if (!this.dispatchVisit(child)) {\n return null;\n }\n }\n return type;\n }\n\n private childTypification(node: AstNode, index: number): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.expectedSetexpr, node.children[index], [labelType(result)]);\n return null;\n }\n return result as Typification;\n }\n\n private childLogic(node: AstNode, index: number): boolean {\n const result = this.visitChild(node, index);\n if (result === null) {\n return false;\n }\n if (result.typeID !== TypeID.logic) {\n this.onError(RSErrorCode.expectedLogic, node.children[index], [labelType(result)]);\n return false;\n }\n return true;\n }\n\n private childTypeDebool(\n node: AstNode,\n index: number,\n errorCode: RSErrorCode,\n operation?: string\n ): Typification | null {\n const result = this.childTypification(node, index);\n if (result === null) {\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n const params =\n errorCode === RSErrorCode.invalidTypeOperation && operation !== undefined\n ? [operation, labelType(result)]\n : [labelType(result)];\n this.onError(errorCode, node.children[index], params);\n return null;\n }\n return debool(result);\n }\n\n private childQuantifierDomain(node: AstNode, index: number, operator: string): Typification | null {\n const result = this.visitChild(node, index);\n if (result === null) {\n return null;\n }\n if (!isTypification(result)) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n if (result.typeID === TypeID.anyTypification) {\n return result;\n }\n if (result.typeID !== TypeID.collection) {\n this.onError(RSErrorCode.invalidQuantifierDomain, node.children[index], [operator, labelType(result)]);\n return null;\n }\n return debool(result);\n }\n\n private visitLocal(node: AstNode): ExpressionType | null {\n return this.locals.getLocalType(node);\n }\n\n private visitGlobal(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n const type = this.context.get(alias);\n if (!type) {\n return this.onError(RSErrorCode.globalNotTyped, node, [alias]);\n }\n if (type.typeID === TypeID.function || type.typeID === TypeID.predicate) {\n return this.onError(RSErrorCode.globalFuncWithoutArgs, node, [alias]);\n }\n return type;\n }\n\n private visitFunctionDefinition(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n if (!this.visitChild(node, 0)) {\n return null;\n }\n\n const args: Argument[] = [];\n for (const local of this.locals.data) {\n if (local.level === 1) {\n args.push({ alias: local.alias, type: local.type });\n }\n }\n\n const result = this.visitChild(node, 1);\n if (result === null || result.typeID === TypeID.function || result.typeID === TypeID.predicate) {\n return null;\n }\n this.locals.endScope(node.children[1]);\n if (result.typeID === TypeID.logic) {\n return {\n typeID: TypeID.predicate,\n result: result,\n args: args\n };\n } else {\n return {\n typeID: TypeID.function,\n result: result,\n args: args\n };\n }\n }\n\n private visitFunctionCall(node: AstNode): ExpressionType | null {\n const funcName = getNodeText(node.children[0]);\n const funcType = this.context.get(funcName);\n if (funcType?.typeID !== TypeID.function && funcType?.typeID !== TypeID.predicate) {\n return this.onError(RSErrorCode.globalNotTyped, node.children[0], [funcName]);\n }\n if (this.annotateTypes) {\n annotateType(node.children[0], funcType);\n }\n\n const substitutes = this.checkFuncArguments(node, funcName, funcType);\n if (substitutes === null) {\n return null;\n }\n if (funcType.result.typeID === TypeID.logic) {\n return funcType.result;\n } else {\n const result = mangleRadicals(funcName, funcType.result);\n if (substitutes.size > 0) {\n substituteBase(result, substitutes);\n }\n return result;\n }\n }\n\n private visitRadical(node: AstNode): ExpressionType | null {\n const alias = getNodeText(node);\n if (!this.isInsideFuncArgument(node)) {\n return this.onError(RSErrorCode.radicalUsage, node, [alias]);\n }\n return bool({ typeID: TypeID.basic, baseID: alias });\n }\n\n private visitEmptySet(node: AstNode): ExpressionType | null {\n const invalidParents: TokenID[] = [\n TokenID.CARD,\n TokenID.DEBOOL,\n TokenID.SET_UNION,\n TokenID.SET_INTERSECTION,\n TokenID.SET_MINUS,\n TokenID.SET_SYMMETRIC_MINUS,\n TokenID.REDUCE,\n TokenID.BIGPR,\n TokenID.SMALLPR\n ];\n if (invalidParents.includes(node.parent?.typeID as TokenID)) {\n return this.onError(RSErrorCode.invalidEmptySetUsage, node);\n }\n return EmptySetT;\n }\n\n private visitArgument(node: AstNode): ExpressionType | null {\n const variable = node.children[0];\n if (variable.typeID === TokenID.NT_TUPLE_DECL) {\n return this.onError(RSErrorCode.invalidArgumentCortegeDeclare, variable);\n }\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return domain;\n }\n\n private visitCard(node: AstNode): ExpressionType | null {\n if (!this.childTypeDebool(node, 0, RSErrorCode.invalidCard)) {\n return null;\n }\n return IntegerT;\n }\n\n private visitArithmetic(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isArithmetic' in type1 && type1.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isArithmetic' in type2 && type2.isArithmetic)) {\n return this.onError(RSErrorCode.arithmeticNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return result;\n }\n\n private visitIntegerPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n if (!('isOrdered' in type1 && type1.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[0], [labelType(type1), operator]);\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!('isOrdered' in type2 && type2.isOrdered)) {\n return this.onError(RSErrorCode.orderingNotSupported, node.children[1], [labelType(type2), operator]);\n }\n\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitQuantifier(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const operator = labelRSLangNode(node);\n const domain = this.childQuantifierDomain(node, 1, operator);\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return LogicT;\n }\n\n private visitNegation(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0)) {\n return null;\n }\n return LogicT;\n }\n\n private visitLogicBinary(node: AstNode): ExpressionType | null {\n if (!this.childLogic(node, 0) || !this.childLogic(node, 1)) {\n return null;\n }\n return LogicT;\n }\n\n private visitEquals(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypification(node, 1);\n if (type2 === null) {\n return null;\n }\n if (!checkCompatibility(type1, type2)) {\n return this.onError(RSErrorCode.typesNotCompatible, node, [labelType(type1), labelType(type2), operator]);\n }\n return LogicT;\n }\n\n private visitSetexprPredicate(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n let type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n const isSubset = this.isSubset(node.typeID as TokenID);\n if (isSubset) {\n type2 = bool(type2);\n }\n const type1 = this.childTypification(node, 0);\n if (type1 === null) {\n return null;\n }\n\n if (!checkCompatibility(type1, type2)) {\n if (isSubset) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(type1), labelType(type2), operator]);\n } else {\n return this.onError(RSErrorCode.invalidElementPredicate, node, [\n labelType(type1),\n operator,\n labelType(bool(type2))\n ]);\n }\n }\n return LogicT;\n }\n\n private visitDecart(node: AstNode): ExpressionType | null {\n const factors: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypeDebool(node, child, RSErrorCode.invalidDecart);\n if (type === null) {\n return null;\n } else {\n factors.push(type);\n }\n }\n return bool(tuple(factors));\n }\n\n private visitBoolean(node: AstNode): ExpressionType | null {\n const type = this.childTypeDebool(node, 0, RSErrorCode.invalidBoolean);\n if (type === null) {\n return null;\n }\n return bool(bool(type));\n }\n\n private visitTuple(node: AstNode): ExpressionType | null {\n const components: Typification[] = [];\n for (let child = 0; child < node.children.length; child++) {\n const type = this.childTypification(node, child);\n if (type === null) {\n return null;\n }\n components.push(type);\n }\n return tuple(components);\n }\n\n private visitEnumeration(node: AstNode): ExpressionType | null {\n let type: ExpressionType | null = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n\n const merge = mergeTypifications(type, childType);\n if (merge === null) {\n return this.onError(RSErrorCode.invalidEnumeration, node.children[child], [\n labelType(type),\n labelType(childType)\n ]);\n }\n type = merge;\n }\n return bool(type);\n }\n\n private visitBool(node: AstNode): ExpressionType | null {\n return this.visitEnumeration(node);\n }\n\n private visitDebool(node: AstNode): ExpressionType | null {\n return this.childTypeDebool(node, 0, RSErrorCode.invalidDebool);\n }\n\n private visitSetexprBinary(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const type1 = this.childTypeDebool(node, 0, RSErrorCode.invalidTypeOperation, operator);\n if (type1 === null) {\n return null;\n }\n\n const type2 = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, operator);\n if (type2 === null) {\n return null;\n }\n\n const result = mergeTypifications(type1, type2);\n if (result === null) {\n return this.onError(RSErrorCode.typesNotEqual, node, [labelType(bool(type1)), labelType(bool(type2)), operator]);\n }\n return bool(result);\n }\n\n private visitProjectSet(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const argNode = node.children[0];\n const argType = this.childTypification(node, 0);\n if (argType === null) {\n return null;\n }\n if (argType.typeID === TypeID.anyTypification) {\n return EmptySetT;\n }\n if (argType.typeID !== TypeID.collection) {\n return this.onError(RSErrorCode.projectionSetArgumentNotSet, argNode, [operator, labelType(argType)]);\n }\n const argument = debool(argType);\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.projectionSetArgumentNotTupleSet, argNode, [operator, labelType(bool(argument))]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.projectionSetIndexOutOfRange, argNode, [\n operator,\n String(index),\n String(argument.factors.length),\n labelType(bool(argument))\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return bool(components[0]);\n } else {\n return bool(tuple(components));\n }\n }\n\n private visitProjectTuple(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const argNode = node.children[0];\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (argument.typeID === TypeID.anyTypification) {\n return argument;\n }\n if (argument.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.projectionTupleArgumentNotTuple, argNode, [operator, labelType(argument)]);\n }\n\n const indices = getNodeIndices(node);\n const components: Typification[] = [];\n for (const index of indices) {\n const newComponent = component(argument, index);\n if (newComponent === null) {\n return this.onError(RSErrorCode.projectionTupleIndexOutOfRange, argNode, [\n operator,\n String(index),\n String(argument.factors.length),\n labelType(argument)\n ]);\n } else {\n components.push(newComponent);\n }\n }\n if (components.length === 1) {\n return components[0];\n } else {\n return tuple(components);\n }\n }\n\n private visitFilter(node: AstNode): ExpressionType | null {\n const operator = labelRSLangNode(node);\n const indices = getNodeIndices(node);\n const tupleParam = indices.length === node.children.length - 1;\n if (!tupleParam && node.children.length > 2) {\n const extraParam = node.children[indices.length];\n return this.onError(RSErrorCode.invalidFilterArity, extraParam ?? node, [\n String(indices.length),\n String(node.children.length - 1),\n operator\n ]);\n }\n\n const argument = this.childTypification(node, node.children.length - 1);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n const expectedArgument = this.expectedFilterArgumentLabel(indices);\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.tuple) {\n return this.onError(RSErrorCode.invalidFilterArgumentType, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n expectedArgument\n ]);\n }\n\n const argBase = debool(argument) as EchelonTuple;\n const bases: Typification[] = [];\n for (const index of indices) {\n const newBase = component(argBase, index);\n if (newBase === null) {\n return this.onError(RSErrorCode.invalidFilterIndex, node.children[node.children.length - 1], [\n operator,\n labelType(argument),\n String(index),\n String(argBase.factors.length)\n ]);\n }\n bases.push(newBase);\n }\n\n if (tupleParam) {\n for (let child = 0; child + 1 < node.children.length; child++) {\n const param = this.childTypification(node, child);\n if (param === null) {\n return null;\n }\n const expectedParam = bool(bases[child]);\n if (param.typeID !== TypeID.collection || !checkCompatibility(bases[child], debool(param))) {\n return this.reportFilterParameterError(node, child, param, expectedParam, operator);\n }\n }\n } else {\n const param = this.childTypification(node, 0);\n if (param === null) {\n return null;\n }\n const paramType = param;\n const expected = bool(tuple(bases));\n if (paramType.typeID !== TypeID.collection || !checkCompatibility(expected, paramType)) {\n return this.reportFilterParameterError(node, 0, paramType, expected, operator);\n }\n }\n return argument;\n }\n\n private expectedFilterArgumentLabel(indices: number[]): string {\n const maxIndex = Math.max(...indices, 0);\n if (maxIndex <= 1) {\n return labelType(bool({ typeID: TypeID.anyTypification }));\n }\n const factors: Typification[] = [];\n for (let index = 1; index <= maxIndex; index++) {\n factors.push({ typeID: TypeID.anyTypification });\n }\n return labelType(bool(tuple(factors)));\n }\n\n private reportFilterParameterError(\n node: AstNode,\n childIndex: number,\n param: Typification,\n expected: Typification,\n operator: string\n ): null {\n const wrapped = bool(param);\n if (checkEquality(wrapped, expected) || checkCompatibility(wrapped, expected)) {\n return this.onError(RSErrorCode.invalidFilterBooleanEchelon, node.children[childIndex], [\n operator,\n labelType(param)\n ]);\n }\n return this.onError(RSErrorCode.invalidFilterParameterType, node.children[childIndex], [\n labelType(param),\n labelType(expected),\n operator\n ]);\n }\n\n private visitReduce(node: AstNode): ExpressionType | null {\n const argument = this.childTypification(node, 0);\n if (argument === null) {\n return null;\n }\n if (\n argument.typeID === TypeID.anyTypification ||\n (argument.typeID === TypeID.collection && argument.base.typeID === TypeID.anyTypification)\n ) {\n return EmptySetT;\n }\n if (argument.typeID !== TypeID.collection || argument.base.typeID !== TypeID.collection) {\n return this.onError(RSErrorCode.invalidReduce, node.children[0], [labelType(argument)]);\n }\n return debool(argument);\n }\n\n private visitArgumentsEnum(node: AstNode): ExpressionType | null {\n return this.visitAllAndReturn(node, LogicT);\n }\n\n private visitDeclarative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const domain = this.childTypeDebool(\n node,\n 1,\n RSErrorCode.invalidTypeOperation,\n labelToken(TokenID.NT_DECLARATIVE_EXPR)\n );\n if (domain === null) {\n return null;\n } else if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n } else if (!this.childLogic(node, 2)) {\n return null;\n }\n\n this.locals.endScope(node.children[2]);\n return bool(domain);\n }\n\n private visitImperative(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n for (let child = 1; child < node.children.length; child++) {\n if (!this.childLogic(node, child)) {\n return null;\n }\n }\n\n const type = this.childTypification(node, 0);\n if (type === null) {\n return null;\n }\n\n this.locals.endScope(node);\n return bool(type);\n }\n\n private visitIterate(node: AstNode): ExpressionType | null {\n const domain = this.childTypeDebool(node, 1, RSErrorCode.invalidTypeOperation, labelToken(TokenID.ITERATE));\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitAssign(node: AstNode): ExpressionType | null {\n const domain = this.childTypification(node, 1);\n if (domain === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, domain)) {\n return null;\n }\n return LogicT;\n }\n\n private visitRecursion(node: AstNode): ExpressionType | null {\n this.locals.startScope();\n\n const initType = this.childTypification(node, 1);\n if (initType === null) {\n return null;\n }\n if (!this.visitChildDeclaration(node, 0, initType)) {\n return null;\n }\n\n const isFull = node.typeID === TokenID.NT_RECURSIVE_FULL;\n const iterationIndex = isFull ? 3 : 2;\n\n let iterationValue = this.childTypification(node, iterationIndex);\n if (iterationValue === null) {\n return null;\n }\n if (!checkCompatibility(iterationValue, initType)) {\n return this.onError(RSErrorCode.typesNotEqual, node.children[iterationIndex], [\n labelType(iterationValue),\n labelType(initType),\n labelToken(node.typeID as TokenID)\n ]);\n }\n\n if (hasGenerics(initType)) {\n for (let retries = TypeAuditor.TYPE_DEDUCTION_DEPTH; retries > 0; retries--) {\n this.locals.endScope(node);\n this.locals.clearUnused();\n this.locals.startScope();\n if (!this.visitChildDeclaration(node, 0, iterationValue)) {\n return null;\n }\n const newIteration = this.childTypification(node, iterationIndex);\n if (newIteration === null) {\n return null;\n }\n if (checkEquality(newIteration, iterationValue)) {\n break;\n }\n iterationValue = newIteration;\n }\n }\n\n if (isFull) {\n if (!this.childLogic(node, 2)) {\n return null;\n }\n }\n\n this.locals.endScope(node);\n return iterationValue;\n }\n\n private isSubset(token: TokenID): boolean {\n return token === TokenID.SUBSET || token === TokenID.SUBSET_OR_EQ || token === TokenID.NOT_SUBSET;\n }\n\n private isInsideFuncArgument(node: AstNode): boolean {\n while (node.parent && node.parent !== node) {\n if (node.typeID === TokenID.NT_ARGUMENTS) return true;\n node = node.parent;\n }\n return false;\n }\n\n private checkFuncArguments(node: AstNode, alias: string, type: Parametrized): Map<string, Typification> | null {\n if (node.children.length - 1 !== type.args.length) {\n return this.onError(RSErrorCode.invalidArgsArity, node, [\n String(type.args.length),\n String(node.children.length - 1)\n ]);\n }\n\n const substitutes = new Map<string, Typification>();\n for (let child = 1; child < node.children.length; child++) {\n const childType = this.childTypification(node, child);\n if (childType === null) {\n return null;\n }\n const argType = mangleRadicals(alias, type.args[child - 1].type);\n if (!compareTemplated(substitutes, argType, childType)) {\n this.onError(RSErrorCode.invalidArgumentType, node.children[child], [\n `${type.args[child - 1].alias}∈${labelType(argType)}`,\n labelType(childType)\n ]);\n return null;\n }\n }\n return substitutes;\n }\n}\n\n// ========= Internals ========\nfunction mangleRadicals(funcName: string, type: Typification): Typification {\n switch (type.typeID) {\n default:\n throw new Error(`Unexpected type for ${funcName}: ${JSON.stringify(type)}`);\n case TypeID.anyTypification:\n case TypeID.integer:\n return type;\n case TypeID.basic: {\n if (isRadical(type.baseID)) {\n return {\n typeID: type.typeID,\n baseID: type.baseID + funcName\n };\n }\n return type;\n }\n case TypeID.collection: {\n return {\n typeID: type.typeID,\n base: mangleRadicals(funcName, debool(type))\n };\n }\n case TypeID.tuple: {\n const factors: Typification[] = [];\n for (let index = 1; index <= type.factors.length; ++index) {\n factors.push(mangleRadicals(funcName, component(type, index)!));\n }\n return {\n typeID: type.typeID,\n factors: factors\n };\n }\n }\n}\n\n/** Local variable data. */\ninterface LocalData {\n alias: string;\n level: number;\n useCount: number;\n type: Typification;\n}\n\nfunction isLogicBinaryNode(typeID: number): boolean {\n return (\n typeID === TokenID.LOGIC_AND ||\n typeID === TokenID.LOGIC_OR ||\n typeID === TokenID.LOGIC_IMPLICATION ||\n typeID === TokenID.LOGIC_EQUIVALENT\n );\n}\n\nfunction isQuantifierNode(typeID: number): boolean {\n return typeID === TokenID.QUANTOR_UNIVERSAL || typeID === TokenID.QUANTOR_EXISTS;\n}\n\n/** Quantifier on the path from `node` up through `stopAt` (inclusive). */\nfunction pathContainsQuantifier(node: AstNode, stopAt: AstNode): boolean {\n let current: AstNode | null = node;\n while (current !== null) {\n if (isQuantifierNode(current.typeID)) {\n return true;\n }\n if (current === stopAt) {\n return false;\n }\n current = current.parent;\n }\n return false;\n}\n\n/** Right operand subtree of the innermost logic binary containing `node`. */\nfunction findRightLogicOperandRoot(node: AstNode): AstNode | null {\n let current: AstNode | null = node;\n while (current !== null && current.parent !== null) {\n const parent: AstNode = current.parent;\n if (isLogicBinaryNode(parent.typeID)) {\n const childIndex = parent.children.indexOf(current);\n if (childIndex > 0) {\n return current;\n }\n }\n current = parent;\n }\n return null;\n}\n\n/** Local variables context. */\nclass LocalContext {\n private onError: (code: RSErrorCode, node: AstNode, params: string[]) => null;\n\n public data: LocalData[] = [];\n\n constructor(onError: (code: RSErrorCode, node: AstNode, params: string[]) => null) {\n this.onError = onError;\n }\n\n startScope(): void {\n for (const local of this.data) {\n if (local.level > 0) {\n local.level = local.level + 1;\n }\n }\n }\n\n endScope(node: AstNode, skipUnused: boolean = false): void {\n for (const local of this.data) {\n local.level--;\n if (!skipUnused && local.level === 0 && local.useCount === 0) {\n this.onError(RSErrorCode.localNotUsed, node, [local.alias]);\n }\n }\n }\n\n clearUnused(): void {\n this.data = this.data.filter(data => data.level > 0);\n }\n\n pushLocal(node: AstNode, type: Typification): boolean {\n const alias = getNodeText(node);\n const existing = this.data.find(data => data.alias === alias);\n if (existing) {\n if (existing.level > 0) {\n this.onError(RSErrorCode.localShadowing, node, [alias]);\n return false;\n } else {\n this.onError(RSErrorCode.localDoubleDeclare, node, [alias]);\n const index = this.data.indexOf(existing);\n if (index !== -1) {\n this.data.splice(index, 1);\n }\n }\n }\n this.data.push({ alias, type, level: 1, useCount: 0 });\n return true;\n }\n\n getLocalType(node: AstNode): Typification | null {\n const alias = getNodeText(node);\n const local = this.data.find(data => data.alias === alias);\n if (local === undefined) {\n this.onError(RSErrorCode.localUndeclared, node, [alias]);\n return null;\n } else if (local.level < 1) {\n const subexprRoot = findRightLogicOperandRoot(node);\n if (subexprRoot !== null) {\n if (pathContainsQuantifier(node, subexprRoot)) {\n return this.onError(RSErrorCode.localUndeclaredInSubexpr, node, [alias, labelType(local.type)]);\n }\n return this.onError(RSErrorCode.localOutOfScopeParentheses, node, [alias]);\n }\n this.onError(RSErrorCode.localOutOfScope, node, [alias]);\n return null;\n } else {\n local.useCount++;\n return local.type;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,IAAa,cAAb,MAAa,YAAY;CACvB,OAAwB,uBAAuB;CAE/C;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAsB;EAChC,KAAK,gBAAgB;EACrB,KAAK,iBAAiB;EACtB,KAAK,UAAU;EACf,KAAK,SAAS,IAAI,aAAa,KAAK,QAAQ,KAAK,IAAI,CAAC;CACxD;CAEA,IACE,KACA,eACA,UACA,iBAA0B,OACH;EACvB,IAAI,IAAI,UACN,OAAO;EAET,KAAK,g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CAAC;IAEhG,OAAO,KAAK,QAAQ,YAAY,4BAA4B,MAAM,CAAC,KAAK,CAAC;GAC3E;GACA,KAAK,QAAQ,YAAY,iBAAiB,MAAM,CAAC,KAAK,CAAC;GACvD,OAAO;EACT,OAAO;GACL,MAAM;GACN,OAAO,MAAM;EACf;CACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "../../ast-C8sIpKdL.js";
|
|
2
|
-
import { t as ErrorReporter } from "../../error-
|
|
2
|
+
import { t as ErrorReporter } from "../../error-Cv4sntcy.js";
|
|
3
3
|
import { n as ValueClassContext, t as ValueClass } from "../../value-class-CNI-lqXJ.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/semantic/value-auditor.d.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { RSErrorCode } from '../rslang/error';
|
|
4
|
+
|
|
5
|
+
import { CstType, type RSForm } from './rsform';
|
|
6
|
+
import { getAnalysisFor, validateAliasFormat } from './rsform-api';
|
|
7
|
+
|
|
8
|
+
const emptySchema = {} as RSForm;
|
|
5
9
|
|
|
6
10
|
describe('validateAliasFormat', () => {
|
|
7
11
|
it('accepts alias with type prefix and numeric suffix', () => {
|
|
@@ -22,3 +26,27 @@ describe('validateAliasFormat', () => {
|
|
|
22
26
|
expect(validateAliasFormat('X1a', CstType.BASE)).toBe(false);
|
|
23
27
|
});
|
|
24
28
|
});
|
|
29
|
+
|
|
30
|
+
describe('getAnalysisFor', () => {
|
|
31
|
+
it('rejects formal definition for basic sets with params', () => {
|
|
32
|
+
const result = getAnalysisFor('Z', CstType.BASE, emptySchema, 'X1');
|
|
33
|
+
expect(result.success).toBe(false);
|
|
34
|
+
expect(result.errors[0]).toMatchObject({
|
|
35
|
+
code: RSErrorCode.definitionNotAllowed,
|
|
36
|
+
from: 0,
|
|
37
|
+
to: 1,
|
|
38
|
+
params: [CstType.BASE, 'X1']
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('rejects formal definition for constants with params', () => {
|
|
43
|
+
const result = getAnalysisFor('X1', CstType.CONSTANT, emptySchema, 'C1');
|
|
44
|
+
expect(result.success).toBe(false);
|
|
45
|
+
expect(result.errors[0]).toMatchObject({
|
|
46
|
+
code: RSErrorCode.definitionNotAllowed,
|
|
47
|
+
from: 0,
|
|
48
|
+
to: 2,
|
|
49
|
+
params: [CstType.CONSTANT, 'C1']
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -396,7 +396,8 @@ export function getAnalysisFor(expression: string, cstType: CstType, schema: RSF
|
|
|
396
396
|
{
|
|
397
397
|
code: RSErrorCode.definitionNotAllowed,
|
|
398
398
|
from: 0,
|
|
399
|
-
to: Math.max(
|
|
399
|
+
to: Math.max(expression.length, 1),
|
|
400
|
+
params: [cstType, alias ?? '']
|
|
400
401
|
}
|
|
401
402
|
],
|
|
402
403
|
ast: null
|
package/src/rslang/error.ts
CHANGED
|
@@ -54,9 +54,12 @@ export const RSErrorCode = {
|
|
|
54
54
|
invalidDebool: 0x8809, // 34825
|
|
55
55
|
globalFuncWithoutArgs: 0x880b, // 34827
|
|
56
56
|
invalidReduce: 0x8810, // 34832
|
|
57
|
-
invalidProjectionTuple: 0x8811, // 34833
|
|
58
|
-
invalidProjectionSet: 0x8812, // 34834
|
|
59
57
|
invalidEnumeration: 0x8813, // 34835
|
|
58
|
+
projectionSetArgumentNotSet: 0x8830, // 34864
|
|
59
|
+
projectionSetArgumentNotTupleSet: 0x8831, // 34865
|
|
60
|
+
projectionSetIndexOutOfRange: 0x8832, // 34866
|
|
61
|
+
projectionTupleArgumentNotTuple: 0x8833, // 34867
|
|
62
|
+
projectionTupleIndexOutOfRange: 0x8834, // 34868
|
|
60
63
|
invalidCortegeDeclare: 0x8814, // 34836
|
|
61
64
|
localOutOfScope: 0x8815, // 34837
|
|
62
65
|
invalidElementPredicate: 0x8816, // 34838
|
|
@@ -45,15 +45,65 @@ describe('RSLang analyzer', () => {
|
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it('Expected type', () => {
|
|
48
|
-
expectError(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
expectError(
|
|
49
|
+
'X1',
|
|
50
|
+
{ expected: TypeClass.logic },
|
|
51
|
+
{
|
|
52
|
+
code: RSErrorCode.expectedType,
|
|
53
|
+
from: 0,
|
|
54
|
+
to: 2,
|
|
55
|
+
params: [String(TypeClass.logic), labelType(bool(basic('X1')))]
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
expectError(
|
|
59
|
+
'1=1',
|
|
60
|
+
{ expected: TypeClass.typification },
|
|
61
|
+
{
|
|
62
|
+
code: RSErrorCode.expectedType,
|
|
63
|
+
from: 0,
|
|
64
|
+
to: 3,
|
|
65
|
+
params: [String(TypeClass.typification), 'Logic']
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
expectError(
|
|
69
|
+
'1=1',
|
|
70
|
+
{ expected: TypeClass.function },
|
|
71
|
+
{
|
|
72
|
+
code: RSErrorCode.expectedType,
|
|
73
|
+
from: 0,
|
|
74
|
+
to: 3,
|
|
75
|
+
params: [String(TypeClass.function), 'Logic']
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
expectError(
|
|
79
|
+
'[a ∈ X1] a=a',
|
|
80
|
+
{ expected: TypeClass.function },
|
|
81
|
+
{
|
|
82
|
+
code: RSErrorCode.expectedType,
|
|
83
|
+
from: 0,
|
|
84
|
+
to: 12,
|
|
85
|
+
params: [String(TypeClass.function), '[X1] → Logic']
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
expectError(
|
|
89
|
+
'[a ∈ X1] a',
|
|
90
|
+
{ expected: TypeClass.predicate },
|
|
91
|
+
{
|
|
92
|
+
code: RSErrorCode.expectedType,
|
|
93
|
+
from: 0,
|
|
94
|
+
to: 10,
|
|
95
|
+
params: [String(TypeClass.predicate), '[X1] → X1']
|
|
96
|
+
}
|
|
97
|
+
);
|
|
53
98
|
});
|
|
54
99
|
|
|
55
100
|
it('Reports analyzer-level ranges for whole-expression errors', () => {
|
|
56
101
|
const result = analyzer.checkFull('X1', { expected: TypeClass.logic });
|
|
57
|
-
expect(result.errors[0]).toMatchObject({
|
|
102
|
+
expect(result.errors[0]).toMatchObject({
|
|
103
|
+
code: RSErrorCode.expectedType,
|
|
104
|
+
from: 0,
|
|
105
|
+
to: 2,
|
|
106
|
+
params: [String(TypeClass.logic), labelType(bool(basic('X1')))]
|
|
107
|
+
});
|
|
58
108
|
});
|
|
59
109
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type AstNode, buildTree } from '../../parsing';
|
|
2
2
|
import { annotateError } from '../ast-annotations';
|
|
3
3
|
import { RSErrorCode, type RSErrorDescription } from '../error';
|
|
4
|
+
import { labelType } from '../labels';
|
|
4
5
|
import { normalizeAST } from '../parser/normalize';
|
|
5
6
|
import { parser as rslangParser } from '../parser/parser';
|
|
6
7
|
import { extractSyntaxErrors } from '../parser/syntax-errors';
|
|
@@ -136,13 +137,15 @@ export class RSLangAnalyzer {
|
|
|
136
137
|
return { success: true, type: debool(type), valueClass: ValueClass.VALUE, errors, ast };
|
|
137
138
|
}
|
|
138
139
|
if (options?.expected && getTypeClass(type.typeID) !== options.expected) {
|
|
140
|
+
const errorParams = [String(options.expected), labelType(type)];
|
|
139
141
|
reporter({
|
|
140
142
|
code: RSErrorCode.expectedType,
|
|
141
143
|
from: ast.from,
|
|
142
|
-
to: ast.to
|
|
144
|
+
to: ast.to,
|
|
145
|
+
params: errorParams
|
|
143
146
|
});
|
|
144
147
|
if (options?.annotateErrors) {
|
|
145
|
-
annotateError(ast, RSErrorCode.expectedType);
|
|
148
|
+
annotateError(ast, RSErrorCode.expectedType, errorParams);
|
|
146
149
|
}
|
|
147
150
|
return { success: false, type: null, valueClass: null, errors, ast };
|
|
148
151
|
}
|
|
@@ -185,6 +185,7 @@ const errorData = [
|
|
|
185
185
|
['∀a∈X1 a=a & a=a', { code: RSErrorCode.localOutOfScopeParentheses, from: 12, to: 13, params: ['a'] }],
|
|
186
186
|
['∀a∈X1 a=a & debool(X1)=a', { code: RSErrorCode.localOutOfScopeParentheses, from: 23, to: 24, params: ['a'] }],
|
|
187
187
|
['∀ξ∈X1 ξ=ξ & ∀φ∈X1 φ=ξ', { code: RSErrorCode.localUndeclaredInSubexpr, from: 20, to: 21, params: ['ξ', 'X1'] }],
|
|
188
|
+
['∀ξ∈X1 ξ=ξ & (ξ=ξ & ∀φ∈X1 φ=φ)', { code: RSErrorCode.localOutOfScopeParentheses, from: 13, to: 14, params: ['ξ'] }],
|
|
188
189
|
['D{t∈X1 | t=t} ∪ {t}', { code: RSErrorCode.localOutOfScope, from: 17, to: 18, params: ['t'] }],
|
|
189
190
|
// Set predicates
|
|
190
191
|
['X1∈X1', { code: RSErrorCode.invalidElementPredicate, from: 0, to: 5, params: ['ℬ(X1)', '∈', 'ℬ(X1)'] }],
|
|
@@ -213,13 +214,22 @@ const errorData = [
|
|
|
213
214
|
['X1 ∪ ∅', { code: RSErrorCode.invalidEmptySetUsage, from: 5, to: 6 }],
|
|
214
215
|
['X1 ∪ S1', { code: RSErrorCode.typesNotEqual, from: 0, to: 7, params: ['ℬ(X1)', 'ℬ(X1×X1)', '∪'] }],
|
|
215
216
|
['S1 ∪ X1', { code: RSErrorCode.typesNotEqual, from: 0, to: 7, params: ['ℬ(X1×X1)', 'ℬ(X1)', '∪'] }],
|
|
216
|
-
['Pr1(X1)', { code: RSErrorCode.
|
|
217
|
-
[
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
[
|
|
222
|
-
|
|
217
|
+
['Pr1(X1)', { code: RSErrorCode.projectionSetArgumentNotTupleSet, from: 4, to: 6, params: ['Pr1', 'ℬ(X1)'] }],
|
|
218
|
+
[
|
|
219
|
+
'Pr3(S1)',
|
|
220
|
+
{ code: RSErrorCode.projectionSetIndexOutOfRange, from: 4, to: 6, params: ['Pr3', '3', '2', 'ℬ(X1×X1)'] }
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
'Pr1,3(S1)',
|
|
224
|
+
{ code: RSErrorCode.projectionSetIndexOutOfRange, from: 6, to: 8, params: ['Pr1,3', '3', '2', 'ℬ(X1×X1)'] }
|
|
225
|
+
],
|
|
226
|
+
['Pr1((1,2))', { code: RSErrorCode.projectionSetArgumentNotSet, from: 4, to: 9, params: ['Pr1', 'Z×Z'] }],
|
|
227
|
+
['pr1(X1)', { code: RSErrorCode.projectionTupleArgumentNotTuple, from: 4, to: 6, params: ['pr1', 'ℬ(X1)'] }],
|
|
228
|
+
['pr1(debool(X1))', { code: RSErrorCode.projectionTupleArgumentNotTuple, from: 4, to: 14, params: ['pr1', 'X1'] }],
|
|
229
|
+
[
|
|
230
|
+
'pr3(debool(S1))',
|
|
231
|
+
{ code: RSErrorCode.projectionTupleIndexOutOfRange, from: 4, to: 14, params: ['pr3', '3', '2', 'X1×X1'] }
|
|
232
|
+
],
|
|
223
233
|
[
|
|
224
234
|
'Fi1[X1](ℬ(X1))',
|
|
225
235
|
{ code: RSErrorCode.invalidFilterArgumentType, from: 8, to: 13, params: ['Fi1', 'ℬℬ(X1)', 'ℬ(R0)'] }
|
|
@@ -673,18 +673,21 @@ export class TypeAuditor {
|
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
private visitProjectSet(node: AstNode): ExpressionType | null {
|
|
676
|
-
const
|
|
677
|
-
|
|
676
|
+
const operator = labelRSLangNode(node);
|
|
677
|
+
const argNode = node.children[0];
|
|
678
|
+
const argType = this.childTypification(node, 0);
|
|
679
|
+
if (argType === null) {
|
|
678
680
|
return null;
|
|
679
681
|
}
|
|
680
|
-
if (
|
|
682
|
+
if (argType.typeID === TypeID.anyTypification) {
|
|
681
683
|
return EmptySetT;
|
|
682
684
|
}
|
|
685
|
+
if (argType.typeID !== TypeID.collection) {
|
|
686
|
+
return this.onError(RSErrorCode.projectionSetArgumentNotSet, argNode, [operator, labelType(argType)]);
|
|
687
|
+
}
|
|
688
|
+
const argument = debool(argType);
|
|
683
689
|
if (argument.typeID !== TypeID.tuple) {
|
|
684
|
-
return this.onError(RSErrorCode.
|
|
685
|
-
labelRSLangNode(node),
|
|
686
|
-
labelType(bool(argument))
|
|
687
|
-
]);
|
|
690
|
+
return this.onError(RSErrorCode.projectionSetArgumentNotTupleSet, argNode, [operator, labelType(bool(argument))]);
|
|
688
691
|
}
|
|
689
692
|
|
|
690
693
|
const indices = getNodeIndices(node);
|
|
@@ -692,8 +695,10 @@ export class TypeAuditor {
|
|
|
692
695
|
for (const index of indices) {
|
|
693
696
|
const newComponent = component(argument, index);
|
|
694
697
|
if (newComponent === null) {
|
|
695
|
-
return this.onError(RSErrorCode.
|
|
696
|
-
|
|
698
|
+
return this.onError(RSErrorCode.projectionSetIndexOutOfRange, argNode, [
|
|
699
|
+
operator,
|
|
700
|
+
String(index),
|
|
701
|
+
String(argument.factors.length),
|
|
697
702
|
labelType(bool(argument))
|
|
698
703
|
]);
|
|
699
704
|
} else {
|
|
@@ -708,6 +713,8 @@ export class TypeAuditor {
|
|
|
708
713
|
}
|
|
709
714
|
|
|
710
715
|
private visitProjectTuple(node: AstNode): ExpressionType | null {
|
|
716
|
+
const operator = labelRSLangNode(node);
|
|
717
|
+
const argNode = node.children[0];
|
|
711
718
|
const argument = this.childTypification(node, 0);
|
|
712
719
|
if (argument === null) {
|
|
713
720
|
return null;
|
|
@@ -716,10 +723,7 @@ export class TypeAuditor {
|
|
|
716
723
|
return argument;
|
|
717
724
|
}
|
|
718
725
|
if (argument.typeID !== TypeID.tuple) {
|
|
719
|
-
return this.onError(RSErrorCode.
|
|
720
|
-
labelRSLangNode(node),
|
|
721
|
-
labelType(argument)
|
|
722
|
-
]);
|
|
726
|
+
return this.onError(RSErrorCode.projectionTupleArgumentNotTuple, argNode, [operator, labelType(argument)]);
|
|
723
727
|
}
|
|
724
728
|
|
|
725
729
|
const indices = getNodeIndices(node);
|
|
@@ -727,8 +731,10 @@ export class TypeAuditor {
|
|
|
727
731
|
for (const index of indices) {
|
|
728
732
|
const newComponent = component(argument, index);
|
|
729
733
|
if (newComponent === null) {
|
|
730
|
-
return this.onError(RSErrorCode.
|
|
731
|
-
|
|
734
|
+
return this.onError(RSErrorCode.projectionTupleIndexOutOfRange, argNode, [
|
|
735
|
+
operator,
|
|
736
|
+
String(index),
|
|
737
|
+
String(argument.factors.length),
|
|
732
738
|
labelType(argument)
|
|
733
739
|
]);
|
|
734
740
|
} else {
|
|
@@ -1080,14 +1086,17 @@ function isQuantifierNode(typeID: number): boolean {
|
|
|
1080
1086
|
return typeID === TokenID.QUANTOR_UNIVERSAL || typeID === TokenID.QUANTOR_EXISTS;
|
|
1081
1087
|
}
|
|
1082
1088
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
if (subtreeContainsQuantifier(child)) {
|
|
1089
|
+
/** Quantifier on the path from `node` up through `stopAt` (inclusive). */
|
|
1090
|
+
function pathContainsQuantifier(node: AstNode, stopAt: AstNode): boolean {
|
|
1091
|
+
let current: AstNode | null = node;
|
|
1092
|
+
while (current !== null) {
|
|
1093
|
+
if (isQuantifierNode(current.typeID)) {
|
|
1089
1094
|
return true;
|
|
1090
1095
|
}
|
|
1096
|
+
if (current === stopAt) {
|
|
1097
|
+
return false;
|
|
1098
|
+
}
|
|
1099
|
+
current = current.parent;
|
|
1091
1100
|
}
|
|
1092
1101
|
return false;
|
|
1093
1102
|
}
|
|
@@ -1167,7 +1176,7 @@ class LocalContext {
|
|
|
1167
1176
|
} else if (local.level < 1) {
|
|
1168
1177
|
const subexprRoot = findRightLogicOperandRoot(node);
|
|
1169
1178
|
if (subexprRoot !== null) {
|
|
1170
|
-
if (
|
|
1179
|
+
if (pathContainsQuantifier(node, subexprRoot)) {
|
|
1171
1180
|
return this.onError(RSErrorCode.localUndeclaredInSubexpr, node, [alias, labelType(local.type)]);
|
|
1172
1181
|
}
|
|
1173
1182
|
return this.onError(RSErrorCode.localOutOfScopeParentheses, node, [alias]);
|