vladx 1.3.2 → 1.5.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/bin/vladx +4 -1
- package/examples/stdlib/ambiente.vx +8 -0
- package/examples/stdlib/archivio_extra.vx +11 -0
- package/examples/stdlib/asserzione.vx +11 -0
- package/examples/stdlib/client_web.vx +7 -0
- package/examples/stdlib/codifica.vx +8 -0
- package/examples/stdlib/collezioni.vx +11 -0
- package/examples/stdlib/compressione.vx +10 -0
- package/examples/stdlib/console.vx +14 -0
- package/examples/stdlib/cripto.vx +8 -0
- package/examples/stdlib/dati.vx +21 -0
- package/examples/stdlib/eventi.vx +10 -0
- package/examples/stdlib/json_extra.vx +7 -0
- package/examples/stdlib/matematica.vx +9 -0
- package/examples/stdlib/percorso.vx +9 -0
- package/examples/stdlib/processo.vx +9 -0
- package/examples/stdlib/server_web.vx +10 -0
- package/examples/stdlib/sql_helper.vx +7 -0
- package/examples/stdlib/tempo.vx +9 -0
- package/examples/stdlib/testo.vx +10 -0
- package/examples/stdlib/url.vx +11 -0
- package/examples/stdlib/validazione.vx +5 -0
- package/package.json +6 -2
- package/programs/1/index.vx +16 -4
- package/programs/main/index.vx +11 -8
- package/programs/main/passports/Alina.json +1 -0
- package/programs/main/passports/Tanya.json +1 -0
- package/programs/main/passports/vlad.json +1 -0
- package/programs/main/test_async.vx +25 -0
- package/programs/main/test_async_advanced.vx +35 -0
- package/programs/main/test_backend.vx +33 -0
- package/programs/tests/test_new_features.vx +53 -0
- package/programs/tests/test_stdlib.vx +26 -0
- package/programs/tests/test_templates.vx +8 -0
- package/src/cli/cli.js +8 -6
- package/src/interpreter/interpreter.js +388 -170
- package/src/lexer/lexer.js +5 -1
- package/src/lexer/tokens.js +9 -1
- package/src/parser/ast.js +59 -4
- package/src/parser/parser.js +152 -18
- package/src/repl/repl.js +5 -5
- package/src/stdlib/registry.js +301 -0
- /package/programs/main/passports/{Vlad.txt → Vlad.json} +0 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VladX Standard Library Registry
|
|
3
|
+
* Contiene le definizioni di tutti i moduli integrati.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const crypto = require('crypto');
|
|
9
|
+
const zlib = require('zlib');
|
|
10
|
+
const { execSync } = require('child_process');
|
|
11
|
+
|
|
12
|
+
const registry = {};
|
|
13
|
+
|
|
14
|
+
// --- 1. TESTO ---
|
|
15
|
+
registry['@std/Testo'] = new Map([
|
|
16
|
+
['maiuscolo', { call: (_, args) => String(args[0]).toUpperCase() }],
|
|
17
|
+
['minuscolo', { call: (_, args) => String(args[0]).toLowerCase() }],
|
|
18
|
+
['capitalizza', {
|
|
19
|
+
call: (_, args) => {
|
|
20
|
+
const s = String(args[0]);
|
|
21
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
22
|
+
}
|
|
23
|
+
}],
|
|
24
|
+
['pulisci', { call: (_, args) => String(args[0]).trim() }],
|
|
25
|
+
['sostituisci', { call: (_, args) => String(args[0]).replace(new RegExp(args[1], 'g'), args[2]) }],
|
|
26
|
+
['dividi', { call: (_, args) => String(args[0]).split(args[1]) }],
|
|
27
|
+
['contiene', { call: (_, args) => String(args[0]).includes(args[1]) }],
|
|
28
|
+
['slugify', { call: (_, args) => String(args[0]).toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, '') }]
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
// --- 2. COLLEZIONI ---
|
|
32
|
+
registry['@std/Collezioni'] = new Map([
|
|
33
|
+
['CreaMappa', { call: () => new Map() }],
|
|
34
|
+
['CreaInsieme', { call: () => new Set() }],
|
|
35
|
+
['unisci', { call: (_, args) => Object.assign({}, ...args) }],
|
|
36
|
+
['chiavi', { call: (_, args) => Object.keys(args[0]) }],
|
|
37
|
+
['valori', { call: (_, args) => Object.values(args[0]) }]
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
// --- 3. PERCORSO ---
|
|
41
|
+
registry['@std/Percorso'] = new Map([
|
|
42
|
+
['unisci', { call: (_, args) => path.join(...args) }],
|
|
43
|
+
['base', { call: (_, args) => path.basename(args[0]) }],
|
|
44
|
+
['cartella', { call: (_, args) => path.dirname(args[0]) }],
|
|
45
|
+
['estensione', { call: (_, args) => path.extname(args[0]) }],
|
|
46
|
+
['assoluto', { call: (_, args) => path.resolve(args[0]) }]
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
// --- 4. CONSOLE ---
|
|
50
|
+
registry['@std/Console'] = new Map([
|
|
51
|
+
['log', { call: (_, args) => console.log(...args) }],
|
|
52
|
+
['errore', { call: (_, args) => console.error('\x1b[31m%s\x1b[0m', ...args) }],
|
|
53
|
+
['avviso', { call: (_, args) => console.warn('\x1b[33m%s\x1b[0m', ...args) }],
|
|
54
|
+
['successo', { call: (_, args) => console.log('\x1b[32m%s\x1b[0m', ...args) }],
|
|
55
|
+
['pulisci', { call: () => console.clear() }],
|
|
56
|
+
['tabella', { call: (_, args) => console.table(args[0]) }]
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
// --- 5. CRIPTO ---
|
|
60
|
+
registry['@std/Cripto'] = new Map([
|
|
61
|
+
['sha256', { call: (_, args) => crypto.createHash('sha256').update(String(args[0])).digest('hex') }],
|
|
62
|
+
['md5', { call: (_, args) => crypto.createHash('md5').update(String(args[0])).digest('hex') }],
|
|
63
|
+
['uuid', { call: () => crypto.randomUUID() }],
|
|
64
|
+
['casuale', { call: (_, args) => crypto.randomBytes(args[0] || 16).toString('hex') }]
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
// --- 6. COMPRESSIONE ---
|
|
68
|
+
registry['@std/Compressione'] = new Map([
|
|
69
|
+
['comprimi', { call: (_, args) => zlib.gzipSync(args[0]).toString('base64') }],
|
|
70
|
+
['decomprimi', { call: (_, args) => zlib.gunzipSync(Buffer.from(args[0], 'base64')).toString() }]
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
// --- 7. URL ---
|
|
74
|
+
registry['@std/Url'] = new Map([
|
|
75
|
+
['analizza', {
|
|
76
|
+
call: (_, args) => {
|
|
77
|
+
const u = new URL(args[0]);
|
|
78
|
+
return {
|
|
79
|
+
protocollo: u.protocol,
|
|
80
|
+
host: u.host,
|
|
81
|
+
percorso: u.pathname,
|
|
82
|
+
query: Object.fromEntries(u.searchParams),
|
|
83
|
+
frammento: u.hash
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}],
|
|
87
|
+
['componi', {
|
|
88
|
+
call: (_, args) => {
|
|
89
|
+
const u = new URL(args[0]);
|
|
90
|
+
Object.entries(args[1] || {}).forEach(([k, v]) => u.searchParams.set(k, v));
|
|
91
|
+
return u.toString();
|
|
92
|
+
}
|
|
93
|
+
}]
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
// --- 8. EVENTI ---
|
|
97
|
+
registry['@std/Eventi'] = new Map([
|
|
98
|
+
['CreaEmitter', {
|
|
99
|
+
call: () => {
|
|
100
|
+
const listeners = {};
|
|
101
|
+
return {
|
|
102
|
+
su: {
|
|
103
|
+
call: (_, args) => {
|
|
104
|
+
const [ev, cb] = args;
|
|
105
|
+
if (!listeners[ev]) listeners[ev] = [];
|
|
106
|
+
listeners[ev].push(cb);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
lancia: {
|
|
110
|
+
call: async (int, args) => {
|
|
111
|
+
const [ev, data] = args;
|
|
112
|
+
if (listeners[ev]) {
|
|
113
|
+
for (const cb of listeners[ev]) await cb.call(int, [data]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}]
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
// --- 9. PROCESSO ---
|
|
123
|
+
registry['@std/Processo'] = new Map([
|
|
124
|
+
['id', process.pid],
|
|
125
|
+
['memoria', { call: () => process.memoryUsage() }],
|
|
126
|
+
['tempoAttivita', { call: () => process.uptime() }],
|
|
127
|
+
['versioneNode', process.version],
|
|
128
|
+
['piattaforma', process.platform]
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
// --- 10. AMBIENTE ---
|
|
132
|
+
registry['@std/Ambiente'] = new Map([
|
|
133
|
+
['prendi', { call: (_, args) => process.env[args[0]] }],
|
|
134
|
+
['tutti', { call: () => process.env }]
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
// --- 11. DATI ---
|
|
138
|
+
registry['@std/Dati'] = new Map([
|
|
139
|
+
['clona', { call: (_, args) => JSON.parse(JSON.stringify(args[0])) }],
|
|
140
|
+
['fondi', {
|
|
141
|
+
call: (_, args) => {
|
|
142
|
+
const merge = (target, source) => {
|
|
143
|
+
for (const key of Object.keys(source)) {
|
|
144
|
+
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key] || {}, source[key]));
|
|
145
|
+
}
|
|
146
|
+
Object.assign(target || {}, source);
|
|
147
|
+
return target;
|
|
148
|
+
};
|
|
149
|
+
return merge(args[0], args[1]);
|
|
150
|
+
}
|
|
151
|
+
}],
|
|
152
|
+
['raggruppa', {
|
|
153
|
+
call: (_, args) => {
|
|
154
|
+
const [arr, key] = args;
|
|
155
|
+
return arr.reduce((rv, x) => {
|
|
156
|
+
(rv[x[key]] = rv[x[key]] || []).push(x);
|
|
157
|
+
return rv;
|
|
158
|
+
}, {});
|
|
159
|
+
}
|
|
160
|
+
}]
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
// --- 12. VALIDAZIONE ---
|
|
164
|
+
registry['@std/Validazione'] = new Map([
|
|
165
|
+
['email', { call: (_, args) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(args[0]) }],
|
|
166
|
+
['url', { call: (_, args) => /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/.test(args[0]) }],
|
|
167
|
+
['numero', { call: (_, args) => !isNaN(args[0]) }],
|
|
168
|
+
['ip', { call: (_, args) => /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(args[0]) }]
|
|
169
|
+
]);
|
|
170
|
+
|
|
171
|
+
// --- 13. CALCOLO ---
|
|
172
|
+
registry['@std/Calcolo'] = new Map([
|
|
173
|
+
['media', { call: (_, args) => args[0].reduce((a, b) => a + b, 0) / args[0].length }],
|
|
174
|
+
['somma', { call: (_, args) => args[0].reduce((a, b) => a + b, 0) }],
|
|
175
|
+
['fattoriale', {
|
|
176
|
+
call: (_, args) => {
|
|
177
|
+
let f = 1;
|
|
178
|
+
for (let i = 1; i <= args[0]; i++) f *= i;
|
|
179
|
+
return f;
|
|
180
|
+
}
|
|
181
|
+
}]
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
// --- 14. CRONOMETRO ---
|
|
185
|
+
registry['@std/Cronometro'] = new Map([
|
|
186
|
+
['oraPrecisa', { call: () => performance.now() }],
|
|
187
|
+
['formattaDurata', {
|
|
188
|
+
call: (_, args) => {
|
|
189
|
+
const ms = args[0];
|
|
190
|
+
const s = Math.floor(ms / 1000);
|
|
191
|
+
const m = Math.floor(s / 60);
|
|
192
|
+
return `${m}:${(s % 60).toString().padStart(2, '0')}.${(Math.floor(ms % 1000)).toString().padStart(3, '0')}`;
|
|
193
|
+
}
|
|
194
|
+
}]
|
|
195
|
+
]);
|
|
196
|
+
|
|
197
|
+
// --- 15. CODIFICA ---
|
|
198
|
+
registry['@std/Codifica'] = new Map([
|
|
199
|
+
['base64', { call: (_, args) => Buffer.from(String(args[0])).toString('base64') }],
|
|
200
|
+
['daBase64', { call: (_, args) => Buffer.from(String(args[0]), 'base64').toString() }],
|
|
201
|
+
['uri', { call: (_, args) => encodeURIComponent(args[0]) }],
|
|
202
|
+
['daUri', { call: (_, args) => decodeURIComponent(args[0]) }],
|
|
203
|
+
['hex', { call: (_, args) => Buffer.from(String(args[0])).toString('hex') }]
|
|
204
|
+
]);
|
|
205
|
+
|
|
206
|
+
// --- 16. ARCHIVIO_EXTRA ---
|
|
207
|
+
registry['@std/ArchivioExtra'] = new Map([
|
|
208
|
+
['elencaTutto', {
|
|
209
|
+
call: (_, args) => {
|
|
210
|
+
const walk = (dir) => {
|
|
211
|
+
let results = [];
|
|
212
|
+
const list = fs.readdirSync(dir);
|
|
213
|
+
list.forEach(file => {
|
|
214
|
+
file = path.resolve(dir, file);
|
|
215
|
+
const stat = fs.statSync(file);
|
|
216
|
+
if (stat && stat.isDirectory()) results = results.concat(walk(file));
|
|
217
|
+
else results.push(file);
|
|
218
|
+
});
|
|
219
|
+
return results;
|
|
220
|
+
};
|
|
221
|
+
return walk(args[0]);
|
|
222
|
+
}
|
|
223
|
+
}],
|
|
224
|
+
['copia', { call: (_, args) => fs.copyFileSync(args[0], args[1]) }]
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
// --- 17. SERVER_WEB ---
|
|
228
|
+
registry['@std/ServerWeb'] = new Map([
|
|
229
|
+
['rispondiJson', {
|
|
230
|
+
call: (_, args) => {
|
|
231
|
+
return { stato: 200, intestazioni: { 'Content-Type': 'application/json' }, corpo: args[0] };
|
|
232
|
+
}
|
|
233
|
+
}],
|
|
234
|
+
['errore', {
|
|
235
|
+
call: (_, args) => {
|
|
236
|
+
return { stato: args[0] || 500, corpo: args[1] || "Errore Interno" };
|
|
237
|
+
}
|
|
238
|
+
}]
|
|
239
|
+
]);
|
|
240
|
+
|
|
241
|
+
// --- 18. CLIENT_WEB ---
|
|
242
|
+
registry['@std/ClientWeb'] = new Map([
|
|
243
|
+
['get', { call: (_, args) => execSync(`curl -sL "${args[0]}"`, { encoding: 'utf8' }) }],
|
|
244
|
+
['post', {
|
|
245
|
+
call: (_, args) => {
|
|
246
|
+
const [url, data] = args;
|
|
247
|
+
return execSync(`curl -sLX POST "${url}" -d '${JSON.stringify(data)}' -H "Content-Type: application/json"`, { encoding: 'utf8' });
|
|
248
|
+
}
|
|
249
|
+
}]
|
|
250
|
+
]);
|
|
251
|
+
|
|
252
|
+
// --- 19. SQL_HELPER ---
|
|
253
|
+
registry['@std/SqlHelper'] = new Map([
|
|
254
|
+
['generaInsert', {
|
|
255
|
+
call: (_, args) => {
|
|
256
|
+
const [tabella, dati] = args;
|
|
257
|
+
const keys = Object.keys(dati);
|
|
258
|
+
const vals = Object.values(dati).map(v => typeof v === 'string' ? `'${v}'` : v);
|
|
259
|
+
return `INSERT INTO ${tabella} (${keys.join(', ')}) VALUES (${vals.join(', ')})`;
|
|
260
|
+
}
|
|
261
|
+
}]
|
|
262
|
+
]);
|
|
263
|
+
|
|
264
|
+
// --- 20. JSON_EXTRA ---
|
|
265
|
+
registry['@std/JsonExtra'] = new Map([
|
|
266
|
+
['codifica', { call: (_, args) => JSON.stringify(args[0], null, 2) }],
|
|
267
|
+
['analizzaSicuro', {
|
|
268
|
+
call: (_, args) => {
|
|
269
|
+
try { return JSON.parse(args[0]); }
|
|
270
|
+
catch (e) { return null; }
|
|
271
|
+
}
|
|
272
|
+
}]
|
|
273
|
+
]);
|
|
274
|
+
|
|
275
|
+
// --- 21. ASSERZIONE ---
|
|
276
|
+
registry['@std/Asserzione'] = new Map([
|
|
277
|
+
['uguale', {
|
|
278
|
+
call: (_, args) => {
|
|
279
|
+
if (args[0] !== args[1]) throw new Error(`Asserzione fallita: ${args[0]} !== ${args[1]}`);
|
|
280
|
+
}
|
|
281
|
+
}],
|
|
282
|
+
['vero', {
|
|
283
|
+
call: (_, args) => {
|
|
284
|
+
if (!args[0]) throw new Error(`Asserzione fallita: atteso vero`);
|
|
285
|
+
}
|
|
286
|
+
}],
|
|
287
|
+
['falso', {
|
|
288
|
+
call: (_, args) => {
|
|
289
|
+
if (args[0]) throw new Error(`Asserzione fallita: atteso falso`);
|
|
290
|
+
}
|
|
291
|
+
}]
|
|
292
|
+
]);
|
|
293
|
+
|
|
294
|
+
// --- ALIAS ---
|
|
295
|
+
registry['@std/Matematica'] = registry['@std/Calcolo'];
|
|
296
|
+
registry['@std/Tempo'] = registry['@std/Cronometro'];
|
|
297
|
+
// Aggiungo anche metodi data/ora a @std/Tempo se mancanti
|
|
298
|
+
registry['@std/Tempo'].set('data', { call: () => new Date().toLocaleDateString() });
|
|
299
|
+
registry['@std/Tempo'].set('ora', { call: () => new Date().toLocaleTimeString() });
|
|
300
|
+
|
|
301
|
+
module.exports = registry;
|
|
File without changes
|