@rsconcept/domain 1.8.1 → 2.0.2

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.
Files changed (43) hide show
  1. package/dist/diagnostics-Clo3mkba.d.ts +279 -0
  2. package/dist/diagnostics-D7SiHAwW.js +518 -0
  3. package/dist/diagnostics-D7SiHAwW.js.map +1 -0
  4. package/dist/index.d.ts +6 -7
  5. package/dist/index.js +7 -6
  6. package/dist/library/diagnostics.d.ts +2 -0
  7. package/dist/library/diagnostics.js +2 -0
  8. package/dist/library/index.d.ts +3 -4
  9. package/dist/library/index.js +5 -5
  10. package/dist/library/oss-api.d.ts +1 -1
  11. package/dist/library/oss-api.js +1 -1
  12. package/dist/library/rsengine.d.ts +1 -2
  13. package/dist/library/rsengine.js +1 -1
  14. package/dist/library/rsform-api.d.ts +2 -2
  15. package/dist/library/rsform-api.js +1 -404
  16. package/dist/library/rsform.d.ts +2 -198
  17. package/dist/library/rsform.js.map +1 -1
  18. package/dist/library/rsmodel-api.d.ts +1 -2
  19. package/dist/library/rsmodel-api.js +2 -4
  20. package/dist/library/rsmodel-api.js.map +1 -1
  21. package/dist/library/rsmodel.d.ts +2 -46
  22. package/dist/library/structure-planner.d.ts +1 -1
  23. package/dist/library/structure-planner.js +1 -1
  24. package/dist/rslang/eval/evaluator.js +2 -2
  25. package/dist/rslang/index.js +2 -2
  26. package/dist/rslang/parser/syntax-errors/index.js +1 -1
  27. package/dist/rslang/semantic/analyzer.js +3 -3
  28. package/dist/rslang/semantic/arguments-extractor.js +1 -1
  29. package/dist/rslang/semantic/type-auditor.js +2 -2
  30. package/dist/rslang/semantic/value-auditor.js +2 -2
  31. package/dist/{syntax-errors-B6c2vsan.js → syntax-errors-D_VV5hAM.js} +3 -3
  32. package/dist/{syntax-errors-B6c2vsan.js.map → syntax-errors-D_VV5hAM.js.map} +1 -1
  33. package/package.json +5 -1
  34. package/src/index.ts +8 -0
  35. package/src/library/diagnostics.test.ts +85 -0
  36. package/src/library/diagnostics.ts +182 -0
  37. package/src/library/index.ts +8 -0
  38. package/src/library/oss-api.test.ts +1 -2
  39. package/src/library/rsform-api.ts +12 -17
  40. package/src/library/rsform.ts +4 -2
  41. package/src/library/rsmodel-api.ts +2 -8
  42. package/src/library/template-instantiation.test.ts +1 -2
  43. package/dist/library/rsform-api.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,14 +1,11 @@
1
1
  import { Grammeme, ReferenceType, supportedGrammemes } from "./cctext/language.js";
2
2
  import { Graph } from "./graph/graph.js";
3
- import { FolderNode, FolderTree } from "./library/folder-tree.js";
4
- import { AccessPolicy, LibraryItemType, LocationHead } from "./library/library.js";
5
- import { NodeType, OperationType, SubstitutionErrorType } from "./library/oss.js";
6
- import { readErrorAnnotation, readTypeAnnotation } from "./rslang/ast-annotations.js";
7
- import { RSErrorCode } from "./rslang/error.js";
8
3
  import { TOKEN_ERROR, buildTree, findByUid, flattenAst, getNodeIndices, getNodeText, printAst, visitAstDFS } from "./parsing/ast.js";
9
4
  import { printTree } from "./parsing/lezer-tree.js";
10
5
  import { TokenID } from "./rslang/parser/token.js";
11
6
  import { AnyTypificationT, EmptySetT, LogicT, TypeClass, TypeID, makeTypePath } from "./rslang/semantic/typification.js";
7
+ import { readErrorAnnotation, readTypeAnnotation } from "./rslang/ast-annotations.js";
8
+ import { RSErrorCode } from "./rslang/error.js";
12
9
  import { applyHash_fnv1a, generateStub } from "./shared/hash.js";
13
10
  import { C as printValue, o as TUPLE_ID, u as makeValuePath } from "./value-COprb2Je.js";
14
11
  import { RSCalculator } from "./rslang/eval/calculator.js";
@@ -18,6 +15,10 @@ import { RSLangAnalyzer } from "./rslang/semantic/analyzer.js";
18
15
  import { applyAsciiTypeSubstitutions, parseTypeText } from "./rslang/semantic/typification-parser.js";
19
16
  import { TypificationGraph } from "./rslang/typification-graph.js";
20
17
  import { CstClass, CstStatus, CstType } from "./library/rsform.js";
18
+ import { a as modelStatusCstDiagnostic, i as hasCstDiagnostic, n as RSDiagnosticCode, r as assignSchemaDiagnostics, t as DiagnosticKind } from "./diagnostics-D7SiHAwW.js";
21
19
  import { DEFAULT_VALUE_TEXT, EvalStatus } from "./library/rsmodel.js";
20
+ import { FolderNode, FolderTree } from "./library/folder-tree.js";
21
+ import { AccessPolicy, LibraryItemType, LocationHead } from "./library/library.js";
22
+ import { NodeType, OperationType, SubstitutionErrorType } from "./library/oss.js";
22
23
  import { RSEngine } from "./library/rsengine.js";
23
- export { AccessPolicy, AnyTypificationT, CstClass, CstStatus, CstType, DEFAULT_VALUE_TEXT, EmptySetT, EvalStatus, FolderNode, FolderTree, Grammeme, Graph, LibraryItemType, LocationHead, LogicT, NodeType, OperationType, RSCalculator, RSEngine, RSErrorCode, RSLangAnalyzer, ReferenceType, SubstitutionErrorType, TOKEN_ERROR, TUPLE_ID, TokenID, TypeClass, TypeID, TypificationGraph, ValueClass, applyAsciiTypeSubstitutions, applyHash_fnv1a, buildTree, findByUid, flattenAst, generateStub, getNodeIndices, getNodeText, makeTypePath, makeValuePath, parseTypeText, printAst, printTree, printValue, readErrorAnnotation, readTypeAnnotation, parser as rslangParser, supportedGrammemes, visitAstDFS };
24
+ export { AccessPolicy, AnyTypificationT, CstClass, CstStatus, CstType, DEFAULT_VALUE_TEXT, DiagnosticKind, EmptySetT, EvalStatus, FolderNode, FolderTree, Grammeme, Graph, LibraryItemType, LocationHead, LogicT, NodeType, OperationType, RSCalculator, RSDiagnosticCode, RSEngine, RSErrorCode, RSLangAnalyzer, ReferenceType, SubstitutionErrorType, TOKEN_ERROR, TUPLE_ID, TokenID, TypeClass, TypeID, TypificationGraph, ValueClass, applyAsciiTypeSubstitutions, applyHash_fnv1a, assignSchemaDiagnostics, buildTree, findByUid, flattenAst, generateStub, getNodeIndices, getNodeText, hasCstDiagnostic, makeTypePath, makeValuePath, modelStatusCstDiagnostic, parseTypeText, printAst, printTree, printValue, readErrorAnnotation, readTypeAnnotation, parser as rslangParser, supportedGrammemes, visitAstDFS };
@@ -0,0 +1,2 @@
1
+ import { a as hasCstDiagnostic, i as assignSchemaDiagnostics, n as DiagnosticKind, o as modelStatusCstDiagnostic, r as RSDiagnosticCode, t as CstDiagnostic } from "../diagnostics-Clo3mkba.js";
2
+ export { CstDiagnostic, DiagnosticKind, RSDiagnosticCode, assignSchemaDiagnostics, hasCstDiagnostic, modelStatusCstDiagnostic };
@@ -0,0 +1,2 @@
1
+ import { a as modelStatusCstDiagnostic, i as hasCstDiagnostic, n as RSDiagnosticCode, r as assignSchemaDiagnostics, t as DiagnosticKind } from "../diagnostics-D7SiHAwW.js";
2
+ export { DiagnosticKind, RSDiagnosticCode, assignSchemaDiagnostics, hasCstDiagnostic, modelStatusCstDiagnostic };
@@ -1,9 +1,8 @@
1
- import { FolderNode, FolderTree } from "./folder-tree.js";
2
1
  import { a as LibraryItemType, i as LibraryItemReference, n as CurrentVersion, o as LocationHead, r as LibraryItem, s as VersionInfo, t as AccessPolicy } from "../library-CYun28Xz.js";
2
+ import { C as TypeInfo, S as Substitution, _ as CstClass, a as hasCstDiagnostic, b as RSForm, c as BasicsContext, d as RSModel, f as RSModelStats, g as Constituenta, h as Attribution, i as assignSchemaDiagnostics, l as DEFAULT_VALUE_TEXT, m as ArgumentValue, n as DiagnosticKind, o as modelStatusCstDiagnostic, r as RSDiagnosticCode, s as BasicBinding, t as CstDiagnostic, u as EvalStatus, v as CstStatus, x as RSFormStats, y as CstType } from "../diagnostics-Clo3mkba.js";
3
+ import { FolderNode, FolderTree } from "./folder-tree.js";
3
4
  import { n as OssLayout, r as Position2D } from "../oss-layout-3glgAqfn.js";
4
5
  import { Block, CstSubstituteInfo, NodeType, Operation, OperationInput, OperationSchema, OperationSchemaStats, OperationSynthesis, OperationType, OssItem, SubstitutionErrorDescription, SubstitutionErrorType } from "./oss.js";
5
- import { ArgumentValue, Attribution, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats, Substitution, TypeInfo } from "./rsform.js";
6
- import { BasicBinding, BasicsContext, DEFAULT_VALUE_TEXT, EvalStatus, RSModel, RSModelStats } from "./rsmodel.js";
7
6
  import { RSEngine } from "./rsengine.js";
8
7
 
9
8
  //#region src/library/template-instantiation.d.ts
@@ -100,5 +99,5 @@ declare class TemplateInstantiationPlanner {
100
99
  private collectDependencies;
101
100
  }
102
101
  //#endregion
103
- export { AccessPolicy, type ArgumentValue, type Attribution, type BasicBinding, type BasicsContext, type Block, type Constituenta, CstClass, CstStatus, type CstSubstituteInfo, CstType, type CurrentVersion, DEFAULT_VALUE_TEXT, EvalStatus, FolderNode, FolderTree, type LibraryItem, type LibraryItemReference, LibraryItemType, LocationHead, NodeType, type Operation, type OperationInput, type OperationSchema, type OperationSchemaStats, type OperationSynthesis, OperationType, type OssItem, type OssLayout, type Position2D, RSEngine, type RSForm, type RSFormStats, type RSModel, type RSModelStats, type Substitution, type SubstitutionErrorDescription, SubstitutionErrorType, type TemplateBindingConflict, type TemplateInstantiationInput, type TemplateInstantiationItem, type TemplateInstantiationPlan, TemplateInstantiationPlanner, type TypeInfo, type VersionInfo, planTemplateInstantiation };
102
+ export { AccessPolicy, type ArgumentValue, type Attribution, type BasicBinding, type BasicsContext, type Block, type Constituenta, CstClass, type CstDiagnostic, CstStatus, type CstSubstituteInfo, CstType, type CurrentVersion, DEFAULT_VALUE_TEXT, DiagnosticKind, EvalStatus, FolderNode, FolderTree, type LibraryItem, type LibraryItemReference, LibraryItemType, LocationHead, NodeType, type Operation, type OperationInput, type OperationSchema, type OperationSchemaStats, type OperationSynthesis, OperationType, type OssItem, type OssLayout, type Position2D, RSDiagnosticCode, RSEngine, type RSForm, type RSFormStats, type RSModel, type RSModelStats, type Substitution, type SubstitutionErrorDescription, SubstitutionErrorType, type TemplateBindingConflict, type TemplateInstantiationInput, type TemplateInstantiationItem, type TemplateInstantiationPlan, TemplateInstantiationPlanner, type TypeInfo, type VersionInfo, assignSchemaDiagnostics, hasCstDiagnostic, modelStatusCstDiagnostic, planTemplateInstantiation };
104
103
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,3 @@
1
- import { FolderNode, FolderTree } from "./folder-tree.js";
2
- import { AccessPolicy, LibraryItemType, LocationHead } from "./library.js";
3
- import { NodeType, OperationType, SubstitutionErrorType } from "./oss.js";
4
1
  import { visitAstDFS } from "../parsing/ast.js";
5
2
  import "../parsing/index.js";
6
3
  import { TokenID } from "../rslang/parser/token.js";
@@ -8,8 +5,11 @@ import { TypeID } from "../rslang/semantic/typification.js";
8
5
  import { labelType } from "../rslang/labels.js";
9
6
  import { applyAliasMapping, isGlobalAlias, parseRSLangExpression, splitTemplateDefinition, substituteLocalAliases, substituteTemplateArgs } from "../rslang/api.js";
10
7
  import { CstClass, CstStatus, CstType } from "./rsform.js";
11
- import { applyMappingToConstituents, argumentValuesToMapping, generateAlias, inferTemplatedType, isFunctional, normalizeExpression } from "./rsform-api.js";
8
+ import { D as isFunctional, a as modelStatusCstDiagnostic, c as applyMappingToConstituents, h as generateAlias, i as hasCstDiagnostic, j as normalizeExpression, l as argumentValuesToMapping, n as RSDiagnosticCode, r as assignSchemaDiagnostics, t as DiagnosticKind, w as inferTemplatedType } from "../diagnostics-D7SiHAwW.js";
12
9
  import { DEFAULT_VALUE_TEXT, EvalStatus } from "./rsmodel.js";
10
+ import { FolderNode, FolderTree } from "./folder-tree.js";
11
+ import { AccessPolicy, LibraryItemType, LocationHead } from "./library.js";
12
+ import { NodeType, OperationType, SubstitutionErrorType } from "./oss.js";
13
13
  import { RSEngine } from "./rsengine.js";
14
14
  //#region src/library/template-instantiation.ts
15
15
  /**
@@ -284,6 +284,6 @@ function topologicalSort(aliases, refs) {
284
284
  return sorted;
285
285
  }
286
286
  //#endregion
287
- export { AccessPolicy, CstClass, CstStatus, CstType, DEFAULT_VALUE_TEXT, EvalStatus, FolderNode, FolderTree, LibraryItemType, LocationHead, NodeType, OperationType, RSEngine, SubstitutionErrorType, TemplateInstantiationPlanner, planTemplateInstantiation };
287
+ export { AccessPolicy, CstClass, CstStatus, CstType, DEFAULT_VALUE_TEXT, DiagnosticKind, EvalStatus, FolderNode, FolderTree, LibraryItemType, LocationHead, NodeType, OperationType, RSDiagnosticCode, RSEngine, SubstitutionErrorType, TemplateInstantiationPlanner, assignSchemaDiagnostics, hasCstDiagnostic, modelStatusCstDiagnostic, planTemplateInstantiation };
288
288
 
289
289
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import { r as LibraryItem } from "../library-CYun28Xz.js";
2
+ import { S as Substitution, b as RSForm, g as Constituenta } from "../diagnostics-Clo3mkba.js";
2
3
  import { NodeType, OperationSchema, SubstitutionErrorDescription } from "./oss.js";
3
- import { Constituenta, RSForm, Substitution } from "./rsform.js";
4
4
 
5
5
  //#region src/library/oss-api.d.ts
6
6
  declare function constructNodeID(type: NodeType, itemID: number): string;
@@ -1,9 +1,9 @@
1
1
  import { Graph } from "../graph/graph.js";
2
- import { NodeType, SubstitutionErrorType } from "./oss.js";
3
2
  import { labelType } from "../rslang/labels.js";
4
3
  import { applyAliasMapping, applyTypificationMapping, isSetTypification } from "../rslang/api.js";
5
4
  import { extractBases } from "../rslang/semantic/typification-api.js";
6
5
  import { CstClass, CstType } from "./rsform.js";
6
+ import { NodeType, SubstitutionErrorType } from "./oss.js";
7
7
  import "../graph/index.js";
8
8
  //#region src/library/oss-api.ts
9
9
  /**
@@ -1,8 +1,7 @@
1
1
  import { t as AstNode } from "../ast-C8sIpKdL.js";
2
2
  import { l as Value } from "../value-BduA_ZGp.js";
3
3
  import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "../calculator-k8BGIKmj.js";
4
- import { CstType, RSForm } from "./rsform.js";
5
- import { BasicBinding, BasicsContext, EvalStatus, RSModel } from "./rsmodel.js";
4
+ import { b as RSForm, c as BasicsContext, d as RSModel, s as BasicBinding, u as EvalStatus, y as CstType } from "../diagnostics-Clo3mkba.js";
6
5
 
7
6
  //#region src/library/rsengine.d.ts
8
7
  /** Services for {@link RSEngine}. */
@@ -4,7 +4,7 @@ import { l as compare } from "../value-COprb2Je.js";
4
4
  import { RSCalculator } from "../rslang/eval/calculator.js";
5
5
  import "../rslang/index.js";
6
6
  import { CstType } from "./rsform.js";
7
- import { getAnalysisFor, isBaseSet, isBasicConcept, isFunctional } from "./rsform-api.js";
7
+ import { D as isFunctional, E as isBasicConcept, T as isBaseSet, g as getAnalysisFor } from "../diagnostics-D7SiHAwW.js";
8
8
  import { TYPE_BASIC } from "./rsmodel.js";
9
9
  import { inferEvalStatus, isInferrable, tryFixValue } from "./rsmodel-api.js";
10
10
  //#region src/library/rsengine.ts
@@ -1,9 +1,9 @@
1
- import { r as LibraryItem } from "../library-CYun28Xz.js";
2
1
  import { t as AstNode } from "../ast-C8sIpKdL.js";
3
2
  import { g as TypeClass, y as TypePath } from "../typification-9lNu9R4k.js";
4
3
  import { t as ValueClass } from "../value-class-CNI-lqXJ.js";
5
4
  import { r as AnalysisFull } from "../analyzer-iqAXyROE.js";
6
- import { ArgumentValue, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats } from "./rsform.js";
5
+ import { r as LibraryItem } from "../library-CYun28Xz.js";
6
+ import { _ as CstClass, b as RSForm, g as Constituenta, m as ArgumentValue, v as CstStatus, x as RSFormStats, y as CstType } from "../diagnostics-Clo3mkba.js";
7
7
  import { AliasMapping } from "../rslang/api.js";
8
8
 
9
9
  //#region src/library/rsform-api.d.ts
@@ -1,405 +1,2 @@
1
- import { RSErrorCode } from "../rslang/error.js";
2
- import { TypeClass, TypeID, basic, bool, constant, isTypification } from "../rslang/semantic/typification.js";
3
- import { generateExpressionFromAst } from "../rslang/parser/expression-generator.js";
4
- import { applyAliasMapping, applyTypificationMapping, parseRSLangExpression } from "../rslang/api.js";
5
- import { applyPath } from "../rslang/semantic/typification-api.js";
6
- import { ValueClass } from "../rslang/semantic/value-class.js";
7
- import "../rslang/index.js";
8
- import { CstClass, CstStatus, CstType } from "./rsform.js";
9
- import { applyEntityReferenceMapping } from "../cctext/language-api.js";
10
- //#region src/library/rsform-api.ts
11
- /**
12
- * Module: API for formal representation for systems of concepts.
13
- */
14
- /** Record of {@link CstType} prefixes. */
15
- const CST_TYPE_PREFIX = {
16
- [CstType.NOMINAL]: "N",
17
- [CstType.BASE]: "X",
18
- [CstType.CONSTANT]: "C",
19
- [CstType.STRUCTURED]: "S",
20
- [CstType.AXIOM]: "A",
21
- [CstType.TERM]: "D",
22
- [CstType.FUNCTION]: "F",
23
- [CstType.PREDICATE]: "P",
24
- [CstType.STATEMENT]: "T"
25
- };
26
- /** Record of {@link CstType} to {@link CstClass} mapping. */
27
- const CST_TYPE_TO_CLASS = {
28
- [CstType.NOMINAL]: CstClass.NOMINAL,
29
- [CstType.BASE]: CstClass.BASIC,
30
- [CstType.CONSTANT]: CstClass.BASIC,
31
- [CstType.STRUCTURED]: CstClass.BASIC,
32
- [CstType.TERM]: CstClass.DERIVED,
33
- [CstType.FUNCTION]: CstClass.DERIVED,
34
- [CstType.AXIOM]: CstClass.STATEMENT,
35
- [CstType.PREDICATE]: CstClass.DERIVED,
36
- [CstType.STATEMENT]: CstClass.STATEMENT
37
- };
38
- /** Checks if {@link Constituenta} is a schema issue. */
39
- function isSchemaIssue(cst) {
40
- if (cst.homonyms.length > 0 || cst.formalDuplicates.length > 0 || cst.status === CstStatus.INCORRECT || cst.status === CstStatus.INCALCULABLE || cst.is_type_mismatch) return true;
41
- if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {
42
- if (!cst.convention || !cst.term_resolved) return true;
43
- }
44
- return false;
45
- }
46
- /** Infers the status of an expression based on parsing and value information. */
47
- function inferStatus(parse, value) {
48
- if (!parse) return CstStatus.INCORRECT;
49
- if (value === null) return CstStatus.INCALCULABLE;
50
- if (value === ValueClass.PROPERTY) return CstStatus.PROPERTY;
51
- return CstStatus.VERIFIED;
52
- }
53
- /** Infers type of constituent for a given template and arguments. */
54
- function inferTemplatedType(templateType, args) {
55
- if (args.length === 0 || args.some((arg) => !arg.value)) return templateType;
56
- else if (templateType === CstType.PREDICATE) return CstType.AXIOM;
57
- else return CstType.TERM;
58
- }
59
- /** Build alias mapping from template argument bindings. */
60
- function argumentValuesToMapping(args) {
61
- const mapping = {};
62
- for (const arg of args) if (arg.value) mapping[arg.alias] = arg.value;
63
- return mapping;
64
- }
65
- /**
66
- * Normalize a RSLang expression for duplicate comparison.
67
- *
68
- * Returns `null` for basic concepts without formal definitions. Pass a pre-parsed `ast`
69
- * when the expression was already analyzed to avoid re-parsing.
70
- */
71
- function normalizeExpression(expression, cst_type, ast) {
72
- if (isBasicConcept(cst_type) && cst_type !== CstType.AXIOM) return null;
73
- const parsed = ast ?? parseRSLangExpression(expression);
74
- let normalized = "";
75
- if (parsed && !parsed.hasError) normalized = generateExpressionFromAst(parsed, { normalize: true });
76
- else normalized = expression;
77
- normalized = normalized.replace(/\s+/g, "");
78
- return normalized === "" ? null : normalized;
79
- }
80
- /** Checks if given expression is a template. */
81
- function inferTemplate(expression) {
82
- const match = expression.match(/R\d+/g);
83
- return (match && match?.length > 0) ?? false;
84
- }
85
- /** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */
86
- function inferClass(type, isTemplate = false) {
87
- if (isTemplate) return CstClass.TEMPLATE;
88
- return CST_TYPE_TO_CLASS[type];
89
- }
90
- /** Check if {@link Constituenta} is a template or a category. */
91
- function isTemplateCst(cst) {
92
- return cst.cst_type === CstType.FUNCTION || cst.cst_type === CstType.PREDICATE || cst.cst_type === CstType.STATEMENT;
93
- }
94
- /** Apply filter based on start {@link Constituenta} type. */
95
- function applyFilterCategory(start, items) {
96
- const startIndex = items.indexOf(start);
97
- if (startIndex === -1) return [];
98
- const nextCategoryIndex = items.findIndex((cst, index) => index > startIndex && cst.cst_type === CstType.STATEMENT);
99
- return items.filter((_, index) => index >= startIndex && (nextCategoryIndex === -1 || index < nextCategoryIndex));
100
- }
101
- /** Prefix for alias indicating {@link CstType}. */
102
- function getCstTypePrefix(type) {
103
- return CST_TYPE_PREFIX[type];
104
- }
105
- /** Guess {@link CstType} from user input hint. */
106
- function guessCstType(hint) {
107
- if (hint.length !== 1) return null;
108
- for (const [type, prefix] of Object.entries(CST_TYPE_PREFIX)) if (hint === prefix) return type;
109
- return null;
110
- }
111
- /** Evaluate if {@link CstType} is basic concept. */
112
- function isBasicConcept(type) {
113
- switch (type) {
114
- case CstType.NOMINAL:
115
- case CstType.BASE:
116
- case CstType.CONSTANT:
117
- case CstType.STRUCTURED:
118
- case CstType.AXIOM: return true;
119
- case CstType.TERM:
120
- case CstType.FUNCTION:
121
- case CstType.PREDICATE:
122
- case CstType.STATEMENT: return false;
123
- }
124
- }
125
- /** Evaluate if {@link CstType} is base set or constant set. */
126
- function isBaseSet(type) {
127
- switch (type) {
128
- case CstType.BASE:
129
- case CstType.CONSTANT: return true;
130
- case CstType.NOMINAL:
131
- case CstType.STRUCTURED:
132
- case CstType.AXIOM:
133
- case CstType.TERM:
134
- case CstType.FUNCTION:
135
- case CstType.PREDICATE:
136
- case CstType.STATEMENT: return false;
137
- }
138
- }
139
- /** Evaluate if {@link CstType} is a function. */
140
- function isFunctional(type) {
141
- switch (type) {
142
- case CstType.FUNCTION:
143
- case CstType.PREDICATE: return true;
144
- case CstType.NOMINAL:
145
- case CstType.BASE:
146
- case CstType.CONSTANT:
147
- case CstType.STRUCTURED:
148
- case CstType.AXIOM:
149
- case CstType.TERM:
150
- case CstType.STATEMENT: return false;
151
- }
152
- }
153
- /** Evaluate if {@link CstType} is logical. */
154
- function isLogical(type) {
155
- switch (type) {
156
- case CstType.AXIOM:
157
- case CstType.STATEMENT: return true;
158
- case CstType.NOMINAL:
159
- case CstType.BASE:
160
- case CstType.CONSTANT:
161
- case CstType.STRUCTURED:
162
- case CstType.TERM:
163
- case CstType.FUNCTION:
164
- case CstType.PREDICATE: return false;
165
- }
166
- }
167
- /** Evaluate if {@link Constituenta} can be used produce structure. */
168
- function canProduceStructure(cst) {
169
- switch (cst.cst_type) {
170
- case CstType.NOMINAL:
171
- case CstType.BASE:
172
- case CstType.CONSTANT:
173
- case CstType.AXIOM:
174
- case CstType.STATEMENT:
175
- case CstType.PREDICATE: return false;
176
- }
177
- if (!cst.effectiveType) return false;
178
- if (cst.cst_type === CstType.FUNCTION) {
179
- const result = cst.effectiveType.result;
180
- return typeCanProduceStructure(result);
181
- }
182
- if (!isTypification(cst.effectiveType)) return false;
183
- return typeCanProduceStructure(cst.effectiveType);
184
- }
185
- /** Evaluate if {@link CstType} can have manual typification. */
186
- function canHaveManualTypification(type) {
187
- switch (type) {
188
- case CstType.STRUCTURED:
189
- case CstType.TERM:
190
- case CstType.FUNCTION:
191
- case CstType.PREDICATE: return true;
192
- case CstType.NOMINAL:
193
- case CstType.BASE:
194
- case CstType.CONSTANT:
195
- case CstType.AXIOM:
196
- case CstType.STATEMENT: return false;
197
- }
198
- }
199
- /** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */
200
- function validateAliasFormat(alias, type) {
201
- if (alias.length < 2) return false;
202
- const prefix = getCstTypePrefix(type);
203
- if (!alias.startsWith(prefix)) return false;
204
- if (!/^\d+$/.exec(alias.substring(prefix.length))) return false;
205
- return true;
206
- }
207
- /** Validate new alias against {@link CstType} and {@link RSForm}. */
208
- function validateNewAlias(alias, type, schema) {
209
- if (!validateAliasFormat(alias, type)) return false;
210
- if (schema.cstByAlias.has(alias)) return false;
211
- return true;
212
- }
213
- /** Generate alias for new {@link Constituenta} of a given {@link CstType} for current {@link RSForm}. */
214
- function generateAlias(type, schema, takenAliases = []) {
215
- const prefix = getCstTypePrefix(type);
216
- if (schema.items.length <= 0) return `${prefix}1`;
217
- let index = schema.items.reduce((prev, cst, index) => {
218
- if (cst.cst_type !== type) return prev;
219
- index = Number(cst.alias.slice(1 - cst.alias.length)) + 1;
220
- return Math.max(prev, index);
221
- }, 1);
222
- let alias = `${prefix}${index}`;
223
- while (takenAliases.includes(alias)) {
224
- index = index + 1;
225
- alias = `${prefix}${index}`;
226
- }
227
- return alias;
228
- }
229
- /**
230
- * Id to pass as `insert_after` when creating a new {@link Constituenta} spawned by `targetId`:
231
- * after the last existing child of that spawner, or after the spawner itself if none.
232
- */
233
- function inferNewSpawnPosition(schema, targetId) {
234
- let last = null;
235
- for (const cst of schema.items) if (cst.spawner === targetId) last = cst.id;
236
- return last ?? targetId;
237
- }
238
- /** Sorts library items relevant for InlineSynthesis with specified {@link RSForm}. */
239
- function sortItemsForInlineSynthesis(receiver, items) {
240
- const result = items.filter((item) => item.location === receiver.location);
241
- for (const item of items) if (item.visible && item.owner === item.owner && !result.includes(item)) result.push(item);
242
- for (const item of items) if (item.visible && !result.includes(item)) result.push(item);
243
- for (const item of items) if (!result.includes(item)) result.push(item);
244
- return result;
245
- }
246
- /**
247
- * Remap formal expressions and terminological entity references in constituent fields.
248
- * Mutates each element of `items` in place; pass owned or cloned data only.
249
- */
250
- function applyMappingToConstituents(items, mapping, changeAliases) {
251
- for (const cst of items) {
252
- if (changeAliases && cst.alias in mapping) cst.alias = mapping[cst.alias];
253
- cst.definition_formal = applyAliasMapping(cst.definition_formal, mapping);
254
- cst.typification_manual = applyTypificationMapping(cst.typification_manual, mapping);
255
- cst.term_raw = applyEntityReferenceMapping(cst.term_raw, mapping);
256
- cst.definition_raw = applyEntityReferenceMapping(cst.definition_raw, mapping);
257
- }
258
- }
259
- /** Remove alias from expression. */
260
- function removeAliasReference(expression, alias) {
261
- const result = expression.replaceAll(new RegExp(`\\b${alias}\\b`, "g"), "DEL");
262
- return result === "DEL" ? "" : result;
263
- }
264
- /** Add alias to expression. */
265
- function addAliasReference(expression, alias) {
266
- return expression + " " + alias;
267
- }
268
- /** Returns expected {@link TypeClass} of formal definition for {@link CstType}. */
269
- function typeClassForCstType(cstType) {
270
- switch (cstType) {
271
- case CstType.NOMINAL:
272
- case CstType.BASE:
273
- case CstType.CONSTANT:
274
- case CstType.STRUCTURED:
275
- case CstType.TERM: return TypeClass.typification;
276
- case CstType.FUNCTION: return TypeClass.function;
277
- case CstType.PREDICATE: return TypeClass.predicate;
278
- case CstType.AXIOM:
279
- case CstType.STATEMENT: return TypeClass.logic;
280
- }
281
- }
282
- /** Checks whether a constituenta type supports formal definitions. */
283
- function canHaveFormalDefinition(cstType) {
284
- return cstType !== CstType.BASE && cstType !== CstType.CONSTANT;
285
- }
286
- /** Analyze expression for {@link RSForm}. */
287
- function getAnalysisFor(expression, cstType, schema, alias) {
288
- if (!canHaveFormalDefinition(cstType)) {
289
- if (expression.trim().length === 0) {
290
- const fallbackAlias = alias && alias.length > 0 ? alias : "X0";
291
- return {
292
- success: true,
293
- type: cstType === CstType.BASE ? bool(basic(fallbackAlias)) : bool(constant(fallbackAlias)),
294
- valueClass: ValueClass.VALUE,
295
- errors: [],
296
- ast: null
297
- };
298
- }
299
- return {
300
- success: false,
301
- type: null,
302
- valueClass: null,
303
- errors: [{
304
- code: RSErrorCode.definitionNotAllowed,
305
- from: 0,
306
- to: Math.max(expression.length, 1),
307
- params: [cstType, alias ?? ""]
308
- }],
309
- ast: null
310
- };
311
- }
312
- return schema.analyzer.checkFull(expression, {
313
- expected: typeClassForCstType(cstType),
314
- isDomain: cstType === CstType.STRUCTURED
315
- });
316
- }
317
- /** Calculate statistics for {@link RSForm}. */
318
- function calculateSchemaStats(target) {
319
- const items = target.items;
320
- return {
321
- count_all: items.length,
322
- count_crucial: items.reduce((sum, cst) => sum + (cst.crucial ? 1 : 0), 0),
323
- step_complexity: items.reduce((sum, cst) => sum + calculateStepComplexity(cst), 0),
324
- count_problematic: items.reduce((sum, cst) => sum + (isSchemaIssue(cst) ? 1 : 0), 0),
325
- count_homonyms: items.reduce((sum, cst) => sum + (cst.homonyms.length > 0 ? 1 : 0), 0),
326
- count_formal_duplicates: items.reduce((sum, cst) => sum + (cst.formalDuplicates.length > 0 ? 1 : 0), 0),
327
- count_missing_convention: items.reduce((sum, cst) => sum + (isMissingConvention(cst) ? 1 : 0), 0),
328
- count_type_mismatch: items.reduce((sum, cst) => sum + (cst.is_type_mismatch ? 1 : 0), 0),
329
- count_incorrect: items.reduce((sum, cst) => sum + (cst.status === CstStatus.INCORRECT ? 1 : 0), 0),
330
- count_property: items.reduce((sum, cst) => sum + (cst.analysis?.valueClass === ValueClass.PROPERTY ? 1 : 0), 0),
331
- count_incalculable: items.reduce((sum, cst) => sum + (cst.analysis?.success && cst.analysis.valueClass === null ? 1 : 0), 0),
332
- count_inherited: items.reduce((sum, cst) => sum + (cst.is_inherited ? 1 : 0), 0),
333
- count_text_term: items.reduce((sum, cst) => sum + (cst.term_raw ? 1 : 0), 0),
334
- count_definition: items.reduce((sum, cst) => sum + (cst.definition_raw ? 1 : 0), 0),
335
- count_convention: items.reduce((sum, cst) => sum + (isBasicConcept(cst.cst_type) && cst.convention ? 1 : 0), 0),
336
- count_comment: items.reduce((sum, cst) => sum + (!isBasicConcept(cst.cst_type) && !cst.convention ? 1 : 0), 0),
337
- count_base: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.BASE ? 1 : 0), 0),
338
- count_constant: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.CONSTANT ? 1 : 0), 0),
339
- count_structured: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STRUCTURED ? 1 : 0), 0),
340
- count_axiom: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.AXIOM ? 1 : 0), 0),
341
- count_term: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.TERM ? 1 : 0), 0),
342
- count_function: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.FUNCTION ? 1 : 0), 0),
343
- count_predicate: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.PREDICATE ? 1 : 0), 0),
344
- count_statement: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STATEMENT ? 1 : 0), 0),
345
- count_nominal: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.NOMINAL ? 1 : 0), 0)
346
- };
347
- }
348
- /** Finds {@link Constituenta} by structure path. */
349
- function findCstByStructure(schema, target, path) {
350
- for (const cst of schema.items) if (cst.spawner === target.id && cst.spawner_path) {
351
- if (cst.spawner_path.length === path.length && cst.spawner_path.every((v, i) => v === path[i])) return cst;
352
- }
353
- return null;
354
- }
355
- /** Retrieves name for piece of target {@link Constituenta} structure. */
356
- function getStructureName(schema, target, path) {
357
- const representation = findCstByStructure(schema, target, path);
358
- if (representation) return `${representation.alias}: ${representation.term_resolved}`;
359
- if (!isTypification(target.effectiveType)) return "";
360
- const type = applyPath(target.effectiveType, path);
361
- if (type?.typeID === TypeID.basic) {
362
- const cst = schema.cstByAlias.get(type.baseID);
363
- if (cst?.term_resolved) return `${cst.alias}: ${cst.term_resolved}`;
364
- }
365
- return "";
366
- }
367
- function calculateStepComplexity(cst) {
368
- if (cst.cst_type === CstType.AXIOM || cst.cst_type === CstType.NOMINAL || !isBasicConcept(cst.cst_type)) return 0;
369
- if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT || !cst.effectiveType) return 1;
370
- const type = cst.effectiveType;
371
- return calculateTypificationComplexity(type) + 1;
372
- }
373
- function calculateTypificationComplexity(type) {
374
- switch (type.typeID) {
375
- case TypeID.basic:
376
- case TypeID.integer:
377
- case TypeID.anyTypification: return 0;
378
- case TypeID.tuple: return type.factors.length + type.factors.reduce((sum, factor) => sum + calculateTypificationComplexity(factor), 0);
379
- case TypeID.collection:
380
- if (type.base.typeID === TypeID.tuple) {
381
- let sum = 0;
382
- type.base.factors.forEach((factor) => {
383
- sum += calculateTypificationComplexity(factor);
384
- });
385
- return sum + type.base.factors.length;
386
- } else if (type.base.typeID === TypeID.collection) return calculateTypificationComplexity(type.base) + 1;
387
- return 0;
388
- }
389
- }
390
- function isMissingConvention(cst) {
391
- if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {
392
- if (!cst.convention || !cst.term_resolved) return true;
393
- }
394
- return false;
395
- }
396
- /** Evaluate if {@link Typification} can be used to produce structure. */
397
- function typeCanProduceStructure(type) {
398
- if (type.typeID === TypeID.basic || type.typeID === TypeID.integer || type.typeID === TypeID.anyTypification) return false;
399
- else if (type.typeID === TypeID.tuple) return true;
400
- else return type.base.typeID !== TypeID.basic && type.base.typeID !== TypeID.integer && type.base.typeID !== TypeID.anyTypification;
401
- }
402
- //#endregion
1
+ import { A as isTemplateCst, C as inferTemplate, D as isFunctional, E as isBasicConcept, F as validateAliasFormat, I as validateNewAlias, M as removeAliasReference, N as sortItemsForInlineSynthesis, O as isLogical, P as typeClassForCstType, S as inferStatus, T as isBaseSet, _ as getCstTypePrefix, b as inferClass, c as applyMappingToConstituents, d as canHaveFormalDefinition, f as canHaveManualTypification, g as getAnalysisFor, h as generateAlias, j as normalizeExpression, k as isSchemaIssue, l as argumentValuesToMapping, m as findCstByStructure, o as addAliasReference, p as canProduceStructure, s as applyFilterCategory, u as calculateSchemaStats, v as getStructureName, w as inferTemplatedType, x as inferNewSpawnPosition, y as guessCstType } from "../diagnostics-D7SiHAwW.js";
403
2
  export { addAliasReference, applyFilterCategory, applyMappingToConstituents, argumentValuesToMapping, calculateSchemaStats, canHaveFormalDefinition, canHaveManualTypification, canProduceStructure, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, normalizeExpression, removeAliasReference, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
404
-
405
- //# sourceMappingURL=rsform-api.js.map