@rsconcept/domain 1.7.7 → 1.8.1
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-DqjdciC5.d.ts → analyzer-iqAXyROE.d.ts} +2 -3
- package/dist/{arguments-extractor-Dd1lFom9.d.ts → arguments-extractor-ngatANBI.d.ts} +2 -2
- package/dist/{ast-annotations-CZCzs9Uk.d.ts → ast-annotations-D6KZDu12.d.ts} +2 -2
- package/dist/{calculator-Dt03dsnd.d.ts → calculator-k8BGIKmj.d.ts} +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/library/index.d.ts +97 -1
- package/dist/library/index.js +283 -1
- package/dist/library/index.js.map +1 -0
- package/dist/library/oss-api.js +1 -1
- package/dist/library/rsengine.d.ts +1 -1
- package/dist/library/rsform-api.d.ts +13 -3
- package/dist/library/rsform-api.js +24 -2
- package/dist/library/rsform-api.js.map +1 -1
- package/dist/library/rsform.d.ts +2 -2
- package/dist/library/rsmodel-api.d.ts +1 -1
- package/dist/library/structure-planner.d.ts +1 -1
- package/dist/library/structure-planner.js +1 -1
- package/dist/rslang/api.d.ts +13 -2
- package/dist/rslang/api.js +31 -2
- package/dist/rslang/api.js.map +1 -1
- package/dist/rslang/ast-annotations.d.ts +1 -1
- package/dist/rslang/eval/calculator.d.ts +1 -1
- package/dist/rslang/eval/value-api.d.ts +1 -1
- package/dist/rslang/index.d.ts +8 -8
- package/dist/rslang/labels.d.ts +4 -2
- package/dist/rslang/labels.js +8 -2
- package/dist/rslang/labels.js.map +1 -1
- package/dist/rslang/parser/syntax-errors/index.d.ts +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +1 -1
- package/dist/rslang/semantic/analyzer.js +5 -13
- package/dist/rslang/semantic/analyzer.js.map +1 -1
- package/dist/rslang/semantic/arguments-extractor.d.ts +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +1 -1
- package/dist/rslang/semantic/type-auditor.js +2 -2
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/typification-api.d.ts +1 -1
- package/dist/rslang/semantic/typification-parser.d.ts +1 -1
- package/dist/rslang/semantic/typification.d.ts +2 -2
- package/dist/rslang/semantic/typification.js +14 -6
- package/dist/rslang/semantic/typification.js.map +1 -1
- package/dist/rslang/typification-graph.d.ts +1 -1
- package/dist/{typification-DDuv88ir.d.ts → typification-9lNu9R4k.d.ts} +8 -4
- package/dist/{typification-graph-8VdK6_Fh.d.ts → typification-graph-BY_oGT82.d.ts} +2 -2
- package/dist/{typification-parser-DHO42ZRc.d.ts → typification-parser-Dytsv9CI.d.ts} +2 -2
- package/dist/{value-api-C2X4Pom5.d.ts → value-api-CXLl_zg0.d.ts} +2 -2
- package/package.json +1 -1
- package/src/library/index.ts +8 -0
- package/src/library/rsform-api.test.ts +11 -1
- package/src/library/rsform-api.ts +40 -1
- package/src/library/template-instantiation.test.ts +427 -0
- package/src/library/template-instantiation.ts +456 -0
- package/src/rslang/api.test.ts +28 -0
- package/src/rslang/api.ts +32 -2
- package/src/rslang/labels.ts +10 -1
- package/src/rslang/semantic/analyzer.ts +6 -14
- package/src/rslang/semantic/type-auditor.test.ts +25 -6
- package/src/rslang/semantic/type-auditor.ts +2 -1
- package/src/rslang/semantic/typification-api.test.ts +21 -5
- package/src/rslang/semantic/typification-parser.test.ts +6 -1
- package/src/rslang/semantic/typification.ts +16 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
|
-
import { f as ExpressionType, g as TypeClass } from "./typification-
|
|
2
|
+
import { f as ExpressionType, g as TypeClass } from "./typification-9lNu9R4k.js";
|
|
3
3
|
import { i as RSErrorDescription } from "./error-CzIbnP-N.js";
|
|
4
4
|
import { t as ValueClass } from "./value-class-CNI-lqXJ.js";
|
|
5
5
|
|
|
@@ -32,8 +32,7 @@ declare class RSLangAnalyzer {
|
|
|
32
32
|
getType(alias: string): ExpressionType | null;
|
|
33
33
|
checkFast(expression: string, options?: AnalysisOptions): AnalysisFast;
|
|
34
34
|
checkFull(expression: string, options?: AnalysisOptions): AnalysisFull;
|
|
35
|
-
private parse;
|
|
36
35
|
}
|
|
37
36
|
//#endregion
|
|
38
37
|
export { RSLangAnalyzer as a, AnalysisOptions as i, AnalysisFast as n, AnalysisFull as r, AnalysisBase as t };
|
|
39
|
-
//# sourceMappingURL=analyzer-
|
|
38
|
+
//# sourceMappingURL=analyzer-iqAXyROE.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
|
-
import { f as ExpressionType } from "./typification-
|
|
2
|
+
import { f as ExpressionType } from "./typification-9lNu9R4k.js";
|
|
3
3
|
|
|
4
4
|
//#region src/rslang/semantic/arguments-extractor.d.ts
|
|
5
5
|
/** Represents function argument definition. */
|
|
@@ -35,4 +35,4 @@ declare class ArgumentsExtractor {
|
|
|
35
35
|
}
|
|
36
36
|
//#endregion
|
|
37
37
|
export { ArgumentsType as n, ArgumentsExtractor as t };
|
|
38
|
-
//# sourceMappingURL=arguments-extractor-
|
|
38
|
+
//# sourceMappingURL=arguments-extractor-ngatANBI.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
|
-
import { f as ExpressionType } from "./typification-
|
|
2
|
+
import { f as ExpressionType } from "./typification-9lNu9R4k.js";
|
|
3
3
|
import { a as RSErrorInfo, r as RSErrorCode } from "./error-CzIbnP-N.js";
|
|
4
4
|
|
|
5
5
|
//#region src/rslang/ast-annotations.d.ts
|
|
@@ -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-D6KZDu12.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AstNode } from "./ast-C8sIpKdL.js";
|
|
2
|
-
import { f as ExpressionType } from "./typification-
|
|
2
|
+
import { f as ExpressionType } from "./typification-9lNu9R4k.js";
|
|
3
3
|
import { i as RSErrorDescription } from "./error-CzIbnP-N.js";
|
|
4
4
|
import { l as Value } from "./value-BduA_ZGp.js";
|
|
5
5
|
|
|
@@ -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-k8BGIKmj.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -8,19 +8,19 @@ import { r as printTree, t as CMSyntaxNode } from "./lezer-tree-iS7LpLBJ.js";
|
|
|
8
8
|
import { a as TOKEN_ERROR, c as flattenAst, d as printAst, f as visitAstDFS, i as FlatAstNode, l as getNodeIndices, n as AstNodeBase, o as buildTree, r as FlatAST, s as findByUid, t as AstNode, u as getNodeText } from "./ast-C8sIpKdL.js";
|
|
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
|
-
import { b as Typification, d as EmptySetT, f as ExpressionType, g as TypeClass,
|
|
11
|
+
import { A 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-9lNu9R4k.js";
|
|
12
12
|
import { i as RSErrorDescription, r as RSErrorCode } from "./error-CzIbnP-N.js";
|
|
13
|
-
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-
|
|
13
|
+
import { i as readTypeAnnotation, r as readErrorAnnotation } from "./ast-annotations-D6KZDu12.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-
|
|
16
|
-
import { d as printValue } from "./value-api-
|
|
15
|
+
import { n as CalculatorResult, r as RSCalculator, t as CalculatorEvaluateOptions } from "./calculator-k8BGIKmj.js";
|
|
16
|
+
import { d as printValue } from "./value-api-CXLl_zg0.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-
|
|
21
|
-
import { n as ArgumentsType } from "./arguments-extractor-
|
|
22
|
-
import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "./typification-parser-
|
|
23
|
-
import { n as TypificationNodeData, t as TypificationGraph } from "./typification-graph-
|
|
20
|
+
import { a as RSLangAnalyzer, n as AnalysisFast, r as AnalysisFull, t as AnalysisBase } from "./analyzer-iqAXyROE.js";
|
|
21
|
+
import { n as ArgumentsType } from "./arguments-extractor-ngatANBI.js";
|
|
22
|
+
import { n as applyAsciiTypeSubstitutions, r as parseTypeText } from "./typification-parser-Dytsv9CI.js";
|
|
23
|
+
import { n as TypificationNodeData, t as TypificationGraph } from "./typification-graph-BY_oGT82.js";
|
|
24
24
|
import { ArgumentValue, Attribution, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats, Substitution, TypeInfo } from "./library/rsform.js";
|
|
25
25
|
import { BasicBinding, BasicsContext, DEFAULT_VALUE_TEXT, EvalStatus, RSModel, RSModelStats } from "./library/rsmodel.js";
|
|
26
26
|
import { RSEngine } from "./library/rsengine.js";
|
package/dist/library/index.d.ts
CHANGED
|
@@ -5,4 +5,100 @@ import { Block, CstSubstituteInfo, NodeType, Operation, OperationInput, Operatio
|
|
|
5
5
|
import { ArgumentValue, Attribution, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats, Substitution, TypeInfo } from "./rsform.js";
|
|
6
6
|
import { BasicBinding, BasicsContext, DEFAULT_VALUE_TEXT, EvalStatus, RSModel, RSModelStats } from "./rsmodel.js";
|
|
7
7
|
import { RSEngine } from "./rsengine.js";
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
//#region src/library/template-instantiation.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Payload for one {@link Constituenta} to create when instantiating an expression-bank template.
|
|
12
|
+
*
|
|
13
|
+
* Aliases are generated for the target schema. Formal definitions and typifications already
|
|
14
|
+
* reflect user argument substitution and remapping of bank aliases to those new aliases.
|
|
15
|
+
*/
|
|
16
|
+
interface TemplateInstantiationItem {
|
|
17
|
+
/** Alias to assign in the target schema. */
|
|
18
|
+
alias: string;
|
|
19
|
+
/** Inferred type after argument substitution (function/predicate may become term/axiom). */
|
|
20
|
+
cst_type: CstType;
|
|
21
|
+
crucial: boolean;
|
|
22
|
+
convention: string;
|
|
23
|
+
definition_formal: string;
|
|
24
|
+
definition_raw: string;
|
|
25
|
+
term_raw: string;
|
|
26
|
+
term_forms: Constituenta['term_forms'];
|
|
27
|
+
typification_manual: string;
|
|
28
|
+
value_is_property: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Conflicting argument bindings inferred for the same template dependency. */
|
|
31
|
+
interface TemplateBindingConflict {
|
|
32
|
+
templateAlias: string;
|
|
33
|
+
paramAlias: string;
|
|
34
|
+
existing: string;
|
|
35
|
+
incoming: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Batch create plan: dependencies first, selected template constituent last.
|
|
39
|
+
*
|
|
40
|
+
* Reuses constituents whose substituted formal definition already exists in the target schema
|
|
41
|
+
* (normalized comparison), even when the bank alias differs from the matched target alias.
|
|
42
|
+
* {@link TemplateInstantiationPlan.mainDuplicateAlias} reports when the selected template is a duplicate.
|
|
43
|
+
* Does not set `insert_after`; the caller supplies insertion on the batch DTO.
|
|
44
|
+
*/
|
|
45
|
+
interface TemplateInstantiationPlan {
|
|
46
|
+
items: TemplateInstantiationItem[];
|
|
47
|
+
/** Set when the selected template expression already exists in the target schema. */
|
|
48
|
+
mainDuplicateAlias: string | null;
|
|
49
|
+
/** Set when nested template calls bind the same parameter to different global aliases. */
|
|
50
|
+
bindingConflict: TemplateBindingConflict | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Input for planning template instantiation into a conceptual schema.
|
|
54
|
+
*/
|
|
55
|
+
interface TemplateInstantiationInput {
|
|
56
|
+
/** Schema that will receive new constituents. */
|
|
57
|
+
targetSchema: RSForm;
|
|
58
|
+
/** All constituents of the selected expression-bank RSForm (not only the prototype). */
|
|
59
|
+
templateItems: Constituenta[];
|
|
60
|
+
/** Template constituent chosen in the UI (main expression to add). */
|
|
61
|
+
prototype: Constituenta;
|
|
62
|
+
/** User bindings from template parameter aliases to target-schema global aliases. */
|
|
63
|
+
userArgs: ArgumentValue[];
|
|
64
|
+
/**
|
|
65
|
+
* Main constituent attributes from the create dialog (alias, labels, flags).
|
|
66
|
+
* `definition_formal` and `cst_type` may be overridden from `prototype` and `userArgs`.
|
|
67
|
+
*/
|
|
68
|
+
mainItem: TemplateInstantiationItem;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a batch create plan for a template expression and its bank dependencies.
|
|
72
|
+
*
|
|
73
|
+
* Walks nested `F#` / `P#` calls in the substituted expression, collects missing term-functions
|
|
74
|
+
* and predicate-functions from `templateItems`, propagates argument bindings into nested calls,
|
|
75
|
+
* topologically orders dependencies, and remaps bank aliases to freshly generated target aliases.
|
|
76
|
+
*/
|
|
77
|
+
declare function planTemplateInstantiation(input: TemplateInstantiationInput): TemplateInstantiationPlan;
|
|
78
|
+
/**
|
|
79
|
+
* Stateful planner for {@link planTemplateInstantiation}.
|
|
80
|
+
*
|
|
81
|
+
* Prefer the function wrapper unless you need to hold or reuse planner state between calls.
|
|
82
|
+
*/
|
|
83
|
+
declare class TemplateInstantiationPlanner {
|
|
84
|
+
private readonly targetSchema;
|
|
85
|
+
private readonly prototype;
|
|
86
|
+
private readonly userArgs;
|
|
87
|
+
private readonly mainItemTemplate;
|
|
88
|
+
private readonly templateByAlias;
|
|
89
|
+
private readonly userMapping;
|
|
90
|
+
private readonly depBindings;
|
|
91
|
+
private readonly depRefs;
|
|
92
|
+
private bindingConflict;
|
|
93
|
+
/** @param input - See {@link TemplateInstantiationInput}. */
|
|
94
|
+
constructor(input: TemplateInstantiationInput);
|
|
95
|
+
/** @returns Dependency items in topological order, then the main template item when it is not a duplicate. */
|
|
96
|
+
plan(): TemplateInstantiationPlan;
|
|
97
|
+
private buildDependencyItems;
|
|
98
|
+
private buildMainItem;
|
|
99
|
+
private ensureDep;
|
|
100
|
+
private collectDependencies;
|
|
101
|
+
}
|
|
102
|
+
//#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 };
|
|
104
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/library/index.js
CHANGED
|
@@ -1,7 +1,289 @@
|
|
|
1
1
|
import { FolderNode, FolderTree } from "./folder-tree.js";
|
|
2
2
|
import { AccessPolicy, LibraryItemType, LocationHead } from "./library.js";
|
|
3
3
|
import { NodeType, OperationType, SubstitutionErrorType } from "./oss.js";
|
|
4
|
+
import { visitAstDFS } from "../parsing/ast.js";
|
|
5
|
+
import "../parsing/index.js";
|
|
6
|
+
import { TokenID } from "../rslang/parser/token.js";
|
|
7
|
+
import { TypeID } from "../rslang/semantic/typification.js";
|
|
8
|
+
import { labelType } from "../rslang/labels.js";
|
|
9
|
+
import { applyAliasMapping, isGlobalAlias, parseRSLangExpression, splitTemplateDefinition, substituteLocalAliases, substituteTemplateArgs } from "../rslang/api.js";
|
|
4
10
|
import { CstClass, CstStatus, CstType } from "./rsform.js";
|
|
11
|
+
import { applyMappingToConstituents, argumentValuesToMapping, generateAlias, inferTemplatedType, isFunctional, normalizeExpression } from "./rsform-api.js";
|
|
5
12
|
import { DEFAULT_VALUE_TEXT, EvalStatus } from "./rsmodel.js";
|
|
6
13
|
import { RSEngine } from "./rsengine.js";
|
|
7
|
-
|
|
14
|
+
//#region src/library/template-instantiation.ts
|
|
15
|
+
/**
|
|
16
|
+
* Module: template instantiation from the expression bank into a target {@link RSForm}.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Build a batch create plan for a template expression and its bank dependencies.
|
|
20
|
+
*
|
|
21
|
+
* Walks nested `F#` / `P#` calls in the substituted expression, collects missing term-functions
|
|
22
|
+
* and predicate-functions from `templateItems`, propagates argument bindings into nested calls,
|
|
23
|
+
* topologically orders dependencies, and remaps bank aliases to freshly generated target aliases.
|
|
24
|
+
*/
|
|
25
|
+
function planTemplateInstantiation(input) {
|
|
26
|
+
return new TemplateInstantiationPlanner(input).plan();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Stateful planner for {@link planTemplateInstantiation}.
|
|
30
|
+
*
|
|
31
|
+
* Prefer the function wrapper unless you need to hold or reuse planner state between calls.
|
|
32
|
+
*/
|
|
33
|
+
var TemplateInstantiationPlanner = class {
|
|
34
|
+
targetSchema;
|
|
35
|
+
prototype;
|
|
36
|
+
userArgs;
|
|
37
|
+
mainItemTemplate;
|
|
38
|
+
templateByAlias;
|
|
39
|
+
userMapping;
|
|
40
|
+
depBindings = /* @__PURE__ */ new Map();
|
|
41
|
+
depRefs = /* @__PURE__ */ new Map();
|
|
42
|
+
bindingConflict = null;
|
|
43
|
+
/** @param input - See {@link TemplateInstantiationInput}. */
|
|
44
|
+
constructor(input) {
|
|
45
|
+
this.targetSchema = input.targetSchema;
|
|
46
|
+
this.prototype = input.prototype;
|
|
47
|
+
this.userArgs = input.userArgs;
|
|
48
|
+
this.mainItemTemplate = input.mainItem;
|
|
49
|
+
this.templateByAlias = new Map(input.templateItems.filter((cst) => isFunctional(cst.cst_type)).map((cst) => [cst.alias, cst]));
|
|
50
|
+
this.userMapping = argumentValuesToMapping(input.userArgs);
|
|
51
|
+
}
|
|
52
|
+
/** @returns Dependency items in topological order, then the main template item when it is not a duplicate. */
|
|
53
|
+
plan() {
|
|
54
|
+
const mainDefinition = substituteTemplateArgs(this.prototype.definition_formal, this.userMapping);
|
|
55
|
+
this.collectDependencies(mainDefinition, this.userMapping);
|
|
56
|
+
if (this.bindingConflict) return {
|
|
57
|
+
items: [],
|
|
58
|
+
mainDuplicateAlias: null,
|
|
59
|
+
bindingConflict: this.bindingConflict
|
|
60
|
+
};
|
|
61
|
+
const definitionIndex = createFormalDefinitionIndex(this.targetSchema);
|
|
62
|
+
const dependencyItems = this.buildDependencyItems(definitionIndex);
|
|
63
|
+
const { item: mainItem, duplicateAlias: mainDuplicateAlias } = this.buildMainItem(mainDefinition, dependencyItems.takenAliases, dependencyItems.aliasMapping, definitionIndex);
|
|
64
|
+
return {
|
|
65
|
+
items: mainItem ? [...dependencyItems.items, mainItem] : dependencyItems.items,
|
|
66
|
+
mainDuplicateAlias,
|
|
67
|
+
bindingConflict: null
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
buildDependencyItems(definitionIndex) {
|
|
71
|
+
const dependencyAliases = topologicalSort([...this.depBindings.keys()], this.depRefs);
|
|
72
|
+
const aliasMapping = {};
|
|
73
|
+
const takenAliases = [];
|
|
74
|
+
const reservedAliases = [this.mainItemTemplate.alias];
|
|
75
|
+
const items = [];
|
|
76
|
+
for (const templateAlias of dependencyAliases) {
|
|
77
|
+
const template = this.templateByAlias.get(templateAlias);
|
|
78
|
+
const bindings = this.depBindings.get(templateAlias);
|
|
79
|
+
const args = bindingMapToArgs(getTemplateParams(template), bindings);
|
|
80
|
+
const cst_type = inferTemplatedType(template.cst_type, args);
|
|
81
|
+
const definition = applyAliasMapping(substituteTemplateArgs(template.definition_formal, argumentValuesToMapping(args)), aliasMapping);
|
|
82
|
+
const existingAlias = definitionIndex.find(cst_type, definition);
|
|
83
|
+
if (existingAlias) {
|
|
84
|
+
aliasMapping[templateAlias] = existingAlias;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const alias = generateAlias(template.cst_type, this.targetSchema, [...reservedAliases, ...takenAliases]);
|
|
88
|
+
takenAliases.push(alias);
|
|
89
|
+
aliasMapping[templateAlias] = alias;
|
|
90
|
+
const item = instantiateTemplateItem(template, args, alias);
|
|
91
|
+
item.definition_formal = definition;
|
|
92
|
+
applyMappingToConstituents([item], aliasMapping, false);
|
|
93
|
+
definitionIndex.register(cst_type, item.definition_formal, alias);
|
|
94
|
+
items.push(item);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
items,
|
|
98
|
+
aliasMapping,
|
|
99
|
+
takenAliases
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
buildMainItem(mainDefinition, takenAliases, aliasMapping, definitionIndex) {
|
|
103
|
+
const mappedDefinition = applyAliasMapping(mainDefinition, aliasMapping);
|
|
104
|
+
const cst_type = inferTemplatedType(this.prototype.cst_type, this.userArgs);
|
|
105
|
+
const duplicateAlias = definitionIndex.find(cst_type, mappedDefinition);
|
|
106
|
+
if (duplicateAlias) return {
|
|
107
|
+
item: null,
|
|
108
|
+
duplicateAlias
|
|
109
|
+
};
|
|
110
|
+
const mainItem = {
|
|
111
|
+
...this.mainItemTemplate,
|
|
112
|
+
definition_formal: mappedDefinition,
|
|
113
|
+
cst_type
|
|
114
|
+
};
|
|
115
|
+
applyMappingToConstituents([mainItem], aliasMapping, false);
|
|
116
|
+
if (takenAliases.includes(mainItem.alias)) mainItem.alias = generateAlias(mainItem.cst_type, this.targetSchema, [...takenAliases, this.mainItemTemplate.alias]);
|
|
117
|
+
return {
|
|
118
|
+
item: mainItem,
|
|
119
|
+
duplicateAlias: null
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
ensureDep(templateAlias, bindings, referrer) {
|
|
123
|
+
if (this.bindingConflict) return;
|
|
124
|
+
if (!this.templateByAlias.has(templateAlias)) return;
|
|
125
|
+
if (referrer && this.depBindings.has(referrer)) {
|
|
126
|
+
const refs = this.depRefs.get(referrer) ?? /* @__PURE__ */ new Set();
|
|
127
|
+
refs.add(templateAlias);
|
|
128
|
+
this.depRefs.set(referrer, refs);
|
|
129
|
+
}
|
|
130
|
+
const mergeResult = mergeBindings(this.depBindings.get(templateAlias), bindings);
|
|
131
|
+
if (!mergeResult.ok) {
|
|
132
|
+
this.bindingConflict = {
|
|
133
|
+
templateAlias,
|
|
134
|
+
...mergeResult.conflict
|
|
135
|
+
};
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const merged = mergeResult.bindings;
|
|
139
|
+
const changed = !this.depBindings.has(templateAlias) || merged.size !== (this.depBindings.get(templateAlias)?.size ?? 0);
|
|
140
|
+
this.depBindings.set(templateAlias, merged);
|
|
141
|
+
if (!changed && referrer) return;
|
|
142
|
+
const template = this.templateByAlias.get(templateAlias);
|
|
143
|
+
const args = bindingMapToArgs(getTemplateParams(template), merged);
|
|
144
|
+
const definition = substituteTemplateArgs(template.definition_formal, argumentValuesToMapping(args));
|
|
145
|
+
this.collectDependencies(definition, argumentValuesToMapping(args), templateAlias);
|
|
146
|
+
}
|
|
147
|
+
collectDependencies(expression, scope, referrer) {
|
|
148
|
+
if (this.bindingConflict) return;
|
|
149
|
+
const ast = parseRSLangExpression(expression);
|
|
150
|
+
if (!ast) return;
|
|
151
|
+
for (const call of extractFuncCalls(ast, expression)) {
|
|
152
|
+
const template = this.templateByAlias.get(call.callee);
|
|
153
|
+
if (!template) continue;
|
|
154
|
+
const scopedArgs = call.args.map((arg) => substituteLocalAliases(arg, scope));
|
|
155
|
+
const bindings = bindingsFromCall(getTemplateParams(template), scopedArgs, scope);
|
|
156
|
+
this.ensureDep(call.callee, bindings, referrer);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
/** Normalized formal definitions in the target schema and in the current plan. */
|
|
161
|
+
var FormalDefinitionIndex = class {
|
|
162
|
+
byKey = /* @__PURE__ */ new Map();
|
|
163
|
+
register(cst_type, definition_formal, alias) {
|
|
164
|
+
const normalized = normalizeExpression(definition_formal, cst_type);
|
|
165
|
+
if (!normalized) return;
|
|
166
|
+
this.byKey.set(formalDefinitionKey(cst_type, normalized), alias);
|
|
167
|
+
}
|
|
168
|
+
find(cst_type, definition_formal) {
|
|
169
|
+
const normalized = normalizeExpression(definition_formal, cst_type);
|
|
170
|
+
if (!normalized) return null;
|
|
171
|
+
return this.byKey.get(formalDefinitionKey(cst_type, normalized)) ?? null;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
function createFormalDefinitionIndex(schema) {
|
|
175
|
+
const index = new FormalDefinitionIndex();
|
|
176
|
+
for (const cst of schema.items) index.register(cst.cst_type, cst.definition_formal, cst.alias);
|
|
177
|
+
return index;
|
|
178
|
+
}
|
|
179
|
+
function formalDefinitionKey(cst_type, normalized) {
|
|
180
|
+
return `${cst_type}\0${normalized}`;
|
|
181
|
+
}
|
|
182
|
+
function instantiateTemplateItem(template, args, alias) {
|
|
183
|
+
return {
|
|
184
|
+
alias,
|
|
185
|
+
cst_type: inferTemplatedType(template.cst_type, args),
|
|
186
|
+
crucial: template.crucial,
|
|
187
|
+
convention: template.convention,
|
|
188
|
+
definition_formal: substituteTemplateArgs(template.definition_formal, argumentValuesToMapping(args)),
|
|
189
|
+
definition_raw: template.definition_raw,
|
|
190
|
+
term_raw: template.term_raw,
|
|
191
|
+
term_forms: [...template.term_forms],
|
|
192
|
+
typification_manual: template.typification_manual,
|
|
193
|
+
value_is_property: template.value_is_property
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function bindingsFromCall(params, callArgs, scope) {
|
|
197
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
198
|
+
params.forEach((param, index) => {
|
|
199
|
+
const value = resolveArgBinding(callArgs[index] ?? "", scope);
|
|
200
|
+
if (value) bindings.set(param.alias, value);
|
|
201
|
+
});
|
|
202
|
+
return bindings;
|
|
203
|
+
}
|
|
204
|
+
function resolveArgBinding(argExpr, scope) {
|
|
205
|
+
const scoped = substituteLocalAliases(argExpr, scope).trim();
|
|
206
|
+
if (isGlobalAlias(scoped)) return scoped;
|
|
207
|
+
}
|
|
208
|
+
function mergeBindings(existing, incoming) {
|
|
209
|
+
const result = new Map(existing);
|
|
210
|
+
for (const [alias, value] of incoming) {
|
|
211
|
+
const existingValue = result.get(alias);
|
|
212
|
+
if (existingValue === void 0) result.set(alias, value);
|
|
213
|
+
else if (existingValue !== value) return {
|
|
214
|
+
ok: false,
|
|
215
|
+
conflict: {
|
|
216
|
+
paramAlias: alias,
|
|
217
|
+
existing: existingValue,
|
|
218
|
+
incoming: value
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
ok: true,
|
|
224
|
+
bindings: result
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function bindingMapToArgs(params, bindings) {
|
|
228
|
+
return params.map((param) => ({
|
|
229
|
+
alias: param.alias,
|
|
230
|
+
typification: param.typification,
|
|
231
|
+
value: bindings.get(param.alias)
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
function getTemplateParams(template) {
|
|
235
|
+
const effectiveType = template.effectiveType;
|
|
236
|
+
if (effectiveType && (effectiveType.typeID === TypeID.function || effectiveType.typeID === TypeID.predicate)) return effectiveType.args.map((arg) => ({
|
|
237
|
+
alias: arg.alias,
|
|
238
|
+
typification: labelType(arg.type)
|
|
239
|
+
}));
|
|
240
|
+
const { head } = splitTemplateDefinition(template.definition_formal);
|
|
241
|
+
if (!head) return [];
|
|
242
|
+
return head.split(",").map((part) => {
|
|
243
|
+
const trimmed = part.trim();
|
|
244
|
+
const separator = trimmed.indexOf("∈");
|
|
245
|
+
if (separator === -1) return {
|
|
246
|
+
alias: trimmed,
|
|
247
|
+
typification: ""
|
|
248
|
+
};
|
|
249
|
+
return {
|
|
250
|
+
alias: trimmed.slice(0, separator).trim(),
|
|
251
|
+
typification: trimmed.slice(separator + 1).trim()
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function extractFuncCalls(ast, expression) {
|
|
256
|
+
const result = [];
|
|
257
|
+
visitAstDFS(ast, (node) => {
|
|
258
|
+
if (node.typeID !== TokenID.NT_FUNC_CALL || node.children.length < 1) return;
|
|
259
|
+
const calleeNode = node.children[0];
|
|
260
|
+
if (calleeNode.typeID !== TokenID.ID_FUNCTION && calleeNode.typeID !== TokenID.ID_PREDICATE && calleeNode.typeID !== TokenID.ID_GLOBAL) return;
|
|
261
|
+
const callee = expression.slice(calleeNode.from, calleeNode.to);
|
|
262
|
+
if (!/^[FP]\d+$/.test(callee)) return;
|
|
263
|
+
result.push({
|
|
264
|
+
callee,
|
|
265
|
+
args: node.children.slice(1).map((child) => expression.slice(child.from, child.to).trim())
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
function topologicalSort(aliases, refs) {
|
|
271
|
+
const remaining = new Set(aliases);
|
|
272
|
+
const sorted = [];
|
|
273
|
+
while (remaining.size > 0) {
|
|
274
|
+
const ready = [...remaining].filter((alias) => {
|
|
275
|
+
return [...refs.get(alias) ?? /* @__PURE__ */ new Set()].every((dep) => !remaining.has(dep));
|
|
276
|
+
});
|
|
277
|
+
if (ready.length === 0) return [...remaining, ...sorted].reverse();
|
|
278
|
+
ready.sort();
|
|
279
|
+
for (const alias of ready) {
|
|
280
|
+
sorted.push(alias);
|
|
281
|
+
remaining.delete(alias);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return sorted;
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
287
|
+
export { AccessPolicy, CstClass, CstStatus, CstType, DEFAULT_VALUE_TEXT, EvalStatus, FolderNode, FolderTree, LibraryItemType, LocationHead, NodeType, OperationType, RSEngine, SubstitutionErrorType, TemplateInstantiationPlanner, planTemplateInstantiation };
|
|
288
|
+
|
|
289
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/library/template-instantiation.ts"],"sourcesContent":["/**\n * Module: template instantiation from the expression bank into a target {@link RSForm}.\n */\n\nimport { type AstNode, visitAstDFS } from '../parsing';\nimport {\n type AliasMapping,\n applyAliasMapping,\n isGlobalAlias,\n parseRSLangExpression,\n splitTemplateDefinition,\n substituteLocalAliases,\n substituteTemplateArgs\n} from '../rslang/api';\nimport { labelType } from '../rslang/labels';\nimport { TokenID } from '../rslang/parser/token';\nimport { TypeID } from '../rslang/semantic/typification';\n\nimport { type ArgumentValue, type Constituenta, type CstType, type RSForm } from './rsform';\nimport {\n applyMappingToConstituents,\n argumentValuesToMapping,\n generateAlias,\n inferTemplatedType,\n isFunctional,\n normalizeExpression\n} from './rsform-api';\n\n/**\n * Payload for one {@link Constituenta} to create when instantiating an expression-bank template.\n *\n * Aliases are generated for the target schema. Formal definitions and typifications already\n * reflect user argument substitution and remapping of bank aliases to those new aliases.\n */\nexport interface TemplateInstantiationItem {\n /** Alias to assign in the target schema. */\n alias: string;\n /** Inferred type after argument substitution (function/predicate may become term/axiom). */\n cst_type: CstType;\n crucial: boolean;\n convention: string;\n definition_formal: string;\n definition_raw: string;\n term_raw: string;\n term_forms: Constituenta['term_forms'];\n typification_manual: string;\n value_is_property: boolean;\n}\n\n/** Conflicting argument bindings inferred for the same template dependency. */\nexport interface TemplateBindingConflict {\n templateAlias: string;\n paramAlias: string;\n existing: string;\n incoming: string;\n}\n\n/**\n * Batch create plan: dependencies first, selected template constituent last.\n *\n * Reuses constituents whose substituted formal definition already exists in the target schema\n * (normalized comparison), even when the bank alias differs from the matched target alias.\n * {@link TemplateInstantiationPlan.mainDuplicateAlias} reports when the selected template is a duplicate.\n * Does not set `insert_after`; the caller supplies insertion on the batch DTO.\n */\nexport interface TemplateInstantiationPlan {\n items: TemplateInstantiationItem[];\n /** Set when the selected template expression already exists in the target schema. */\n mainDuplicateAlias: string | null;\n /** Set when nested template calls bind the same parameter to different global aliases. */\n bindingConflict: TemplateBindingConflict | null;\n}\n\n/**\n * Input for planning template instantiation into a conceptual schema.\n */\nexport interface TemplateInstantiationInput {\n /** Schema that will receive new constituents. */\n targetSchema: RSForm;\n /** All constituents of the selected expression-bank RSForm (not only the prototype). */\n templateItems: Constituenta[];\n /** Template constituent chosen in the UI (main expression to add). */\n prototype: Constituenta;\n /** User bindings from template parameter aliases to target-schema global aliases. */\n userArgs: ArgumentValue[];\n /**\n * Main constituent attributes from the create dialog (alias, labels, flags).\n * `definition_formal` and `cst_type` may be overridden from `prototype` and `userArgs`.\n */\n mainItem: TemplateInstantiationItem;\n}\n\ninterface FuncCallRef {\n callee: string;\n args: string[];\n}\n\ninterface TemplateParam {\n alias: string;\n typification: string;\n}\n\n/**\n * Build a batch create plan for a template expression and its bank dependencies.\n *\n * Walks nested `F#` / `P#` calls in the substituted expression, collects missing term-functions\n * and predicate-functions from `templateItems`, propagates argument bindings into nested calls,\n * topologically orders dependencies, and remaps bank aliases to freshly generated target aliases.\n */\nexport function planTemplateInstantiation(input: TemplateInstantiationInput): TemplateInstantiationPlan {\n return new TemplateInstantiationPlanner(input).plan();\n}\n\n/**\n * Stateful planner for {@link planTemplateInstantiation}.\n *\n * Prefer the function wrapper unless you need to hold or reuse planner state between calls.\n */\nexport class TemplateInstantiationPlanner {\n private readonly targetSchema: RSForm;\n private readonly prototype: Constituenta;\n private readonly userArgs: ArgumentValue[];\n private readonly mainItemTemplate: TemplateInstantiationItem;\n private readonly templateByAlias: Map<string, Constituenta>;\n private readonly userMapping: AliasMapping;\n private readonly depBindings = new Map<string, Map<string, string>>();\n private readonly depRefs = new Map<string, Set<string>>();\n private bindingConflict: TemplateBindingConflict | null = null;\n\n /** @param input - See {@link TemplateInstantiationInput}. */\n constructor(input: TemplateInstantiationInput) {\n this.targetSchema = input.targetSchema;\n this.prototype = input.prototype;\n this.userArgs = input.userArgs;\n this.mainItemTemplate = input.mainItem;\n this.templateByAlias = new Map(\n input.templateItems.filter(cst => isFunctional(cst.cst_type)).map(cst => [cst.alias, cst])\n );\n this.userMapping = argumentValuesToMapping(input.userArgs);\n }\n\n /** @returns Dependency items in topological order, then the main template item when it is not a duplicate. */\n plan(): TemplateInstantiationPlan {\n const mainDefinition = substituteTemplateArgs(this.prototype.definition_formal, this.userMapping);\n this.collectDependencies(mainDefinition, this.userMapping);\n\n if (this.bindingConflict) {\n return { items: [], mainDuplicateAlias: null, bindingConflict: this.bindingConflict };\n }\n\n const definitionIndex = createFormalDefinitionIndex(this.targetSchema);\n const dependencyItems = this.buildDependencyItems(definitionIndex);\n const { item: mainItem, duplicateAlias: mainDuplicateAlias } = this.buildMainItem(\n mainDefinition,\n dependencyItems.takenAliases,\n dependencyItems.aliasMapping,\n definitionIndex\n );\n\n return {\n items: mainItem ? [...dependencyItems.items, mainItem] : dependencyItems.items,\n mainDuplicateAlias,\n bindingConflict: null\n };\n }\n\n private buildDependencyItems(definitionIndex: FormalDefinitionIndex): {\n items: TemplateInstantiationItem[];\n aliasMapping: AliasMapping;\n takenAliases: string[];\n } {\n const dependencyAliases = topologicalSort([...this.depBindings.keys()], this.depRefs);\n const aliasMapping: AliasMapping = {};\n const takenAliases: string[] = [];\n const reservedAliases = [this.mainItemTemplate.alias];\n const items: TemplateInstantiationItem[] = [];\n\n for (const templateAlias of dependencyAliases) {\n const template = this.templateByAlias.get(templateAlias)!;\n const bindings = this.depBindings.get(templateAlias)!;\n const args = bindingMapToArgs(getTemplateParams(template), bindings);\n const cst_type = inferTemplatedType(template.cst_type, args);\n const definition = applyAliasMapping(\n substituteTemplateArgs(template.definition_formal, argumentValuesToMapping(args)),\n aliasMapping\n );\n\n const existingAlias = definitionIndex.find(cst_type, definition);\n if (existingAlias) {\n aliasMapping[templateAlias] = existingAlias;\n continue;\n }\n\n const alias = generateAlias(template.cst_type, this.targetSchema, [...reservedAliases, ...takenAliases]);\n takenAliases.push(alias);\n aliasMapping[templateAlias] = alias;\n\n const item = instantiateTemplateItem(template, args, alias);\n item.definition_formal = definition;\n applyMappingToConstituents([item], aliasMapping, false);\n definitionIndex.register(cst_type, item.definition_formal, alias);\n items.push(item);\n }\n\n return { items, aliasMapping, takenAliases };\n }\n\n private buildMainItem(\n mainDefinition: string,\n takenAliases: string[],\n aliasMapping: AliasMapping,\n definitionIndex: FormalDefinitionIndex\n ): { item: TemplateInstantiationItem | null; duplicateAlias: string | null } {\n const mappedDefinition = applyAliasMapping(mainDefinition, aliasMapping);\n const cst_type = inferTemplatedType(this.prototype.cst_type, this.userArgs);\n\n const duplicateAlias = definitionIndex.find(cst_type, mappedDefinition);\n if (duplicateAlias) {\n return { item: null, duplicateAlias };\n }\n\n const mainItem: TemplateInstantiationItem = {\n ...this.mainItemTemplate,\n definition_formal: mappedDefinition,\n cst_type\n };\n applyMappingToConstituents([mainItem], aliasMapping, false);\n\n if (takenAliases.includes(mainItem.alias)) {\n mainItem.alias = generateAlias(mainItem.cst_type, this.targetSchema, [\n ...takenAliases,\n this.mainItemTemplate.alias\n ]);\n }\n\n return { item: mainItem, duplicateAlias: null };\n }\n\n private ensureDep(templateAlias: string, bindings: Map<string, string>, referrer?: string): void {\n if (this.bindingConflict) {\n return;\n }\n if (!this.templateByAlias.has(templateAlias)) {\n return;\n }\n if (referrer && this.depBindings.has(referrer)) {\n const refs = this.depRefs.get(referrer) ?? new Set<string>();\n refs.add(templateAlias);\n this.depRefs.set(referrer, refs);\n }\n const mergeResult = mergeBindings(this.depBindings.get(templateAlias), bindings);\n if (!mergeResult.ok) {\n this.bindingConflict = { templateAlias, ...mergeResult.conflict };\n return;\n }\n const merged = mergeResult.bindings;\n const changed =\n !this.depBindings.has(templateAlias) || merged.size !== (this.depBindings.get(templateAlias)?.size ?? 0);\n this.depBindings.set(templateAlias, merged);\n if (!changed && referrer) {\n return;\n }\n const template = this.templateByAlias.get(templateAlias)!;\n const args = bindingMapToArgs(getTemplateParams(template), merged);\n const definition = substituteTemplateArgs(template.definition_formal, argumentValuesToMapping(args));\n this.collectDependencies(definition, argumentValuesToMapping(args), templateAlias);\n }\n\n private collectDependencies(expression: string, scope: AliasMapping, referrer?: string): void {\n if (this.bindingConflict) {\n return;\n }\n const ast = parseRSLangExpression(expression);\n if (!ast) {\n return;\n }\n for (const call of extractFuncCalls(ast, expression)) {\n const template = this.templateByAlias.get(call.callee);\n if (!template) {\n continue;\n }\n const scopedArgs = call.args.map(arg => substituteLocalAliases(arg, scope));\n const bindings = bindingsFromCall(getTemplateParams(template), scopedArgs, scope);\n this.ensureDep(call.callee, bindings, referrer);\n }\n }\n}\n\n// ======= Internals ========\n\n/** Normalized formal definitions in the target schema and in the current plan. */\nclass FormalDefinitionIndex {\n private readonly byKey = new Map<string, string>();\n\n register(cst_type: CstType, definition_formal: string, alias: string): void {\n const normalized = normalizeExpression(definition_formal, cst_type);\n if (!normalized) {\n return;\n }\n this.byKey.set(formalDefinitionKey(cst_type, normalized), alias);\n }\n\n find(cst_type: CstType, definition_formal: string): string | null {\n const normalized = normalizeExpression(definition_formal, cst_type);\n if (!normalized) {\n return null;\n }\n return this.byKey.get(formalDefinitionKey(cst_type, normalized)) ?? null;\n }\n}\n\nfunction createFormalDefinitionIndex(schema: RSForm): FormalDefinitionIndex {\n const index = new FormalDefinitionIndex();\n for (const cst of schema.items) {\n index.register(cst.cst_type, cst.definition_formal, cst.alias);\n }\n return index;\n}\n\nfunction formalDefinitionKey(cst_type: CstType, normalized: string): string {\n return `${cst_type}\\0${normalized}`;\n}\n\nfunction instantiateTemplateItem(\n template: Constituenta,\n args: ArgumentValue[],\n alias: string\n): TemplateInstantiationItem {\n return {\n alias,\n cst_type: inferTemplatedType(template.cst_type, args),\n crucial: template.crucial,\n convention: template.convention,\n definition_formal: substituteTemplateArgs(template.definition_formal, argumentValuesToMapping(args)),\n definition_raw: template.definition_raw,\n term_raw: template.term_raw,\n term_forms: [...template.term_forms],\n typification_manual: template.typification_manual,\n value_is_property: template.value_is_property\n };\n}\n\nfunction bindingsFromCall(params: TemplateParam[], callArgs: string[], scope: AliasMapping): Map<string, string> {\n const bindings = new Map<string, string>();\n params.forEach((param, index) => {\n const value = resolveArgBinding(callArgs[index] ?? '', scope);\n if (value) {\n bindings.set(param.alias, value);\n }\n });\n return bindings;\n}\n\nfunction resolveArgBinding(argExpr: string, scope: AliasMapping): string | undefined {\n const scoped = substituteLocalAliases(argExpr, scope).trim();\n if (isGlobalAlias(scoped)) {\n return scoped;\n }\n return undefined;\n}\n\ntype MergeBindingsResult =\n | { ok: true; bindings: Map<string, string> }\n | { ok: false; conflict: { paramAlias: string; existing: string; incoming: string } };\n\nfunction mergeBindings(existing: Map<string, string> | undefined, incoming: Map<string, string>): MergeBindingsResult {\n const result = new Map(existing);\n for (const [alias, value] of incoming) {\n const existingValue = result.get(alias);\n if (existingValue === undefined) {\n result.set(alias, value);\n } else if (existingValue !== value) {\n return { ok: false, conflict: { paramAlias: alias, existing: existingValue, incoming: value } };\n }\n }\n return { ok: true, bindings: result };\n}\n\nfunction bindingMapToArgs(params: TemplateParam[], bindings: Map<string, string>): ArgumentValue[] {\n return params.map(param => ({\n alias: param.alias,\n typification: param.typification,\n value: bindings.get(param.alias)\n }));\n}\n\nfunction getTemplateParams(template: Constituenta): TemplateParam[] {\n const effectiveType = template.effectiveType;\n if (effectiveType && (effectiveType.typeID === TypeID.function || effectiveType.typeID === TypeID.predicate)) {\n return effectiveType.args.map(arg => ({\n alias: arg.alias,\n typification: labelType(arg.type)\n }));\n }\n const { head } = splitTemplateDefinition(template.definition_formal);\n if (!head) {\n return [];\n }\n return head.split(',').map(part => {\n const trimmed = part.trim();\n const separator = trimmed.indexOf('∈');\n if (separator === -1) {\n return { alias: trimmed, typification: '' };\n }\n return {\n alias: trimmed.slice(0, separator).trim(),\n typification: trimmed.slice(separator + 1).trim()\n };\n });\n}\n\nfunction extractFuncCalls(ast: AstNode, expression: string): FuncCallRef[] {\n const result: FuncCallRef[] = [];\n visitAstDFS(ast, node => {\n if (node.typeID !== TokenID.NT_FUNC_CALL || node.children.length < 1) {\n return;\n }\n const calleeNode = node.children[0];\n if (\n calleeNode.typeID !== TokenID.ID_FUNCTION &&\n calleeNode.typeID !== TokenID.ID_PREDICATE &&\n calleeNode.typeID !== TokenID.ID_GLOBAL\n ) {\n return;\n }\n const callee = expression.slice(calleeNode.from, calleeNode.to);\n if (!/^[FP]\\d+$/.test(callee)) {\n return;\n }\n result.push({\n callee,\n args: node.children.slice(1).map(child => expression.slice(child.from, child.to).trim())\n });\n });\n return result;\n}\n\nfunction topologicalSort(aliases: string[], refs: Map<string, Set<string>>): string[] {\n const remaining = new Set(aliases);\n const sorted: string[] = [];\n while (remaining.size > 0) {\n const ready = [...remaining].filter(alias => {\n const deps = refs.get(alias) ?? new Set<string>();\n return [...deps].every(dep => !remaining.has(dep));\n });\n if (ready.length === 0) {\n return [...remaining, ...sorted].reverse();\n }\n ready.sort();\n for (const alias of ready) {\n sorted.push(alias);\n remaining.delete(alias);\n }\n }\n return sorted;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6GA,SAAgB,0BAA0B,OAA8D;CACtG,OAAO,IAAI,6BAA6B,KAAK,CAAC,CAAC,KAAK;AACtD;;;;;;AAOA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SubstitutionErrorType } from "./oss.js";
|
|
3
3
|
import { labelType } from "../rslang/labels.js";
|
|
4
|
+
import { applyAliasMapping, applyTypificationMapping, isSetTypification } from "../rslang/api.js";
|
|
4
5
|
import { extractBases } from "../rslang/semantic/typification-api.js";
|
|
5
6
|
import { CstClass, CstType } from "./rsform.js";
|
|
6
|
-
import { applyAliasMapping, applyTypificationMapping, isSetTypification } from "../rslang/api.js";
|
|
7
7
|
import "../graph/index.js";
|
|
8
8
|
//#region src/library/oss-api.ts
|
|
9
9
|
/**
|
|
@@ -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-k8BGIKmj.js";
|
|
4
4
|
import { CstType, RSForm } from "./rsform.js";
|
|
5
5
|
import { BasicBinding, BasicsContext, EvalStatus, RSModel } from "./rsmodel.js";
|
|
6
6
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { r as LibraryItem } from "../library-CYun28Xz.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as AstNode } from "../ast-C8sIpKdL.js";
|
|
3
|
+
import { g as TypeClass, y as TypePath } from "../typification-9lNu9R4k.js";
|
|
3
4
|
import { t as ValueClass } from "../value-class-CNI-lqXJ.js";
|
|
4
|
-
import { r as AnalysisFull } from "../analyzer-
|
|
5
|
+
import { r as AnalysisFull } from "../analyzer-iqAXyROE.js";
|
|
5
6
|
import { ArgumentValue, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats } from "./rsform.js";
|
|
6
7
|
import { AliasMapping } from "../rslang/api.js";
|
|
7
8
|
|
|
@@ -12,6 +13,15 @@ declare function isSchemaIssue(cst: Constituenta): boolean;
|
|
|
12
13
|
declare function inferStatus(parse: boolean, value?: ValueClass | null): CstStatus;
|
|
13
14
|
/** Infers type of constituent for a given template and arguments. */
|
|
14
15
|
declare function inferTemplatedType(templateType: CstType, args: ArgumentValue[]): CstType;
|
|
16
|
+
/** Build alias mapping from template argument bindings. */
|
|
17
|
+
declare function argumentValuesToMapping(args: ArgumentValue[]): AliasMapping;
|
|
18
|
+
/**
|
|
19
|
+
* Normalize a RSLang expression for duplicate comparison.
|
|
20
|
+
*
|
|
21
|
+
* Returns `null` for basic concepts without formal definitions. Pass a pre-parsed `ast`
|
|
22
|
+
* when the expression was already analyzed to avoid re-parsing.
|
|
23
|
+
*/
|
|
24
|
+
declare function normalizeExpression(expression: string, cst_type: CstType, ast?: AstNode | null): string | null;
|
|
15
25
|
/** Checks if given expression is a template. */
|
|
16
26
|
declare function inferTemplate(expression: string): boolean;
|
|
17
27
|
/** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */
|
|
@@ -79,5 +89,5 @@ declare function findCstByStructure(schema: RSForm, target: Constituenta, path:
|
|
|
79
89
|
/** Retrieves name for piece of target {@link Constituenta} structure. */
|
|
80
90
|
declare function getStructureName(schema: RSForm, target: Constituenta, path: TypePath): string;
|
|
81
91
|
//#endregion
|
|
82
|
-
export { ConstituentaMappableFields, addAliasReference, applyFilterCategory, applyMappingToConstituents, calculateSchemaStats, canHaveFormalDefinition, canHaveManualTypification, canProduceStructure, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, removeAliasReference, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
|
|
92
|
+
export { ConstituentaMappableFields, 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 };
|
|
83
93
|
//# sourceMappingURL=rsform-api.d.ts.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { RSErrorCode } from "../rslang/error.js";
|
|
2
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";
|
|
3
5
|
import { applyPath } from "../rslang/semantic/typification-api.js";
|
|
4
6
|
import { ValueClass } from "../rslang/semantic/value-class.js";
|
|
5
7
|
import "../rslang/index.js";
|
|
6
8
|
import { CstClass, CstStatus, CstType } from "./rsform.js";
|
|
7
9
|
import { applyEntityReferenceMapping } from "../cctext/language-api.js";
|
|
8
|
-
import { applyAliasMapping, applyTypificationMapping } from "../rslang/api.js";
|
|
9
10
|
//#region src/library/rsform-api.ts
|
|
10
11
|
/**
|
|
11
12
|
* Module: API for formal representation for systems of concepts.
|
|
@@ -55,6 +56,27 @@ function inferTemplatedType(templateType, args) {
|
|
|
55
56
|
else if (templateType === CstType.PREDICATE) return CstType.AXIOM;
|
|
56
57
|
else return CstType.TERM;
|
|
57
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
|
+
}
|
|
58
80
|
/** Checks if given expression is a template. */
|
|
59
81
|
function inferTemplate(expression) {
|
|
60
82
|
const match = expression.match(/R\d+/g);
|
|
@@ -378,6 +400,6 @@ function typeCanProduceStructure(type) {
|
|
|
378
400
|
else return type.base.typeID !== TypeID.basic && type.base.typeID !== TypeID.integer && type.base.typeID !== TypeID.anyTypification;
|
|
379
401
|
}
|
|
380
402
|
//#endregion
|
|
381
|
-
export { addAliasReference, applyFilterCategory, applyMappingToConstituents, calculateSchemaStats, canHaveFormalDefinition, canHaveManualTypification, canProduceStructure, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, removeAliasReference, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
|
|
403
|
+
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 };
|
|
382
404
|
|
|
383
405
|
//# sourceMappingURL=rsform-api.js.map
|