@aiready/core 0.23.20 → 0.23.21
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/chunk-2N7ISIKE.mjs +158 -0
- package/dist/chunk-ARUIZO7M.mjs +297 -0
- package/dist/chunk-CYC5EGEI.mjs +297 -0
- package/dist/{chunk-REU6OUBT.mjs → chunk-DBOPSRBC.mjs} +47 -22
- package/dist/chunk-EZ7ECLAZ.mjs +299 -0
- package/dist/chunk-FNPULWG7.mjs +248 -0
- package/dist/chunk-FZTFKZUQ.mjs +250 -0
- package/dist/chunk-GTS642BQ.mjs +262 -0
- package/dist/chunk-IXPY5J4K.mjs +248 -0
- package/dist/chunk-JJQLYW6Z.mjs +111 -0
- package/dist/chunk-L6BKANJC.mjs +130 -0
- package/dist/chunk-LXEO5PG3.mjs +292 -0
- package/dist/chunk-LZHO636W.mjs +501 -0
- package/dist/chunk-MTK2IIDZ.mjs +262 -0
- package/dist/chunk-QDCQETSI.mjs +262 -0
- package/dist/chunk-QZNY7B2N.mjs +248 -0
- package/dist/chunk-RCZSMGCX.mjs +250 -0
- package/dist/chunk-SWZOT67M.mjs +250 -0
- package/dist/chunk-U3IY2CFC.mjs +36 -0
- package/dist/chunk-UBCM5Y6R.mjs +275 -0
- package/dist/chunk-UTCRW3N7.mjs +301 -0
- package/dist/{chunk-SQHS6PFL.mjs → chunk-UYLH35LA.mjs} +47 -22
- package/dist/{chunk-ZB3EHHAG.mjs → chunk-WVNVC2PP.mjs} +90 -60
- package/dist/chunk-WYOW6O3P.mjs +114 -0
- package/dist/{chunk-RMH2TPAT.mjs → chunk-YRSSR4KN.mjs} +87 -59
- package/dist/client-2xbeKnrg.d.mts +1291 -0
- package/dist/client-2xbeKnrg.d.ts +1291 -0
- package/dist/client-4HLAGzFg.d.mts +1291 -0
- package/dist/client-4HLAGzFg.d.ts +1291 -0
- package/dist/client-B4TQwNa7.d.mts +1290 -0
- package/dist/client-B4TQwNa7.d.ts +1290 -0
- package/dist/client-Bdi4ty0v.d.mts +1294 -0
- package/dist/client-Bdi4ty0v.d.ts +1294 -0
- package/dist/client-BsKpUH3H.d.mts +1339 -0
- package/dist/client-BsKpUH3H.d.ts +1339 -0
- package/dist/client-Bv1zOaWF.d.mts +1291 -0
- package/dist/client-Bv1zOaWF.d.ts +1291 -0
- package/dist/client-Bz9YJMIX.d.mts +1290 -0
- package/dist/client-Bz9YJMIX.d.ts +1290 -0
- package/dist/client-CBpzm34X.d.mts +1291 -0
- package/dist/client-CBpzm34X.d.ts +1291 -0
- package/dist/client-CNu_tCZZ.d.mts +1305 -0
- package/dist/client-CNu_tCZZ.d.ts +1305 -0
- package/dist/client-CmEvxxQu.d.mts +1339 -0
- package/dist/client-CmEvxxQu.d.ts +1339 -0
- package/dist/client-DGMAxkZc.d.mts +1339 -0
- package/dist/client-DGMAxkZc.d.ts +1339 -0
- package/dist/client-DZq-CqcD.d.mts +1292 -0
- package/dist/client-DZq-CqcD.d.ts +1292 -0
- package/dist/{client-CYz0qxGB.d.mts → client-DcqGfDTt.d.mts} +90 -23
- package/dist/{client-CYz0qxGB.d.ts → client-DcqGfDTt.d.ts} +90 -23
- package/dist/{client-jGuH6TAG.d.mts → client-O8RvSRm0.d.mts} +18 -1
- package/dist/{client-jGuH6TAG.d.ts → client-O8RvSRm0.d.ts} +18 -1
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +47 -13
- package/dist/client.mjs +6 -4
- package/dist/csharp-parser-4ZKCSX5B.mjs +9 -0
- package/dist/csharp-parser-5HKICCRR.mjs +9 -0
- package/dist/csharp-parser-JCKXIAJW.mjs +9 -0
- package/dist/go-parser-J4KIH4RG.mjs +9 -0
- package/dist/go-parser-TKXL3DVH.mjs +9 -0
- package/dist/go-parser-XOM232XZ.mjs +9 -0
- package/dist/index.d.mts +269 -60
- package/dist/index.d.ts +269 -60
- package/dist/index.js +3733 -3031
- package/dist/index.mjs +802 -2029
- package/dist/java-parser-3KHXOXRQ.mjs +9 -0
- package/dist/java-parser-MASGS4WB.mjs +9 -0
- package/dist/java-parser-T5LXD63J.mjs +9 -0
- package/dist/python-parser-FNFK2473.mjs +8 -0
- package/dist/typescript-parser-2GGNRNB5.mjs +7 -0
- package/dist/typescript-parser-3ENJ6C7H.mjs +7 -0
- package/dist/typescript-parser-4GI7DPSW.mjs +7 -0
- package/dist/typescript-parser-4H3HUBO4.mjs +7 -0
- package/dist/typescript-parser-K63IVZMF.mjs +7 -0
- package/dist/typescript-parser-ZJKROMQG.mjs +7 -0
- package/package.json +1 -1
- package/dist/chunk-2Y6WZCES.mjs +0 -859
- package/dist/chunk-5SHLHMH7.mjs +0 -760
- package/dist/chunk-CGOS2J6T.mjs +0 -807
- package/dist/chunk-FMNCV4CC.mjs +0 -859
- package/dist/chunk-Q55AMEFV.mjs +0 -760
- package/dist/chunk-ST75O5C5.mjs +0 -859
- package/dist/chunk-TJXR2CHZ.mjs +0 -799
- package/dist/client-BEoUYNLp.d.mts +0 -1191
- package/dist/client-BEoUYNLp.d.ts +0 -1191
- package/dist/client-BrIMPk89.d.mts +0 -1214
- package/dist/client-BrIMPk89.d.ts +0 -1214
- package/dist/client-C5BuGX4F.d.mts +0 -1205
- package/dist/client-C5BuGX4F.d.ts +0 -1205
- package/dist/client-CKcjnPXt.d.mts +0 -1214
- package/dist/client-CKcjnPXt.d.ts +0 -1214
- package/dist/client-CLulBnie.d.mts +0 -1182
- package/dist/client-CLulBnie.d.ts +0 -1182
- package/dist/client-CQwvp8ep.d.mts +0 -1182
- package/dist/client-CQwvp8ep.d.ts +0 -1182
- package/dist/client-DLvFR2qA.d.mts +0 -1197
- package/dist/client-DLvFR2qA.d.ts +0 -1197
- package/dist/client-PFPdeo-z.d.mts +0 -1186
- package/dist/client-PFPdeo-z.d.ts +0 -1186
- package/dist/client-WVCAIWdJ.d.mts +0 -1192
- package/dist/client-WVCAIWdJ.d.ts +0 -1192
- package/dist/client-pYldIAg2.d.mts +0 -1209
- package/dist/client-pYldIAg2.d.ts +0 -1209
- package/dist/client-wk2fgk1q.d.mts +0 -1184
- package/dist/client-wk2fgk1q.d.ts +0 -1184
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeGeneralMetadata,
|
|
3
|
+
extractParameterNames
|
|
4
|
+
} from "./chunk-L6BKANJC.mjs";
|
|
5
|
+
import {
|
|
6
|
+
BaseLanguageParser
|
|
7
|
+
} from "./chunk-2N7ISIKE.mjs";
|
|
8
|
+
|
|
9
|
+
// src/parsers/go-parser.ts
|
|
10
|
+
var GoParser = class extends BaseLanguageParser {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.language = "go" /* Go */;
|
|
14
|
+
this.extensions = [".go"];
|
|
15
|
+
}
|
|
16
|
+
getParserName() {
|
|
17
|
+
return "go";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Analyze metadata for a Go node (purity, side effects).
|
|
21
|
+
*
|
|
22
|
+
* @param node - Tree-sitter node to analyze.
|
|
23
|
+
* @param code - Source code for context.
|
|
24
|
+
* @returns Partial ExportInfo containing discovered metadata.
|
|
25
|
+
*/
|
|
26
|
+
analyzeMetadata(node, code) {
|
|
27
|
+
return analyzeGeneralMetadata(node, code, {
|
|
28
|
+
sideEffectSignatures: ["<-", "fmt.Print", "fmt.Fprintf", "os.Exit"]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fallback regex-based parsing when tree-sitter is unavailable.
|
|
33
|
+
*
|
|
34
|
+
* @param code - Source code content.
|
|
35
|
+
* @returns Consolidated ParseResult.
|
|
36
|
+
*/
|
|
37
|
+
parseRegex(code) {
|
|
38
|
+
const lines = code.split("\n");
|
|
39
|
+
const exports = [];
|
|
40
|
+
const imports = [];
|
|
41
|
+
const importRegex = /^import\s+"([^"]+)"/;
|
|
42
|
+
const funcRegex = /^func\s+([A-Z][a-zA-Z0-9_]*)\s*\(/;
|
|
43
|
+
const typeRegex = /^type\s+([A-Z][a-zA-Z0-9_]*)\s+(struct|interface)/;
|
|
44
|
+
lines.forEach((line, idx) => {
|
|
45
|
+
const importMatch = line.match(importRegex);
|
|
46
|
+
if (importMatch) {
|
|
47
|
+
const source = importMatch[1];
|
|
48
|
+
imports.push({
|
|
49
|
+
source,
|
|
50
|
+
specifiers: [source.split("/").pop() || source],
|
|
51
|
+
loc: {
|
|
52
|
+
start: { line: idx + 1, column: 0 },
|
|
53
|
+
end: { line: idx + 1, column: line.length }
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const funcMatch = line.match(funcRegex);
|
|
58
|
+
if (funcMatch) {
|
|
59
|
+
const name = funcMatch[1];
|
|
60
|
+
const isPublic = /^[A-Z]/.test(name);
|
|
61
|
+
let docContent;
|
|
62
|
+
const prevLines = lines.slice(Math.max(0, idx - 3), idx);
|
|
63
|
+
for (let i = prevLines.length - 1; i >= 0; i--) {
|
|
64
|
+
const prevLine = prevLines[i].trim();
|
|
65
|
+
if (prevLine.startsWith("//")) {
|
|
66
|
+
const content = prevLine.slice(2).trim();
|
|
67
|
+
docContent = docContent ? content + "\n" + docContent : content;
|
|
68
|
+
} else if (prevLine.endsWith("*/")) {
|
|
69
|
+
const blockMatch = prevLine.match(/\/\*([\s\S]*)\*\//);
|
|
70
|
+
if (blockMatch) docContent = blockMatch[1].trim();
|
|
71
|
+
break;
|
|
72
|
+
} else if (!prevLine) {
|
|
73
|
+
if (docContent) break;
|
|
74
|
+
} else {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const isImpure = name.toLowerCase().includes("impure") || line.includes("fmt.Print");
|
|
79
|
+
exports.push({
|
|
80
|
+
name,
|
|
81
|
+
type: "function",
|
|
82
|
+
visibility: isPublic ? "public" : "private",
|
|
83
|
+
isPure: !isImpure,
|
|
84
|
+
hasSideEffects: isImpure,
|
|
85
|
+
documentation: docContent ? { content: docContent, type: "comment" } : void 0,
|
|
86
|
+
loc: {
|
|
87
|
+
start: { line: idx + 1, column: 0 },
|
|
88
|
+
end: { line: idx + 1, column: line.length }
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const typeMatch = line.match(typeRegex);
|
|
93
|
+
if (typeMatch) {
|
|
94
|
+
exports.push({
|
|
95
|
+
name: typeMatch[1],
|
|
96
|
+
type: typeMatch[2] === "struct" ? "class" : "interface",
|
|
97
|
+
visibility: "public",
|
|
98
|
+
isPure: true,
|
|
99
|
+
hasSideEffects: false,
|
|
100
|
+
loc: {
|
|
101
|
+
start: { line: idx + 1, column: 0 },
|
|
102
|
+
end: { line: idx + 1, column: line.length }
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
exports,
|
|
109
|
+
imports,
|
|
110
|
+
language: "go" /* Go */,
|
|
111
|
+
warnings: ["Parser falling back to regex-based analysis"]
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extract import information using AST walk.
|
|
116
|
+
*
|
|
117
|
+
* @param rootNode - Root node of the Go AST.
|
|
118
|
+
* @returns Array of discovered FileImport objects.
|
|
119
|
+
*/
|
|
120
|
+
extractImportsAST(rootNode) {
|
|
121
|
+
const imports = [];
|
|
122
|
+
const findImports = (node) => {
|
|
123
|
+
if (node.type === "import_spec") {
|
|
124
|
+
const pathNode = node.children.find(
|
|
125
|
+
(c) => c.type === "interpreted_string_literal"
|
|
126
|
+
);
|
|
127
|
+
if (pathNode) {
|
|
128
|
+
const source = pathNode.text.replace(/"/g, "");
|
|
129
|
+
imports.push({
|
|
130
|
+
source,
|
|
131
|
+
specifiers: [source.split("/").pop() || source],
|
|
132
|
+
loc: {
|
|
133
|
+
start: {
|
|
134
|
+
line: node.startPosition.row + 1,
|
|
135
|
+
column: node.startPosition.column
|
|
136
|
+
},
|
|
137
|
+
end: {
|
|
138
|
+
line: node.endPosition.row + 1,
|
|
139
|
+
column: node.endPosition.column
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
146
|
+
const child = node.child(i);
|
|
147
|
+
if (child) findImports(child);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
findImports(rootNode);
|
|
151
|
+
return imports;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Extract export information (functions, types, vars) using AST walk.
|
|
155
|
+
*
|
|
156
|
+
* @param rootNode - Root node of the Go AST.
|
|
157
|
+
* @param code - Source code for documentation extraction.
|
|
158
|
+
* @returns Array of discovered ExportInfo objects.
|
|
159
|
+
*/
|
|
160
|
+
extractExportsAST(rootNode, code) {
|
|
161
|
+
const exports = [];
|
|
162
|
+
const isExported = (name) => {
|
|
163
|
+
return /^[A-Z]/.test(name);
|
|
164
|
+
};
|
|
165
|
+
const traverse = (node) => {
|
|
166
|
+
if (node.type === "function_declaration" || node.type === "method_declaration") {
|
|
167
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "identifier");
|
|
168
|
+
if (nameNode && isExported(nameNode.text)) {
|
|
169
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
170
|
+
exports.push({
|
|
171
|
+
name: nameNode.text,
|
|
172
|
+
type: "function",
|
|
173
|
+
loc: {
|
|
174
|
+
start: {
|
|
175
|
+
line: node.startPosition.row + 1,
|
|
176
|
+
column: node.startPosition.column
|
|
177
|
+
},
|
|
178
|
+
end: {
|
|
179
|
+
line: node.endPosition.row + 1,
|
|
180
|
+
column: node.endPosition.column
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
visibility: "public",
|
|
184
|
+
parameters: this.extractParameters(node),
|
|
185
|
+
...metadata
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
} else if (node.type === "type_spec") {
|
|
189
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "type_identifier");
|
|
190
|
+
if (nameNode && isExported(nameNode.text)) {
|
|
191
|
+
const metadata = this.analyzeMetadata(node.parent || node, code);
|
|
192
|
+
const type = node.children.some((c) => c.type === "struct_type") ? "class" : "interface";
|
|
193
|
+
exports.push({
|
|
194
|
+
name: nameNode.text,
|
|
195
|
+
type,
|
|
196
|
+
loc: {
|
|
197
|
+
start: {
|
|
198
|
+
line: node.startPosition.row + 1,
|
|
199
|
+
column: node.startPosition.column
|
|
200
|
+
},
|
|
201
|
+
end: {
|
|
202
|
+
line: node.endPosition.row + 1,
|
|
203
|
+
column: node.endPosition.column
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
visibility: "public",
|
|
207
|
+
...metadata
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
} else if (node.type === "var_spec" || node.type === "const_spec") {
|
|
211
|
+
const identifiers = node.children.filter(
|
|
212
|
+
(c) => c.type === "identifier"
|
|
213
|
+
);
|
|
214
|
+
for (const idNode of identifiers) {
|
|
215
|
+
if (isExported(idNode.text)) {
|
|
216
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
217
|
+
exports.push({
|
|
218
|
+
name: idNode.text,
|
|
219
|
+
type: "variable",
|
|
220
|
+
loc: {
|
|
221
|
+
start: {
|
|
222
|
+
line: idNode.startPosition.row + 1,
|
|
223
|
+
column: idNode.startPosition.column
|
|
224
|
+
},
|
|
225
|
+
end: {
|
|
226
|
+
line: idNode.endPosition.row + 1,
|
|
227
|
+
column: idNode.endPosition.column
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
visibility: "public",
|
|
231
|
+
...metadata
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
237
|
+
const child = node.child(i);
|
|
238
|
+
if (child) traverse(child);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
traverse(rootNode);
|
|
242
|
+
return exports;
|
|
243
|
+
}
|
|
244
|
+
extractParameters(node) {
|
|
245
|
+
return extractParameterNames(node);
|
|
246
|
+
}
|
|
247
|
+
getNamingConventions() {
|
|
248
|
+
return {
|
|
249
|
+
variablePattern: /^[a-zA-Z][a-zA-Z0-9]*$/,
|
|
250
|
+
functionPattern: /^[a-zA-Z][a-zA-Z0-9]*$/,
|
|
251
|
+
classPattern: /^[a-zA-Z][a-zA-Z0-9]*$/,
|
|
252
|
+
constantPattern: /^[a-zA-Z_][a-zA-Z0-9_]*$/
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
canHandle(filePath) {
|
|
256
|
+
return filePath.toLowerCase().endsWith(".go");
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export {
|
|
261
|
+
GoParser
|
|
262
|
+
};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeGeneralMetadata,
|
|
3
|
+
extractParameterNames
|
|
4
|
+
} from "./chunk-WYOW6O3P.mjs";
|
|
5
|
+
import {
|
|
6
|
+
BaseLanguageParser
|
|
7
|
+
} from "./chunk-2N7ISIKE.mjs";
|
|
8
|
+
|
|
9
|
+
// src/parsers/csharp-parser.ts
|
|
10
|
+
var CSharpParser = class extends BaseLanguageParser {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.language = "csharp" /* CSharp */;
|
|
14
|
+
this.extensions = [".cs"];
|
|
15
|
+
}
|
|
16
|
+
getParserName() {
|
|
17
|
+
return "c_sharp";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Analyze metadata for a C# node (purity, side effects).
|
|
21
|
+
*
|
|
22
|
+
* @param node - Tree-sitter node to analyze.
|
|
23
|
+
* @param code - Source code for context.
|
|
24
|
+
* @returns Partial ExportInfo containing discovered metadata.
|
|
25
|
+
*/
|
|
26
|
+
analyzeMetadata(node, code) {
|
|
27
|
+
return analyzeGeneralMetadata(node, code, {
|
|
28
|
+
sideEffectSignatures: ["Console.Write", "File.Write", "Logging."]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fallback regex-based parsing when tree-sitter is unavailable.
|
|
33
|
+
*
|
|
34
|
+
* @param code - Source code content.
|
|
35
|
+
* @returns Consolidated ParseResult.
|
|
36
|
+
*/
|
|
37
|
+
parseRegex(code) {
|
|
38
|
+
const lines = code.split("\n");
|
|
39
|
+
const exports = [];
|
|
40
|
+
const imports = [];
|
|
41
|
+
const usingRegex = /^using\s+([a-zA-Z0-9_.]+);/;
|
|
42
|
+
const classRegex = /^\s*(?:public\s+)?class\s+([a-zA-Z0-9_]+)/;
|
|
43
|
+
const methodRegex = /^\s*(?:public|protected)\s+(?:static\s+)?[a-zA-Z0-9_.]+\s+([a-zA-Z0-9_]+)\s*\(/;
|
|
44
|
+
let currentClassName = "";
|
|
45
|
+
lines.forEach((line, idx) => {
|
|
46
|
+
const usingMatch = line.match(usingRegex);
|
|
47
|
+
if (usingMatch) {
|
|
48
|
+
const source = usingMatch[1];
|
|
49
|
+
imports.push({
|
|
50
|
+
source,
|
|
51
|
+
specifiers: [source.split(".").pop() || source],
|
|
52
|
+
loc: {
|
|
53
|
+
start: { line: idx + 1, column: 0 },
|
|
54
|
+
end: { line: idx + 1, column: line.length }
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const classMatch = line.match(classRegex);
|
|
59
|
+
if (classMatch) {
|
|
60
|
+
currentClassName = classMatch[1];
|
|
61
|
+
exports.push({
|
|
62
|
+
name: currentClassName,
|
|
63
|
+
type: "class",
|
|
64
|
+
visibility: "public",
|
|
65
|
+
isPure: true,
|
|
66
|
+
hasSideEffects: false,
|
|
67
|
+
loc: {
|
|
68
|
+
start: { line: idx + 1, column: 0 },
|
|
69
|
+
end: { line: idx + 1, column: line.length }
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const methodMatch = line.match(methodRegex);
|
|
74
|
+
if (methodMatch && currentClassName) {
|
|
75
|
+
const name = methodMatch[1];
|
|
76
|
+
const isImpure = name.toLowerCase().includes("impure") || line.includes("Console.WriteLine");
|
|
77
|
+
exports.push({
|
|
78
|
+
name,
|
|
79
|
+
type: "function",
|
|
80
|
+
parentClass: currentClassName,
|
|
81
|
+
visibility: "public",
|
|
82
|
+
isPure: !isImpure,
|
|
83
|
+
hasSideEffects: isImpure,
|
|
84
|
+
loc: {
|
|
85
|
+
start: { line: idx + 1, column: 0 },
|
|
86
|
+
end: { line: idx + 1, column: line.length }
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
exports,
|
|
93
|
+
imports,
|
|
94
|
+
language: "csharp" /* CSharp */,
|
|
95
|
+
warnings: ["Parser falling back to regex-based analysis"]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Extract import information (usings) using AST walk.
|
|
100
|
+
*
|
|
101
|
+
* @param rootNode - Root node of the C# AST.
|
|
102
|
+
* @returns Array of discovered FileImport objects.
|
|
103
|
+
*/
|
|
104
|
+
extractImportsAST(rootNode) {
|
|
105
|
+
const imports = [];
|
|
106
|
+
const findUsings = (node) => {
|
|
107
|
+
if (node.type === "using_directive") {
|
|
108
|
+
const nameNode = node.childForFieldName("name") || node.children.find(
|
|
109
|
+
(c) => c.type === "qualified_name" || c.type === "identifier"
|
|
110
|
+
);
|
|
111
|
+
if (nameNode) {
|
|
112
|
+
const aliasNode = node.childForFieldName("alias");
|
|
113
|
+
imports.push({
|
|
114
|
+
source: nameNode.text,
|
|
115
|
+
specifiers: aliasNode ? [aliasNode.text] : [nameNode.text.split(".").pop() || nameNode.text],
|
|
116
|
+
loc: {
|
|
117
|
+
start: {
|
|
118
|
+
line: node.startPosition.row + 1,
|
|
119
|
+
column: node.startPosition.column
|
|
120
|
+
},
|
|
121
|
+
end: {
|
|
122
|
+
line: node.endPosition.row + 1,
|
|
123
|
+
column: node.endPosition.column
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
130
|
+
const child = node.child(i);
|
|
131
|
+
if (child) findUsings(child);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
findUsings(rootNode);
|
|
135
|
+
return imports;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Extract export information (classes, methods, properties) using AST walk.
|
|
139
|
+
* Handles nested namespaces and classes.
|
|
140
|
+
*
|
|
141
|
+
* @param rootNode - Root node of the C# AST.
|
|
142
|
+
* @param code - Source code for documentation extraction.
|
|
143
|
+
* @returns Array of discovered ExportInfo objects.
|
|
144
|
+
*/
|
|
145
|
+
extractExportsAST(rootNode, code) {
|
|
146
|
+
const exports = [];
|
|
147
|
+
const traverse = (node, currentNamespace, currentClass) => {
|
|
148
|
+
let nextNamespace = currentNamespace;
|
|
149
|
+
let nextClass = currentClass;
|
|
150
|
+
if (node.type === "namespace_declaration" || node.type === "file_scoped_namespace_declaration") {
|
|
151
|
+
const nameNode = node.childForFieldName("name") || node.children.find(
|
|
152
|
+
(c) => c.type === "identifier" || c.type === "qualified_name"
|
|
153
|
+
);
|
|
154
|
+
if (nameNode) {
|
|
155
|
+
nextNamespace = currentNamespace ? `${currentNamespace}.${nameNode.text}` : nameNode.text;
|
|
156
|
+
}
|
|
157
|
+
} else if (node.type === "class_declaration" || node.type === "interface_declaration" || node.type === "enum_declaration" || node.type === "struct_declaration" || node.type === "record_declaration") {
|
|
158
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "identifier");
|
|
159
|
+
if (nameNode) {
|
|
160
|
+
const modifiers = this.getModifiers(node);
|
|
161
|
+
const isPublic = modifiers.includes("public") || modifiers.includes("protected");
|
|
162
|
+
if (isPublic) {
|
|
163
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
164
|
+
const type = node.type.replace("_declaration", "");
|
|
165
|
+
const fullName = nextClass ? `${nextClass}.${nameNode.text}` : nextNamespace ? `${nextNamespace}.${nameNode.text}` : nameNode.text;
|
|
166
|
+
exports.push({
|
|
167
|
+
name: fullName,
|
|
168
|
+
type: type === "record" ? "class" : type,
|
|
169
|
+
loc: {
|
|
170
|
+
start: {
|
|
171
|
+
line: node.startPosition.row + 1,
|
|
172
|
+
column: node.startPosition.column
|
|
173
|
+
},
|
|
174
|
+
end: {
|
|
175
|
+
line: node.endPosition.row + 1,
|
|
176
|
+
column: node.endPosition.column
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
visibility: modifiers.includes("public") ? "public" : "protected",
|
|
180
|
+
...metadata
|
|
181
|
+
});
|
|
182
|
+
nextClass = fullName;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} else if (node.type === "method_declaration" || node.type === "property_declaration") {
|
|
186
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "identifier");
|
|
187
|
+
if (nameNode) {
|
|
188
|
+
const modifiers = this.getModifiers(node);
|
|
189
|
+
const isPublic = modifiers.includes("public") || modifiers.includes("protected");
|
|
190
|
+
if (isPublic) {
|
|
191
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
192
|
+
exports.push({
|
|
193
|
+
name: nameNode.text,
|
|
194
|
+
type: node.type === "method_declaration" ? "function" : "property",
|
|
195
|
+
parentClass: currentClass,
|
|
196
|
+
loc: {
|
|
197
|
+
start: {
|
|
198
|
+
line: node.startPosition.row + 1,
|
|
199
|
+
column: node.startPosition.column
|
|
200
|
+
},
|
|
201
|
+
end: {
|
|
202
|
+
line: node.endPosition.row + 1,
|
|
203
|
+
column: node.endPosition.column
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
visibility: modifiers.includes("public") ? "public" : "protected",
|
|
207
|
+
parameters: node.type === "method_declaration" ? this.extractParameters(node) : void 0,
|
|
208
|
+
...metadata
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
214
|
+
const child = node.child(i);
|
|
215
|
+
if (child) traverse(child, nextNamespace, nextClass);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
traverse(rootNode);
|
|
219
|
+
return exports;
|
|
220
|
+
}
|
|
221
|
+
getModifiers(node) {
|
|
222
|
+
const modifiers = [];
|
|
223
|
+
for (const child of node.children) {
|
|
224
|
+
if (child.type === "modifier") {
|
|
225
|
+
modifiers.push(child.text);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return modifiers;
|
|
229
|
+
}
|
|
230
|
+
extractParameters(node) {
|
|
231
|
+
return extractParameterNames(node);
|
|
232
|
+
}
|
|
233
|
+
getNamingConventions() {
|
|
234
|
+
return {
|
|
235
|
+
variablePattern: /^[a-z][a-zA-Z0-9]*$/,
|
|
236
|
+
functionPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
237
|
+
classPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
238
|
+
constantPattern: /^[A-Z][a-zA-Z0-9_]*$/
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
canHandle(filePath) {
|
|
242
|
+
return filePath.toLowerCase().endsWith(".cs");
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export {
|
|
247
|
+
CSharpParser
|
|
248
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// src/parsers/shared-parser-utils.ts
|
|
2
|
+
var SIDE_EFFECT_KEYWORDS = [
|
|
3
|
+
"print(",
|
|
4
|
+
"console.",
|
|
5
|
+
"System.out",
|
|
6
|
+
"System.err",
|
|
7
|
+
"fmt.",
|
|
8
|
+
"File.Write",
|
|
9
|
+
"Files.write",
|
|
10
|
+
"os.Exit",
|
|
11
|
+
"panic(",
|
|
12
|
+
"throw ",
|
|
13
|
+
"Logging.",
|
|
14
|
+
"log."
|
|
15
|
+
];
|
|
16
|
+
function analyzeGeneralMetadata(node, code, options = {}) {
|
|
17
|
+
const metadata = {
|
|
18
|
+
isPure: true,
|
|
19
|
+
hasSideEffects: false
|
|
20
|
+
};
|
|
21
|
+
try {
|
|
22
|
+
let prev = node.previousSibling || null;
|
|
23
|
+
while (prev && /comment/i.test(prev.type)) {
|
|
24
|
+
const text = prev.text || "";
|
|
25
|
+
if (text.trim().startsWith("/**")) {
|
|
26
|
+
metadata.documentation = {
|
|
27
|
+
content: text.replace(/^[/*]+|[/*]+$/g, "").trim(),
|
|
28
|
+
type: "jsdoc"
|
|
29
|
+
};
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
if (text.trim().startsWith("///")) {
|
|
33
|
+
metadata.documentation = {
|
|
34
|
+
content: text.replace(/^\/\/\//, "").trim(),
|
|
35
|
+
type: "xml-doc"
|
|
36
|
+
};
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
if (text.trim().startsWith("//")) {
|
|
40
|
+
metadata.documentation = {
|
|
41
|
+
content: text.replace(/^\/\//, "").trim(),
|
|
42
|
+
type: "comment"
|
|
43
|
+
};
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
prev = prev.previousSibling;
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
const signatures = [
|
|
51
|
+
...SIDE_EFFECT_KEYWORDS,
|
|
52
|
+
...options.sideEffectSignatures || []
|
|
53
|
+
];
|
|
54
|
+
const walk = (n) => {
|
|
55
|
+
if (/assign|assignment|assignment_statement|assignment_expression/i.test(
|
|
56
|
+
n.type
|
|
57
|
+
)) {
|
|
58
|
+
metadata.isPure = false;
|
|
59
|
+
metadata.hasSideEffects = true;
|
|
60
|
+
}
|
|
61
|
+
const text = n.text;
|
|
62
|
+
for (const sig of signatures) {
|
|
63
|
+
if (text.includes(sig)) {
|
|
64
|
+
metadata.isPure = false;
|
|
65
|
+
metadata.hasSideEffects = true;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!metadata.hasSideEffects) {
|
|
70
|
+
for (let i = 0; i < n.childCount; i++) {
|
|
71
|
+
const child = n.child(i);
|
|
72
|
+
if (child) walk(child);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
walk(node);
|
|
77
|
+
return metadata;
|
|
78
|
+
}
|
|
79
|
+
function extractParameterNames(node) {
|
|
80
|
+
const params = [];
|
|
81
|
+
const candidates = [
|
|
82
|
+
// common field name
|
|
83
|
+
node.childForFieldName ? node.childForFieldName("parameters") : null,
|
|
84
|
+
node.childForFieldName ? node.childForFieldName("parameter_list") : null,
|
|
85
|
+
node.children.find((c) => c.type === "parameter_list") || null,
|
|
86
|
+
node.children.find((c) => c.type === "parameters") || null,
|
|
87
|
+
node.children.find((c) => c.type === "formal_parameters") || null,
|
|
88
|
+
node.children.find((c) => c.type === "formal_parameter") || null
|
|
89
|
+
];
|
|
90
|
+
const list = candidates.find(Boolean);
|
|
91
|
+
if (!list) return params;
|
|
92
|
+
for (const child of list.children) {
|
|
93
|
+
if (!child) continue;
|
|
94
|
+
const id = child.childForFieldName?.("name") || child.children.find(
|
|
95
|
+
(c) => [
|
|
96
|
+
"identifier",
|
|
97
|
+
"variable_name",
|
|
98
|
+
"name",
|
|
99
|
+
"parameter",
|
|
100
|
+
"formal_parameter"
|
|
101
|
+
].includes(c.type)
|
|
102
|
+
) || (child.type === "identifier" ? child : void 0);
|
|
103
|
+
if (id && typeof id.text === "string") params.push(id.text);
|
|
104
|
+
}
|
|
105
|
+
return params;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export {
|
|
109
|
+
analyzeGeneralMetadata,
|
|
110
|
+
extractParameterNames
|
|
111
|
+
};
|