@rsconcept/domain 2.2.0 → 3.0.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/{diagnostics-Db1F7ruF.d.ts → diagnostics-DsEhmFh0.d.ts} +6 -4
- package/dist/{diagnostics-B1OfMra1.js → diagnostics-ndGYbvgh.js} +374 -15
- package/dist/diagnostics-ndGYbvgh.js.map +1 -0
- package/dist/index-DpiTybDB.d.ts +376 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/library/diagnostics.d.ts +1 -1
- package/dist/library/diagnostics.js +1 -1
- package/dist/library/index.d.ts +6 -5
- package/dist/library/index.js +1 -1
- package/dist/library/index.js.map +1 -1
- package/dist/library/oss-api.d.ts +1 -1
- package/dist/library/oss-api.js +1 -1
- package/dist/library/oss-api.js.map +1 -1
- package/dist/library/rsengine.d.ts +1 -1
- package/dist/library/rsengine.js +2 -2
- package/dist/library/rsform-api/index.d.ts +2 -146
- package/dist/library/rsform-api/index.js +2 -2
- package/dist/library/rsform.d.ts +2 -2
- package/dist/library/rsform.js.map +1 -1
- package/dist/library/rsmodel-api.d.ts +9 -4
- package/dist/library/rsmodel-api.js +7 -3
- package/dist/library/rsmodel-api.js.map +1 -1
- package/dist/library/rsmodel.d.ts +1 -1
- package/dist/library/structure-planner.d.ts +1 -1
- package/dist/library/structure-planner.js +2 -2
- package/dist/library/structure-planner.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/library/diagnostics.ts +20 -9
- package/src/library/index.ts +1 -0
- package/src/library/oss-api.ts +5 -1
- package/src/library/rsform-api/alias.ts +60 -4
- package/src/library/rsform-api/attribution.ts +87 -0
- package/src/library/rsform-api/cst-type.ts +7 -5
- package/src/library/rsform-api/expression.ts +3 -3
- package/src/library/rsform-api/formal-graph.test.ts +2 -2
- package/src/library/rsform-api/formal-graph.ts +6 -10
- package/src/library/rsform-api/index.ts +38 -2
- package/src/library/rsform-api/semantic-relations.ts +4 -7
- package/src/library/rsform-api/stats.ts +6 -5
- package/src/library/rsform-api/structure.ts +12 -6
- package/src/library/rsform-api/substitution.ts +82 -0
- package/src/library/rsform-api/synthesis.test.ts +157 -0
- package/src/library/rsform-api/synthesis.ts +149 -6
- package/src/library/rsform-api/text-resolution.test.ts +84 -0
- package/src/library/rsform-api/text-resolution.ts +152 -0
- package/src/library/rsform-api/transforms.test.ts +161 -0
- package/src/library/rsform-api/transforms.ts +42 -0
- package/src/library/rsform-api/types.ts +102 -4
- package/src/library/rsform.ts +1 -1
- package/src/library/rsmodel-api.ts +10 -5
- package/src/library/structure-planner.ts +6 -2
- package/src/library/template-instantiation.ts +11 -9
- package/dist/diagnostics-B1OfMra1.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { TokenID } from "./rslang/parser/token.js";
|
|
|
6
6
|
import { AnyTypificationT, EmptySetT, LogicT, TypeClass, TypeID, makeTypePath } from "./rslang/semantic/typification.js";
|
|
7
7
|
import { parser } from "./rslang/parser/parser.js";
|
|
8
8
|
import { readErrorAnnotation, readTypeAnnotation } from "./rslang/ast-annotations.js";
|
|
9
|
+
import { CstClass, CstStatus, CstType } from "./library/rsform.js";
|
|
9
10
|
import { RSErrorCode } from "./rslang/error.js";
|
|
10
11
|
import { applyHash_fnv1a, generateStub } from "./shared/hash.js";
|
|
11
12
|
import { C as printValue, o as TUPLE_ID, u as makeValuePath } from "./value-COprb2Je.js";
|
|
@@ -14,8 +15,7 @@ import { ValueClass } from "./rslang/semantic/value-class.js";
|
|
|
14
15
|
import { RSLangAnalyzer } from "./rslang/semantic/analyzer.js";
|
|
15
16
|
import { applyAsciiTypeSubstitutions, parseTypeText } from "./rslang/semantic/typification-parser.js";
|
|
16
17
|
import { TypificationGraph } from "./rslang/typification-graph.js";
|
|
17
|
-
import {
|
|
18
|
-
import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "./diagnostics-B1OfMra1.js";
|
|
18
|
+
import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "./diagnostics-ndGYbvgh.js";
|
|
19
19
|
import { DEFAULT_VALUE_TEXT, EvalStatus } from "./library/rsmodel.js";
|
|
20
20
|
import { FolderNode, FolderTree } from "./library/folder-tree.js";
|
|
21
21
|
import { AccessPolicy, LibraryItemType, LocationHead } from "./library/library.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as detectDependencyCycleDiagnostics, c as modelStatusCstDiagnostic, i as assignSchemaDiagnostics, n as DiagnosticKind, o as formatDependencyCycle, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic } from "../diagnostics-
|
|
1
|
+
import { a as detectDependencyCycleDiagnostics, c as modelStatusCstDiagnostic, i as assignSchemaDiagnostics, n as DiagnosticKind, o as formatDependencyCycle, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic } from "../diagnostics-DsEhmFh0.js";
|
|
2
2
|
export { CstDiagnostic, DiagnosticKind, RSDiagnosticCode, assignSchemaDiagnostics, detectDependencyCycleDiagnostics, formatDependencyCycle, hasCstDiagnostic, modelStatusCstDiagnostic };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "../diagnostics-
|
|
1
|
+
import { a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind } from "../diagnostics-ndGYbvgh.js";
|
|
2
2
|
export { DiagnosticKind, RSDiagnosticCode, assignSchemaDiagnostics, detectDependencyCycleDiagnostics, formatDependencyCycle, hasCstDiagnostic, modelStatusCstDiagnostic };
|
package/dist/library/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
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 RSFormStats, S as RSForm, T as
|
|
2
|
+
import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, a as detectDependencyCycleDiagnostics, b as CstStatus, c as modelStatusCstDiagnostic, d as DEFAULT_VALUE_TEXT, f as EvalStatus, g as ArgumentValue, i as assignSchemaDiagnostics, l as BasicBinding, m as RSModelStats, n as DiagnosticKind, o as formatDependencyCycle, p as RSModel, r as RSDiagnosticCode, s as hasCstDiagnostic, t as CstDiagnostic, u as BasicsContext, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "../diagnostics-DsEhmFh0.js";
|
|
3
3
|
import { FolderNode, FolderTree } from "./folder-tree.js";
|
|
4
4
|
import { n as OssLayout, r as Position2D } from "../oss-layout-3glgAqfn.js";
|
|
5
5
|
import { Block, CstSubstituteInfo, NodeType, Operation, OperationInput, OperationSchema, OperationSchemaStats, OperationSynthesis, OperationType, OssItem, SubstitutionErrorDescription, SubstitutionErrorType } from "./oss.js";
|
|
6
6
|
import { RSEngine } from "./rsengine.js";
|
|
7
|
+
import { mt as TemplateSourceFields } from "../index-DpiTybDB.js";
|
|
7
8
|
|
|
8
9
|
//#region src/library/template-instantiation.d.ts
|
|
9
10
|
/**
|
|
@@ -22,7 +23,7 @@ interface TemplateInstantiationItem {
|
|
|
22
23
|
definition_formal: string;
|
|
23
24
|
definition_raw: string;
|
|
24
25
|
term_raw: string;
|
|
25
|
-
term_forms:
|
|
26
|
+
term_forms: TermForm[];
|
|
26
27
|
typification_manual: string;
|
|
27
28
|
value_is_property: boolean;
|
|
28
29
|
}
|
|
@@ -55,9 +56,9 @@ interface TemplateInstantiationInput {
|
|
|
55
56
|
/** Schema that will receive new constituents. */
|
|
56
57
|
targetSchema: RSForm;
|
|
57
58
|
/** All constituents of the selected expression-bank RSForm (not only the prototype). */
|
|
58
|
-
templateItems:
|
|
59
|
+
templateItems: TemplateSourceFields[];
|
|
59
60
|
/** Template constituent chosen in the UI (main expression to add). */
|
|
60
|
-
prototype:
|
|
61
|
+
prototype: TemplateSourceFields;
|
|
61
62
|
/** User bindings from template parameter aliases to target-schema global aliases. */
|
|
62
63
|
userArgs: ArgumentValue[];
|
|
63
64
|
/**
|
|
@@ -99,5 +100,5 @@ declare class TemplateInstantiationPlanner {
|
|
|
99
100
|
private collectDependencies;
|
|
100
101
|
}
|
|
101
102
|
//#endregion
|
|
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, detectDependencyCycleDiagnostics, formatDependencyCycle, hasCstDiagnostic, modelStatusCstDiagnostic, planTemplateInstantiation };
|
|
103
|
+
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 TermForm, type TypeInfo, type VersionInfo, assignSchemaDiagnostics, detectDependencyCycleDiagnostics, formatDependencyCycle, hasCstDiagnostic, modelStatusCstDiagnostic, planTemplateInstantiation };
|
|
103
104
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/library/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { TypeID } from "../rslang/semantic/typification.js";
|
|
|
5
5
|
import { labelType } from "../rslang/labels.js";
|
|
6
6
|
import { applyAliasMapping, isGlobalAlias, parseRSLangExpression, splitTemplateDefinition, substituteLocalAliases, substituteTemplateArgs } from "../rslang/api.js";
|
|
7
7
|
import { CstClass, CstStatus, CstType } from "./rsform.js";
|
|
8
|
-
import {
|
|
8
|
+
import { $ as isFunctional, A as normalizeExpression, R as applyMappingToConstituents, V as generateAlias, a as formatDependencyCycle, i as detectDependencyCycleDiagnostics, k as inferTemplatedType, n as RSDiagnosticCode, o as hasCstDiagnostic, r as assignSchemaDiagnostics, s as modelStatusCstDiagnostic, t as DiagnosticKind, z as argumentValuesToMapping } from "../diagnostics-ndGYbvgh.js";
|
|
9
9
|
import { DEFAULT_VALUE_TEXT, EvalStatus } from "./rsmodel.js";
|
|
10
10
|
import { FolderNode, FolderTree } from "./folder-tree.js";
|
|
11
11
|
import { AccessPolicy, LibraryItemType, LocationHead } from "./library.js";
|
|
@@ -1 +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,IAAa,+BAAb,MAA0C;CACxC;CACA;CACA;CACA;CACA;CACA;CACA,8BAA+B,IAAI,IAAiC;CACpE,0BAA2B,IAAI,IAAyB;CACxD,kBAA0D;;CAG1D,YAAY,OAAmC;EAC7C,KAAK,eAAe,MAAM;EAC1B,KAAK,YAAY,MAAM;EACvB,KAAK,WAAW,MAAM;EACtB,KAAK,mBAAmB,MAAM;EAC9B,KAAK,kBAAkB,IAAI,IACzB,MAAM,cAAc,QAAO,QAAO,aAAa,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAI,QAAO,CAAC,IAAI,OAAO,GAAG,CAAC,CAC3F;EACA,KAAK,cAAc,wBAAwB,MAAM,QAAQ;CAC3D;;CAGA,OAAkC;EAChC,MAAM,iBAAiB,uBAAuB,KAAK,UAAU,mBAAmB,KAAK,WAAW;EAChG,KAAK,oBAAoB,gBAAgB,KAAK,WAAW;EAEzD,IAAI,KAAK,iBACP,OAAO;GAAE,OAAO,CAA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AEA,SAAS,gBAAgB,SAAmB,MAA0C;CACpF,MAAM,YAAY,IAAI,IAAI,OAAO;CACjC,MAAM,SAAmB,CAAC;CAC1B,OAAO,UAAU,OAAO,GAAG;EACzB,MAAM,QAAQ,CAAC,GAAG,SAAS,CAAC,CAAC,QAAO,UAAS;GAE3C,OAAO,CAAC,GADK,KAAK,IAAI,KAAK,qBAAK,IAAI,IAAY,CACjC,CAAC,CAAC,OAAM,QAAO,CAAC,UAAU,IAAI,GAAG,CAAC;EACnD,CAAC;EACD,IAAI,MAAM,WAAW,GACnB,OAAO,CAAC,GAAG,WAAW,GAAG,MAAM,CAAC,CAAC,QAAQ;EAE3C,MAAM,KAAK;EACX,KAAK,MAAM,SAAS,OAAO;GACzB,OAAO,KAAK,KAAK;GACjB,UAAU,OAAO,KAAK;EACxB;CACF;CACA,OAAO;AACT"}
|
|
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 CstType, type RSForm, type TermForm } from './rsform';\nimport {\n applyMappingToConstituents,\n argumentValuesToMapping,\n generateAlias,\n inferTemplatedType,\n isFunctional,\n normalizeExpression,\n type TemplateParamSourceFields,\n type TemplateSourceFields\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: TermForm[];\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: TemplateSourceFields[];\n /** Template constituent chosen in the UI (main expression to add). */\n prototype: TemplateSourceFields;\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: TemplateSourceFields;\n private readonly userArgs: ArgumentValue[];\n private readonly mainItemTemplate: TemplateInstantiationItem;\n private readonly templateByAlias: Map<string, TemplateSourceFields>;\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: TemplateSourceFields,\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: TemplateParamSourceFields): 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":";;;;;;;;;;;;;;;;;;;;;;;;AA+GA,SAAgB,0BAA0B,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|
1
1
|
import { r as LibraryItem } from "../library-CYun28Xz.js";
|
|
2
|
-
import { S as RSForm, v as Constituenta, w as Substitution } from "../diagnostics-
|
|
2
|
+
import { S as RSForm, v as Constituenta, w as Substitution } from "../diagnostics-DsEhmFh0.js";
|
|
3
3
|
import { NodeType, OperationSchema, SubstitutionErrorDescription } from "./oss.js";
|
|
4
4
|
|
|
5
5
|
//#region src/library/oss-api.d.ts
|
package/dist/library/oss-api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Graph } from "../graph/graph.js";
|
|
2
2
|
import { labelType } from "../rslang/labels.js";
|
|
3
3
|
import { applyAliasMapping, applyTypificationMapping, isSetTypification } from "../rslang/api.js";
|
|
4
|
-
import { extractBases } from "../rslang/semantic/typification-api.js";
|
|
5
4
|
import { CstClass, CstType } from "./rsform.js";
|
|
5
|
+
import { extractBases } from "../rslang/semantic/typification-api.js";
|
|
6
6
|
import "../graph/index.js";
|
|
7
7
|
import { NodeType, SubstitutionErrorType } from "./oss.js";
|
|
8
8
|
//#region src/library/oss-api.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oss-api.js","names":[],"sources":["../../src/library/oss-api.ts"],"sourcesContent":["/**\n * Module: API for OperationSystem.\n */\n\nimport { Graph } from '../graph';\nimport { type AliasMapping, applyAliasMapping, applyTypificationMapping, isSetTypification } from '../rslang/api';\nimport { labelType } from '../rslang/labels';\nimport { extractBases } from '../rslang/semantic/typification-api';\n\nimport { type LibraryItem } from './library';\nimport { NodeType, type OperationSchema, type SubstitutionErrorDescription, SubstitutionErrorType } from './oss';\nimport { type Constituenta, CstClass, CstType, type RSForm, type Substitution } from './rsform';\n\nconst STARTING_SUB_INDEX = 900; // max semantic index for starting substitution\n\nexport function constructNodeID(type: NodeType, itemID: number): string {\n return type === NodeType.OPERATION ? 'o' + String(itemID) : 'b' + String(itemID);\n}\n\n/** Sorts library items relevant for the specified {@link OperationSchema}. */\nexport function sortItemsForOSS(oss: OperationSchema, items: readonly LibraryItem[]): LibraryItem[] {\n const result = items.filter(item => item.location === oss.location);\n for (const item of items) {\n if (item.visible && item.owner === oss.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\ntype CrossMapping = Map<number, AliasMapping>;\n\n/** Validator for Substitution table. */\nexport class SubstitutionValidator {\n public errors: SubstitutionErrorDescription[] = [];\n public suggestions: Substitution[] = [];\n\n private schemas: RSForm[];\n private substitutions: Substitution[];\n private constituents = new Set<number>();\n private originals = new Set<number>();\n private mapping: CrossMapping = new Map();\n\n private cstByID = new Map<number, Constituenta>();\n private schemaByID = new Map<number, RSForm>();\n private schemaByCst = new Map<number, RSForm>();\n\n constructor(schemas: RSForm[], substitutions: Substitution[]) {\n this.schemas = schemas;\n this.substitutions = substitutions;\n if (schemas.length === 0) {\n return;\n }\n\n for (const schema of schemas) {\n this.schemaByID.set(schema.id, schema);\n this.mapping.set(schema.id, {});\n for (const item of schema.items) {\n this.cstByID.set(item.id, item);\n this.schemaByCst.set(item.id, schema);\n }\n }\n if (substitutions.length === 0) {\n return;\n }\n let index = STARTING_SUB_INDEX;\n for (const item of substitutions) {\n this.constituents.add(item.original);\n this.constituents.add(item.substitution);\n this.originals.add(item.original);\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return;\n }\n index++;\n const newAlias = `${substitution.alias[0]}${index}`;\n this.mapping.get(original.schema)![original.alias] = newAlias;\n this.mapping.get(substitution.schema)![substitution.alias] = newAlias;\n }\n }\n\n public validate(): boolean {\n this.errors = [];\n this.suggestions = [];\n this.calculateSuggestions();\n if (this.substitutions.length === 0) {\n return true;\n }\n if (!this.checkTypes()) {\n return false;\n }\n if (!this.checkCycles()) {\n return false;\n }\n if (!this.checkSubstitutions()) {\n return false;\n }\n return true;\n }\n\n private calculateSuggestions(): void {\n const candidates = new Map<number, string>();\n const minors = new Set<number>();\n const schemaByCst = new Map<number, RSForm>();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (this.originals.has(cst.id)) {\n continue;\n }\n if (cst.cst_class === CstClass.BASIC || cst.definition_formal.length === 0) {\n continue;\n }\n const inputs = schema.graph.at(cst.id)!.inputs;\n if (inputs.some(id => !this.constituents.has(id))) {\n continue;\n }\n if (inputs.some(id => this.originals.has(id))) {\n minors.add(cst.id);\n }\n candidates.set(\n cst.id,\n applyAliasMapping(cst.definition_formal, this.mapping.get(schema.id)!).replace(/\\s+/g, '')\n );\n schemaByCst.set(cst.id, schema);\n }\n }\n for (const [key1, value1] of candidates) {\n for (const [key2, value2] of candidates) {\n if (key1 >= key2) {\n continue;\n }\n if (schemaByCst.get(key1) === schemaByCst.get(key2)) {\n continue;\n }\n if (value1 != value2) {\n continue;\n }\n if (minors.has(key2)) {\n this.suggestions.push({\n original: key2,\n substitution: key1\n });\n } else {\n this.suggestions.push({\n original: key1,\n substitution: key2\n });\n }\n }\n }\n }\n\n private checkTypes(): boolean {\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return this.reportError(SubstitutionErrorType.invalidIDs, []);\n }\n if (\n substitution.analysis &&\n original.analysis &&\n (!original.analysis.success || !substitution.analysis.success)\n ) {\n return this.reportError(SubstitutionErrorType.incorrectCst, [substitution.alias, original.alias]);\n }\n switch (substitution.cst_type) {\n case CstType.NOMINAL: {\n if (original.cst_type !== CstType.NOMINAL) {\n return this.reportError(SubstitutionErrorType.invalidNominal, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.BASE: {\n if (\n original.cst_type !== CstType.BASE &&\n original.cst_type !== CstType.CONSTANT &&\n original.cst_type !== CstType.NOMINAL\n ) {\n return this.reportError(SubstitutionErrorType.invalidBasic, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.CONSTANT: {\n if (original.cst_type !== CstType.CONSTANT) {\n return this.reportError(SubstitutionErrorType.invalidConstant, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.AXIOM:\n case CstType.STATEMENT: {\n if (original.cst_type !== CstType.AXIOM && original.cst_type !== CstType.STATEMENT) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.FUNCTION: {\n if (original.cst_type !== CstType.FUNCTION) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.PREDICATE: {\n if (original.cst_type !== CstType.PREDICATE) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.TERM:\n case CstType.STRUCTURED: {\n if (\n original.cst_type !== CstType.TERM &&\n original.cst_type !== CstType.STRUCTURED &&\n original.cst_type !== CstType.BASE\n ) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n }\n }\n return true;\n }\n\n private checkCycles(): boolean {\n const graph = new Graph();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n graph.addNode(cst.id);\n }\n }\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n const substitution = this.cstByID.get(item.substitution)!;\n for (const cst of [original, substitution]) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n continue;\n }\n graph.addNode(cst.id);\n if (cst.effectiveType === null) {\n continue;\n }\n const parents = extractBases(cst.effectiveType);\n if (parents.size === 0) {\n continue;\n }\n const schema = this.schemaByID.get(cst.schema)!;\n for (const alias of parents) {\n const parent = schema.cstByAlias.get(alias);\n if (parent) {\n graph.addEdge(parent.id, cst.id);\n }\n }\n }\n graph.addEdge(substitution.id, original.id);\n }\n const cycle = graph.findCycle();\n if (cycle !== null) {\n const cycleMsg = cycle\n .map(id => {\n const cst = this.cstByID.get(id)!;\n const schema = this.schemaByID.get(cst.schema)!;\n return `[${schema.alias}]-${cst.alias}`;\n })\n .join(', ');\n return this.reportError(SubstitutionErrorType.typificationCycle, [cycleMsg]);\n }\n return true;\n }\n\n private checkSubstitutions(): boolean {\n const baseMappings = this.prepareBaseMappings();\n const typeMappings = this.calculateSubstituteMappings(baseMappings);\n if (typeMappings === null) {\n return false;\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (\n original.cst_type === CstType.BASE ||\n original.cst_type === CstType.CONSTANT ||\n original.cst_type === CstType.NOMINAL\n ) {\n continue;\n }\n const substitution = this.cstByID.get(item.substitution)!;\n if (original.cst_type === substitution.cst_type && original.cst_class !== CstClass.BASIC) {\n if (!this.checkEqual(original, substitution)) {\n this.reportError(SubstitutionErrorType.unequalExpressions, [substitution.alias, original.alias]);\n // Note: do not interrupt the validation process. Only warn about the problem.\n }\n }\n\n if (original.analysis.success !== substitution.analysis.success) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n if (!original.analysis.success || !substitution.analysis.success) {\n continue;\n }\n\n const originalType = applyTypificationMapping(\n applyAliasMapping(labelType(original.effectiveType), baseMappings.get(original.schema)!),\n typeMappings\n );\n const substitutionType = applyTypificationMapping(\n applyAliasMapping(labelType(substitution.effectiveType), baseMappings.get(substitution.schema)!),\n typeMappings\n );\n if (originalType !== substitutionType) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n }\n return true;\n }\n\n private prepareBaseMappings(): CrossMapping {\n const result: CrossMapping = new Map();\n let baseCount = 0;\n let constCount = 0;\n for (const schema of this.schemas) {\n const mapping: AliasMapping = {};\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE) {\n baseCount++;\n mapping[cst.alias] = `X${baseCount}`;\n } else if (cst.cst_type === CstType.CONSTANT) {\n constCount++;\n mapping[cst.alias] = `C${constCount}`;\n }\n result.set(schema.id, mapping);\n }\n }\n return result;\n }\n\n private calculateSubstituteMappings(baseMappings: CrossMapping): AliasMapping | null {\n const result: AliasMapping = {};\n const processed = new Set<string>();\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (original.cst_type !== CstType.BASE && original.cst_type !== CstType.CONSTANT) {\n continue;\n }\n const originalAlias = baseMappings.get(original.schema)![original.alias];\n\n const substitution = this.cstByID.get(item.substitution)!;\n let substitutionText = '';\n if (substitution.cst_type === original.cst_type || !substitution.effectiveType) {\n substitutionText = baseMappings.get(substitution.schema)![substitution.alias];\n } else {\n const typeText = labelType(substitution.effectiveType);\n substitutionText = applyAliasMapping(typeText, baseMappings.get(substitution.schema)!);\n substitutionText = applyTypificationMapping(substitutionText, result);\n if (!isSetTypification(substitutionText)) {\n this.reportError(SubstitutionErrorType.baseSubstitutionNotSet, [substitution.alias, typeText]);\n return null;\n }\n if (substitutionText.includes('×') || substitutionText.startsWith('ℬℬ')) {\n substitutionText = substitutionText.slice(1);\n } else {\n substitutionText = substitutionText.slice(2, -1);\n }\n }\n for (const prevAlias of processed) {\n result[prevAlias] = applyTypificationMapping(result[prevAlias], { [originalAlias]: substitutionText });\n }\n result[originalAlias] = substitutionText;\n processed.add(originalAlias);\n }\n return result;\n }\n\n private checkEqual(left: Constituenta, right: Constituenta): boolean {\n const schema1 = this.schemaByID.get(left.schema)!;\n const inputs1 = schema1.graph.at(left.id)!.inputs;\n if (inputs1.some(id => !this.constituents.has(id))) {\n return false;\n }\n const schema2 = this.schemaByID.get(right.schema)!;\n const inputs2 = schema2.graph.at(right.id)!.inputs;\n if (inputs2.some(id => !this.constituents.has(id))) {\n return false;\n }\n const expression1 = applyAliasMapping(left.definition_formal, this.mapping.get(schema1.id)!);\n const expression2 = applyAliasMapping(right.definition_formal, this.mapping.get(schema2.id)!);\n return expression1.replace(/\\s+/g, '') === expression2.replace(/\\s+/g, '');\n }\n\n private reportError(errorType: SubstitutionErrorType, params: string[]): boolean {\n this.errors.push({\n errorType: errorType,\n params: params\n });\n return false;\n }\n}\n\n/** Filter relocate candidates from gives schema. */\nexport function getRelocateCandidates(\n source: number,\n destination: number,\n schema: RSForm,\n oss: OperationSchema\n): Constituenta[] {\n const destinationSchema = oss.operationByID.get(destination)?.result;\n if (!destinationSchema) {\n return [];\n }\n const node = oss.graph.at(source);\n if (!node) {\n return [];\n }\n\n if (node.outputs.includes(destination)) {\n return schema.items;\n }\n\n const addedCst = schema.items.filter(item => !item.is_inherited).map(cst => cst.id);\n\n const unreachableBases: number[] = [];\n for (const cst of schema.items.filter(item => item.is_inherited)) {\n if (cst.parent_schema == destinationSchema) {\n continue;\n }\n const parent = schema.inheritance.find(item => item.child === cst.id && item.child_source === cst.schema)?.parent;\n if (parent) {\n const original = oss.substitutions.find(sub => sub.substitution === parent)?.original;\n if (original) {\n continue;\n }\n }\n unreachableBases.push(cst.id);\n }\n const unreachable = schema.graph.expandAllOutputs(unreachableBases);\n return schema.items.filter(\n cst => cst.parent_schema === destinationSchema || (addedCst.includes(cst.id) && !unreachable.includes(cst.id))\n );\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,qBAAqB;AAE3B,SAAgB,gBAAgB,MAAgB,QAAwB;CACtE,OAAO,SAAS,SAAS,YAAY,MAAM,OAAO,MAAM,IAAI,MAAM,OAAO,MAAM;AACjF;;AAGA,SAAgB,gBAAgB,KAAsB,OAA8C;CAClG,MAAM,SAAS,MAAM,QAAO,SAAQ,KAAK,aAAa,IAAI,QAAQ;CAClE,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,KAAK,UAAU,IAAI,SAAS,CAAC,OAAO,SAAS,IAAI,GACnE,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,CAAC,OAAO,SAAS,IAAI,GACvC,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,CAAC,OAAO,SAAS,IAAI,GACvB,OAAO,KAAK,IAAI;CAGpB,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A6B,CAAC;CACpC,KAAK,MAAM,OAAO,OAAO,MAAM,QAAO,SAAQ,KAAK,YAAY,GAAG;EAChE,IAAI,IAAI,iBAAiB,mBACvB;EAEF,MAAM,SAAS,OAAO,YAAY,MAAK,SAAQ,KAAK,UAAU,IAAI,MAAM,KAAK,iBAAiB,IAAI,MAAM,CAAC,EAAE;EAC3G,IAAI,QAEF;OADiB,IAAI,cAAc,MAAK,QAAO,IAAI,iBAAiB,MAAM,CAAC,EAAE,UAE3E;EACF;EAEF,iBAAiB,KAAK,IAAI,EAAE;CAC9B;CACA,MAAM,cAAc,OAAO,MAAM,iBAAiB,gBAAgB;CAClE,OAAO,OAAO,MAAM,QAClB,QAAO,IAAI,kBAAkB,qBAAsB,SAAS,SAAS,IAAI,EAAE,KAAK,CAAC,YAAY,SAAS,IAAI,EAAE,CAC9G;AACF"}
|
|
1
|
+
{"version":3,"file":"oss-api.js","names":[],"sources":["../../src/library/oss-api.ts"],"sourcesContent":["/**\n * Module: API for OperationSystem.\n */\n\nimport { Graph } from '../graph';\nimport { type AliasMapping, applyAliasMapping, applyTypificationMapping, isSetTypification } from '../rslang/api';\nimport { labelType } from '../rslang/labels';\nimport { extractBases } from '../rslang/semantic/typification-api';\n\nimport { type LibraryItem } from './library';\nimport { NodeType, type OperationSchema, type SubstitutionErrorDescription, SubstitutionErrorType } from './oss';\nimport { type Constituenta, CstClass, CstType, type RSForm, type Substitution } from './rsform';\nimport { type FormalOrderFields } from './rsform-api';\n\nconst STARTING_SUB_INDEX = 900; // max semantic index for starting substitution\n\nexport function constructNodeID(type: NodeType, itemID: number): string {\n return type === NodeType.OPERATION ? 'o' + String(itemID) : 'b' + String(itemID);\n}\n\n/** Sorts library items relevant for the specified {@link OperationSchema}. */\nexport function sortItemsForOSS(oss: OperationSchema, items: readonly LibraryItem[]): LibraryItem[] {\n const result = items.filter(item => item.location === oss.location);\n for (const item of items) {\n if (item.visible && item.owner === oss.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\ntype CrossMapping = Map<number, AliasMapping>;\n\n/** Validator for Substitution table. */\nexport class SubstitutionValidator {\n public errors: SubstitutionErrorDescription[] = [];\n public suggestions: Substitution[] = [];\n\n private schemas: RSForm[];\n private substitutions: Substitution[];\n private constituents = new Set<number>();\n private originals = new Set<number>();\n private mapping: CrossMapping = new Map();\n\n private cstByID = new Map<number, Constituenta>();\n private schemaByID = new Map<number, RSForm>();\n private schemaByCst = new Map<number, RSForm>();\n\n constructor(schemas: RSForm[], substitutions: Substitution[]) {\n this.schemas = schemas;\n this.substitutions = substitutions;\n if (schemas.length === 0) {\n return;\n }\n\n for (const schema of schemas) {\n this.schemaByID.set(schema.id, schema);\n this.mapping.set(schema.id, {});\n for (const item of schema.items) {\n this.cstByID.set(item.id, item);\n this.schemaByCst.set(item.id, schema);\n }\n }\n if (substitutions.length === 0) {\n return;\n }\n let index = STARTING_SUB_INDEX;\n for (const item of substitutions) {\n this.constituents.add(item.original);\n this.constituents.add(item.substitution);\n this.originals.add(item.original);\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return;\n }\n index++;\n const newAlias = `${substitution.alias[0]}${index}`;\n this.mapping.get(original.schema)![original.alias] = newAlias;\n this.mapping.get(substitution.schema)![substitution.alias] = newAlias;\n }\n }\n\n public validate(): boolean {\n this.errors = [];\n this.suggestions = [];\n this.calculateSuggestions();\n if (this.substitutions.length === 0) {\n return true;\n }\n if (!this.checkTypes()) {\n return false;\n }\n if (!this.checkCycles()) {\n return false;\n }\n if (!this.checkSubstitutions()) {\n return false;\n }\n return true;\n }\n\n private calculateSuggestions(): void {\n const candidates = new Map<number, string>();\n const minors = new Set<number>();\n const schemaByCst = new Map<number, RSForm>();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (this.originals.has(cst.id)) {\n continue;\n }\n if (cst.cst_class === CstClass.BASIC || cst.definition_formal.length === 0) {\n continue;\n }\n const inputs = schema.graph.at(cst.id)!.inputs;\n if (inputs.some(id => !this.constituents.has(id))) {\n continue;\n }\n if (inputs.some(id => this.originals.has(id))) {\n minors.add(cst.id);\n }\n candidates.set(\n cst.id,\n applyAliasMapping(cst.definition_formal, this.mapping.get(schema.id)!).replace(/\\s+/g, '')\n );\n schemaByCst.set(cst.id, schema);\n }\n }\n for (const [key1, value1] of candidates) {\n for (const [key2, value2] of candidates) {\n if (key1 >= key2) {\n continue;\n }\n if (schemaByCst.get(key1) === schemaByCst.get(key2)) {\n continue;\n }\n if (value1 != value2) {\n continue;\n }\n if (minors.has(key2)) {\n this.suggestions.push({\n original: key2,\n substitution: key1\n });\n } else {\n this.suggestions.push({\n original: key1,\n substitution: key2\n });\n }\n }\n }\n }\n\n private checkTypes(): boolean {\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original);\n const substitution = this.cstByID.get(item.substitution);\n if (!original || !substitution) {\n return this.reportError(SubstitutionErrorType.invalidIDs, []);\n }\n if (\n substitution.analysis &&\n original.analysis &&\n (!original.analysis.success || !substitution.analysis.success)\n ) {\n return this.reportError(SubstitutionErrorType.incorrectCst, [substitution.alias, original.alias]);\n }\n switch (substitution.cst_type) {\n case CstType.NOMINAL: {\n if (original.cst_type !== CstType.NOMINAL) {\n return this.reportError(SubstitutionErrorType.invalidNominal, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.BASE: {\n if (\n original.cst_type !== CstType.BASE &&\n original.cst_type !== CstType.CONSTANT &&\n original.cst_type !== CstType.NOMINAL\n ) {\n return this.reportError(SubstitutionErrorType.invalidBasic, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.CONSTANT: {\n if (original.cst_type !== CstType.CONSTANT) {\n return this.reportError(SubstitutionErrorType.invalidConstant, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.AXIOM:\n case CstType.STATEMENT: {\n if (original.cst_type !== CstType.AXIOM && original.cst_type !== CstType.STATEMENT) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.FUNCTION: {\n if (original.cst_type !== CstType.FUNCTION) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n case CstType.PREDICATE: {\n if (original.cst_type !== CstType.PREDICATE) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n\n case CstType.TERM:\n case CstType.STRUCTURED: {\n if (\n original.cst_type !== CstType.TERM &&\n original.cst_type !== CstType.STRUCTURED &&\n original.cst_type !== CstType.BASE\n ) {\n return this.reportError(SubstitutionErrorType.invalidClasses, [substitution.alias, original.alias]);\n }\n break;\n }\n }\n }\n return true;\n }\n\n private checkCycles(): boolean {\n const graph = new Graph();\n for (const schema of this.schemas) {\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n graph.addNode(cst.id);\n }\n }\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n const substitution = this.cstByID.get(item.substitution)!;\n for (const cst of [original, substitution]) {\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT) {\n continue;\n }\n graph.addNode(cst.id);\n if (cst.effectiveType === null) {\n continue;\n }\n const parents = extractBases(cst.effectiveType);\n if (parents.size === 0) {\n continue;\n }\n const schema = this.schemaByID.get(cst.schema)!;\n for (const alias of parents) {\n const parent = schema.cstByAlias.get(alias);\n if (parent) {\n graph.addEdge(parent.id, cst.id);\n }\n }\n }\n graph.addEdge(substitution.id, original.id);\n }\n const cycle = graph.findCycle();\n if (cycle !== null) {\n const cycleMsg = cycle\n .map(id => {\n const cst = this.cstByID.get(id)!;\n const schema = this.schemaByID.get(cst.schema)!;\n return `[${schema.alias}]-${cst.alias}`;\n })\n .join(', ');\n return this.reportError(SubstitutionErrorType.typificationCycle, [cycleMsg]);\n }\n return true;\n }\n\n private checkSubstitutions(): boolean {\n const baseMappings = this.prepareBaseMappings();\n const typeMappings = this.calculateSubstituteMappings(baseMappings);\n if (typeMappings === null) {\n return false;\n }\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (\n original.cst_type === CstType.BASE ||\n original.cst_type === CstType.CONSTANT ||\n original.cst_type === CstType.NOMINAL\n ) {\n continue;\n }\n const substitution = this.cstByID.get(item.substitution)!;\n if (original.cst_type === substitution.cst_type && original.cst_class !== CstClass.BASIC) {\n if (!this.checkEqual(original, substitution)) {\n this.reportError(SubstitutionErrorType.unequalExpressions, [substitution.alias, original.alias]);\n // Note: do not interrupt the validation process. Only warn about the problem.\n }\n }\n\n if (original.analysis.success !== substitution.analysis.success) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n if (!original.analysis.success || !substitution.analysis.success) {\n continue;\n }\n\n const originalType = applyTypificationMapping(\n applyAliasMapping(labelType(original.effectiveType), baseMappings.get(original.schema)!),\n typeMappings\n );\n const substitutionType = applyTypificationMapping(\n applyAliasMapping(labelType(substitution.effectiveType), baseMappings.get(substitution.schema)!),\n typeMappings\n );\n if (originalType !== substitutionType) {\n return this.reportError(SubstitutionErrorType.unequalTypification, [substitution.alias, original.alias]);\n }\n }\n return true;\n }\n\n private prepareBaseMappings(): CrossMapping {\n const result: CrossMapping = new Map();\n let baseCount = 0;\n let constCount = 0;\n for (const schema of this.schemas) {\n const mapping: AliasMapping = {};\n for (const cst of schema.items) {\n if (cst.cst_type === CstType.BASE) {\n baseCount++;\n mapping[cst.alias] = `X${baseCount}`;\n } else if (cst.cst_type === CstType.CONSTANT) {\n constCount++;\n mapping[cst.alias] = `C${constCount}`;\n }\n result.set(schema.id, mapping);\n }\n }\n return result;\n }\n\n private calculateSubstituteMappings(baseMappings: CrossMapping): AliasMapping | null {\n const result: AliasMapping = {};\n const processed = new Set<string>();\n for (const item of this.substitutions) {\n const original = this.cstByID.get(item.original)!;\n if (original.cst_type !== CstType.BASE && original.cst_type !== CstType.CONSTANT) {\n continue;\n }\n const originalAlias = baseMappings.get(original.schema)![original.alias];\n\n const substitution = this.cstByID.get(item.substitution)!;\n let substitutionText = '';\n if (substitution.cst_type === original.cst_type || !substitution.effectiveType) {\n substitutionText = baseMappings.get(substitution.schema)![substitution.alias];\n } else {\n const typeText = labelType(substitution.effectiveType);\n substitutionText = applyAliasMapping(typeText, baseMappings.get(substitution.schema)!);\n substitutionText = applyTypificationMapping(substitutionText, result);\n if (!isSetTypification(substitutionText)) {\n this.reportError(SubstitutionErrorType.baseSubstitutionNotSet, [substitution.alias, typeText]);\n return null;\n }\n if (substitutionText.includes('×') || substitutionText.startsWith('ℬℬ')) {\n substitutionText = substitutionText.slice(1);\n } else {\n substitutionText = substitutionText.slice(2, -1);\n }\n }\n for (const prevAlias of processed) {\n result[prevAlias] = applyTypificationMapping(result[prevAlias], { [originalAlias]: substitutionText });\n }\n result[originalAlias] = substitutionText;\n processed.add(originalAlias);\n }\n return result;\n }\n\n private checkEqual(\n left: FormalOrderFields & { schema: number },\n right: FormalOrderFields & { schema: number }\n ): boolean {\n const schema1 = this.schemaByID.get(left.schema)!;\n const inputs1 = schema1.graph.at(left.id)!.inputs;\n if (inputs1.some(id => !this.constituents.has(id))) {\n return false;\n }\n const schema2 = this.schemaByID.get(right.schema)!;\n const inputs2 = schema2.graph.at(right.id)!.inputs;\n if (inputs2.some(id => !this.constituents.has(id))) {\n return false;\n }\n const expression1 = applyAliasMapping(left.definition_formal, this.mapping.get(schema1.id)!);\n const expression2 = applyAliasMapping(right.definition_formal, this.mapping.get(schema2.id)!);\n return expression1.replace(/\\s+/g, '') === expression2.replace(/\\s+/g, '');\n }\n\n private reportError(errorType: SubstitutionErrorType, params: string[]): boolean {\n this.errors.push({\n errorType: errorType,\n params: params\n });\n return false;\n }\n}\n\n/** Filter relocate candidates from gives schema. */\nexport function getRelocateCandidates(\n source: number,\n destination: number,\n schema: RSForm,\n oss: OperationSchema\n): Constituenta[] {\n const destinationSchema = oss.operationByID.get(destination)?.result;\n if (!destinationSchema) {\n return [];\n }\n const node = oss.graph.at(source);\n if (!node) {\n return [];\n }\n\n if (node.outputs.includes(destination)) {\n return schema.items;\n }\n\n const addedCst = schema.items.filter(item => !item.is_inherited).map(cst => cst.id);\n\n const unreachableBases: number[] = [];\n for (const cst of schema.items.filter(item => item.is_inherited)) {\n if (cst.parent_schema == destinationSchema) {\n continue;\n }\n const parent = schema.inheritance.find(item => item.child === cst.id && item.child_source === cst.schema)?.parent;\n if (parent) {\n const original = oss.substitutions.find(sub => sub.substitution === parent)?.original;\n if (original) {\n continue;\n }\n }\n unreachableBases.push(cst.id);\n }\n const unreachable = schema.graph.expandAllOutputs(unreachableBases);\n return schema.items.filter(\n cst => cst.parent_schema === destinationSchema || (addedCst.includes(cst.id) && !unreachable.includes(cst.id))\n );\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,qBAAqB;AAE3B,SAAgB,gBAAgB,MAAgB,QAAwB;CACtE,OAAO,SAAS,SAAS,YAAY,MAAM,OAAO,MAAM,IAAI,MAAM,OAAO,MAAM;AACjF;;AAGA,SAAgB,gBAAgB,KAAsB,OAA8C;CAClG,MAAM,SAAS,MAAM,QAAO,SAAQ,KAAK,aAAa,IAAI,QAAQ;CAClE,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,KAAK,UAAU,IAAI,SAAS,CAAC,OAAO,SAAS,IAAI,GACnE,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,WAAW,CAAC,OAAO,SAAS,IAAI,GACvC,OAAO,KAAK,IAAI;CAGpB,KAAK,MAAM,QAAQ,OACjB,IAAI,CAAC,OAAO,SAAS,IAAI,GACvB,OAAO,KAAK,IAAI;CAGpB,OAAO;AACT;;AAKA,IAAa,wBAAb,MAAmC;CACjC,SAAgD,CAAC;CACjD,cAAqC,CAAC;CAEtC;CACA;CACA,+B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mBACvB;EAEF,MAAM,SAAS,OAAO,YAAY,MAAK,SAAQ,KAAK,UAAU,IAAI,MAAM,KAAK,iBAAiB,IAAI,MAAM,CAAC,EAAE;EAC3G,IAAI,QAEF;OADiB,IAAI,cAAc,MAAK,QAAO,IAAI,iBAAiB,MAAM,CAAC,EAAE,UAE3E;EACF;EAEF,iBAAiB,KAAK,IAAI,EAAE;CAC9B;CACA,MAAM,cAAc,OAAO,MAAM,iBAAiB,gBAAgB;CAClE,OAAO,OAAO,MAAM,QAClB,QAAO,IAAI,kBAAkB,qBAAsB,SAAS,SAAS,IAAI,EAAE,KAAK,CAAC,YAAY,SAAS,IAAI,EAAE,CAC9G;AACF"}
|
|
@@ -1,7 +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-DE89LtIM.js";
|
|
4
|
-
import { S as RSForm, f as EvalStatus, l as BasicBinding, p as RSModel, u as BasicsContext, x as CstType } from "../diagnostics-
|
|
4
|
+
import { S as RSForm, f as EvalStatus, l as BasicBinding, p as RSModel, u as BasicsContext, x as CstType } from "../diagnostics-DsEhmFh0.js";
|
|
5
5
|
|
|
6
6
|
//#region src/library/rsengine.d.ts
|
|
7
7
|
/** Services for {@link RSEngine}. */
|
package/dist/library/rsengine.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TypeID } from "../rslang/semantic/typification.js";
|
|
2
2
|
import { normalizeType } from "../rslang/labels.js";
|
|
3
|
+
import { CstType } from "./rsform.js";
|
|
3
4
|
import { l as compare } from "../value-COprb2Je.js";
|
|
4
5
|
import { RSCalculator } from "../rslang/eval/calculator.js";
|
|
5
6
|
import "../rslang/index.js";
|
|
6
|
-
import {
|
|
7
|
-
import { F as isBasicConcept, I as isFunctional, P as isBaseSet, b as getAnalysisFor } from "../diagnostics-B1OfMra1.js";
|
|
7
|
+
import { $ as isFunctional, P as getAnalysisFor, Q as isBasicConcept, Z as isBaseSet } from "../diagnostics-ndGYbvgh.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,146 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
import { g as TypeClass, y as TypePath } from "../../typification-9lNu9R4k.js";
|
|
4
|
-
import { t as ValueClass } from "../../value-class-CNI-lqXJ.js";
|
|
5
|
-
import { r as AnalysisFull } from "../../analyzer-fNhkwO-6.js";
|
|
6
|
-
import { r as LibraryItem } from "../../library-CYun28Xz.js";
|
|
7
|
-
import { C as RSFormStats, S as RSForm, b as CstStatus, g as ArgumentValue, v as Constituenta, x as CstType, y as CstClass } from "../../diagnostics-Db1F7ruF.js";
|
|
8
|
-
import { t as AliasMapping } from "../../api-Bf0f_uiI.js";
|
|
9
|
-
|
|
10
|
-
//#region src/library/rsform-api/alias.d.ts
|
|
11
|
-
/** Fields of {@link Constituenta} updated in place by alias mapping. */
|
|
12
|
-
interface ConstituentaMappableFields {
|
|
13
|
-
alias: string;
|
|
14
|
-
definition_formal: string;
|
|
15
|
-
typification_manual: string;
|
|
16
|
-
term_raw: string;
|
|
17
|
-
definition_raw: string;
|
|
18
|
-
}
|
|
19
|
-
/** Build alias mapping from template argument bindings. */
|
|
20
|
-
declare function argumentValuesToMapping(args: ArgumentValue[]): AliasMapping;
|
|
21
|
-
/** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */
|
|
22
|
-
declare function validateAliasFormat(alias: string, type: CstType): boolean;
|
|
23
|
-
/** Validate new alias against {@link CstType} and {@link RSForm}. */
|
|
24
|
-
declare function validateNewAlias(alias: string, type: CstType, schema: RSForm): boolean;
|
|
25
|
-
/** Generate alias for new {@link Constituenta} of a given {@link CstType} for current {@link RSForm}. */
|
|
26
|
-
declare function generateAlias(type: CstType, schema: RSForm, takenAliases?: string[]): string;
|
|
27
|
-
/**
|
|
28
|
-
* Remap formal expressions and terminological entity references in constituent fields.
|
|
29
|
-
* Mutates each element of `items` in place; pass owned or cloned data only.
|
|
30
|
-
*/
|
|
31
|
-
declare function applyMappingToConstituents<T extends ConstituentaMappableFields>(items: T[], mapping: AliasMapping, changeAliases: boolean): void;
|
|
32
|
-
/** Remove alias from expression. */
|
|
33
|
-
declare function removeAliasReference(expression: string, alias: string): string;
|
|
34
|
-
/** Add alias to expression. */
|
|
35
|
-
declare function addAliasReference(expression: string, alias: string): string;
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/library/rsform-api/analysis.d.ts
|
|
38
|
-
declare function getAnalysisFor(expression: string, cstType: CstType, schema: RSForm, alias?: string): AnalysisFull;
|
|
39
|
-
/**
|
|
40
|
-
* When an untyped / bare F·P reference names a constituent on a definition cycle with the
|
|
41
|
-
* current expression, replace that error with {@link RSDiagnosticCode.schemaDependencyCycle}.
|
|
42
|
-
*
|
|
43
|
-
* Covers both semantic `globalNotTyped` (e.g. `F3[σ]`) and parser `globalFuncWithoutArgs`
|
|
44
|
-
* (bare `P1` / `F1` treated as a call without arguments).
|
|
45
|
-
*
|
|
46
|
-
* Uses a draft dependency graph: incoming edges of the edited constituent are taken from
|
|
47
|
-
* `expression`, so Check works before Save.
|
|
48
|
-
*/
|
|
49
|
-
declare function refineAnalysisForDependencyCycles(analysis: AnalysisFull, expression: string, schema: RSForm, alias?: string): AnalysisFull;
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/library/rsform-api/cst-type.d.ts
|
|
52
|
-
/** Prefix for alias indicating {@link CstType}. */
|
|
53
|
-
declare function getCstTypePrefix(type: CstType): string;
|
|
54
|
-
/** Guess {@link CstType} from user input hint. */
|
|
55
|
-
declare function guessCstType(hint: string): CstType | null;
|
|
56
|
-
/** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */
|
|
57
|
-
declare function inferClass(type: CstType, isTemplate?: boolean): CstClass;
|
|
58
|
-
/** Check if {@link Constituenta} is a template or a category. */
|
|
59
|
-
declare function isTemplateCst(cst: Constituenta): boolean;
|
|
60
|
-
/** Evaluate if {@link CstType} is basic concept. */
|
|
61
|
-
declare function isBasicConcept(type: CstType): boolean;
|
|
62
|
-
/** Evaluate if {@link CstType} is base set or constant set. */
|
|
63
|
-
declare function isBaseSet(type: CstType): boolean;
|
|
64
|
-
/** Evaluate if {@link CstType} is a function. */
|
|
65
|
-
declare function isFunctional(type: CstType): boolean;
|
|
66
|
-
/** Evaluate if {@link CstType} is logical. */
|
|
67
|
-
declare function isLogical(type: CstType): boolean;
|
|
68
|
-
/** Evaluate if {@link CstType} can have manual typification. */
|
|
69
|
-
declare function canHaveManualTypification(type: CstType): boolean;
|
|
70
|
-
/** Checks whether a constituenta type supports formal definitions. */
|
|
71
|
-
declare function canHaveFormalDefinition(cstType: CstType): boolean;
|
|
72
|
-
/** Returns expected {@link TypeClass} of formal definition for {@link CstType}. */
|
|
73
|
-
declare function typeClassForCstType(cstType: CstType): TypeClass;
|
|
74
|
-
/** Evaluate if {@link Constituenta} can be used produce structure. */
|
|
75
|
-
declare function canProduceStructure(cst: Constituenta): boolean;
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/library/rsform-api/expression.d.ts
|
|
78
|
-
/** Infers the status of an expression based on parsing and value information. */
|
|
79
|
-
declare function inferStatus(parse: boolean, value?: ValueClass | null): CstStatus;
|
|
80
|
-
/** Infers type of constituent for a given template and arguments. */
|
|
81
|
-
declare function inferTemplatedType(templateType: CstType, args: ArgumentValue[]): CstType;
|
|
82
|
-
/**
|
|
83
|
-
* Normalize a RSLang expression for duplicate comparison.
|
|
84
|
-
*
|
|
85
|
-
* Returns `null` for basic concepts without formal definitions. Pass a pre-parsed `ast`
|
|
86
|
-
* when the expression was already analyzed to avoid re-parsing.
|
|
87
|
-
*/
|
|
88
|
-
declare function normalizeExpression(expression: string, cst_type: CstType, ast?: AstNode | null): string | null;
|
|
89
|
-
/** Checks if given expression is a template. */
|
|
90
|
-
declare function inferTemplate(expression: string): boolean;
|
|
91
|
-
/** Apply filter based on start {@link Constituenta} type. */
|
|
92
|
-
declare function applyFilterCategory(start: Constituenta, items: Constituenta[]): Constituenta[];
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/library/rsform-api/types.d.ts
|
|
95
|
-
/** Minimal constituent fields required to restore order. */
|
|
96
|
-
interface OrderableConstituenta {
|
|
97
|
-
id: number;
|
|
98
|
-
alias: string;
|
|
99
|
-
cst_type: CstType;
|
|
100
|
-
definition_formal: string;
|
|
101
|
-
}
|
|
102
|
-
/** Semantic parent/children derived from formal definitions (backend SemanticInfo). */
|
|
103
|
-
interface SemanticRelations {
|
|
104
|
-
/** Parent id for each constituenta (self when none). */
|
|
105
|
-
parentOf: Map<number, number>;
|
|
106
|
-
/** Semantic children ids for each constituenta. */
|
|
107
|
-
childrenOf: Map<number, number[]>;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/library/rsform-api/formal-graph.d.ts
|
|
111
|
-
/**
|
|
112
|
-
* Build the formal dependency graph: supplier → dependent.
|
|
113
|
-
* Matches backend {@code RSForm.graph_formal}.
|
|
114
|
-
*/
|
|
115
|
-
declare function buildFormalDependencyGraph(items: readonly OrderableConstituenta[]): Graph<number>;
|
|
116
|
-
/**
|
|
117
|
-
* Reorder constituents: formal topology hard, semantic children sticky when ready,
|
|
118
|
-
* otherwise stable against type/kernel preferred ranks.
|
|
119
|
-
*
|
|
120
|
-
* One Kahn pass over the formal dependency graph.
|
|
121
|
-
*/
|
|
122
|
-
declare function restoreConstituentOrder<T extends OrderableConstituenta>(items: readonly T[], graph?: Graph<number>, relations?: SemanticRelations): T[];
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/library/rsform-api/stats.d.ts
|
|
125
|
-
/** Checks if {@link Constituenta} is a schema issue. */
|
|
126
|
-
declare function isSchemaIssue(cst: Constituenta): boolean;
|
|
127
|
-
/** Calculate statistics for {@link RSForm}. */
|
|
128
|
-
declare function calculateSchemaStats(target: RSForm): RSFormStats;
|
|
129
|
-
//#endregion
|
|
130
|
-
//#region src/library/rsform-api/structure.d.ts
|
|
131
|
-
/**
|
|
132
|
-
* Id to pass as `insert_after` when creating a new {@link Constituenta} spawned by `targetId`:
|
|
133
|
-
* after the last existing child of that spawner, or after the spawner itself if none.
|
|
134
|
-
*/
|
|
135
|
-
declare function inferNewSpawnPosition(schema: RSForm, targetId: number): number;
|
|
136
|
-
/** Finds {@link Constituenta} by structure path. */
|
|
137
|
-
declare function findCstByStructure(schema: RSForm, target: Constituenta, path: TypePath): Constituenta | null;
|
|
138
|
-
/** Retrieves name for piece of target {@link Constituenta} structure. */
|
|
139
|
-
declare function getStructureName(schema: RSForm, target: Constituenta, path: TypePath): string;
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/library/rsform-api/synthesis.d.ts
|
|
142
|
-
/** Sorts library items relevant for InlineSynthesis with specified {@link RSForm}. */
|
|
143
|
-
declare function sortItemsForInlineSynthesis(receiver: RSForm, items: readonly LibraryItem[]): LibraryItem[];
|
|
144
|
-
//#endregion
|
|
145
|
-
export { addAliasReference, applyFilterCategory, applyMappingToConstituents, argumentValuesToMapping, calculateSchemaStats, canHaveManualTypification, canProduceStructure, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, normalizeExpression, refineAnalysisForDependencyCycles, removeAliasReference, restoreConstituentOrder, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
|
|
146
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { $ as removeAliasReference, A as canProduceStructure, B as filterAttributions, C as restoreConstituentOrder, D as inferTemplatedType, E as inferTemplate, F as isBasicConcept, G as MappableFields, H as remapAttributionsUnderSubstitution, I as isFunctional, J as applyMappingToConstituents, K as addAliasReference, L as isLogical, M as guessCstType, N as inferClass, O as normalizeExpression, P as isBaseSet, Q as maxAliasIndex, R as isTemplateCst, S as buildFormalDependencyGraph, T as inferStatus, U as getAnalysisFor, V as importAttributions, W as refineAnalysisForDependencyCycles, X as buildSequentialAliasMapping, Y as argumentValuesToMapping, Z as generateAlias, _ as findCstByStructure, a as buildDefinitionReferenceGraph, at as DiagnosticSourceFields, b as calculateSchemaStats, c as resolveConstituentTextChange, ct as SchemaIssueFields, d as SynthesizableFields, dt as SpawnPathFields, et as validateAliasFormat, f as inlineSynthesis, ft as StructureCapableFields, g as remapSubstitutionsAfterImport, h as applyConstituentSubstitutions, ht as TextResolvableFields, i as TextChangeOptions, it as DescribableFields, j as getCstTypePrefix, k as canHaveManualTypification, l as InlineSynthesisInput, lt as SearchableFields, m as SubstitutionResult, mt as TemplateSourceFields, n as moveIdsInOrder, nt as AliasTypedFields, o as buildTermReferenceGraph, ot as FormalOrderFields, p as sortItemsForInlineSynthesis, pt as TemplateParamSourceFields, q as allocateImportAliases, r as reorderItemsByIds, rt as BasicTextCheckFields, s as resolveAllConstituentTexts, st as ModelEvalFields, t as insertItemAfter, tt as validateNewAlias, u as InlineSynthesisResult, ut as SemanticRelations, v as getStructureName, w as applyFilterCategory, x as isSchemaIssue, y as inferNewSpawnPosition, z as typeClassForCstType } from "../../index-DpiTybDB.js";
|
|
2
|
+
export { type AliasTypedFields, type BasicTextCheckFields, type DescribableFields, type DiagnosticSourceFields, type FormalOrderFields, type InlineSynthesisInput, type InlineSynthesisResult, type MappableFields, type ModelEvalFields, type SchemaIssueFields, type SearchableFields, type SemanticRelations, type SpawnPathFields, type StructureCapableFields, type SubstitutionResult, type SynthesizableFields, type TemplateParamSourceFields, type TemplateSourceFields, type TextChangeOptions, type TextResolvableFields, addAliasReference, allocateImportAliases, applyConstituentSubstitutions, applyFilterCategory, applyMappingToConstituents, argumentValuesToMapping, buildDefinitionReferenceGraph, buildFormalDependencyGraph, buildSequentialAliasMapping, buildTermReferenceGraph, calculateSchemaStats, canHaveManualTypification, canProduceStructure, filterAttributions, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, importAttributions, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, inlineSynthesis, insertItemAfter, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, maxAliasIndex, moveIdsInOrder, normalizeExpression, refineAnalysisForDependencyCycles, remapAttributionsUnderSubstitution, remapSubstitutionsAfterImport, removeAliasReference, reorderItemsByIds, resolveAllConstituentTexts, resolveConstituentTextChange, restoreConstituentOrder, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { addAliasReference, applyFilterCategory, applyMappingToConstituents, argumentValuesToMapping, calculateSchemaStats, canHaveManualTypification, canProduceStructure, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, normalizeExpression, refineAnalysisForDependencyCycles, removeAliasReference, restoreConstituentOrder, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
|
|
1
|
+
import { $ as isFunctional, A as normalizeExpression, B as buildSequentialAliasMapping, C as isSchemaIssue, D as inferStatus, E as applyFilterCategory, F as refineAnalysisForDependencyCycles, G as validateNewAlias, H as maxAliasIndex, I as addAliasReference, J as getCstTypePrefix, K as canHaveManualTypification, L as allocateImportAliases, M as importAttributions, N as remapAttributionsUnderSubstitution, O as inferTemplate, P as getAnalysisFor, Q as isBasicConcept, R as applyMappingToConstituents, S as calculateSchemaStats, T as restoreConstituentOrder, U as removeAliasReference, V as generateAlias, W as validateAliasFormat, X as inferClass, Y as guessCstType, Z as isBaseSet, _ as applyConstituentSubstitutions, b as getStructureName, c as insertItemAfter, d as inlineSynthesis, et as isLogical, f as sortItemsForInlineSynthesis, g as resolveConstituentTextChange, h as resolveAllConstituentTexts, j as filterAttributions, k as inferTemplatedType, l as moveIdsInOrder, m as buildTermReferenceGraph, nt as typeClassForCstType, p as buildDefinitionReferenceGraph, q as canProduceStructure, tt as isTemplateCst, u as reorderItemsByIds, v as remapSubstitutionsAfterImport, w as buildFormalDependencyGraph, x as inferNewSpawnPosition, y as findCstByStructure, z as argumentValuesToMapping } from "../../diagnostics-ndGYbvgh.js";
|
|
2
|
+
export { addAliasReference, allocateImportAliases, applyConstituentSubstitutions, applyFilterCategory, applyMappingToConstituents, argumentValuesToMapping, buildDefinitionReferenceGraph, buildFormalDependencyGraph, buildSequentialAliasMapping, buildTermReferenceGraph, calculateSchemaStats, canHaveManualTypification, canProduceStructure, filterAttributions, findCstByStructure, generateAlias, getAnalysisFor, getCstTypePrefix, getStructureName, guessCstType, importAttributions, inferClass, inferNewSpawnPosition, inferStatus, inferTemplate, inferTemplatedType, inlineSynthesis, insertItemAfter, isBaseSet, isBasicConcept, isFunctional, isLogical, isSchemaIssue, isTemplateCst, maxAliasIndex, moveIdsInOrder, normalizeExpression, refineAnalysisForDependencyCycles, remapAttributionsUnderSubstitution, remapSubstitutionsAfterImport, removeAliasReference, reorderItemsByIds, resolveAllConstituentTexts, resolveConstituentTextChange, restoreConstituentOrder, sortItemsForInlineSynthesis, typeClassForCstType, validateAliasFormat, validateNewAlias };
|
package/dist/library/rsform.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as RSFormStats, S as RSForm, T as
|
|
2
|
-
export { ArgumentValue, Attribution, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats, Substitution, TypeInfo };
|
|
1
|
+
import { C as RSFormStats, E as TypeInfo, S as RSForm, T as TermForm, _ as Attribution, b as CstStatus, g as ArgumentValue, v as Constituenta, w as Substitution, x as CstType, y as CstClass } from "../diagnostics-DsEhmFh0.js";
|
|
2
|
+
export { ArgumentValue, Attribution, Constituenta, CstClass, CstStatus, CstType, RSForm, RSFormStats, Substitution, TermForm, TypeInfo };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsform.js","names":[],"sources":["../../src/library/rsform.ts"],"sourcesContent":["/**\n * Module: Models for formal representation for systems of concepts.\n */\n\nimport { type Graph } from '../graph';\nimport { type AnalysisBase, type ExpressionType, type RSLangAnalyzer, type TypePath } from '../rslang';\n\nimport { type CstDiagnostic } from './diagnostics';\nimport { type CurrentVersion, type LibraryItem, type LibraryItemReference, type VersionInfo } from './library';\n\n/** Represents {@link Constituenta} type. */\nexport const CstType = {\n NOMINAL: 'nominal',\n BASE: 'basic',\n STRUCTURED: 'structure',\n TERM: 'term',\n AXIOM: 'axiom',\n FUNCTION: 'function',\n PREDICATE: 'predicate',\n CONSTANT: 'constant',\n STATEMENT: 'statement'\n} as const;\nexport type CstType = (typeof CstType)[keyof typeof CstType];\n\n/** Represents attribution of a {@link Constituenta} to another {@link Constituenta}. */\nexport interface Attribution {\n container: number;\n attribute: number;\n}\n\n/** Represents global identifier type info. */\nexport interface TypeInfo {\n alias: string;\n type: ExpressionType;\n}\n\n/** Represents function argument value. */\nexport interface ArgumentValue {\n alias: string;\n typification: string;\n value?: string;\n}\n\n/** Represents Constituenta classification in terms of system of concepts. */\nexport const CstClass = {\n NOMINAL: 'nominal',\n BASIC: 'basic',\n DERIVED: 'derived',\n STATEMENT: 'statement',\n TEMPLATE: 'template'\n} as const;\nexport type CstClass = (typeof CstClass)[keyof typeof CstClass];\n\n/** Represents formal expression Status. */\nexport const CstStatus = {\n VERIFIED: 'verified',\n INCORRECT: 'incorrect',\n INCALCULABLE: 'incalculable',\n PROPERTY: 'property',\n UNKNOWN: 'unknown'\n} as const;\nexport type CstStatus = (typeof CstStatus)[keyof typeof CstStatus];\n\n/** Represents substitution of {@link Constituenta}. */\nexport interface Substitution {\n original: number;\n substitution: number;\n}\n\n/** Represents word form for natural language. */\
|
|
1
|
+
{"version":3,"file":"rsform.js","names":[],"sources":["../../src/library/rsform.ts"],"sourcesContent":["/**\n * Module: Models for formal representation for systems of concepts.\n */\n\nimport { type Graph } from '../graph';\nimport { type AnalysisBase, type ExpressionType, type RSLangAnalyzer, type TypePath } from '../rslang';\n\nimport { type CstDiagnostic } from './diagnostics';\nimport { type CurrentVersion, type LibraryItem, type LibraryItemReference, type VersionInfo } from './library';\n\n/** Represents {@link Constituenta} type. */\nexport const CstType = {\n NOMINAL: 'nominal',\n BASE: 'basic',\n STRUCTURED: 'structure',\n TERM: 'term',\n AXIOM: 'axiom',\n FUNCTION: 'function',\n PREDICATE: 'predicate',\n CONSTANT: 'constant',\n STATEMENT: 'statement'\n} as const;\nexport type CstType = (typeof CstType)[keyof typeof CstType];\n\n/** Represents attribution of a {@link Constituenta} to another {@link Constituenta}. */\nexport interface Attribution {\n container: number;\n attribute: number;\n}\n\n/** Represents global identifier type info. */\nexport interface TypeInfo {\n alias: string;\n type: ExpressionType;\n}\n\n/** Represents function argument value. */\nexport interface ArgumentValue {\n alias: string;\n typification: string;\n value?: string;\n}\n\n/** Represents Constituenta classification in terms of system of concepts. */\nexport const CstClass = {\n NOMINAL: 'nominal',\n BASIC: 'basic',\n DERIVED: 'derived',\n STATEMENT: 'statement',\n TEMPLATE: 'template'\n} as const;\nexport type CstClass = (typeof CstClass)[keyof typeof CstClass];\n\n/** Represents formal expression Status. */\nexport const CstStatus = {\n VERIFIED: 'verified',\n INCORRECT: 'incorrect',\n INCALCULABLE: 'incalculable',\n PROPERTY: 'property',\n UNKNOWN: 'unknown'\n} as const;\nexport type CstStatus = (typeof CstStatus)[keyof typeof CstStatus];\n\n/** Represents substitution of {@link Constituenta}. */\nexport interface Substitution {\n original: number;\n substitution: number;\n}\n\n/** Represents word form for natural language. */\nexport interface TermForm {\n text: string;\n tags: string;\n}\n\n/** Represents Constituenta. */\nexport interface Constituenta {\n id: number;\n crucial: boolean;\n alias: string;\n convention: string;\n cst_type: CstType;\n definition_formal: string;\n definition_raw: string;\n definition_resolved: string;\n term_raw: string;\n term_resolved: string;\n term_forms: TermForm[];\n attributes: number[];\n\n /** Manual typification of the constituent */\n typification_manual: string;\n\n /** Controls whether base concepts expose property values or full values */\n value_is_property: boolean;\n\n analysis: AnalysisBase;\n\n /** Schema-kind {@link CstDiagnostic} list, populated during schema loading. */\n diagnostics: CstDiagnostic[];\n\n /** Typification used for dependents, model values, and display (manual when it overrides computed). */\n effectiveType: ExpressionType | null;\n\n /**\n * True when manual typification is non-empty, parses to a type, and its label differs from the\n * typification inferred from the formal definition ({@link Constituenta.analysis}.type).\n */\n is_type_mismatch: boolean;\n\n /** Identifier of {@link LibraryItem} containing this {@link Constituenta}. */\n schema: number;\n\n /** {@link CstClass} of this {@link Constituenta}. */\n cst_class: CstClass;\n /** {@link CstStatus} of this {@link Constituenta}. */\n status: CstStatus;\n\n /** Indicates if this {@link Constituenta} is a template. */\n is_template: boolean;\n /** Indicates if this {@link Constituenta} has a simple expression. */\n is_simple_expression: boolean;\n\n /** Index of {@link LibraryItem} that contains this cst (or inheritance parent).\n * 0 - not inherited, 1 - inherited by 1st schema, 2 - inherited by 2nd schema, etc.\n */\n parent_schema_index: number;\n /** {@link LibraryItem} that contains parent of this inherited {@link Constituenta}. */\n parent_schema: number | null;\n /** Indicates if this {@link Constituenta} is inherited. */\n is_inherited: boolean;\n /** Indicates if this {@link Constituenta} has children that are inherited. */\n has_inherited_children: boolean;\n\n /** {@link Constituenta} that spawned this one. */\n spawner?: number;\n /** Alias of {@link Constituenta} that spawned this one. */\n spawner_alias?: string;\n /** Structure path that spawned this one. */\n spawner_path?: TypePath;\n\n /** List of {@link Constituenta} that are spawned by this one. */\n spawn: number[];\n /** List of aliases of {@link Constituenta} that are spawned by this one. */\n spawn_alias: string[];\n}\n\n/** Represents {@link RSForm} statistics. */\nexport interface RSFormStats {\n step_complexity: number;\n\n /** Total number of constituents in the RSForm. */\n count_all: number;\n /** Number of crucial constituents in the RSForm. */\n count_crucial: number;\n\n count_problematic: number;\n /** Constituents that have same term. */\n count_homonyms: number;\n /** Constituents that have same formal definition and term. */\n count_formal_duplicates: number;\n /** Non-logical basic constituents missing convention and/or resolved term. */\n count_missing_basic_text: number;\n /** Constituents with non-empty manual typification that disagrees with inferred typification. */\n count_type_mismatch: number;\n\n count_incorrect: number;\n count_property: number;\n count_incalculable: number;\n count_inherited: number;\n\n count_text_term: number;\n count_definition: number;\n count_convention: number;\n count_comment: number;\n\n count_base: number;\n count_constant: number;\n count_structured: number;\n count_axiom: number;\n count_term: number;\n count_function: number;\n count_predicate: number;\n count_statement: number;\n count_nominal: number;\n}\n\n/** Represents inheritance data for {@link RSForm}. */\ninterface InheritanceInfo {\n child: number;\n child_source: number;\n parent: number;\n parent_source: number;\n}\n\n/** Represents formal explication for set of concepts. */\nexport interface RSForm extends LibraryItem {\n /** Whether this RSForm was produced (vs imported or inherited) */\n is_produced: boolean;\n /** Whether this RSForm has attribution feature */\n is_attributive: boolean;\n /** List of user IDs who can edit this RSForm */\n editors: number[];\n /** Information about the current version of this RSForm */\n version: CurrentVersion;\n /** Full version history of this RSForm */\n versions: VersionInfo[];\n\n /** Full list of constituents in the RSForm */\n items: Constituenta[];\n /** List of inheritance relationships between constituents */\n inheritance: InheritanceInfo[];\n /** List of constituent attribution relationships */\n attribution: Attribution[];\n /** References to Operational Schemes/Systems associated with the RSForm */\n oss: LibraryItemReference[];\n /** References to conceptual models associated with the RSForm */\n models: LibraryItemReference[];\n\n /** Analyzer instance for RS language features and validation */\n analyzer: RSLangAnalyzer;\n /** Graph structure representing formal dependencies between constituents */\n graph: Graph;\n /** Graph structure representing attribution relationships */\n attribution_graph: Graph;\n /** Map for quick lookup of constituents by alias */\n cstByAlias: Map<string, Constituenta>;\n /** Map for quick lookup of constituents by ID */\n cstByID: Map<number, Constituenta>;\n}\n"],"mappings":";;AAWA,MAAa,UAAU;CACrB,SAAS;CACT,MAAM;CACN,YAAY;CACZ,MAAM;CACN,OAAO;CACP,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;AACb;;AAuBA,MAAa,WAAW;CACtB,SAAS;CACT,OAAO;CACP,SAAS;CACT,WAAW;CACX,UAAU;AACZ;;AAIA,MAAa,YAAY;CACvB,UAAU;CACV,WAAW;CACX,cAAc;CACd,UAAU;CACV,SAAS;AACX"}
|