driftdetect-core 0.6.1 → 0.7.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.
- package/LICENSE +21 -0
- package/dist/constants/analysis/categorizer.d.ts +27 -0
- package/dist/constants/analysis/categorizer.d.ts.map +1 -0
- package/dist/constants/analysis/categorizer.js +364 -0
- package/dist/constants/analysis/categorizer.js.map +1 -0
- package/dist/constants/analysis/consistency-analyzer.d.ts +77 -0
- package/dist/constants/analysis/consistency-analyzer.d.ts.map +1 -0
- package/dist/constants/analysis/consistency-analyzer.js +176 -0
- package/dist/constants/analysis/consistency-analyzer.js.map +1 -0
- package/dist/constants/analysis/dead-constant-detector.d.ts +79 -0
- package/dist/constants/analysis/dead-constant-detector.d.ts.map +1 -0
- package/dist/constants/analysis/dead-constant-detector.js +242 -0
- package/dist/constants/analysis/dead-constant-detector.js.map +1 -0
- package/dist/constants/analysis/magic-detector.d.ts +116 -0
- package/dist/constants/analysis/magic-detector.d.ts.map +1 -0
- package/dist/constants/analysis/magic-detector.js +425 -0
- package/dist/constants/analysis/magic-detector.js.map +1 -0
- package/dist/constants/analysis/reference-finder.d.ts +87 -0
- package/dist/constants/analysis/reference-finder.d.ts.map +1 -0
- package/dist/constants/analysis/reference-finder.js +269 -0
- package/dist/constants/analysis/reference-finder.js.map +1 -0
- package/dist/constants/analysis/security-scanner.d.ts +115 -0
- package/dist/constants/analysis/security-scanner.d.ts.map +1 -0
- package/dist/constants/analysis/security-scanner.js +429 -0
- package/dist/constants/analysis/security-scanner.js.map +1 -0
- package/dist/constants/extractors/base-extractor.d.ts +97 -0
- package/dist/constants/extractors/base-extractor.d.ts.map +1 -0
- package/dist/constants/extractors/base-extractor.js +285 -0
- package/dist/constants/extractors/base-extractor.js.map +1 -0
- package/dist/constants/extractors/regex/base-regex.d.ts +67 -0
- package/dist/constants/extractors/regex/base-regex.d.ts.map +1 -0
- package/dist/constants/extractors/regex/base-regex.js +209 -0
- package/dist/constants/extractors/regex/base-regex.js.map +1 -0
- package/dist/constants/extractors/regex/csharp-regex.d.ts +39 -0
- package/dist/constants/extractors/regex/csharp-regex.d.ts.map +1 -0
- package/dist/constants/extractors/regex/csharp-regex.js +316 -0
- package/dist/constants/extractors/regex/csharp-regex.js.map +1 -0
- package/dist/constants/extractors/regex/go-regex.d.ts +40 -0
- package/dist/constants/extractors/regex/go-regex.d.ts.map +1 -0
- package/dist/constants/extractors/regex/go-regex.js +297 -0
- package/dist/constants/extractors/regex/go-regex.js.map +1 -0
- package/dist/constants/extractors/regex/java-regex.d.ts +43 -0
- package/dist/constants/extractors/regex/java-regex.d.ts.map +1 -0
- package/dist/constants/extractors/regex/java-regex.js +276 -0
- package/dist/constants/extractors/regex/java-regex.js.map +1 -0
- package/dist/constants/extractors/regex/php-regex.d.ts +39 -0
- package/dist/constants/extractors/regex/php-regex.d.ts.map +1 -0
- package/dist/constants/extractors/regex/php-regex.js +270 -0
- package/dist/constants/extractors/regex/php-regex.js.map +1 -0
- package/dist/constants/extractors/regex/python-regex.d.ts +39 -0
- package/dist/constants/extractors/regex/python-regex.d.ts.map +1 -0
- package/dist/constants/extractors/regex/python-regex.js +287 -0
- package/dist/constants/extractors/regex/python-regex.js.map +1 -0
- package/dist/constants/extractors/regex/typescript-regex.d.ts +35 -0
- package/dist/constants/extractors/regex/typescript-regex.d.ts.map +1 -0
- package/dist/constants/extractors/regex/typescript-regex.js +313 -0
- package/dist/constants/extractors/regex/typescript-regex.js.map +1 -0
- package/dist/constants/index.d.ts +26 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +36 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/integration/callgraph-adapter.d.ts +167 -0
- package/dist/constants/integration/callgraph-adapter.d.ts.map +1 -0
- package/dist/constants/integration/callgraph-adapter.js +287 -0
- package/dist/constants/integration/callgraph-adapter.js.map +1 -0
- package/dist/constants/integration/index.d.ts +10 -0
- package/dist/constants/integration/index.d.ts.map +1 -0
- package/dist/constants/integration/index.js +13 -0
- package/dist/constants/integration/index.js.map +1 -0
- package/dist/constants/integration/pattern-adapter.d.ts +171 -0
- package/dist/constants/integration/pattern-adapter.d.ts.map +1 -0
- package/dist/constants/integration/pattern-adapter.js +331 -0
- package/dist/constants/integration/pattern-adapter.js.map +1 -0
- package/dist/constants/integration/scanner-adapter.d.ts +153 -0
- package/dist/constants/integration/scanner-adapter.d.ts.map +1 -0
- package/dist/constants/integration/scanner-adapter.js +337 -0
- package/dist/constants/integration/scanner-adapter.js.map +1 -0
- package/dist/constants/store/constant-store.d.ts +117 -0
- package/dist/constants/store/constant-store.d.ts.map +1 -0
- package/dist/constants/store/constant-store.js +367 -0
- package/dist/constants/store/constant-store.js.map +1 -0
- package/dist/constants/types.d.ts +423 -0
- package/dist/constants/types.d.ts.map +1 -0
- package/dist/constants/types.js +43 -0
- package/dist/constants/types.js.map +1 -0
- package/dist/constraints/store/constraint-store.d.ts.map +1 -1
- package/dist/constraints/store/constraint-store.js +37 -2
- package/dist/constraints/store/constraint-store.js.map +1 -1
- package/dist/environment/env-scanner.d.ts +53 -0
- package/dist/environment/env-scanner.d.ts.map +1 -0
- package/dist/environment/env-scanner.js +290 -0
- package/dist/environment/env-scanner.js.map +1 -0
- package/dist/environment/env-store.d.ts +70 -0
- package/dist/environment/env-store.d.ts.map +1 -0
- package/dist/environment/env-store.js +201 -0
- package/dist/environment/env-store.js.map +1 -0
- package/dist/environment/extractors/base-env-extractor.d.ts +56 -0
- package/dist/environment/extractors/base-env-extractor.d.ts.map +1 -0
- package/dist/environment/extractors/base-env-extractor.js +74 -0
- package/dist/environment/extractors/base-env-extractor.js.map +1 -0
- package/dist/environment/extractors/csharp-env-extractor.d.ts +49 -0
- package/dist/environment/extractors/csharp-env-extractor.d.ts.map +1 -0
- package/dist/environment/extractors/csharp-env-extractor.js +240 -0
- package/dist/environment/extractors/csharp-env-extractor.js.map +1 -0
- package/dist/environment/extractors/go-env-extractor.d.ts +53 -0
- package/dist/environment/extractors/go-env-extractor.d.ts.map +1 -0
- package/dist/environment/extractors/go-env-extractor.js +267 -0
- package/dist/environment/extractors/go-env-extractor.js.map +1 -0
- package/dist/environment/extractors/index.d.ts +13 -0
- package/dist/environment/extractors/index.d.ts.map +1 -0
- package/dist/environment/extractors/index.js +13 -0
- package/dist/environment/extractors/index.js.map +1 -0
- package/dist/environment/extractors/java-env-extractor.d.ts +58 -0
- package/dist/environment/extractors/java-env-extractor.d.ts.map +1 -0
- package/dist/environment/extractors/java-env-extractor.js +219 -0
- package/dist/environment/extractors/java-env-extractor.js.map +1 -0
- package/dist/environment/extractors/php-env-extractor.d.ts +58 -0
- package/dist/environment/extractors/php-env-extractor.d.ts.map +1 -0
- package/dist/environment/extractors/php-env-extractor.js +231 -0
- package/dist/environment/extractors/php-env-extractor.js.map +1 -0
- package/dist/environment/extractors/python-env-extractor.d.ts +50 -0
- package/dist/environment/extractors/python-env-extractor.d.ts.map +1 -0
- package/dist/environment/extractors/python-env-extractor.js +219 -0
- package/dist/environment/extractors/python-env-extractor.js.map +1 -0
- package/dist/environment/extractors/typescript-env-extractor.d.ts +54 -0
- package/dist/environment/extractors/typescript-env-extractor.d.ts.map +1 -0
- package/dist/environment/extractors/typescript-env-extractor.js +228 -0
- package/dist/environment/extractors/typescript-env-extractor.js.map +1 -0
- package/dist/environment/index.d.ts +11 -0
- package/dist/environment/index.d.ts.map +1 -0
- package/dist/environment/index.js +15 -0
- package/dist/environment/index.js.map +1 -0
- package/dist/environment/types.d.ts +145 -0
- package/dist/environment/types.d.ts.map +1 -0
- package/dist/environment/types.js +84 -0
- package/dist/environment/types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C# Constant Regex Extractor
|
|
3
|
+
*
|
|
4
|
+
* Regex-based extraction for C# constants and enums.
|
|
5
|
+
* Used as fallback when tree-sitter is unavailable.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseConstantRegexExtractor } from './base-regex.js';
|
|
8
|
+
/**
|
|
9
|
+
* C# constant regex extractor
|
|
10
|
+
*/
|
|
11
|
+
export class CSharpConstantRegexExtractor extends BaseConstantRegexExtractor {
|
|
12
|
+
language = 'csharp';
|
|
13
|
+
/**
|
|
14
|
+
* Extract constants from C# source
|
|
15
|
+
*/
|
|
16
|
+
extractConstants(source, filePath) {
|
|
17
|
+
const constants = [];
|
|
18
|
+
let match;
|
|
19
|
+
// Pattern 1: const fields
|
|
20
|
+
// public const int MaxRetries = 3;
|
|
21
|
+
// private const string ApiUrl = "https://api.example.com";
|
|
22
|
+
const constPattern = /(public|private|protected|internal)?\s*(const)\s+(\w+(?:<[^>]+>)?)\s+(\w+)\s*=\s*([^;]+);/g;
|
|
23
|
+
while ((match = constPattern.exec(source)) !== null) {
|
|
24
|
+
const visibility = match[1] ?? 'private';
|
|
25
|
+
const type = match[3];
|
|
26
|
+
const name = match[4];
|
|
27
|
+
if (!name || !type)
|
|
28
|
+
continue;
|
|
29
|
+
const rawValue = match[5]?.trim();
|
|
30
|
+
if (!rawValue)
|
|
31
|
+
continue;
|
|
32
|
+
// Skip if name doesn't look like a constant (PascalCase or UPPER_CASE)
|
|
33
|
+
if (!/^[A-Z]/.test(name))
|
|
34
|
+
continue;
|
|
35
|
+
const line = this.getLineNumber(source, match.index);
|
|
36
|
+
const column = this.getColumnNumber(source, match.index);
|
|
37
|
+
const className = this.findContainingClass(source, match.index);
|
|
38
|
+
const docComment = this.extractDocComment(source, line);
|
|
39
|
+
const kind = this.inferCSharpKind(rawValue, type);
|
|
40
|
+
const value = this.extractCSharpValue(rawValue, kind);
|
|
41
|
+
constants.push({
|
|
42
|
+
id: this.generateId(filePath, className ? `${className}.${name}` : name, line),
|
|
43
|
+
name,
|
|
44
|
+
qualifiedName: className ? `${className}.${name}` : name,
|
|
45
|
+
file: filePath,
|
|
46
|
+
line,
|
|
47
|
+
column,
|
|
48
|
+
endLine: line,
|
|
49
|
+
language: this.language,
|
|
50
|
+
kind: 'class_constant',
|
|
51
|
+
category: 'uncategorized',
|
|
52
|
+
value,
|
|
53
|
+
rawValue: this.truncateValue(rawValue),
|
|
54
|
+
type,
|
|
55
|
+
isExported: visibility === 'public',
|
|
56
|
+
...(className ? { parentName: className } : {}),
|
|
57
|
+
parentType: 'class',
|
|
58
|
+
decorators: [],
|
|
59
|
+
modifiers: ['const'],
|
|
60
|
+
confidence: 0.75,
|
|
61
|
+
...(docComment ? { docComment } : {}),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Pattern 2: static readonly fields
|
|
65
|
+
// public static readonly TimeSpan Timeout = TimeSpan.FromSeconds(30);
|
|
66
|
+
const staticReadonlyPattern = /(public|private|protected|internal)?\s*(static)\s+(readonly)\s+(\w+(?:<[^>]+>)?)\s+(\w+)\s*=\s*([^;]+);/g;
|
|
67
|
+
while ((match = staticReadonlyPattern.exec(source)) !== null) {
|
|
68
|
+
const visibility = match[1] ?? 'private';
|
|
69
|
+
const type = match[4];
|
|
70
|
+
const name = match[5];
|
|
71
|
+
if (!name || !type)
|
|
72
|
+
continue;
|
|
73
|
+
const rawValue = match[6]?.trim();
|
|
74
|
+
if (!rawValue)
|
|
75
|
+
continue;
|
|
76
|
+
// Skip if name doesn't look like a constant
|
|
77
|
+
if (!/^[A-Z]/.test(name))
|
|
78
|
+
continue;
|
|
79
|
+
const line = this.getLineNumber(source, match.index);
|
|
80
|
+
const column = this.getColumnNumber(source, match.index);
|
|
81
|
+
const className = this.findContainingClass(source, match.index);
|
|
82
|
+
const docComment = this.extractDocComment(source, line);
|
|
83
|
+
// Skip if already captured as const
|
|
84
|
+
if (constants.some(c => c.name === name && c.line === line)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const kind = this.inferCSharpKind(rawValue, type);
|
|
88
|
+
const value = this.extractCSharpValue(rawValue, kind);
|
|
89
|
+
constants.push({
|
|
90
|
+
id: this.generateId(filePath, className ? `${className}.${name}` : name, line),
|
|
91
|
+
name,
|
|
92
|
+
qualifiedName: className ? `${className}.${name}` : name,
|
|
93
|
+
file: filePath,
|
|
94
|
+
line,
|
|
95
|
+
column,
|
|
96
|
+
endLine: line,
|
|
97
|
+
language: this.language,
|
|
98
|
+
kind: kind === 'primitive' ? 'class_constant' : kind,
|
|
99
|
+
category: 'uncategorized',
|
|
100
|
+
value,
|
|
101
|
+
rawValue: this.truncateValue(rawValue),
|
|
102
|
+
type,
|
|
103
|
+
isExported: visibility === 'public',
|
|
104
|
+
...(className ? { parentName: className } : {}),
|
|
105
|
+
parentType: 'class',
|
|
106
|
+
decorators: [],
|
|
107
|
+
modifiers: ['static', 'readonly'],
|
|
108
|
+
confidence: 0.7,
|
|
109
|
+
...(docComment ? { docComment } : {}),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return constants;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extract enums from C# source
|
|
116
|
+
*/
|
|
117
|
+
extractEnums(source, filePath) {
|
|
118
|
+
const enums = [];
|
|
119
|
+
// Pattern: [Flags]? public enum EnumName : type? { ... }
|
|
120
|
+
const enumPattern = /(\[Flags\]\s*)?(public|private|protected|internal)?\s*enum\s+(\w+)\s*(?::\s*(\w+))?\s*\{([^}]*)\}/gs;
|
|
121
|
+
let match;
|
|
122
|
+
while ((match = enumPattern.exec(source)) !== null) {
|
|
123
|
+
const isFlags = !!match[1];
|
|
124
|
+
const visibility = match[2] ?? 'internal';
|
|
125
|
+
const name = match[3];
|
|
126
|
+
if (!name)
|
|
127
|
+
continue;
|
|
128
|
+
const backingType = match[4] ?? 'int';
|
|
129
|
+
const body = match[5];
|
|
130
|
+
if (!body)
|
|
131
|
+
continue;
|
|
132
|
+
const line = this.getLineNumber(source, match.index);
|
|
133
|
+
const endLine = this.getLineNumber(source, match.index + match[0].length);
|
|
134
|
+
const docComment = this.extractDocComment(source, line);
|
|
135
|
+
const members = this.parseCSharpEnumMembers(body, line, isFlags);
|
|
136
|
+
enums.push({
|
|
137
|
+
id: this.generateId(filePath, name, line),
|
|
138
|
+
name,
|
|
139
|
+
qualifiedName: name,
|
|
140
|
+
file: filePath,
|
|
141
|
+
line,
|
|
142
|
+
endLine,
|
|
143
|
+
language: this.language,
|
|
144
|
+
isExported: visibility === 'public',
|
|
145
|
+
members,
|
|
146
|
+
isFlags,
|
|
147
|
+
isStringEnum: false,
|
|
148
|
+
backingType,
|
|
149
|
+
decorators: isFlags ? ['Flags'] : [],
|
|
150
|
+
modifiers: visibility !== 'internal' ? [visibility] : [],
|
|
151
|
+
confidence: 0.8,
|
|
152
|
+
...(docComment ? { docComment } : {}),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return enums;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Parse C# enum members
|
|
159
|
+
*/
|
|
160
|
+
parseCSharpEnumMembers(body, startLine, isFlags) {
|
|
161
|
+
const members = [];
|
|
162
|
+
const lines = body.split('\n');
|
|
163
|
+
let currentLine = startLine;
|
|
164
|
+
let autoValue = isFlags ? 1 : 0;
|
|
165
|
+
for (const line of lines) {
|
|
166
|
+
currentLine++;
|
|
167
|
+
const trimmed = line.trim();
|
|
168
|
+
// Skip empty lines and comments
|
|
169
|
+
if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('/*')) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
// Match enum member: Name = value, or just Name,
|
|
173
|
+
const memberMatch = trimmed.match(/^(\w+)\s*(?:=\s*([^,]+))?\s*,?\s*(?:\/\/.*)?$/);
|
|
174
|
+
if (memberMatch) {
|
|
175
|
+
const memberName = memberMatch[1];
|
|
176
|
+
if (!memberName)
|
|
177
|
+
continue;
|
|
178
|
+
const rawValue = memberMatch[2]?.trim();
|
|
179
|
+
let value;
|
|
180
|
+
let isAutoValue = false;
|
|
181
|
+
if (rawValue) {
|
|
182
|
+
// Handle hex values
|
|
183
|
+
if (rawValue.startsWith('0x') || rawValue.startsWith('0X')) {
|
|
184
|
+
value = parseInt(rawValue, 16);
|
|
185
|
+
}
|
|
186
|
+
else if (/^-?\d+$/.test(rawValue)) {
|
|
187
|
+
value = parseInt(rawValue, 10);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// Expression like 1 << 2
|
|
191
|
+
value = undefined;
|
|
192
|
+
}
|
|
193
|
+
if (value !== undefined) {
|
|
194
|
+
autoValue = isFlags ? value * 2 : value + 1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
value = autoValue;
|
|
199
|
+
autoValue = isFlags ? autoValue * 2 : autoValue + 1;
|
|
200
|
+
isAutoValue = true;
|
|
201
|
+
}
|
|
202
|
+
members.push({
|
|
203
|
+
name: memberName,
|
|
204
|
+
...(value !== undefined ? { value } : {}),
|
|
205
|
+
line: currentLine,
|
|
206
|
+
isAutoValue,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return members;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Infer kind from C# value and type
|
|
214
|
+
*/
|
|
215
|
+
inferCSharpKind(value, type) {
|
|
216
|
+
const trimmed = value.trim();
|
|
217
|
+
// Array initializer
|
|
218
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('new ') && trimmed.includes('[')) {
|
|
219
|
+
return 'array';
|
|
220
|
+
}
|
|
221
|
+
// Object creation
|
|
222
|
+
if (trimmed.startsWith('new ')) {
|
|
223
|
+
return 'object';
|
|
224
|
+
}
|
|
225
|
+
// String (including verbatim and interpolated)
|
|
226
|
+
if (trimmed.startsWith('"') || trimmed.startsWith('@"') || trimmed.startsWith('$"')) {
|
|
227
|
+
return 'primitive';
|
|
228
|
+
}
|
|
229
|
+
// Character
|
|
230
|
+
if (trimmed.startsWith("'")) {
|
|
231
|
+
return 'primitive';
|
|
232
|
+
}
|
|
233
|
+
// Number
|
|
234
|
+
if (/^-?\d+(\.\d+)?[MmFfDdLlUu]*$/.test(trimmed)) {
|
|
235
|
+
return 'primitive';
|
|
236
|
+
}
|
|
237
|
+
// Boolean
|
|
238
|
+
if (trimmed === 'true' || trimmed === 'false') {
|
|
239
|
+
return 'primitive';
|
|
240
|
+
}
|
|
241
|
+
// null
|
|
242
|
+
if (trimmed === 'null') {
|
|
243
|
+
return 'primitive';
|
|
244
|
+
}
|
|
245
|
+
// Primitive types
|
|
246
|
+
if (['int', 'long', 'short', 'byte', 'float', 'double', 'decimal', 'bool', 'char', 'string', 'String'].includes(type)) {
|
|
247
|
+
return 'primitive';
|
|
248
|
+
}
|
|
249
|
+
return 'computed';
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Extract value from C# literal
|
|
253
|
+
*/
|
|
254
|
+
extractCSharpValue(rawValue, kind) {
|
|
255
|
+
if (kind === 'object' || kind === 'array' || kind === 'computed') {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const trimmed = rawValue.trim();
|
|
259
|
+
// Verbatim string literal
|
|
260
|
+
if (trimmed.startsWith('@"') && trimmed.endsWith('"')) {
|
|
261
|
+
return trimmed.slice(2, -1);
|
|
262
|
+
}
|
|
263
|
+
// Interpolated string
|
|
264
|
+
if (trimmed.startsWith('$"') && trimmed.endsWith('"')) {
|
|
265
|
+
return trimmed.slice(2, -1);
|
|
266
|
+
}
|
|
267
|
+
// Regular string literal
|
|
268
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
269
|
+
return trimmed.slice(1, -1);
|
|
270
|
+
}
|
|
271
|
+
// Character literal
|
|
272
|
+
if (trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
273
|
+
return trimmed.slice(1, -1);
|
|
274
|
+
}
|
|
275
|
+
// Decimal literal
|
|
276
|
+
if (/^-?\d+(\.\d+)?[Mm]$/.test(trimmed)) {
|
|
277
|
+
return parseFloat(trimmed.slice(0, -1));
|
|
278
|
+
}
|
|
279
|
+
// Long/ULong literal
|
|
280
|
+
if (/^-?\d+[LlUu]+$/.test(trimmed)) {
|
|
281
|
+
return parseInt(trimmed.replace(/[LlUu]+$/, ''), 10);
|
|
282
|
+
}
|
|
283
|
+
// Float/Double literal
|
|
284
|
+
if (/^-?\d+(\.\d+)?[FfDd]$/.test(trimmed)) {
|
|
285
|
+
return parseFloat(trimmed.slice(0, -1));
|
|
286
|
+
}
|
|
287
|
+
// Integer
|
|
288
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
289
|
+
return parseInt(trimmed, 10);
|
|
290
|
+
}
|
|
291
|
+
// Decimal number
|
|
292
|
+
if (/^-?\d+\.\d+$/.test(trimmed)) {
|
|
293
|
+
return parseFloat(trimmed);
|
|
294
|
+
}
|
|
295
|
+
// Boolean
|
|
296
|
+
if (trimmed === 'true')
|
|
297
|
+
return true;
|
|
298
|
+
if (trimmed === 'false')
|
|
299
|
+
return false;
|
|
300
|
+
if (trimmed === 'null')
|
|
301
|
+
return null;
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Find the containing class/struct name
|
|
306
|
+
*/
|
|
307
|
+
findContainingClass(source, position) {
|
|
308
|
+
const beforePosition = source.slice(0, position);
|
|
309
|
+
const classMatch = beforePosition.match(/(class|struct|record)\s+(\w+)(?:<[^>]+>)?(?:\s*:\s*[\w,\s<>]+)?\s*\{[^}]*$/);
|
|
310
|
+
if (classMatch && classMatch[2]) {
|
|
311
|
+
return classMatch[2];
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=csharp-regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csharp-regex.js","sourceRoot":"","sources":["../../../../src/constants/extractors/regex/csharp-regex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D;;GA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EAAE,CAAC;YAC1C,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC;QAED,UAAU;QACV,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC/B,CAAC;QAED,iBAAiB;QACjB,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACjC,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAED,UAAU;QACV,IAAI,OAAO,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QACpC,IAAI,OAAO,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC;QACtC,IAAI,OAAO,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACK,mBAAmB,CAAC,MAAc,EAAE,QAAgB;QAC1D,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACjD,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,4EAA4E,CAAC,CAAC;QAEtH,IAAI,UAAU,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;YAChC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go Constant Regex Extractor
|
|
3
|
+
*
|
|
4
|
+
* Regex-based extraction for Go constants.
|
|
5
|
+
* Used as fallback when tree-sitter is unavailable.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConstantExtraction, EnumExtraction } from '../../types.js';
|
|
8
|
+
import { BaseConstantRegexExtractor } from './base-regex.js';
|
|
9
|
+
/**
|
|
10
|
+
* Go constant regex extractor
|
|
11
|
+
*/
|
|
12
|
+
export declare class GoConstantRegexExtractor extends BaseConstantRegexExtractor {
|
|
13
|
+
readonly language: "go";
|
|
14
|
+
/**
|
|
15
|
+
* Extract constants from Go source
|
|
16
|
+
*/
|
|
17
|
+
protected extractConstants(source: string, filePath: string): ConstantExtraction[];
|
|
18
|
+
/**
|
|
19
|
+
* Parse a const block
|
|
20
|
+
*/
|
|
21
|
+
private parseConstBlock;
|
|
22
|
+
/**
|
|
23
|
+
* Go doesn't have traditional enums, but we can detect iota-based const blocks
|
|
24
|
+
* as pseudo-enums
|
|
25
|
+
*/
|
|
26
|
+
protected extractEnums(_source: string, _filePath: string): EnumExtraction[];
|
|
27
|
+
/**
|
|
28
|
+
* Check if position is inside a const block
|
|
29
|
+
*/
|
|
30
|
+
private isInsideConstBlock;
|
|
31
|
+
/**
|
|
32
|
+
* Infer kind from Go value
|
|
33
|
+
*/
|
|
34
|
+
private inferGoKind;
|
|
35
|
+
/**
|
|
36
|
+
* Extract value from Go literal
|
|
37
|
+
*/
|
|
38
|
+
private extractGoValue;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=go-regex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"go-regex.d.ts","sourceRoot":"","sources":["../../../../src/constants/extractors/regex/go-regex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EAEf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,0BAA0B;IACtE,QAAQ,CAAC,QAAQ,EAAG,IAAI,CAAU;IAElC;;OAEG;IACH,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,kBAAkB,EAAE;IAgHlF;;OAEG;IACH,OAAO,CAAC,eAAe;IAkFvB;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,EAAE;IAM5E;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;OAEG;IACH,OAAO,CAAC,WAAW;IA2CnB;;OAEG;IACH,OAAO,CAAC,cAAc;CAoDvB"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go Constant Regex Extractor
|
|
3
|
+
*
|
|
4
|
+
* Regex-based extraction for Go constants.
|
|
5
|
+
* Used as fallback when tree-sitter is unavailable.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseConstantRegexExtractor } from './base-regex.js';
|
|
8
|
+
/**
|
|
9
|
+
* Go constant regex extractor
|
|
10
|
+
*/
|
|
11
|
+
export class GoConstantRegexExtractor extends BaseConstantRegexExtractor {
|
|
12
|
+
language = 'go';
|
|
13
|
+
/**
|
|
14
|
+
* Extract constants from Go source
|
|
15
|
+
*/
|
|
16
|
+
extractConstants(source, filePath) {
|
|
17
|
+
const constants = [];
|
|
18
|
+
let match;
|
|
19
|
+
// Pattern 1: Single const declaration
|
|
20
|
+
// const MaxRetries = 3
|
|
21
|
+
// const ApiUrl string = "https://api.example.com"
|
|
22
|
+
const singleConstPattern = /^const\s+(\w+)\s*(?:(\w+)\s*)?=\s*(.+?)$/gm;
|
|
23
|
+
while ((match = singleConstPattern.exec(source)) !== null) {
|
|
24
|
+
const name = match[1];
|
|
25
|
+
if (!name)
|
|
26
|
+
continue;
|
|
27
|
+
const type = match[2];
|
|
28
|
+
const rawValue = match[3]?.trim();
|
|
29
|
+
if (!rawValue)
|
|
30
|
+
continue;
|
|
31
|
+
// Skip if inside a const block (will be handled separately)
|
|
32
|
+
const beforeMatch = source.slice(0, match.index);
|
|
33
|
+
if (this.isInsideConstBlock(beforeMatch)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const line = this.getLineNumber(source, match.index);
|
|
37
|
+
const column = this.getColumnNumber(source, match.index);
|
|
38
|
+
const docComment = this.extractDocComment(source, line);
|
|
39
|
+
const isExported = /^[A-Z]/.test(name);
|
|
40
|
+
const kind = this.inferGoKind(rawValue);
|
|
41
|
+
const value = this.extractGoValue(rawValue, kind);
|
|
42
|
+
constants.push({
|
|
43
|
+
id: this.generateId(filePath, name, line),
|
|
44
|
+
name,
|
|
45
|
+
qualifiedName: name,
|
|
46
|
+
file: filePath,
|
|
47
|
+
line,
|
|
48
|
+
column,
|
|
49
|
+
endLine: line,
|
|
50
|
+
language: this.language,
|
|
51
|
+
kind,
|
|
52
|
+
category: 'uncategorized',
|
|
53
|
+
value,
|
|
54
|
+
rawValue: this.truncateValue(rawValue),
|
|
55
|
+
isExported,
|
|
56
|
+
decorators: [],
|
|
57
|
+
modifiers: ['const'],
|
|
58
|
+
confidence: 0.75,
|
|
59
|
+
...(type ? { type } : {}),
|
|
60
|
+
...(docComment ? { docComment } : {}),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Pattern 2: Const block
|
|
64
|
+
// const (
|
|
65
|
+
// StatusPending = iota
|
|
66
|
+
// StatusActive
|
|
67
|
+
// StatusCompleted
|
|
68
|
+
// )
|
|
69
|
+
const constBlockPattern = /const\s*\(\s*([\s\S]*?)\s*\)/g;
|
|
70
|
+
while ((match = constBlockPattern.exec(source)) !== null) {
|
|
71
|
+
const blockContent = match[1];
|
|
72
|
+
if (!blockContent)
|
|
73
|
+
continue;
|
|
74
|
+
const blockStartLine = this.getLineNumber(source, match.index);
|
|
75
|
+
this.parseConstBlock(blockContent, blockStartLine, filePath, constants);
|
|
76
|
+
}
|
|
77
|
+
// Pattern 3: Package-level var (exported, effectively constant)
|
|
78
|
+
// var DefaultConfig = Config{Timeout: 30}
|
|
79
|
+
const varPattern = /^var\s+([A-Z]\w*)\s*(?:(\w+)\s*)?=\s*(.+?)$/gm;
|
|
80
|
+
while ((match = varPattern.exec(source)) !== null) {
|
|
81
|
+
const name = match[1];
|
|
82
|
+
if (!name)
|
|
83
|
+
continue;
|
|
84
|
+
const type = match[2];
|
|
85
|
+
const rawValue = match[3]?.trim();
|
|
86
|
+
if (!rawValue)
|
|
87
|
+
continue;
|
|
88
|
+
const line = this.getLineNumber(source, match.index);
|
|
89
|
+
const column = this.getColumnNumber(source, match.index);
|
|
90
|
+
const docComment = this.extractDocComment(source, line);
|
|
91
|
+
const kind = this.inferGoKind(rawValue);
|
|
92
|
+
const value = this.extractGoValue(rawValue, kind);
|
|
93
|
+
constants.push({
|
|
94
|
+
id: this.generateId(filePath, name, line),
|
|
95
|
+
name,
|
|
96
|
+
qualifiedName: name,
|
|
97
|
+
file: filePath,
|
|
98
|
+
line,
|
|
99
|
+
column,
|
|
100
|
+
endLine: line,
|
|
101
|
+
language: this.language,
|
|
102
|
+
kind,
|
|
103
|
+
category: 'uncategorized',
|
|
104
|
+
value,
|
|
105
|
+
rawValue: this.truncateValue(rawValue),
|
|
106
|
+
isExported: true,
|
|
107
|
+
decorators: [],
|
|
108
|
+
modifiers: ['var'],
|
|
109
|
+
confidence: 0.6, // Lower confidence for var
|
|
110
|
+
...(type ? { type } : {}),
|
|
111
|
+
...(docComment ? { docComment } : {}),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return constants;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Parse a const block
|
|
118
|
+
*/
|
|
119
|
+
parseConstBlock(content, startLine, filePath, constants) {
|
|
120
|
+
const lines = content.split('\n');
|
|
121
|
+
let currentLine = startLine;
|
|
122
|
+
let iotaValue = 0;
|
|
123
|
+
let lastType;
|
|
124
|
+
for (const line of lines) {
|
|
125
|
+
currentLine++;
|
|
126
|
+
const trimmed = line.trim();
|
|
127
|
+
// Skip empty lines and comments
|
|
128
|
+
if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('/*')) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
// Match: Name Type = value, Name = value, or just Name (iota continuation)
|
|
132
|
+
const constMatch = trimmed.match(/^(\w+)\s*(?:(\w+)\s*)?(?:=\s*(.+?))?(?:\s*\/\/.*)?$/);
|
|
133
|
+
if (!constMatch)
|
|
134
|
+
continue;
|
|
135
|
+
const name = constMatch[1];
|
|
136
|
+
if (!name)
|
|
137
|
+
continue;
|
|
138
|
+
const type = constMatch[2] ?? lastType;
|
|
139
|
+
const rawValue = constMatch[3]?.trim();
|
|
140
|
+
if (type) {
|
|
141
|
+
lastType = type;
|
|
142
|
+
}
|
|
143
|
+
const isExported = /^[A-Z]/.test(name);
|
|
144
|
+
let value = null;
|
|
145
|
+
let kind = 'primitive';
|
|
146
|
+
if (rawValue) {
|
|
147
|
+
if (rawValue === 'iota') {
|
|
148
|
+
value = iotaValue;
|
|
149
|
+
iotaValue++;
|
|
150
|
+
}
|
|
151
|
+
else if (rawValue.includes('iota')) {
|
|
152
|
+
// Expression with iota like 1 << iota
|
|
153
|
+
value = iotaValue;
|
|
154
|
+
iotaValue++;
|
|
155
|
+
kind = 'computed';
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
kind = this.inferGoKind(rawValue);
|
|
159
|
+
value = this.extractGoValue(rawValue, kind);
|
|
160
|
+
// Reset iota if explicit value
|
|
161
|
+
if (typeof value === 'number') {
|
|
162
|
+
iotaValue = value + 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Implicit iota continuation
|
|
168
|
+
value = iotaValue;
|
|
169
|
+
iotaValue++;
|
|
170
|
+
}
|
|
171
|
+
constants.push({
|
|
172
|
+
id: this.generateId(filePath, name, currentLine),
|
|
173
|
+
name,
|
|
174
|
+
qualifiedName: name,
|
|
175
|
+
file: filePath,
|
|
176
|
+
line: currentLine,
|
|
177
|
+
column: 1,
|
|
178
|
+
endLine: currentLine,
|
|
179
|
+
language: this.language,
|
|
180
|
+
kind,
|
|
181
|
+
category: 'uncategorized',
|
|
182
|
+
value,
|
|
183
|
+
rawValue: rawValue ?? String(value),
|
|
184
|
+
isExported,
|
|
185
|
+
decorators: [],
|
|
186
|
+
modifiers: ['const'],
|
|
187
|
+
confidence: 0.75,
|
|
188
|
+
...(type ? { type } : {}),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Go doesn't have traditional enums, but we can detect iota-based const blocks
|
|
194
|
+
* as pseudo-enums
|
|
195
|
+
*/
|
|
196
|
+
extractEnums(_source, _filePath) {
|
|
197
|
+
// Go doesn't have enums - iota-based constants are handled in extractConstants
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Check if position is inside a const block
|
|
202
|
+
*/
|
|
203
|
+
isInsideConstBlock(beforeText) {
|
|
204
|
+
const lastConstParen = beforeText.lastIndexOf('const (');
|
|
205
|
+
const lastCloseParen = beforeText.lastIndexOf(')');
|
|
206
|
+
return lastConstParen > lastCloseParen;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Infer kind from Go value
|
|
210
|
+
*/
|
|
211
|
+
inferGoKind(value) {
|
|
212
|
+
const trimmed = value.trim();
|
|
213
|
+
// Struct literal
|
|
214
|
+
if (trimmed.includes('{') && trimmed.includes('}')) {
|
|
215
|
+
return 'object';
|
|
216
|
+
}
|
|
217
|
+
// Slice/array literal
|
|
218
|
+
if (trimmed.startsWith('[]') || trimmed.match(/^\[\d*\]/)) {
|
|
219
|
+
return 'array';
|
|
220
|
+
}
|
|
221
|
+
// Map literal
|
|
222
|
+
if (trimmed.startsWith('map[')) {
|
|
223
|
+
return 'object';
|
|
224
|
+
}
|
|
225
|
+
// String
|
|
226
|
+
if (trimmed.startsWith('"') || trimmed.startsWith('`')) {
|
|
227
|
+
return 'primitive';
|
|
228
|
+
}
|
|
229
|
+
// Rune (character)
|
|
230
|
+
if (trimmed.startsWith("'")) {
|
|
231
|
+
return 'primitive';
|
|
232
|
+
}
|
|
233
|
+
// Number
|
|
234
|
+
if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
235
|
+
return 'primitive';
|
|
236
|
+
}
|
|
237
|
+
// Boolean
|
|
238
|
+
if (trimmed === 'true' || trimmed === 'false') {
|
|
239
|
+
return 'primitive';
|
|
240
|
+
}
|
|
241
|
+
// nil
|
|
242
|
+
if (trimmed === 'nil') {
|
|
243
|
+
return 'primitive';
|
|
244
|
+
}
|
|
245
|
+
// iota
|
|
246
|
+
if (trimmed === 'iota' || trimmed.includes('iota')) {
|
|
247
|
+
return 'primitive';
|
|
248
|
+
}
|
|
249
|
+
return 'computed';
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Extract value from Go literal
|
|
253
|
+
*/
|
|
254
|
+
extractGoValue(rawValue, kind) {
|
|
255
|
+
if (kind === 'object' || kind === 'array' || kind === 'computed') {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const trimmed = rawValue.trim();
|
|
259
|
+
// Double-quoted string
|
|
260
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
261
|
+
return trimmed.slice(1, -1);
|
|
262
|
+
}
|
|
263
|
+
// Raw string (backtick)
|
|
264
|
+
if (trimmed.startsWith('`') && trimmed.endsWith('`')) {
|
|
265
|
+
return trimmed.slice(1, -1);
|
|
266
|
+
}
|
|
267
|
+
// Rune (character)
|
|
268
|
+
if (trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
269
|
+
return trimmed.slice(1, -1);
|
|
270
|
+
}
|
|
271
|
+
// Integer
|
|
272
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
273
|
+
return parseInt(trimmed, 10);
|
|
274
|
+
}
|
|
275
|
+
// Float
|
|
276
|
+
if (/^-?\d+\.\d+$/.test(trimmed)) {
|
|
277
|
+
return parseFloat(trimmed);
|
|
278
|
+
}
|
|
279
|
+
// Hex
|
|
280
|
+
if (/^0x[0-9a-fA-F]+$/.test(trimmed)) {
|
|
281
|
+
return parseInt(trimmed, 16);
|
|
282
|
+
}
|
|
283
|
+
// Boolean
|
|
284
|
+
if (trimmed === 'true')
|
|
285
|
+
return true;
|
|
286
|
+
if (trimmed === 'false')
|
|
287
|
+
return false;
|
|
288
|
+
if (trimmed === 'nil')
|
|
289
|
+
return null;
|
|
290
|
+
// iota
|
|
291
|
+
if (trimmed === 'iota') {
|
|
292
|
+
return 0; // Will be adjusted by caller
|
|
293
|
+
}
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=go-regex.js.map
|