yukigo 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/.mocharc.json +3 -3
  2. package/README.md +193 -199
  3. package/dist/analyzer/GraphBuilder.d.ts +29 -0
  4. package/dist/analyzer/GraphBuilder.js +99 -0
  5. package/dist/analyzer/index.d.ts +10 -22
  6. package/dist/analyzer/index.js +99 -58
  7. package/dist/analyzer/inspections/functional/functional.d.ts +44 -0
  8. package/dist/analyzer/inspections/functional/functional.js +149 -0
  9. package/dist/analyzer/inspections/functional/smells.d.ts +16 -0
  10. package/dist/analyzer/inspections/functional/smells.js +98 -0
  11. package/dist/analyzer/inspections/{generic.d.ts → generic/generic.d.ts} +70 -43
  12. package/dist/analyzer/inspections/generic/generic.js +604 -0
  13. package/dist/analyzer/inspections/generic/smells.d.ts +61 -0
  14. package/dist/analyzer/inspections/generic/smells.js +349 -0
  15. package/dist/analyzer/inspections/imperative/imperative.d.ts +35 -0
  16. package/dist/analyzer/inspections/imperative/imperative.js +109 -0
  17. package/dist/analyzer/inspections/imperative/smells.d.ts +16 -0
  18. package/dist/analyzer/inspections/imperative/smells.js +58 -0
  19. package/dist/analyzer/inspections/logic/logic.d.ts +32 -0
  20. package/dist/analyzer/inspections/logic/logic.js +96 -0
  21. package/dist/analyzer/inspections/logic/smells.d.ts +15 -0
  22. package/dist/analyzer/inspections/logic/smells.js +60 -0
  23. package/dist/analyzer/inspections/object/object.d.ts +88 -0
  24. package/dist/analyzer/inspections/object/object.js +319 -0
  25. package/dist/analyzer/inspections/object/smells.d.ts +30 -0
  26. package/dist/analyzer/inspections/object/smells.js +135 -0
  27. package/dist/analyzer/utils.d.ts +26 -4
  28. package/dist/analyzer/utils.js +71 -13
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/interpreter/components/EnvBuilder.d.ts +9 -5
  32. package/dist/interpreter/components/EnvBuilder.js +100 -30
  33. package/dist/interpreter/components/FunctionRuntime.d.ts +2 -2
  34. package/dist/interpreter/components/FunctionRuntime.js +34 -5
  35. package/dist/interpreter/components/LazyRuntime.d.ts +2 -2
  36. package/dist/interpreter/components/LazyRuntime.js +32 -13
  37. package/dist/interpreter/components/LogicEngine.d.ts +5 -2
  38. package/dist/interpreter/components/LogicEngine.js +40 -19
  39. package/dist/interpreter/components/LogicResolver.d.ts +1 -2
  40. package/dist/interpreter/components/LogicResolver.js +18 -8
  41. package/dist/interpreter/components/ObjectRuntime.d.ts +33 -0
  42. package/dist/interpreter/components/ObjectRuntime.js +123 -0
  43. package/dist/interpreter/components/Operations.d.ts +4 -4
  44. package/dist/interpreter/components/Operations.js +17 -2
  45. package/dist/interpreter/components/PatternMatcher.d.ts +46 -17
  46. package/dist/interpreter/components/PatternMatcher.js +264 -119
  47. package/dist/interpreter/components/RuntimeContext.d.ts +34 -0
  48. package/dist/interpreter/components/RuntimeContext.js +86 -0
  49. package/dist/interpreter/components/TestRunner.d.ts +18 -0
  50. package/dist/interpreter/components/TestRunner.js +144 -0
  51. package/dist/interpreter/components/Visitor.d.ts +63 -57
  52. package/dist/interpreter/components/Visitor.js +519 -172
  53. package/dist/interpreter/components/logic/LogicEngine.d.ts +29 -0
  54. package/dist/interpreter/components/logic/LogicEngine.js +259 -0
  55. package/dist/interpreter/components/logic/LogicResolver.d.ts +53 -0
  56. package/dist/interpreter/components/logic/LogicResolver.js +471 -0
  57. package/dist/interpreter/components/logic/LogicTranslator.d.ts +14 -0
  58. package/dist/interpreter/components/logic/LogicTranslator.js +99 -0
  59. package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +11 -0
  60. package/dist/interpreter/components/runtimes/FunctionRuntime.js +120 -0
  61. package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +14 -0
  62. package/dist/interpreter/components/runtimes/LazyRuntime.js +238 -0
  63. package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +35 -0
  64. package/dist/interpreter/components/runtimes/ObjectRuntime.js +126 -0
  65. package/dist/interpreter/errors.d.ts +1 -1
  66. package/dist/interpreter/index.d.ts +4 -12
  67. package/dist/interpreter/index.js +10 -13
  68. package/dist/interpreter/trampoline.d.ts +17 -0
  69. package/dist/interpreter/trampoline.js +38 -0
  70. package/dist/interpreter/utils.d.ts +4 -7
  71. package/dist/interpreter/utils.js +25 -17
  72. package/dist/tester/index.d.ts +25 -0
  73. package/dist/tester/index.js +108 -0
  74. package/dist/utils/helpers.d.ts +0 -4
  75. package/dist/utils/helpers.js +20 -24
  76. package/package.json +2 -2
  77. package/src/analyzer/GraphBuilder.ts +142 -0
  78. package/src/analyzer/index.ts +184 -132
  79. package/src/analyzer/inspections/functional/functional.ts +121 -0
  80. package/src/analyzer/inspections/functional/smells.ts +102 -0
  81. package/src/analyzer/inspections/{generic.ts → generic/generic.ts} +581 -499
  82. package/src/analyzer/inspections/generic/smells.ts +365 -0
  83. package/src/analyzer/inspections/imperative/imperative.ts +101 -0
  84. package/src/analyzer/inspections/imperative/smells.ts +54 -0
  85. package/src/analyzer/inspections/logic/logic.ts +90 -0
  86. package/src/analyzer/inspections/logic/smells.ts +54 -0
  87. package/src/analyzer/inspections/{object.ts → object/object.ts} +264 -282
  88. package/src/analyzer/inspections/object/smells.ts +144 -0
  89. package/src/analyzer/utils.ts +109 -26
  90. package/src/index.ts +3 -2
  91. package/src/interpreter/components/EnvBuilder.ts +202 -97
  92. package/src/interpreter/components/Operations.ts +99 -81
  93. package/src/interpreter/components/PatternMatcher.ts +473 -254
  94. package/src/interpreter/components/RuntimeContext.ts +113 -0
  95. package/src/interpreter/components/TestRunner.ts +187 -0
  96. package/src/interpreter/components/Visitor.ts +1078 -493
  97. package/src/interpreter/components/logic/LogicEngine.ts +519 -0
  98. package/src/interpreter/components/logic/LogicResolver.ts +858 -0
  99. package/src/interpreter/components/logic/LogicTranslator.ts +149 -0
  100. package/src/interpreter/components/runtimes/FunctionRuntime.ts +188 -0
  101. package/src/interpreter/components/runtimes/LazyRuntime.ts +301 -0
  102. package/src/interpreter/components/runtimes/ObjectRuntime.ts +224 -0
  103. package/src/interpreter/errors.ts +47 -47
  104. package/src/interpreter/index.ts +52 -59
  105. package/src/interpreter/trampoline.ts +71 -0
  106. package/src/interpreter/utils.ts +84 -79
  107. package/src/tester/index.ts +128 -0
  108. package/src/utils/helpers.ts +67 -73
  109. package/tests/analyzer/functional.spec.ts +207 -221
  110. package/tests/analyzer/generic.spec.ts +164 -100
  111. package/tests/analyzer/helpers.spec.ts +83 -83
  112. package/tests/analyzer/logic.spec.ts +237 -292
  113. package/tests/analyzer/oop.spec.ts +323 -338
  114. package/tests/analyzer/transitive.spec.ts +166 -0
  115. package/tests/interpreter/EnvBuilder.spec.ts +183 -178
  116. package/tests/interpreter/FunctionRuntime.spec.ts +223 -234
  117. package/tests/interpreter/LazyRuntime.spec.ts +225 -190
  118. package/tests/interpreter/LogicEngine.spec.ts +327 -194
  119. package/tests/interpreter/LogicSubstitution.spec.ts +80 -0
  120. package/tests/interpreter/ObjectRuntime.spec.ts +606 -0
  121. package/tests/interpreter/Operations.spec.ts +220 -220
  122. package/tests/interpreter/PatternSystem.spec.ts +213 -189
  123. package/tests/interpreter/Tests.spec.ts +122 -0
  124. package/tests/interpreter/interpreter.spec.ts +981 -937
  125. package/tests/tester/Tester.spec.ts +153 -0
  126. package/tsconfig.build.json +15 -7
  127. package/tsconfig.json +25 -17
  128. package/tsconfig.tsbuildinfo +1 -0
  129. package/dist/analyzer/inspections/functional.d.ts +0 -46
  130. package/dist/analyzer/inspections/functional.js +0 -123
  131. package/dist/analyzer/inspections/generic.js +0 -427
  132. package/dist/analyzer/inspections/imperative.d.ts +0 -37
  133. package/dist/analyzer/inspections/imperative.js +0 -105
  134. package/dist/analyzer/inspections/logic.d.ts +0 -49
  135. package/dist/analyzer/inspections/logic.js +0 -140
  136. package/dist/analyzer/inspections/object.d.ts +0 -83
  137. package/dist/analyzer/inspections/object.js +0 -235
  138. package/src/analyzer/inspections/functional.ts +0 -159
  139. package/src/analyzer/inspections/imperative.ts +0 -129
  140. package/src/analyzer/inspections/logic.ts +0 -166
  141. package/src/interpreter/components/FunctionRuntime.ts +0 -79
  142. package/src/interpreter/components/LazyRuntime.ts +0 -97
  143. package/src/interpreter/components/LogicEngine.ts +0 -227
  144. package/src/interpreter/components/LogicResolver.ts +0 -130
package/.mocharc.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "extension": ["ts"],
3
- "spec": "tests/**/*.spec.ts"
1
+ {
2
+ "extension": ["ts"],
3
+ "spec": "tests/**/*.spec.ts"
4
4
  }
package/README.md CHANGED
@@ -1,199 +1,193 @@
1
- # ❄️ Yukigo (WIP)
2
- A universal, multi-language, multi-paradigm code analyzer highly inspired in [mulang](https://github.com/mumuki/mulang)
3
-
4
- > [!WARNING]
5
- > This project is still in a "work in progress" state. Everything is subject to change :)
6
-
7
-
8
- ## Components
9
-
10
- ### **Abstract Semantic Tree:**
11
-
12
- This is the intermediate representation of any language. Allows us to analyse the semantics of the code independently of the paradigm or the language.
13
-
14
- ### **Inspector:**
15
-
16
- We provide a set of built-in expectations for analysing code. Also allows to define custom expectations at runtime.
17
-
18
- ### **Translator:**
19
-
20
- Translation AST-to-Typescript, this allows us to have an equivalent code to run input-output tests everywhere.
21
-
22
- ### **Tester:**
23
-
24
- Runs tests for the Typescript translated code on an isolated enviroment.
25
-
26
- # Usage
27
-
28
- ## Installation
29
-
30
- We will be using Haskell as the target language in this example.
31
-
32
- ```
33
- npm install yukigo yukigo-haskell-parser
34
- ```
35
-
36
- or
37
-
38
- ```
39
- yarn add yukigo yukigo-haskell-parser
40
- ```
41
-
42
- ## Example
43
-
44
- ```ts
45
- import { ASTAnalyzer } from "yukigo";
46
- import { YukigoHaskellParser } from "yukigo-haskell-parser";
47
-
48
- const code = "doble num = num * 2";
49
- const expectations = [
50
- {
51
- inspection: "HasBinding",
52
- args: { name: "minimoEntre" },
53
- expected: false,
54
- },
55
- {
56
- inspection: "HasBinding",
57
- args: { name: "doble" },
58
- expected: true,
59
- },
60
- ];
61
-
62
- const parser = new YukigoHaskellParser();
63
- const ast = parser.parse(code);
64
-
65
- const analyser = new ASTAnalyzer(ast);
66
- const result = analyser.analyse(expectations);
67
-
68
- console.log(results);
69
- // [
70
- // {
71
- // rule: {
72
- // inspection: "HasBinding",
73
- // args: { name: "minimoEntre" },
74
- // expected: false,
75
- // },
76
- // passed: true,
77
- // actual: false,
78
- // },
79
- // {
80
- // rule: {
81
- // inspection: "HasBinding",
82
- // args: { name: "doble" },
83
- // expected: true,
84
- // },
85
- // passed: true,
86
- // actual: true,
87
- // },
88
- // ];
89
- ```
90
-
91
- ## Example with Mulang's Inspections (in a YAML file)
92
-
93
- ```ts
94
- import { ASTAnalyzer, translateMulangToInspectionRules } from "yukigo";
95
- import { YukigoHaskellParser } from "yukigo-haskell-parser";
96
-
97
- const code = `
98
- squareList :: [Int] -> [Int]
99
- squareList xs = map (\n -> n * n) xs
100
-
101
- square :: Int -> Int
102
- square n = n * n
103
-
104
- squareList2 :: [Int] -> [Int]
105
- squareList2 = map square
106
- `;
107
-
108
- // Assuming the expectations are in a yaml file. Implement a way to load the actual file.
109
- const mulangInspections = `
110
- expectations:
111
- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
112
- binding: squareList
113
- inspection: HasBinding
114
- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
115
- binding: squareList
116
- inspection: HasLambdaExpression
117
- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
118
- binding: square
119
- inspection: HasArithmetic
120
- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
121
- binding: doble
122
- inspection: Not:HasBinding
123
- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
124
- binding: square
125
- inspection: Uses:n
126
- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
127
- binding: squareList2
128
- inspection: Uses:map
129
- `;
130
-
131
- const expectations = translateMulangToInspectionRules(mulangInspections);
132
-
133
- const parser = new YukigoHaskellParser();
134
- const ast = parser.parse(code);
135
-
136
- const analyser = new ASTAnalyzer(ast);
137
- const result = analyser.analyse(expectations);
138
-
139
- console.log(results);
140
- // [
141
- // {
142
- // rule: { inspection: "HasBinding", args: [Object], expected: true },
143
- // passed: true,
144
- // actual: true,
145
- // },
146
- // {
147
- // rule: {
148
- // inspection: "HasLambdaExpression",
149
- // args: [Object],
150
- // expected: true,
151
- // },
152
- // passed: true,
153
- // actual: true,
154
- // },
155
- // {
156
- // rule: { inspection: "HasArithmetic", args: [Object], expected: true },
157
- // passed: true,
158
- // actual: true,
159
- // },
160
- // {
161
- // rule: { inspection: "HasBinding", args: [Object], expected: false },
162
- // passed: true,
163
- // actual: false,
164
- // },
165
- // {
166
- // rule: { inspection: "Uses", args: [Object], expected: true },
167
- // passed: true,
168
- // actual: true,
169
- // },
170
- // {
171
- // rule: { inspection: "Uses", args: [Object], expected: true },
172
- // passed: true,
173
- // actual: true,
174
- // },
175
- // ];
176
- ```
177
-
178
- # Relevant tools
179
- - yukigo-ast: A library of AST's node definitions
180
-
181
- ## Tools
182
- - [CLI](https://github.com/noiseArch/yukigo-cli)
183
-
184
- ## Parsers
185
- - Haskell
186
- - Prolog
187
-
188
- # How to make a parser
189
-
190
- A yukigo's parser is a class that implements the interface `YukigoParser` which exposes a public method called `parse` and an `errors` array like this:
191
- ```ts
192
- errors: string[];
193
- parse: (code: string) => AST;
194
- ```
195
-
196
- The package `yukigo-ast` has all the current supported AST nodes.
197
- For the grammar, you can use a tool like Jison or Nearley.
198
-
199
- Here's a tutorial for implementing a small custom language.
1
+ # ❄️ Yukigo
2
+ A universal, multi-language, multi-paradigm code analyzer highly inspired in [mulang](https://github.com/mumuki/mulang)
3
+
4
+ ## Components
5
+
6
+ ### **Abstract Semantic Tree:**
7
+
8
+ This is the intermediate representation of any language. Allows us to analyse the semantics of the code independently of the paradigm or the language.
9
+
10
+ ### **Analyzer:**
11
+
12
+ The Analyzer is the component that traverses the AST and runs the specified inspections.
13
+
14
+ ### **Interpreter:**
15
+
16
+ The Interpreter is the component that evaluates provided Expression nodes and returns the resultant PrimitiveValue
17
+
18
+ # Usage
19
+
20
+ ## Installation
21
+
22
+ We will be using Haskell as the target language in this example.
23
+
24
+ ```
25
+ npm install yukigo yukigo-haskell-parser
26
+ ```
27
+
28
+ or
29
+
30
+ ```
31
+ yarn add yukigo yukigo-haskell-parser
32
+ ```
33
+
34
+ ## Example
35
+
36
+ ```ts
37
+ import { Analyzer } from "yukigo";
38
+ import { YukigoHaskellParser } from "yukigo-haskell-parser";
39
+
40
+ const code = "doble num = num * 2";
41
+ const expectations = [
42
+ {
43
+ inspection: "HasBinding",
44
+ args: { name: "minimoEntre" },
45
+ expected: false,
46
+ },
47
+ {
48
+ inspection: "HasBinding",
49
+ args: { name: "doble" },
50
+ expected: true,
51
+ },
52
+ ];
53
+
54
+ const parser = new YukigoHaskellParser();
55
+ const ast = parser.parse(code);
56
+
57
+ const analyzer = new ASTAnalyzer(ast);
58
+ const result = analyzer.analyse(expectations);
59
+
60
+ console.log(results);
61
+ // [
62
+ // {
63
+ // rule: {
64
+ // inspection: "HasBinding",
65
+ // args: { name: "minimoEntre" },
66
+ // expected: false,
67
+ // },
68
+ // passed: true,
69
+ // actual: false,
70
+ // },
71
+ // {
72
+ // rule: {
73
+ // inspection: "HasBinding",
74
+ // args: { name: "doble" },
75
+ // expected: true,
76
+ // },
77
+ // passed: true,
78
+ // actual: true,
79
+ // },
80
+ // ];
81
+ ```
82
+
83
+ ## Example with Mulang's Inspections (in a YAML file)
84
+
85
+ ```ts
86
+ import { Analyzer, translateMulangToInspectionRules } from "yukigo";
87
+ import { YukigoHaskellParser } from "yukigo-haskell-parser";
88
+
89
+ const code = `
90
+ squareList :: [Int] -> [Int]
91
+ squareList xs = map (\n -> n * n) xs
92
+
93
+ square :: Int -> Int
94
+ square n = n * n
95
+
96
+ squareList2 :: [Int] -> [Int]
97
+ squareList2 = map square
98
+ `;
99
+
100
+ // Assuming the expectations are in a yaml file. Implement a way to load the actual file.
101
+ const mulangInspections = `
102
+ expectations:
103
+ - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
104
+ binding: squareList
105
+ inspection: HasBinding
106
+ - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
107
+ binding: squareList
108
+ inspection: HasLambdaExpression
109
+ - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
110
+ binding: square
111
+ inspection: HasArithmetic
112
+ - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
113
+ binding: doble
114
+ inspection: Not:HasBinding
115
+ - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
116
+ binding: square
117
+ inspection: Uses:n
118
+ - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
119
+ binding: squareList2
120
+ inspection: Uses:map
121
+ `;
122
+
123
+ const expectations = translateMulangToInspectionRules(mulangInspections);
124
+
125
+ const parser = new YukigoHaskellParser();
126
+ const ast = parser.parse(code);
127
+
128
+ const analyzer = new Analyzer(ast);
129
+ const result = analyzer.analyse(expectations);
130
+
131
+ console.log(results);
132
+ // [
133
+ // {
134
+ // rule: { inspection: "HasBinding", args: [Object], expected: true },
135
+ // passed: true,
136
+ // actual: true,
137
+ // },
138
+ // {
139
+ // rule: {
140
+ // inspection: "HasLambdaExpression",
141
+ // args: [Object],
142
+ // expected: true,
143
+ // },
144
+ // passed: true,
145
+ // actual: true,
146
+ // },
147
+ // {
148
+ // rule: { inspection: "HasArithmetic", args: [Object], expected: true },
149
+ // passed: true,
150
+ // actual: true,
151
+ // },
152
+ // {
153
+ // rule: { inspection: "HasBinding", args: [Object], expected: false },
154
+ // passed: true,
155
+ // actual: false,
156
+ // },
157
+ // {
158
+ // rule: { inspection: "Uses", args: [Object], expected: true },
159
+ // passed: true,
160
+ // actual: true,
161
+ // },
162
+ // {
163
+ // rule: { inspection: "Uses", args: [Object], expected: true },
164
+ // passed: true,
165
+ // actual: true,
166
+ // },
167
+ // ];
168
+ ```
169
+
170
+ # Relevant tools
171
+ - yukigo-ast: A library of AST node definitions and utilities for making yukigo parsers
172
+
173
+ ## Tools
174
+ - [CLI](https://github.com/noiseArch/yukigo-cli)
175
+ - create-yukigo-parser: A scaffolding tool to quickstart a yukigo parser with recommended configuration
176
+
177
+ ## Parsers
178
+ - Haskell
179
+ - Prolog
180
+ - Wollok
181
+
182
+ # How to make a parser
183
+
184
+ A yukigo's parser is a class that implements the interface `YukigoParser` which exposes a public method called `parse` and an `errors` array like this:
185
+ ```ts
186
+ errors: string[];
187
+ parse: (code: string) => AST;
188
+ ```
189
+
190
+ The package `yukigo-ast` has all the current supported AST nodes.
191
+ For the grammar, you can use a tool like Jison or Nearley.
192
+
193
+ Here's a [tutorial](https://miyukiproject.github.io/yukigo/guides/making-a-parser.html) for implementing a small custom language.
@@ -0,0 +1,29 @@
1
+ import { Application, AST, ASTNode, Call, Class, Fact, Function, Interface, Method, New, Object as YuObject, Procedure, Rule, TraverseVisitor, TypeAlias, TypeSignature, Exist } from "yukigo-ast";
2
+ type DefinitionMap = Map<string, ASTNode[]>;
3
+ type CallsMap = Map<string, string[]>;
4
+ export type SymbolGraph = {
5
+ defs: DefinitionMap;
6
+ calls: CallsMap;
7
+ };
8
+ export declare class GraphBuilder extends TraverseVisitor {
9
+ private defs;
10
+ private calls;
11
+ private scope;
12
+ build(ast: AST): SymbolGraph;
13
+ private addDefinition;
14
+ visitFunction(node: Function): void;
15
+ visitMethod(node: Method): void;
16
+ visitProcedure(node: Procedure): void;
17
+ visitRule(node: Rule): void;
18
+ visitFact(node: Fact): void;
19
+ visitClass(node: Class): void;
20
+ visitObject(node: YuObject): void;
21
+ visitInterface(node: Interface): void;
22
+ visitTypeAlias(node: TypeAlias): void;
23
+ visitTypeSignature(node: TypeSignature): void;
24
+ visitCall(node: Call): void;
25
+ visitApplication(node: Application): void;
26
+ visitNew(node: New): void;
27
+ visitExist(node: Exist): void;
28
+ }
29
+ export {};
@@ -0,0 +1,99 @@
1
+ import { SymbolPrimitive, TraverseVisitor, } from "yukigo-ast";
2
+ export class GraphBuilder extends TraverseVisitor {
3
+ defs = new Map();
4
+ calls = new Map();
5
+ scope = "";
6
+ build(ast) {
7
+ ast.forEach((node) => node.accept(this));
8
+ return { defs: this.defs, calls: this.calls };
9
+ }
10
+ addDefinition(name, node) {
11
+ const existing = this.defs.get(name) || [];
12
+ this.defs.set(name, [...existing, node]);
13
+ }
14
+ visitFunction(node) {
15
+ this.scope = node.identifier.value;
16
+ this.addDefinition(this.scope, node);
17
+ this.traverseCollection(node.equations);
18
+ this.scope = "";
19
+ }
20
+ visitMethod(node) {
21
+ this.scope = node.identifier.value;
22
+ this.addDefinition(this.scope, node);
23
+ this.traverseCollection(node.equations);
24
+ this.scope = "";
25
+ }
26
+ visitProcedure(node) {
27
+ this.scope = node.identifier.value;
28
+ this.addDefinition(this.scope, node);
29
+ this.traverseCollection(node.equations);
30
+ this.scope = "";
31
+ }
32
+ visitRule(node) {
33
+ this.scope = node.identifier.value;
34
+ this.addDefinition(this.scope, node);
35
+ this.traverseCollection(node.equations);
36
+ this.scope = "";
37
+ }
38
+ visitFact(node) {
39
+ this.scope = node.identifier.value;
40
+ this.addDefinition(this.scope, node);
41
+ this.traverseCollection(node.patterns);
42
+ this.scope = "";
43
+ }
44
+ visitClass(node) {
45
+ this.scope = node.identifier.value;
46
+ this.addDefinition(this.scope, node);
47
+ node.expression.accept(this);
48
+ this.scope = "";
49
+ }
50
+ visitObject(node) {
51
+ this.scope = node.identifier.value;
52
+ this.addDefinition(this.scope, node);
53
+ node.expression.accept(this);
54
+ this.scope = "";
55
+ }
56
+ visitInterface(node) {
57
+ this.scope = node.identifier.value;
58
+ this.addDefinition(this.scope, node);
59
+ node.expression.accept(this);
60
+ this.scope = "";
61
+ }
62
+ visitTypeAlias(node) {
63
+ this.scope = node.identifier.value;
64
+ this.addDefinition(this.scope, node);
65
+ this.scope = "";
66
+ }
67
+ visitTypeSignature(node) {
68
+ this.scope = node.identifier.value;
69
+ this.addDefinition(this.scope, node);
70
+ this.scope = "";
71
+ }
72
+ visitCall(node) {
73
+ if (!this.scope)
74
+ return;
75
+ const arr = this.calls.get(this.scope) || [];
76
+ this.calls.set(this.scope, [node.callee.value, ...arr]);
77
+ }
78
+ visitApplication(node) {
79
+ if (!this.scope)
80
+ return;
81
+ const arr = this.calls.get(this.scope) || [];
82
+ if (node.functionExpr instanceof SymbolPrimitive)
83
+ this.calls.set(this.scope, [node.functionExpr.value, ...arr]);
84
+ else
85
+ node.functionExpr.accept(this);
86
+ }
87
+ visitNew(node) {
88
+ if (!this.scope)
89
+ return;
90
+ const arr = this.calls.get(this.scope) || [];
91
+ this.calls.set(this.scope, [node.identifier.value, ...arr]);
92
+ }
93
+ visitExist(node) {
94
+ if (!this.scope)
95
+ return;
96
+ const arr = this.calls.get(this.scope) || [];
97
+ this.calls.set(this.scope, [node.identifier.value, ...arr]);
98
+ }
99
+ }
@@ -1,5 +1,5 @@
1
- import { AST } from "@yukigo/ast";
2
- import { InspectionHandler, InspectionMap } from "./utils.js";
1
+ import { AST } from "yukigo-ast";
2
+ import { InspectionMap, VisitorConstructor } from "./utils.js";
3
3
  export type AnalysisResult = {
4
4
  rule: InspectionRule;
5
5
  passed: boolean;
@@ -12,11 +12,12 @@ export type InspectionRule = {
12
12
  args: string[];
13
13
  expected: boolean;
14
14
  };
15
- export declare const defaultInspectionSet: InspectionMap;
15
+ export declare const DefaultInspectionSet: InspectionMap;
16
+ export declare const DefaultSmellsSet: InspectionMap;
16
17
  /**
17
18
  * The Analyzer class.
18
19
  * @remarks
19
- * The Analyzer is the part of Yukigo which runs the inspections on the AST.
20
+ * The Analyzer is the part of Yukigo which runs the inspections on the AST.s
20
21
  */
21
22
  export declare class Analyzer {
22
23
  /**
@@ -24,27 +25,15 @@ export declare class Analyzer {
24
25
  * You can load your set of inspections or leave the default one.
25
26
  * @defaultValue a default set of inspections for each supported paradigm
26
27
  */
27
- private inspectionHandlers;
28
- constructor(inspectionSet?: InspectionMap);
28
+ private inspectionConstructors;
29
+ private smellsConstructors;
30
+ constructor(inspectionSet?: InspectionMap, smellsSet?: InspectionMap);
29
31
  /**
30
32
  * Registers a new custom inspection handler after Analyzer was instantiated.
31
33
  * @param name The name of the inspection (e.g., "HasArithmetic").
32
- * @param handler The function that implements the inspection logic.
33
- *
34
- * @example
35
- * // Implementation of HasArithmetic inspection
36
- * export class UsesArithmetic extends TraverseVisitor {
37
- * visitArithmeticBinaryOperation(node: ArithmeticBinaryOperation): void {
38
- * throw new StopTraversalException();
39
- * }
40
- * visitArithmeticUnaryOperation(node: ArithmeticUnaryOperation): void {
41
- * throw new StopTraversalException();
42
- * }
43
- * }
44
- * const analyzer = new ASTAnalyzer(ast);
45
- * analyzer.registerInspection("HasArithmetic", (node, args) => executeVisitor(node, new UsesArithmetic()));
34
+ * @param visitorConstructor The constructor for the TraverseVisitor class.
46
35
  */
47
- registerInspection(name: string, handler: InspectionHandler): void;
36
+ registerInspection(name: string, visitorConstructor: VisitorConstructor): void;
48
37
  /**
49
38
  * Runs a list of inspection rules against the AST.
50
39
  * @param ast The parsed AST.
@@ -67,5 +56,4 @@ export declare class Analyzer {
67
56
  * const analysisResults = analyzer.analyze(expectations);
68
57
  */
69
58
  analyze(ast: AST, rules: InspectionRule[]): AnalysisResult[];
70
- private runRule;
71
59
  }