yukigo 0.2.3 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +3 -3
- package/CHANGELOG.md +105 -40
- package/README.md +193 -193
- package/dist/analyzer/GraphBuilder.d.ts +1 -0
- package/dist/analyzer/GraphBuilder.js +2 -1
- package/dist/analyzer/index.d.ts +0 -7
- package/dist/analyzer/index.js +3 -3
- package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
- package/dist/analyzer/inspections/functional/functional.js +1 -1
- package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
- package/dist/analyzer/inspections/functional/smells.js +27 -35
- package/dist/analyzer/inspections/generic/generic.d.ts +22 -14
- package/dist/analyzer/inspections/generic/generic.js +82 -60
- package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
- package/dist/analyzer/inspections/generic/smells.js +55 -64
- package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
- package/dist/analyzer/inspections/imperative/imperative.js +3 -3
- package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
- package/dist/analyzer/inspections/imperative/smells.js +8 -5
- package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
- package/dist/analyzer/inspections/logic/logic.js +5 -5
- package/dist/analyzer/inspections/logic/smells.js +2 -2
- package/dist/analyzer/inspections/object/object.d.ts +5 -5
- package/dist/analyzer/inspections/object/object.js +22 -21
- package/dist/analyzer/inspections/object/smells.js +11 -23
- package/dist/analyzer/utils.d.ts +6 -2
- package/dist/analyzer/utils.js +6 -2
- package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
- package/dist/interpreter/components/EnvBuilder.js +211 -66
- package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
- package/dist/interpreter/components/EqualityComparer.js +69 -0
- package/dist/interpreter/components/Operations.d.ts +17 -14
- package/dist/interpreter/components/Operations.js +61 -62
- package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
- package/dist/interpreter/components/PatternMatcher.js +185 -286
- package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
- package/dist/interpreter/components/RuntimeContext.js +43 -4
- package/dist/interpreter/components/TestRunner.d.ts +15 -13
- package/dist/interpreter/components/TestRunner.js +86 -53
- package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
- package/dist/interpreter/components/evaluators/index.d.ts +110 -0
- package/dist/interpreter/components/evaluators/index.js +21 -0
- package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
- package/dist/interpreter/components/evaluators/utils.js +50 -0
- package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
- package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
- package/dist/interpreter/components/kernel/commands.d.ts +122 -0
- package/dist/interpreter/components/kernel/commands.js +203 -0
- package/dist/interpreter/components/kernel/index.d.ts +51 -0
- package/dist/interpreter/components/kernel/index.js +176 -0
- package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
- package/dist/interpreter/components/logic/LogicEngine.js +234 -221
- package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
- package/dist/interpreter/components/logic/LogicResolver.js +73 -440
- package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
- package/dist/interpreter/components/logic/LogicTerm.js +423 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
- package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
- package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
- package/dist/interpreter/errors.d.ts +10 -0
- package/dist/interpreter/errors.js +17 -0
- package/dist/interpreter/index.d.ts +9 -5
- package/dist/interpreter/index.js +11 -13
- package/dist/interpreter/primitives/YuValue.d.ts +21 -0
- package/dist/interpreter/primitives/YuValue.js +40 -0
- package/dist/interpreter/primitives/capabilities.d.ts +90 -0
- package/dist/interpreter/primitives/capabilities.js +1 -0
- package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
- package/dist/interpreter/primitives/entities/LazyList.js +164 -0
- package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
- package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
- package/dist/interpreter/primitives/index.d.ts +14 -0
- package/dist/interpreter/primitives/index.js +14 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
- package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
- package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
- package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
- package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
- package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
- package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
- package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
- package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
- package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
- package/dist/interpreter/primitives/sequences/YuString.js +130 -0
- package/dist/interpreter/utils.d.ts +23 -10
- package/dist/interpreter/utils.js +25 -30
- package/dist/tester/index.d.ts +3 -3
- package/dist/tester/index.js +39 -28
- package/dist/utils/helpers.d.ts +13 -5
- package/dist/utils/helpers.js +38 -85
- package/package.json +3 -16
- package/src/analyzer/GraphBuilder.ts +143 -142
- package/src/analyzer/index.ts +185 -194
- package/src/analyzer/inspections/functional/functional.ts +121 -121
- package/src/analyzer/inspections/functional/smells.ts +88 -102
- package/src/analyzer/inspections/generic/generic.ts +610 -577
- package/src/analyzer/inspections/generic/smells.ts +355 -365
- package/src/analyzer/inspections/imperative/imperative.ts +104 -101
- package/src/analyzer/inspections/imperative/smells.ts +58 -54
- package/src/analyzer/inspections/logic/logic.ts +84 -90
- package/src/analyzer/inspections/logic/smells.ts +54 -54
- package/src/analyzer/inspections/object/object.ts +295 -264
- package/src/analyzer/inspections/object/smells.ts +130 -144
- package/src/analyzer/utils.ts +115 -109
- package/src/index.ts +3 -3
- package/src/interpreter/components/EnvBuilder.ts +405 -202
- package/src/interpreter/components/EqualityComparer.ts +107 -0
- package/src/interpreter/components/Operations.ts +126 -99
- package/src/interpreter/components/PatternMatcher.ts +375 -475
- package/src/interpreter/components/RuntimeContext.ts +181 -119
- package/src/interpreter/components/TestRunner.ts +223 -151
- package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
- package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
- package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
- package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
- package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
- package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
- package/src/interpreter/components/evaluators/index.ts +34 -0
- package/src/interpreter/components/evaluators/utils.ts +64 -0
- package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
- package/src/interpreter/components/kernel/commands.ts +255 -0
- package/src/interpreter/components/kernel/index.ts +222 -0
- package/src/interpreter/components/logic/LogicEngine.ts +509 -519
- package/src/interpreter/components/logic/LogicResolver.ts +209 -858
- package/src/interpreter/components/logic/LogicTerm.ts +477 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
- package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
- package/src/interpreter/errors.ts +68 -47
- package/src/interpreter/index.ts +50 -52
- package/src/interpreter/primitives/YuValue.ts +64 -0
- package/src/interpreter/primitives/capabilities.ts +111 -0
- package/src/interpreter/primitives/entities/LazyList.ts +225 -0
- package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
- package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
- package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
- package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
- package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
- package/src/interpreter/primitives/index.ts +17 -0
- package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
- package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
- package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
- package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
- package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
- package/src/interpreter/primitives/sequences/YuString.ts +165 -0
- package/src/interpreter/utils.ts +105 -84
- package/src/tester/index.ts +157 -128
- package/src/utils/helpers.ts +113 -169
- package/tests/analyzer/functional.spec.ts +221 -207
- package/tests/analyzer/generic.spec.ts +178 -178
- package/tests/analyzer/helpers.spec.ts +83 -89
- package/tests/analyzer/logic.spec.ts +237 -237
- package/tests/analyzer/oop.spec.ts +320 -323
- package/tests/analyzer/transitive.spec.ts +166 -166
- package/tests/interpreter/EnvBuilder.spec.ts +181 -183
- package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
- package/tests/interpreter/LazyRuntime.spec.ts +227 -225
- package/tests/interpreter/LogicEngine.spec.ts +371 -327
- package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
- package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
- package/tests/interpreter/Operations.spec.ts +312 -220
- package/tests/interpreter/PatternSystem.spec.ts +254 -213
- package/tests/interpreter/Tests.spec.ts +122 -122
- package/tests/interpreter/interpreter.spec.ts +1143 -991
- package/tests/kernel/YukigoKernel.spec.ts +112 -0
- package/tests/tester/Tester.spec.ts +156 -152
- package/tsconfig.build.json +16 -15
- package/tsconfig.json +27 -25
- package/dist/interpreter/components/Visitor.d.ts +0 -70
- package/dist/interpreter/components/Visitor.js +0 -634
- package/dist/interpreter/entities.d.ts +0 -105
- package/dist/interpreter/entities.js +0 -96
- package/dist/interpreter/trampoline.d.ts +0 -17
- package/dist/interpreter/trampoline.js +0 -38
- package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
- package/dist/src/analyzer/GraphBuilder.js +0 -100
- package/dist/src/analyzer/index.d.ts +0 -59
- package/dist/src/analyzer/index.js +0 -152
- package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
- package/dist/src/analyzer/inspections/functional/functional.js +0 -149
- package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/functional/smells.js +0 -98
- package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
- package/dist/src/analyzer/inspections/generic/generic.js +0 -604
- package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
- package/dist/src/analyzer/inspections/generic/smells.js +0 -349
- package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
- package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
- package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
- package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
- package/dist/src/analyzer/inspections/logic/logic.js +0 -96
- package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
- package/dist/src/analyzer/inspections/logic/smells.js +0 -60
- package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
- package/dist/src/analyzer/inspections/object/object.js +0 -321
- package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
- package/dist/src/analyzer/inspections/object/smells.js +0 -135
- package/dist/src/analyzer/utils.d.ts +0 -30
- package/dist/src/analyzer/utils.js +0 -78
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -4
- package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
- package/dist/src/interpreter/components/EnvBuilder.js +0 -155
- package/dist/src/interpreter/components/Operations.d.ts +0 -14
- package/dist/src/interpreter/components/Operations.js +0 -84
- package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
- package/dist/src/interpreter/components/PatternMatcher.js +0 -358
- package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
- package/dist/src/interpreter/components/RuntimeContext.js +0 -93
- package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
- package/dist/src/interpreter/components/TestRunner.js +0 -110
- package/dist/src/interpreter/components/Visitor.d.ts +0 -71
- package/dist/src/interpreter/components/Visitor.js +0 -638
- package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
- package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
- package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
- package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
- package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
- package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
- package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
- package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
- package/dist/src/interpreter/errors.d.ts +0 -19
- package/dist/src/interpreter/errors.js +0 -36
- package/dist/src/interpreter/index.d.ts +0 -24
- package/dist/src/interpreter/index.js +0 -41
- package/dist/src/interpreter/trampoline.d.ts +0 -17
- package/dist/src/interpreter/trampoline.js +0 -38
- package/dist/src/interpreter/utils.d.ts +0 -11
- package/dist/src/interpreter/utils.js +0 -65
- package/dist/src/tester/index.d.ts +0 -25
- package/dist/src/tester/index.js +0 -113
- package/dist/src/utils/helpers.d.ts +0 -13
- package/dist/src/utils/helpers.js +0 -52
- package/src/interpreter/components/Visitor.ts +0 -1065
- package/src/interpreter/trampoline.ts +0 -71
package/dist/utils/helpers.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { parseDocument } from "yaml";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"HasNot",
|
|
2
|
+
const V0_INSPECTIONS_Has = [
|
|
3
|
+
"HasComposition",
|
|
4
|
+
"HasComprehension",
|
|
5
|
+
"HasForeach",
|
|
6
|
+
"HasIf",
|
|
7
|
+
"HasGuards",
|
|
8
|
+
"HasConditional",
|
|
9
|
+
"HasLambda",
|
|
10
|
+
"HasRepeat",
|
|
11
|
+
"HasWhile",
|
|
12
|
+
"HasAnonymousVariable",
|
|
13
|
+
"HasNot",
|
|
14
|
+
"HasForall",
|
|
15
|
+
"HasFindall",
|
|
16
|
+
];
|
|
17
|
+
const V0_INSPECTIONS_Declares = new Map([
|
|
18
|
+
["HasBinding", "Declares"],
|
|
19
|
+
["HasTypeDeclaration", "DeclaresTypeAlias"],
|
|
20
|
+
["HasTypeSignature", "DeclaresTypeSignature"],
|
|
21
|
+
["HasVariable", "DeclaresVariable"],
|
|
22
|
+
["HasArity", "DeclaresComputationWithArity"],
|
|
23
|
+
["HasDirectRecursion", "DeclaresRecursively"],
|
|
24
|
+
["HasUsage", "Uses"],
|
|
14
25
|
]);
|
|
15
|
-
const NEGATION_PREFIXES = new Set(["Not", "Except"]);
|
|
16
|
-
const SUFFIX_ARGS = new Set(["like", "except"]);
|
|
17
26
|
const isValidFormat = (inspection) => typeof inspection === "object" &&
|
|
18
27
|
"inspection" in inspection &&
|
|
19
28
|
"binding" in inspection;
|
|
@@ -26,17 +35,16 @@ export class MulangAdapter {
|
|
|
26
35
|
translateMulangInspection(mulangInspection) {
|
|
27
36
|
if (!isValidFormat(mulangInspection))
|
|
28
37
|
throw new Error(`Skipping malformed Mulang inspection entry: ${mulangInspection}`);
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
38
|
+
const inspection = mulangInspection.inspection.split(":");
|
|
39
|
+
const expected = inspection[0] !== "Not" && inspection[0] !== "Except";
|
|
40
|
+
const args = inspection.slice(expected ? 1 : 2);
|
|
41
|
+
const inspectionV0 = expected ? inspection[0] : inspection[1];
|
|
42
|
+
const inspectionV2 = this.translateV0Inspection(inspectionV0);
|
|
32
43
|
return {
|
|
33
|
-
inspection,
|
|
44
|
+
inspection: inspectionV2,
|
|
34
45
|
expected,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// these should not exist in the InspectionRule if they are undefined
|
|
38
|
-
...(targetSuffix !== undefined && { targetSuffix }),
|
|
39
|
-
...(matcher !== undefined && { matcher }),
|
|
46
|
+
args,
|
|
47
|
+
binding: mulangInspection.binding,
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
translateMulangExpectations(mulangYamlString) {
|
|
@@ -55,69 +63,14 @@ export class MulangAdapter {
|
|
|
55
63
|
else {
|
|
56
64
|
throw new Error("Invalid Mulang YAML structure. Expected 'expectations' to be an array.");
|
|
57
65
|
}
|
|
58
|
-
const inspectionRules =
|
|
59
|
-
for (const mulangInspection of expectations) {
|
|
60
|
-
const inspection = this.translateMulangInspection(mulangInspection);
|
|
61
|
-
inspectionRules.push(inspection);
|
|
62
|
-
}
|
|
66
|
+
const inspectionRules = expectations.map((insp) => this.translateMulangInspection(insp));
|
|
63
67
|
return inspectionRules;
|
|
64
68
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
parseNegation(parts) {
|
|
73
|
-
const negated = NEGATION_PREFIXES.has(parts[0]);
|
|
74
|
-
return {
|
|
75
|
-
expected: !negated,
|
|
76
|
-
inspection: parts[negated ? 1 : 0],
|
|
77
|
-
args: parts.slice(negated ? 2 : 1),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
applyV0ToV2(inspection, args, binding) {
|
|
81
|
-
if (inspection in declareMap)
|
|
82
|
-
return {
|
|
83
|
-
inspection: declareMap[inspection],
|
|
84
|
-
...promoteBindingToTarget(args, binding),
|
|
85
|
-
};
|
|
86
|
-
if (inspection === "HasArity")
|
|
87
|
-
return {
|
|
88
|
-
inspection: "DeclaresComputationWithArity",
|
|
89
|
-
args: [args[0], ...(binding && binding !== "*" ? [binding] : [])],
|
|
90
|
-
binding: "*",
|
|
91
|
-
};
|
|
92
|
-
if (V0_HAS_INSPECTIONS.has(inspection))
|
|
93
|
-
return { inspection: inspection === "HasUsage" ? "Uses" : inspection.replace(/^Has/, "Uses"), args, binding };
|
|
94
|
-
return { inspection, args, binding };
|
|
95
|
-
}
|
|
96
|
-
retrieveArguments(args) {
|
|
97
|
-
const targetSuffix = args.find((a) => SUFFIX_ARGS.has(a));
|
|
98
|
-
const matcherIndex = args.findIndex((a) => a.startsWith("With"));
|
|
99
|
-
const matcher = matcherIndex !== -1
|
|
100
|
-
? {
|
|
101
|
-
type: "with_" + args[matcherIndex].slice(4).toLowerCase(),
|
|
102
|
-
value: args[matcherIndex + 1],
|
|
103
|
-
}
|
|
104
|
-
: undefined;
|
|
105
|
-
const consumed = new Set([
|
|
106
|
-
...(targetSuffix ? [targetSuffix] : []),
|
|
107
|
-
...(matcherIndex !== -1
|
|
108
|
-
? [args[matcherIndex], args[matcherIndex + 1]]
|
|
109
|
-
: []),
|
|
110
|
-
]);
|
|
111
|
-
const resolvedArgs = args.filter((a) => !consumed.has(a));
|
|
112
|
-
return {
|
|
113
|
-
targetSuffix: targetSuffix ??
|
|
114
|
-
(resolvedArgs.length > 0 ? "named" : undefined),
|
|
115
|
-
matcher,
|
|
116
|
-
resolvedArgs,
|
|
117
|
-
};
|
|
69
|
+
translateV0Inspection(inspection) {
|
|
70
|
+
if (V0_INSPECTIONS_Declares.has(inspection))
|
|
71
|
+
return V0_INSPECTIONS_Declares.get(inspection);
|
|
72
|
+
if (V0_INSPECTIONS_Has.includes(inspection))
|
|
73
|
+
return inspection.replace("Has", "Uses");
|
|
74
|
+
return inspection;
|
|
118
75
|
}
|
|
119
76
|
}
|
|
120
|
-
const promoteBindingToTarget = (args, binding) => ({
|
|
121
|
-
args: binding && binding !== "*" ? [binding, ...args] : args,
|
|
122
|
-
binding: "*",
|
|
123
|
-
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yukigo",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,20 +13,7 @@
|
|
|
13
13
|
"test": "mocha --import=tsx"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
},
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"yukigo-ast": "^0.2.0"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/chai": "^5.2.2",
|
|
24
|
-
"@types/mocha": "^10.0.10",
|
|
25
|
-
"@types/node": "^24.2.0",
|
|
26
|
-
"chai": "^6.2.0",
|
|
27
|
-
"mocha": "^11.7.1",
|
|
28
|
-
"ts-node": "^10.9.2",
|
|
29
|
-
"tsx": "^4.21.0",
|
|
30
|
-
"typescript-eslint": "^8.33.1"
|
|
16
|
+
"yaml": "^2.8.0",
|
|
17
|
+
"yukigo-ast": "^0.3.0"
|
|
31
18
|
}
|
|
32
19
|
}
|
|
@@ -1,142 +1,143 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Application,
|
|
3
|
-
AST,
|
|
4
|
-
ASTNode,
|
|
5
|
-
Call,
|
|
6
|
-
Class,
|
|
7
|
-
Fact,
|
|
8
|
-
Function,
|
|
9
|
-
Interface,
|
|
10
|
-
Method,
|
|
11
|
-
New,
|
|
12
|
-
Object as YuObject,
|
|
13
|
-
Procedure,
|
|
14
|
-
Rule,
|
|
15
|
-
SymbolPrimitive,
|
|
16
|
-
TraverseVisitor,
|
|
17
|
-
TypeAlias,
|
|
18
|
-
TypeSignature,
|
|
19
|
-
Exist,
|
|
20
|
-
} from "yukigo-ast";
|
|
21
|
-
|
|
22
|
-
type DefinitionMap = Map<string, ASTNode[]>;
|
|
23
|
-
type CallsMap = Map<string, string[]>;
|
|
24
|
-
|
|
25
|
-
export type SymbolGraph = {
|
|
26
|
-
defs: DefinitionMap;
|
|
27
|
-
calls: CallsMap;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class GraphBuilder extends TraverseVisitor {
|
|
31
|
-
private defs: DefinitionMap = new Map();
|
|
32
|
-
private calls: CallsMap = new Map();
|
|
33
|
-
private scope: string = "";
|
|
34
|
-
|
|
35
|
-
public build(ast: AST): SymbolGraph {
|
|
36
|
-
ast.forEach((node) => node.accept(this));
|
|
37
|
-
return { defs: this.defs, calls: this.calls };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private addDefinition(name: string, node: ASTNode): void {
|
|
41
|
-
const existing = this.defs.get(name) || [];
|
|
42
|
-
this.defs.set(name, [...existing, node]);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
visitFunction(node: Function): void {
|
|
46
|
-
this.scope = node.identifier.value;
|
|
47
|
-
this.addDefinition(this.scope, node);
|
|
48
|
-
this.traverseCollection(node.equations);
|
|
49
|
-
this.scope = "";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
visitMethod(node: Method): void {
|
|
53
|
-
this.scope = node.identifier.value;
|
|
54
|
-
this.addDefinition(this.scope, node);
|
|
55
|
-
this.traverseCollection(node.equations);
|
|
56
|
-
this.scope = "";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
visitProcedure(node: Procedure): void {
|
|
60
|
-
this.scope = node.identifier.value;
|
|
61
|
-
this.addDefinition(this.scope, node);
|
|
62
|
-
this.traverseCollection(node.equations);
|
|
63
|
-
this.scope = "";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
visitRule(node: Rule): void {
|
|
67
|
-
this.scope = node.identifier.value;
|
|
68
|
-
this.addDefinition(this.scope, node);
|
|
69
|
-
this.traverseCollection(node.equations);
|
|
70
|
-
this.scope = "";
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
visitFact(node: Fact): void {
|
|
74
|
-
this.scope = node.identifier.value;
|
|
75
|
-
this.addDefinition(this.scope, node);
|
|
76
|
-
this.traverseCollection(node.patterns);
|
|
77
|
-
this.scope = "";
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
visitClass(node: Class): void {
|
|
81
|
-
this.scope = node.identifier.value;
|
|
82
|
-
this.addDefinition(this.scope, node);
|
|
83
|
-
node.expression.accept(this);
|
|
84
|
-
this.scope = "";
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
visitObject(node: YuObject): void {
|
|
88
|
-
this.scope = node.identifier.value;
|
|
89
|
-
this.addDefinition(this.scope, node);
|
|
90
|
-
node.expression.accept(this);
|
|
91
|
-
this.scope = "";
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
visitInterface(node: Interface): void {
|
|
95
|
-
this.scope = node.identifier.value;
|
|
96
|
-
this.addDefinition(this.scope, node);
|
|
97
|
-
node.expression.accept(this);
|
|
98
|
-
this.scope = "";
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
visitTypeAlias(node: TypeAlias): void {
|
|
102
|
-
this.scope = node.identifier.value;
|
|
103
|
-
this.addDefinition(this.scope, node);
|
|
104
|
-
this.scope = "";
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
visitTypeSignature(node: TypeSignature): void {
|
|
108
|
-
this.scope = node.identifier.value;
|
|
109
|
-
this.addDefinition(this.scope, node);
|
|
110
|
-
this.scope = "";
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
visitCall(node: Call): void {
|
|
114
|
-
if (!this.scope) return;
|
|
115
|
-
|
|
116
|
-
const arr = this.calls.get(this.scope) || [];
|
|
117
|
-
this.calls.set(this.scope, [node.callee.value, ...arr]);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
visitApplication(node: Application): void {
|
|
121
|
-
if (!this.scope) return;
|
|
122
|
-
|
|
123
|
-
const arr = this.calls.get(this.scope) || [];
|
|
124
|
-
if (node.functionExpr
|
|
125
|
-
this.calls.set(this.scope, [node.functionExpr.value, ...arr]);
|
|
126
|
-
else node.functionExpr.accept(this);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
visitNew(node: New): void {
|
|
130
|
-
if (!this.scope) return;
|
|
131
|
-
|
|
132
|
-
const arr = this.calls.get(this.scope) || [];
|
|
133
|
-
this.calls.set(this.scope, [node.identifier.value, ...arr]);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
visitExist(node: Exist): void {
|
|
137
|
-
if (!this.scope) return;
|
|
138
|
-
|
|
139
|
-
const arr = this.calls.get(this.scope) || [];
|
|
140
|
-
this.calls.set(this.scope, [node.identifier.value, ...arr]);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Application,
|
|
3
|
+
AST,
|
|
4
|
+
ASTNode,
|
|
5
|
+
Call,
|
|
6
|
+
Class,
|
|
7
|
+
Fact,
|
|
8
|
+
Function,
|
|
9
|
+
Interface,
|
|
10
|
+
Method,
|
|
11
|
+
New,
|
|
12
|
+
Object as YuObject,
|
|
13
|
+
Procedure,
|
|
14
|
+
Rule,
|
|
15
|
+
SymbolPrimitive,
|
|
16
|
+
TraverseVisitor,
|
|
17
|
+
TypeAlias,
|
|
18
|
+
TypeSignature,
|
|
19
|
+
Exist,
|
|
20
|
+
} from "yukigo-ast";
|
|
21
|
+
|
|
22
|
+
type DefinitionMap = Map<string, ASTNode[]>;
|
|
23
|
+
type CallsMap = Map<string, string[]>;
|
|
24
|
+
|
|
25
|
+
export type SymbolGraph = {
|
|
26
|
+
defs: DefinitionMap;
|
|
27
|
+
calls: CallsMap;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class GraphBuilder extends TraverseVisitor {
|
|
31
|
+
private defs: DefinitionMap = new Map();
|
|
32
|
+
private calls: CallsMap = new Map();
|
|
33
|
+
private scope: string = "";
|
|
34
|
+
|
|
35
|
+
public build(ast: AST): SymbolGraph {
|
|
36
|
+
ast.forEach((node) => node.accept(this));
|
|
37
|
+
return { defs: this.defs, calls: this.calls };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private addDefinition(name: string, node: ASTNode): void {
|
|
41
|
+
const existing = this.defs.get(name) || [];
|
|
42
|
+
this.defs.set(name, [...existing, node]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
visitFunction(node: Function): void {
|
|
46
|
+
this.scope = node.identifier.value;
|
|
47
|
+
this.addDefinition(this.scope, node);
|
|
48
|
+
this.traverseCollection(node.equations);
|
|
49
|
+
this.scope = "";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
visitMethod(node: Method): void {
|
|
53
|
+
this.scope = node.identifier.value;
|
|
54
|
+
this.addDefinition(this.scope, node);
|
|
55
|
+
this.traverseCollection(node.equations);
|
|
56
|
+
this.scope = "";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
visitProcedure(node: Procedure): void {
|
|
60
|
+
this.scope = node.identifier.value;
|
|
61
|
+
this.addDefinition(this.scope, node);
|
|
62
|
+
this.traverseCollection(node.equations);
|
|
63
|
+
this.scope = "";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
visitRule(node: Rule): void {
|
|
67
|
+
this.scope = node.identifier.value;
|
|
68
|
+
this.addDefinition(this.scope, node);
|
|
69
|
+
this.traverseCollection(node.equations);
|
|
70
|
+
this.scope = "";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
visitFact(node: Fact): void {
|
|
74
|
+
this.scope = node.identifier.value;
|
|
75
|
+
this.addDefinition(this.scope, node);
|
|
76
|
+
this.traverseCollection(node.patterns);
|
|
77
|
+
this.scope = "";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
visitClass(node: Class): void {
|
|
81
|
+
this.scope = node.identifier.value;
|
|
82
|
+
this.addDefinition(this.scope, node);
|
|
83
|
+
node.expression.accept(this);
|
|
84
|
+
this.scope = "";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
visitObject(node: YuObject): void {
|
|
88
|
+
this.scope = node.identifier.value;
|
|
89
|
+
this.addDefinition(this.scope, node);
|
|
90
|
+
node.expression.accept(this);
|
|
91
|
+
this.scope = "";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
visitInterface(node: Interface): void {
|
|
95
|
+
this.scope = node.identifier.value;
|
|
96
|
+
this.addDefinition(this.scope, node);
|
|
97
|
+
node.expression.accept(this);
|
|
98
|
+
this.scope = "";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
visitTypeAlias(node: TypeAlias): void {
|
|
102
|
+
this.scope = node.identifier.value;
|
|
103
|
+
this.addDefinition(this.scope, node);
|
|
104
|
+
this.scope = "";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
visitTypeSignature(node: TypeSignature): void {
|
|
108
|
+
this.scope = node.identifier.value;
|
|
109
|
+
this.addDefinition(this.scope, node);
|
|
110
|
+
this.scope = "";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
visitCall(node: Call): void {
|
|
114
|
+
if (!this.scope) return;
|
|
115
|
+
|
|
116
|
+
const arr = this.calls.get(this.scope) || [];
|
|
117
|
+
this.calls.set(this.scope, [node.callee.value, ...arr]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
visitApplication(node: Application): void {
|
|
121
|
+
if (!this.scope) return;
|
|
122
|
+
|
|
123
|
+
const arr = this.calls.get(this.scope) || [];
|
|
124
|
+
if (node.functionExpr.is(SymbolPrimitive))
|
|
125
|
+
this.calls.set(this.scope, [node.functionExpr.value, ...arr]);
|
|
126
|
+
else node.functionExpr.accept(this);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
visitNew(node: New): void {
|
|
130
|
+
if (!this.scope) return;
|
|
131
|
+
|
|
132
|
+
const arr = this.calls.get(this.scope) || [];
|
|
133
|
+
this.calls.set(this.scope, [node.identifier.value, ...arr]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
visitExist(node: Exist): void {
|
|
137
|
+
if (!this.scope) return;
|
|
138
|
+
|
|
139
|
+
const arr = this.calls.get(this.scope) || [];
|
|
140
|
+
this.calls.set(this.scope, [node.identifier.value, ...arr]);
|
|
141
|
+
}
|
|
142
|
+
public fallback(node: ASTNode): void {}
|
|
143
|
+
}
|