pure-dango 1.8.0 → 1.8.2
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/PureDango.cjs +9426 -0
- package/dist/PureDangoLauncher.exe +0 -0
- package/dist/lib/parser/main.js +481 -0
- package/dist/lib/tokenizer/tokenizer.js +298 -0
- package/package.json +15 -4
- package/src/index.ts +1 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var tokenizer_exports = {};
|
|
30
|
+
__export(tokenizer_exports, {
|
|
31
|
+
tokenizer: () => tokenizer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(tokenizer_exports);
|
|
34
|
+
var import_errors = require("../../runtime/errors");
|
|
35
|
+
var quote_crimes = __toESM(require("./funnies"), 1);
|
|
36
|
+
const REGEX = new RegExp([
|
|
37
|
+
// strings
|
|
38
|
+
"(`(?:[^`\\\\]|\\\\.)*`)",
|
|
39
|
+
// backtick strings
|
|
40
|
+
"('(?:[^'\\\\]|\\\\.)*')",
|
|
41
|
+
// single quote strings
|
|
42
|
+
"(\u201C(?:[^\u201C\u201D\\\\]|\\\\.)*\u201D)",
|
|
43
|
+
// curly single quote strings
|
|
44
|
+
"(\u2018(?:[^\u2018\u2019\\\\]|\\\\.)*\u2019)",
|
|
45
|
+
// curly double quote strings
|
|
46
|
+
// multi-char operators
|
|
47
|
+
"\\?\\?",
|
|
48
|
+
"&&",
|
|
49
|
+
"\\|\\|",
|
|
50
|
+
"!=",
|
|
51
|
+
"<=",
|
|
52
|
+
">=",
|
|
53
|
+
"==",
|
|
54
|
+
"--",
|
|
55
|
+
"\\+\\+",
|
|
56
|
+
"-=",
|
|
57
|
+
"\\+=",
|
|
58
|
+
"/=",
|
|
59
|
+
"\\*=",
|
|
60
|
+
"&=",
|
|
61
|
+
"\\|=",
|
|
62
|
+
"\\^=",
|
|
63
|
+
// bitwise assignment
|
|
64
|
+
"<<=",
|
|
65
|
+
">>=",
|
|
66
|
+
">>>=",
|
|
67
|
+
// shift assignment
|
|
68
|
+
">>>",
|
|
69
|
+
">>",
|
|
70
|
+
"<<",
|
|
71
|
+
// shifts (longest first)
|
|
72
|
+
"\\.\\..",
|
|
73
|
+
// spread
|
|
74
|
+
// number literals
|
|
75
|
+
"0b[01]+",
|
|
76
|
+
// binary
|
|
77
|
+
"0x[0-9a-fA-F]+",
|
|
78
|
+
// hex
|
|
79
|
+
"\\d+(\\.\\d+)?",
|
|
80
|
+
// float
|
|
81
|
+
// identifiers
|
|
82
|
+
"[\\p{L}_][\\p{L}\\d_]*",
|
|
83
|
+
// single char
|
|
84
|
+
"[+\\-*/=()&^%$#@!<>?:~,|]",
|
|
85
|
+
"[\\[\\]{}]",
|
|
86
|
+
"[\\n;]",
|
|
87
|
+
"\\."
|
|
88
|
+
].join("|"), "gu");
|
|
89
|
+
const keywordSet = /* @__PURE__ */ new Set(["new", "const", "if", "else", "while", "continue", "break", "for", "in", "of", "function", "return", "import", "class", "extends", "inst", "internal", "try", "catch", "finally", "do", "switch", "case", "default"]);
|
|
90
|
+
const separatorSet = /* @__PURE__ */ new Set(["\n", ",", " ", ";"]);
|
|
91
|
+
const operatorSet = /* @__PURE__ */ new Set([
|
|
92
|
+
"...",
|
|
93
|
+
"??",
|
|
94
|
+
"&&",
|
|
95
|
+
"||",
|
|
96
|
+
"{",
|
|
97
|
+
"}",
|
|
98
|
+
"[",
|
|
99
|
+
"]",
|
|
100
|
+
"!=",
|
|
101
|
+
"<=",
|
|
102
|
+
">=",
|
|
103
|
+
"==",
|
|
104
|
+
"-=",
|
|
105
|
+
"+=",
|
|
106
|
+
"++",
|
|
107
|
+
"/=",
|
|
108
|
+
"*=",
|
|
109
|
+
"--",
|
|
110
|
+
"&=",
|
|
111
|
+
"|=",
|
|
112
|
+
"^=",
|
|
113
|
+
"<<=",
|
|
114
|
+
">>=",
|
|
115
|
+
">>>=",
|
|
116
|
+
">>>",
|
|
117
|
+
">>",
|
|
118
|
+
"<<",
|
|
119
|
+
"+",
|
|
120
|
+
"-",
|
|
121
|
+
"*",
|
|
122
|
+
"/",
|
|
123
|
+
"%",
|
|
124
|
+
"=",
|
|
125
|
+
"(",
|
|
126
|
+
")",
|
|
127
|
+
"&",
|
|
128
|
+
"^",
|
|
129
|
+
"!",
|
|
130
|
+
"<",
|
|
131
|
+
">",
|
|
132
|
+
"?",
|
|
133
|
+
":",
|
|
134
|
+
"~",
|
|
135
|
+
".",
|
|
136
|
+
"|"
|
|
137
|
+
]);
|
|
138
|
+
function getType(code) {
|
|
139
|
+
if (keywordSet.has(code))
|
|
140
|
+
return "Keyword";
|
|
141
|
+
if (separatorSet.has(code))
|
|
142
|
+
return "Separator";
|
|
143
|
+
if (operatorSet.has(code))
|
|
144
|
+
return "Operator";
|
|
145
|
+
if (/^["'`]/.test(code))
|
|
146
|
+
return "StringLiteral";
|
|
147
|
+
if (/^\d/.test(code))
|
|
148
|
+
return "Literal";
|
|
149
|
+
return "Identifier";
|
|
150
|
+
}
|
|
151
|
+
function tokenizer(code) {
|
|
152
|
+
const tokens = [];
|
|
153
|
+
const uid = Math.random().toString(36).slice(2);
|
|
154
|
+
const stringMeta = /* @__PURE__ */ new Map();
|
|
155
|
+
const out = [];
|
|
156
|
+
let row = 1;
|
|
157
|
+
let column = 1;
|
|
158
|
+
let i = 0;
|
|
159
|
+
let stringIndex = 0;
|
|
160
|
+
while (i < code.length) {
|
|
161
|
+
const character = code[i];
|
|
162
|
+
if (character === "#") {
|
|
163
|
+
while (i < code.length && code[i] !== "\n")
|
|
164
|
+
i++;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (character === "/" && code[i + 1] === "*") {
|
|
168
|
+
while (i < code.length && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
169
|
+
if (code[i] === "\n") {
|
|
170
|
+
row++;
|
|
171
|
+
column = 1;
|
|
172
|
+
}
|
|
173
|
+
i++;
|
|
174
|
+
}
|
|
175
|
+
i += 2;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if ((character === '"' || character === "\u201C" || character === "'" || character === "\u2018" || character === "`") && (i === 0 || !/[\p{L}\d]/u.test(code[i - 1]))) {
|
|
179
|
+
const quote = character === "\u201C" ? "\u201D" : character === "\u2018" ? "\u2019" : character;
|
|
180
|
+
const stringRow = row;
|
|
181
|
+
const stringColumn = column;
|
|
182
|
+
const start = i;
|
|
183
|
+
i++;
|
|
184
|
+
column++;
|
|
185
|
+
while (i < code.length && code[i] !== quote) {
|
|
186
|
+
const type = quote === "\u201D" ? "double" : "single";
|
|
187
|
+
const opening = type === "double" ? "\u201C" : "\u2018";
|
|
188
|
+
if (code[i] === "\u201C" && quote === "\u201D" || code[i] === "\u2018" && quote === "\u2019") {
|
|
189
|
+
const quoteCrimesMessage = quote_crimes.QuoteCrimesMessage(quote_crimes.incrementQuoteCrimes() - 1, opening) + " ";
|
|
190
|
+
throw new import_errors.Tokenizer(
|
|
191
|
+
quoteCrimesMessage + `Found: ${opening}...${opening}. Tip: Either match them or just use normal ${type} quotes`,
|
|
192
|
+
row,
|
|
193
|
+
column
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
if (code[i] === "\\") {
|
|
197
|
+
i += 2;
|
|
198
|
+
column += 2;
|
|
199
|
+
} else {
|
|
200
|
+
if (code[i] === "\n") {
|
|
201
|
+
row++;
|
|
202
|
+
column = 1;
|
|
203
|
+
} else
|
|
204
|
+
column++;
|
|
205
|
+
i++;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
i++;
|
|
209
|
+
column++;
|
|
210
|
+
const raw = code.slice(start, i);
|
|
211
|
+
const placeholder = `__STRING${uid}_${stringIndex++}__`;
|
|
212
|
+
stringMeta.set(
|
|
213
|
+
placeholder,
|
|
214
|
+
{
|
|
215
|
+
value: raw.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'").replace(/\\\\/g, "\\").replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\r/g, "\r"),
|
|
216
|
+
row: stringRow,
|
|
217
|
+
column: stringColumn
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
out.push(placeholder);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (character === "\n") {
|
|
224
|
+
row++;
|
|
225
|
+
column = 1;
|
|
226
|
+
} else
|
|
227
|
+
column++;
|
|
228
|
+
out.push(character);
|
|
229
|
+
i++;
|
|
230
|
+
}
|
|
231
|
+
const processed = out.join("");
|
|
232
|
+
row = 1;
|
|
233
|
+
column = 1;
|
|
234
|
+
let commented = false;
|
|
235
|
+
const matches = processed.matchAll(REGEX);
|
|
236
|
+
for (const match of matches) {
|
|
237
|
+
const value = match[0];
|
|
238
|
+
if (value === "\n") {
|
|
239
|
+
row++;
|
|
240
|
+
column = 1;
|
|
241
|
+
commented = false;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (value === "#") {
|
|
245
|
+
commented = true;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (commented || value === " ") {
|
|
249
|
+
column += value.length;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (value === ",") {
|
|
253
|
+
tokens.push(
|
|
254
|
+
{
|
|
255
|
+
type: "Separator",
|
|
256
|
+
value,
|
|
257
|
+
row,
|
|
258
|
+
column
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
column += value.length;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (stringMeta.has(value)) {
|
|
265
|
+
const meta = stringMeta.get(value);
|
|
266
|
+
tokens.push(
|
|
267
|
+
{
|
|
268
|
+
type: "StringLiteral",
|
|
269
|
+
value: meta.value,
|
|
270
|
+
row: meta.row,
|
|
271
|
+
column: meta.column
|
|
272
|
+
}
|
|
273
|
+
);
|
|
274
|
+
column += value.length;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const lines = value.split("\n");
|
|
278
|
+
if (lines.length > 1) {
|
|
279
|
+
row += lines.length - 1;
|
|
280
|
+
column = lines[lines.length - 1].length + 1;
|
|
281
|
+
}
|
|
282
|
+
tokens.push(
|
|
283
|
+
{
|
|
284
|
+
type: getType(value),
|
|
285
|
+
value,
|
|
286
|
+
row,
|
|
287
|
+
column
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
if (lines.length === 1)
|
|
291
|
+
column += value.length;
|
|
292
|
+
}
|
|
293
|
+
return tokens;
|
|
294
|
+
}
|
|
295
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
296
|
+
0 && (module.exports = {
|
|
297
|
+
tokenizer
|
|
298
|
+
});
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pure-dango",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A simple programming language built in JavaScript",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"src/core",
|
|
9
|
+
"src/runtime",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
8
12
|
"bin": {
|
|
9
13
|
"pure-dango": "src/index.ts"
|
|
10
14
|
},
|
|
11
15
|
"scripts": {
|
|
12
16
|
"dev": "tsx src/index.ts",
|
|
13
17
|
"prebuild": "node src/scripts/libs.cjs",
|
|
14
|
-
"build": "node src/scripts/build.js"
|
|
18
|
+
"build": "node src/scripts/build.js",
|
|
19
|
+
"build:lib": "esbuild src/core/tokenizer/tokenizer.ts src/core/parser/main.ts --bundle=false --format=cjs --outdir=dist/lib --platform=node"
|
|
15
20
|
},
|
|
16
21
|
"dependencies": {
|
|
17
22
|
"gmp-wasm": "^1.3.2"
|
|
@@ -41,5 +46,11 @@
|
|
|
41
46
|
"node22-linux-x64",
|
|
42
47
|
"node22-linux-arm64"
|
|
43
48
|
]
|
|
49
|
+
},
|
|
50
|
+
"main": "./dist/PureDango.cjs",
|
|
51
|
+
"exports": {
|
|
52
|
+
".": "./dist/PureDango.cjs",
|
|
53
|
+
"./src/core/tokenizer/tokenizer.js": "./dist/lib/tokenizer.js",
|
|
54
|
+
"./src/core/parser/main.js": "./dist/lib/main.js"
|
|
44
55
|
}
|
|
45
|
-
}
|
|
56
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ const
|
|
|
38
38
|
const packageJson =
|
|
39
39
|
{
|
|
40
40
|
name: typeof PACKAGE_NAME !== "undefined" ? PACKAGE_NAME : "pure-dango",
|
|
41
|
-
version: typeof PACKAGE_VERSION !== "undefined" ? PACKAGE_VERSION : "1.8.
|
|
41
|
+
version: typeof PACKAGE_VERSION !== "undefined" ? PACKAGE_VERSION : "1.8.1",
|
|
42
42
|
description: typeof PACKAGE_DESCRIPTION !== "undefined" ? PACKAGE_DESCRIPTION : "A simple programming language built in JavaScript"
|
|
43
43
|
};
|
|
44
44
|
|