@aiready/core 0.24.4 → 0.24.6
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-RCZSMGCX.mjs → chunk-2IUCKF4Z.mjs} +1 -1
- package/dist/{chunk-WYOW6O3P.mjs → chunk-3D3I5K5W.mjs} +33 -7
- package/dist/{chunk-GTS642BQ.mjs → chunk-3FAI4YNO.mjs} +1 -1
- package/dist/{chunk-EZ7ECLAZ.mjs → chunk-5IVDH26E.mjs} +21 -16
- package/dist/{chunk-SWZOT67M.mjs → chunk-6T5O7OAY.mjs} +1 -1
- package/dist/{chunk-L6BKANJC.mjs → chunk-DHFOYNMW.mjs} +12 -8
- package/dist/{chunk-QZNY7B2N.mjs → chunk-EHUK4VMH.mjs} +16 -8
- package/dist/{chunk-MTK2IIDZ.mjs → chunk-EJ74KPCV.mjs} +1 -1
- package/dist/{chunk-2ILVUVRK.mjs → chunk-FAESSLG7.mjs} +44 -17
- package/dist/{chunk-UTCRW3N7.mjs → chunk-Q4LOPVH6.mjs} +18 -14
- package/dist/{chunk-WH4ZGRVF.mjs → chunk-QY5YG2AZ.mjs} +12 -9
- package/dist/{chunk-IXPY5J4K.mjs → chunk-X63YJX5G.mjs} +16 -8
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +44 -17
- package/dist/client/index.mjs +1 -1
- package/dist/{csharp-parser-4ZKCSX5B.mjs → csharp-parser-C52DNAKT.mjs} +2 -2
- package/dist/{csharp-parser-5HKICCRR.mjs → csharp-parser-XW7WHE77.mjs} +2 -2
- package/dist/{go-parser-TKXL3DVH.mjs → go-parser-GO4BIRDD.mjs} +2 -2
- package/dist/{go-parser-XOM232XZ.mjs → go-parser-KTG4CGF5.mjs} +2 -2
- package/dist/{index-CkM98qn1.d.mts → index-ChiWzeQs.d.mts} +188 -180
- package/dist/{index-CkM98qn1.d.ts → index-ChiWzeQs.d.ts} +188 -180
- package/dist/{index-EQ2jRSlB.d.mts → index-PI6qMP2H.d.mts} +182 -178
- package/dist/{index-EQ2jRSlB.d.ts → index-PI6qMP2H.d.ts} +182 -178
- package/dist/index.d.mts +50 -15
- package/dist/index.d.ts +50 -15
- package/dist/index.js +272 -114
- package/dist/index.mjs +161 -66
- package/dist/{java-parser-MASGS4WB.mjs → java-parser-EOKMGQ6B.mjs} +2 -2
- package/dist/{java-parser-T5LXD63J.mjs → java-parser-G47O53QP.mjs} +2 -2
- package/dist/{python-parser-FNFK2473.mjs → python-parser-BCI7JVLF.mjs} +1 -1
- package/dist/{typescript-parser-2GGNRNB5.mjs → typescript-parser-4BA4VYAF.mjs} +1 -1
- package/dist/{typescript-parser-3ENJ6C7H.mjs → typescript-parser-WFGH52WB.mjs} +1 -1
- package/package.json +1 -1
- package/dist/chunk-ARUIZO7M.mjs +0 -297
- package/dist/chunk-AZRUQG5T.mjs +0 -537
- package/dist/chunk-CYC5EGEI.mjs +0 -297
- package/dist/chunk-DBOPSRBC.mjs +0 -884
- package/dist/chunk-E55RNGGK.mjs +0 -852
- package/dist/chunk-FNPULWG7.mjs +0 -248
- package/dist/chunk-FZTFKZUQ.mjs +0 -250
- package/dist/chunk-G4Z45SMK.mjs +0 -852
- package/dist/chunk-JJQLYW6Z.mjs +0 -111
- package/dist/chunk-LEITCMH3.mjs +0 -535
- package/dist/chunk-LTAZ7Z62.mjs +0 -855
- package/dist/chunk-LXEO5PG3.mjs +0 -292
- package/dist/chunk-LZHO636W.mjs +0 -501
- package/dist/chunk-MPWWAAHQ.mjs +0 -548
- package/dist/chunk-QDCQETSI.mjs +0 -262
- package/dist/chunk-SM6INS52.mjs +0 -501
- package/dist/chunk-UBCM5Y6R.mjs +0 -275
- package/dist/chunk-UYLH35LA.mjs +0 -884
- package/dist/chunk-WVNVC2PP.mjs +0 -852
- package/dist/chunk-XQSEJ7WN.mjs +0 -547
- package/dist/chunk-YRSSR4KN.mjs +0 -850
- package/dist/client-2xbeKnrg.d.mts +0 -1291
- package/dist/client-2xbeKnrg.d.ts +0 -1291
- package/dist/client-4HLAGzFg.d.mts +0 -1291
- package/dist/client-4HLAGzFg.d.ts +0 -1291
- package/dist/client-B4TQwNa7.d.mts +0 -1290
- package/dist/client-B4TQwNa7.d.ts +0 -1290
- package/dist/client-Bdi4ty0v.d.mts +0 -1294
- package/dist/client-Bdi4ty0v.d.ts +0 -1294
- package/dist/client-BsKpUH3H.d.mts +0 -1339
- package/dist/client-BsKpUH3H.d.ts +0 -1339
- package/dist/client-Bv1zOaWF.d.mts +0 -1291
- package/dist/client-Bv1zOaWF.d.ts +0 -1291
- package/dist/client-Bz9YJMIX.d.mts +0 -1290
- package/dist/client-Bz9YJMIX.d.ts +0 -1290
- package/dist/client-CBpzm34X.d.mts +0 -1291
- package/dist/client-CBpzm34X.d.ts +0 -1291
- package/dist/client-CNu_tCZZ.d.mts +0 -1305
- package/dist/client-CNu_tCZZ.d.ts +0 -1305
- package/dist/client-CmEvxxQu.d.mts +0 -1339
- package/dist/client-CmEvxxQu.d.ts +0 -1339
- package/dist/client-Ctl_0z6F.d.mts +0 -1294
- package/dist/client-Ctl_0z6F.d.ts +0 -1294
- package/dist/client-DGMAxkZc.d.mts +0 -1339
- package/dist/client-DGMAxkZc.d.ts +0 -1339
- package/dist/client-DZq-CqcD.d.mts +0 -1292
- package/dist/client-DZq-CqcD.d.ts +0 -1292
- package/dist/client-DcqGfDTt.d.mts +0 -1284
- package/dist/client-DcqGfDTt.d.ts +0 -1284
- package/dist/client-O8RvSRm0.d.mts +0 -1261
- package/dist/client-O8RvSRm0.d.ts +0 -1261
- package/dist/client.d.mts +0 -2
- package/dist/client.d.ts +0 -2
- package/dist/client.js +0 -922
- package/dist/client.mjs +0 -104
- package/dist/csharp-parser-JCKXIAJW.mjs +0 -9
- package/dist/go-parser-J4KIH4RG.mjs +0 -9
- package/dist/index-Ctl_0z6F.d.mts +0 -1294
- package/dist/index-Ctl_0z6F.d.ts +0 -1294
- package/dist/index-DLHCsiAk.d.mts +0 -1294
- package/dist/index-DLHCsiAk.d.ts +0 -1294
- package/dist/java-parser-3KHXOXRQ.mjs +0 -9
- package/dist/python-parser-7QISP7LK.mjs +0 -8
- package/dist/python-parser-PDCO35VN.mjs +0 -8
- package/dist/python-parser-QAAL56MC.mjs +0 -8
- package/dist/python-parser-R7HLPNZK.mjs +0 -8
- package/dist/python-parser-SJ3LFZFJ.mjs +0 -8
- package/dist/python-parser-UFLCDT6L.mjs +0 -8
- package/dist/typescript-parser-4GI7DPSW.mjs +0 -7
- package/dist/typescript-parser-4H3HUBO4.mjs +0 -7
- package/dist/typescript-parser-K63IVZMF.mjs +0 -7
- package/dist/typescript-parser-ZJKROMQG.mjs +0 -7
package/dist/chunk-XQSEJ7WN.mjs
DELETED
|
@@ -1,547 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseLanguageParser
|
|
3
|
-
} from "./chunk-2N7ISIKE.mjs";
|
|
4
|
-
|
|
5
|
-
// src/parsers/metadata-utils.ts
|
|
6
|
-
function analyzeNodeMetadata(node, code, options) {
|
|
7
|
-
const metadata = {
|
|
8
|
-
isPure: true,
|
|
9
|
-
hasSideEffects: false
|
|
10
|
-
};
|
|
11
|
-
try {
|
|
12
|
-
let prev = node.previousSibling || null;
|
|
13
|
-
while (prev && /comment/i.test(prev.type)) {
|
|
14
|
-
const text = prev.text || "";
|
|
15
|
-
const loc = {
|
|
16
|
-
start: {
|
|
17
|
-
line: prev.startPosition.row + 1,
|
|
18
|
-
column: prev.startPosition.column
|
|
19
|
-
},
|
|
20
|
-
end: {
|
|
21
|
-
line: prev.endPosition.row + 1,
|
|
22
|
-
column: prev.endPosition.column
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
if (text.trim().startsWith("/**") || text.trim().startsWith("/*")) {
|
|
26
|
-
metadata.documentation = {
|
|
27
|
-
content: text.replace(/^[/*]+|[/*]+$/g, "").trim(),
|
|
28
|
-
type: "comment",
|
|
29
|
-
loc
|
|
30
|
-
};
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
if (text.trim().startsWith("///")) {
|
|
34
|
-
metadata.documentation = {
|
|
35
|
-
content: text.replace(/^\/\/\//, "").trim(),
|
|
36
|
-
type: "xml-doc",
|
|
37
|
-
loc
|
|
38
|
-
};
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
if (text.trim().startsWith("//")) {
|
|
42
|
-
metadata.documentation = {
|
|
43
|
-
content: text.replace(/^\/\//, "").trim(),
|
|
44
|
-
type: "comment",
|
|
45
|
-
loc
|
|
46
|
-
};
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
prev = prev.previousSibling;
|
|
50
|
-
}
|
|
51
|
-
if (node.type === "function_definition" || node.type === "class_definition") {
|
|
52
|
-
const body2 = node.childForFieldName ? node.childForFieldName("body") : node.children.find((c) => c.type === "block");
|
|
53
|
-
if (body2 && body2.children.length > 0) {
|
|
54
|
-
const firstStmt = body2.children[0];
|
|
55
|
-
if (firstStmt.type === "expression_statement" && firstStmt.firstChild?.type === "string") {
|
|
56
|
-
metadata.documentation = {
|
|
57
|
-
content: firstStmt.firstChild.text.replace(/['"`]/g, "").trim(),
|
|
58
|
-
type: "docstring",
|
|
59
|
-
loc: {
|
|
60
|
-
start: {
|
|
61
|
-
line: firstStmt.startPosition.row + 1,
|
|
62
|
-
column: firstStmt.startPosition.column
|
|
63
|
-
},
|
|
64
|
-
end: {
|
|
65
|
-
line: firstStmt.endPosition.row + 1,
|
|
66
|
-
column: firstStmt.endPosition.column
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} catch {
|
|
74
|
-
}
|
|
75
|
-
const defaultSignatures = [
|
|
76
|
-
"console.",
|
|
77
|
-
"fmt.",
|
|
78
|
-
"panic(",
|
|
79
|
-
"os.Exit",
|
|
80
|
-
"log.",
|
|
81
|
-
"Console.Write",
|
|
82
|
-
"File.Write",
|
|
83
|
-
"System.out",
|
|
84
|
-
"System.err",
|
|
85
|
-
"Files.write",
|
|
86
|
-
"process.exit",
|
|
87
|
-
"exit("
|
|
88
|
-
];
|
|
89
|
-
const signatures = Array.from(
|
|
90
|
-
/* @__PURE__ */ new Set([...options?.sideEffectSignatures || [], ...defaultSignatures])
|
|
91
|
-
);
|
|
92
|
-
const walk = (n) => {
|
|
93
|
-
try {
|
|
94
|
-
const t = n.type || "";
|
|
95
|
-
if (/assign|assignment|assignment_statement|assignment_expression|throw|throw_statement|send_statement|global_statement|nonlocal_statement/i.test(
|
|
96
|
-
t
|
|
97
|
-
)) {
|
|
98
|
-
metadata.isPure = false;
|
|
99
|
-
metadata.hasSideEffects = true;
|
|
100
|
-
}
|
|
101
|
-
const text = n.text || "";
|
|
102
|
-
for (const s of signatures) {
|
|
103
|
-
if (text.includes(s)) {
|
|
104
|
-
metadata.isPure = false;
|
|
105
|
-
metadata.hasSideEffects = true;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
for (let i = 0; i < n.childCount; i++) {
|
|
110
|
-
const c = n.child(i);
|
|
111
|
-
if (c) walk(c);
|
|
112
|
-
}
|
|
113
|
-
} catch {
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const body = node.childForFieldName?.("body") || node.children.find(
|
|
117
|
-
(c) => /body|block|class_body|declaration_list|function_body/.test(c.type)
|
|
118
|
-
);
|
|
119
|
-
if (body) walk(body);
|
|
120
|
-
return metadata;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/parsers/python-parser.ts
|
|
124
|
-
var PYTHON_CONSTANTS = {
|
|
125
|
-
NODES: {
|
|
126
|
-
IMPORT_STATEMENT: "import_statement",
|
|
127
|
-
IMPORT_FROM_STATEMENT: "import_from_statement",
|
|
128
|
-
DOTTED_NAME: "dotted_name",
|
|
129
|
-
ALIASED_IMPORT: "aliased_import",
|
|
130
|
-
WILDCARD_IMPORT: "wildcard_import",
|
|
131
|
-
FUNCTION_DEFINITION: "function_definition",
|
|
132
|
-
CLASS_DEFINITION: "class_definition",
|
|
133
|
-
EXPRESSION_STATEMENT: "expression_statement",
|
|
134
|
-
ASSIGNMENT: "assignment",
|
|
135
|
-
IDENTIFIER: "identifier",
|
|
136
|
-
TYPED_PARAMETER: "typed_parameter",
|
|
137
|
-
DEFAULT_PARAMETER: "default_parameter"
|
|
138
|
-
},
|
|
139
|
-
FIELDS: {
|
|
140
|
-
NAME: "name",
|
|
141
|
-
MODULE_NAME: "module_name",
|
|
142
|
-
LEFT: "left",
|
|
143
|
-
PARAMETERS: "parameters"
|
|
144
|
-
},
|
|
145
|
-
SPECIAL: {
|
|
146
|
-
WILDCARD: "*",
|
|
147
|
-
DUNDER_ALL: "__all__",
|
|
148
|
-
DUNDER_VERSION: "__version__",
|
|
149
|
-
DUNDER_AUTHOR: "__author__",
|
|
150
|
-
DUNDER_INIT: "__init__",
|
|
151
|
-
DUNDER_STR: "__str__",
|
|
152
|
-
DUNDER_REPR: "__repr__",
|
|
153
|
-
DUNDER_NAME: "__name__",
|
|
154
|
-
DUNDER_MAIN: "__main__",
|
|
155
|
-
DUNDER_FILE: "__file__",
|
|
156
|
-
DUNDER_DOC: "__doc__",
|
|
157
|
-
DUNDER_DICT: "__dict__",
|
|
158
|
-
DUNDER_CLASS: "__class__",
|
|
159
|
-
DUNDER_MODULE: "__module__",
|
|
160
|
-
DUNDER_BASES: "__bases__",
|
|
161
|
-
MAIN_VAL: "__main__"
|
|
162
|
-
},
|
|
163
|
-
BUILTINS: {
|
|
164
|
-
PRINT: "print(",
|
|
165
|
-
INPUT: "input(",
|
|
166
|
-
OPEN: "open("
|
|
167
|
-
},
|
|
168
|
-
TYPES: {
|
|
169
|
-
FUNCTION: "function",
|
|
170
|
-
CLASS: "class",
|
|
171
|
-
VARIABLE: "variable",
|
|
172
|
-
CONST: "const",
|
|
173
|
-
DOCSTRING: "docstring"
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
var PythonParser = class extends BaseLanguageParser {
|
|
177
|
-
constructor() {
|
|
178
|
-
super(...arguments);
|
|
179
|
-
this.language = "python" /* Python */;
|
|
180
|
-
this.extensions = [".py"];
|
|
181
|
-
}
|
|
182
|
-
getParserName() {
|
|
183
|
-
return "python";
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Analyze metadata for a Python node (purity, side effects).
|
|
187
|
-
*/
|
|
188
|
-
analyzeMetadata(node, code) {
|
|
189
|
-
return analyzeNodeMetadata(node, code, {
|
|
190
|
-
sideEffectSignatures: [
|
|
191
|
-
PYTHON_CONSTANTS.BUILTINS.PRINT,
|
|
192
|
-
PYTHON_CONSTANTS.BUILTINS.INPUT,
|
|
193
|
-
PYTHON_CONSTANTS.BUILTINS.OPEN
|
|
194
|
-
]
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Extract import information using AST walk.
|
|
199
|
-
*/
|
|
200
|
-
extractImportsAST(rootNode) {
|
|
201
|
-
const imports = [];
|
|
202
|
-
const processImportNode = (node) => {
|
|
203
|
-
if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_STATEMENT) {
|
|
204
|
-
for (const child of node.children) {
|
|
205
|
-
if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME) {
|
|
206
|
-
const source = child.text;
|
|
207
|
-
imports.push({
|
|
208
|
-
source,
|
|
209
|
-
specifiers: [source],
|
|
210
|
-
loc: {
|
|
211
|
-
start: {
|
|
212
|
-
line: child.startPosition.row + 1,
|
|
213
|
-
column: child.startPosition.column
|
|
214
|
-
},
|
|
215
|
-
end: {
|
|
216
|
-
line: child.endPosition.row + 1,
|
|
217
|
-
column: child.endPosition.column
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
} else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
|
|
222
|
-
const nameNode = child.childForFieldName(
|
|
223
|
-
PYTHON_CONSTANTS.FIELDS.NAME
|
|
224
|
-
);
|
|
225
|
-
if (nameNode) {
|
|
226
|
-
const source = nameNode.text;
|
|
227
|
-
imports.push({
|
|
228
|
-
source,
|
|
229
|
-
specifiers: [source],
|
|
230
|
-
loc: {
|
|
231
|
-
start: {
|
|
232
|
-
line: child.startPosition.row + 1,
|
|
233
|
-
column: child.startPosition.column
|
|
234
|
-
},
|
|
235
|
-
end: {
|
|
236
|
-
line: child.endPosition.row + 1,
|
|
237
|
-
column: child.endPosition.column
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
} else if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_FROM_STATEMENT) {
|
|
245
|
-
const moduleNameNode = node.childForFieldName(
|
|
246
|
-
PYTHON_CONSTANTS.FIELDS.MODULE_NAME
|
|
247
|
-
);
|
|
248
|
-
if (moduleNameNode) {
|
|
249
|
-
const source = moduleNameNode.text;
|
|
250
|
-
const specifiers = [];
|
|
251
|
-
for (const child of node.children) {
|
|
252
|
-
if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME && child !== moduleNameNode) {
|
|
253
|
-
specifiers.push(child.text);
|
|
254
|
-
} else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
|
|
255
|
-
const nameNode = child.childForFieldName(
|
|
256
|
-
PYTHON_CONSTANTS.FIELDS.NAME
|
|
257
|
-
);
|
|
258
|
-
if (nameNode) specifiers.push(nameNode.text);
|
|
259
|
-
} else if (child.type === PYTHON_CONSTANTS.NODES.WILDCARD_IMPORT) {
|
|
260
|
-
specifiers.push(PYTHON_CONSTANTS.SPECIAL.WILDCARD);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (specifiers.length > 0) {
|
|
264
|
-
imports.push({
|
|
265
|
-
source,
|
|
266
|
-
specifiers,
|
|
267
|
-
loc: {
|
|
268
|
-
start: {
|
|
269
|
-
line: node.startPosition.row + 1,
|
|
270
|
-
column: node.startPosition.column
|
|
271
|
-
},
|
|
272
|
-
end: {
|
|
273
|
-
line: node.endPosition.row + 1,
|
|
274
|
-
column: node.endPosition.column
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
for (const node of rootNode.children) {
|
|
283
|
-
processImportNode(node);
|
|
284
|
-
}
|
|
285
|
-
return imports;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Extract export information using AST walk.
|
|
289
|
-
*/
|
|
290
|
-
extractExportsAST(rootNode, code) {
|
|
291
|
-
const exports = [];
|
|
292
|
-
for (const node of rootNode.children) {
|
|
293
|
-
if (node.type === PYTHON_CONSTANTS.NODES.FUNCTION_DEFINITION) {
|
|
294
|
-
const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
295
|
-
if (nameNode) {
|
|
296
|
-
const name = nameNode.text;
|
|
297
|
-
const isPrivate = name.startsWith("_") && !name.startsWith("__");
|
|
298
|
-
if (!isPrivate) {
|
|
299
|
-
const metadata = this.analyzeMetadata(node, code);
|
|
300
|
-
exports.push({
|
|
301
|
-
name,
|
|
302
|
-
type: PYTHON_CONSTANTS.TYPES.FUNCTION,
|
|
303
|
-
loc: {
|
|
304
|
-
start: {
|
|
305
|
-
line: node.startPosition.row + 1,
|
|
306
|
-
column: node.startPosition.column
|
|
307
|
-
},
|
|
308
|
-
end: {
|
|
309
|
-
line: node.endPosition.row + 1,
|
|
310
|
-
column: node.endPosition.column
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
parameters: this.extractParameters(node),
|
|
314
|
-
...metadata
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
} else if (node.type === PYTHON_CONSTANTS.NODES.CLASS_DEFINITION) {
|
|
319
|
-
const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
320
|
-
if (nameNode) {
|
|
321
|
-
const metadata = this.analyzeMetadata(node, code);
|
|
322
|
-
exports.push({
|
|
323
|
-
name: nameNode.text,
|
|
324
|
-
type: PYTHON_CONSTANTS.TYPES.CLASS,
|
|
325
|
-
loc: {
|
|
326
|
-
start: {
|
|
327
|
-
line: node.startPosition.row + 1,
|
|
328
|
-
column: node.startPosition.column
|
|
329
|
-
},
|
|
330
|
-
end: {
|
|
331
|
-
line: node.endPosition.row + 1,
|
|
332
|
-
column: node.endPosition.column
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
...metadata
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
} else if (node.type === PYTHON_CONSTANTS.NODES.EXPRESSION_STATEMENT) {
|
|
339
|
-
const assignment = node.firstChild;
|
|
340
|
-
if (assignment && assignment.type === PYTHON_CONSTANTS.NODES.ASSIGNMENT) {
|
|
341
|
-
const left = assignment.childForFieldName(
|
|
342
|
-
PYTHON_CONSTANTS.FIELDS.LEFT
|
|
343
|
-
);
|
|
344
|
-
if (left && left.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) {
|
|
345
|
-
const name = left.text;
|
|
346
|
-
const isInternal = name === PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR;
|
|
347
|
-
const isPrivate = name.startsWith("_") && !name.startsWith("__");
|
|
348
|
-
if (!isInternal && !isPrivate) {
|
|
349
|
-
exports.push({
|
|
350
|
-
name,
|
|
351
|
-
type: name === name.toUpperCase() ? PYTHON_CONSTANTS.TYPES.CONST : PYTHON_CONSTANTS.TYPES.VARIABLE,
|
|
352
|
-
loc: {
|
|
353
|
-
start: {
|
|
354
|
-
line: node.startPosition.row + 1,
|
|
355
|
-
column: node.startPosition.column
|
|
356
|
-
},
|
|
357
|
-
end: {
|
|
358
|
-
line: node.endPosition.row + 1,
|
|
359
|
-
column: node.endPosition.column
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return exports;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Extract parameter names from a function definition node.
|
|
372
|
-
*/
|
|
373
|
-
extractParameters(node) {
|
|
374
|
-
const paramsNode = node.childForFieldName(
|
|
375
|
-
PYTHON_CONSTANTS.FIELDS.PARAMETERS
|
|
376
|
-
);
|
|
377
|
-
if (!paramsNode) return [];
|
|
378
|
-
return paramsNode.children.filter(
|
|
379
|
-
(c) => c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER || c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER
|
|
380
|
-
).map((c) => {
|
|
381
|
-
if (c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) return c.text;
|
|
382
|
-
if (c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER) {
|
|
383
|
-
return c.firstChild?.text || "unknown";
|
|
384
|
-
}
|
|
385
|
-
return "unknown";
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Fallback regex-based parsing when tree-sitter is unavailable.
|
|
390
|
-
*/
|
|
391
|
-
parseRegex(code, filePath) {
|
|
392
|
-
try {
|
|
393
|
-
const imports = this.extractImportsRegex(code, filePath);
|
|
394
|
-
const exports = this.extractExportsRegex(code, filePath);
|
|
395
|
-
return {
|
|
396
|
-
exports,
|
|
397
|
-
imports,
|
|
398
|
-
language: "python" /* Python */,
|
|
399
|
-
warnings: [
|
|
400
|
-
"Python parsing is currently using regex-based extraction as tree-sitter wasm was not available."
|
|
401
|
-
]
|
|
402
|
-
};
|
|
403
|
-
} catch (error) {
|
|
404
|
-
throw new Error(
|
|
405
|
-
`Failed to parse Python file ${filePath}: ${error.message}`
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
getNamingConventions() {
|
|
410
|
-
return {
|
|
411
|
-
variablePattern: /^[a-z_][a-z0-9_]*$/,
|
|
412
|
-
functionPattern: /^[a-z_][a-z0-9_]*$/,
|
|
413
|
-
classPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
414
|
-
constantPattern: /^[A-Z][A-Z0-9_]*$/,
|
|
415
|
-
exceptions: [
|
|
416
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_INIT,
|
|
417
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_STR,
|
|
418
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_REPR,
|
|
419
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_NAME,
|
|
420
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_MAIN,
|
|
421
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_FILE,
|
|
422
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_DOC,
|
|
423
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL,
|
|
424
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION,
|
|
425
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR,
|
|
426
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_DICT,
|
|
427
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_CLASS,
|
|
428
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_MODULE,
|
|
429
|
-
PYTHON_CONSTANTS.SPECIAL.DUNDER_BASES
|
|
430
|
-
]
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
canHandle(filePath) {
|
|
434
|
-
return filePath.toLowerCase().endsWith(".py");
|
|
435
|
-
}
|
|
436
|
-
extractImportsRegex(code, _filePath) {
|
|
437
|
-
void _filePath;
|
|
438
|
-
const imports = [];
|
|
439
|
-
const lines = code.split("\n");
|
|
440
|
-
const importRegex = /^\s*import\s+([a-zA-Z0-9_., ]+)/;
|
|
441
|
-
const fromImportRegex = /^\s*from\s+([a-zA-Z0-9_.]+)\s+import\s+(.+)/;
|
|
442
|
-
lines.forEach((line, idx) => {
|
|
443
|
-
if (line.trim().startsWith("#")) return;
|
|
444
|
-
const importMatch = line.match(importRegex);
|
|
445
|
-
if (importMatch) {
|
|
446
|
-
const modules = importMatch[1].split(",").map((m) => m.trim().split(" as ")[0]);
|
|
447
|
-
modules.forEach((module) => {
|
|
448
|
-
imports.push({
|
|
449
|
-
source: module,
|
|
450
|
-
specifiers: [module],
|
|
451
|
-
loc: {
|
|
452
|
-
start: { line: idx + 1, column: 0 },
|
|
453
|
-
end: { line: idx + 1, column: line.length }
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
});
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
const fromMatch = line.match(fromImportRegex);
|
|
460
|
-
if (fromMatch) {
|
|
461
|
-
const module = fromMatch[1];
|
|
462
|
-
const importsStr = fromMatch[2];
|
|
463
|
-
if (importsStr.trim() === PYTHON_CONSTANTS.SPECIAL.WILDCARD) {
|
|
464
|
-
imports.push({
|
|
465
|
-
source: module,
|
|
466
|
-
specifiers: [PYTHON_CONSTANTS.SPECIAL.WILDCARD],
|
|
467
|
-
loc: {
|
|
468
|
-
start: { line: idx + 1, column: 0 },
|
|
469
|
-
end: { line: idx + 1, column: line.length }
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
const specifiers = importsStr.split(",").map((s) => s.trim().split(" as ")[0]);
|
|
475
|
-
imports.push({
|
|
476
|
-
source: module,
|
|
477
|
-
specifiers,
|
|
478
|
-
loc: {
|
|
479
|
-
start: { line: idx + 1, column: 0 },
|
|
480
|
-
end: { line: idx + 1, column: line.length }
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
return imports;
|
|
486
|
-
}
|
|
487
|
-
extractExportsRegex(code, _filePath) {
|
|
488
|
-
void _filePath;
|
|
489
|
-
const exports = [];
|
|
490
|
-
const lines = code.split("\n");
|
|
491
|
-
const funcRegex = /^def\s+([a-zA-Z0-9_]+)\s*\(/;
|
|
492
|
-
const classRegex = /^class\s+([a-zA-Z0-9_]+)/;
|
|
493
|
-
lines.forEach((line, idx) => {
|
|
494
|
-
const indent = line.search(/\S/);
|
|
495
|
-
if (indent !== 0) return;
|
|
496
|
-
const classMatch = line.match(classRegex);
|
|
497
|
-
if (classMatch) {
|
|
498
|
-
exports.push({
|
|
499
|
-
name: classMatch[1],
|
|
500
|
-
type: PYTHON_CONSTANTS.TYPES.CLASS,
|
|
501
|
-
visibility: "public",
|
|
502
|
-
isPure: true,
|
|
503
|
-
hasSideEffects: false,
|
|
504
|
-
loc: {
|
|
505
|
-
start: { line: idx + 1, column: 0 },
|
|
506
|
-
end: { line: idx + 1, column: line.length }
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const funcMatch = line.match(funcRegex);
|
|
512
|
-
if (funcMatch) {
|
|
513
|
-
const name = funcMatch[1];
|
|
514
|
-
if (name.startsWith("_") && !name.startsWith("__")) return;
|
|
515
|
-
let docContent;
|
|
516
|
-
const nextLines = lines.slice(idx + 1, idx + 4);
|
|
517
|
-
for (const nextLine of nextLines) {
|
|
518
|
-
const docMatch = nextLine.match(/^\s*"""([\s\S]*?)"""/) || nextLine.match(/^\s*'''([\s\S]*?)'''/);
|
|
519
|
-
if (docMatch) {
|
|
520
|
-
docContent = docMatch[1].trim();
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
if (nextLine.trim() && !nextLine.trim().startsWith('"""') && !nextLine.trim().startsWith("'''"))
|
|
524
|
-
break;
|
|
525
|
-
}
|
|
526
|
-
const isImpure = name.toLowerCase().includes("impure") || line.includes(PYTHON_CONSTANTS.BUILTINS.PRINT) || idx + 1 < lines.length && lines[idx + 1].includes(PYTHON_CONSTANTS.BUILTINS.PRINT);
|
|
527
|
-
exports.push({
|
|
528
|
-
name,
|
|
529
|
-
type: PYTHON_CONSTANTS.TYPES.FUNCTION,
|
|
530
|
-
visibility: "public",
|
|
531
|
-
isPure: !isImpure,
|
|
532
|
-
hasSideEffects: isImpure,
|
|
533
|
-
documentation: docContent ? { content: docContent, type: PYTHON_CONSTANTS.TYPES.DOCSTRING } : void 0,
|
|
534
|
-
loc: {
|
|
535
|
-
start: { line: idx + 1, column: 0 },
|
|
536
|
-
end: { line: idx + 1, column: line.length }
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
return exports;
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
export {
|
|
546
|
-
PythonParser
|
|
547
|
-
};
|