godot-export-presets 0.1.0 → 0.1.5
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/index.cjs +124 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/dist/index.cjs
CHANGED
|
@@ -86,8 +86,14 @@ function get_token(stream) {
|
|
|
86
86
|
return { type: "PARENTHESIS_OPEN", value: c, line };
|
|
87
87
|
case ")":
|
|
88
88
|
return { type: "PARENTHESIS_CLOSE", value: c, line };
|
|
89
|
+
case "{":
|
|
90
|
+
return { type: "CURLY_BRACKET_OPEN", value: c, line };
|
|
91
|
+
case "}":
|
|
92
|
+
return { type: "CURLY_BRACKET_CLOSE", value: c, line };
|
|
89
93
|
case "=":
|
|
90
94
|
return { type: "EQUAL", value: c, line };
|
|
95
|
+
case ":":
|
|
96
|
+
return { type: "COLON", value: c, line };
|
|
91
97
|
case ",":
|
|
92
98
|
return { type: "COMMA", value: c, line };
|
|
93
99
|
case ";":
|
|
@@ -229,6 +235,115 @@ function parse_construct_args(stream) {
|
|
|
229
235
|
}
|
|
230
236
|
return args;
|
|
231
237
|
}
|
|
238
|
+
function parse_string_construct_args(stream) {
|
|
239
|
+
const args = [];
|
|
240
|
+
let token = get_token(stream);
|
|
241
|
+
if (token.type !== "PARENTHESIS_OPEN") {
|
|
242
|
+
throw new ParseError("Expected '(' in constructor", token.line);
|
|
243
|
+
}
|
|
244
|
+
let first = true;
|
|
245
|
+
while (true) {
|
|
246
|
+
if (!first) {
|
|
247
|
+
token = get_token(stream);
|
|
248
|
+
if (token.type === "COMMA") ; else if (token.type === "PARENTHESIS_CLOSE") {
|
|
249
|
+
break;
|
|
250
|
+
} else {
|
|
251
|
+
throw new ParseError("Expected ',' or ')' in constructor", token.line);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
token = get_token(stream);
|
|
255
|
+
if (first && token.type === "PARENTHESIS_CLOSE") {
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
if (token.type === "STRING") {
|
|
259
|
+
args.push(token.value);
|
|
260
|
+
} else {
|
|
261
|
+
throw new ParseError("Expected string in constructor", token.line);
|
|
262
|
+
}
|
|
263
|
+
first = false;
|
|
264
|
+
}
|
|
265
|
+
return args;
|
|
266
|
+
}
|
|
267
|
+
function parse_dictionary(stream) {
|
|
268
|
+
const dict = {};
|
|
269
|
+
let needComma = false;
|
|
270
|
+
while (true) {
|
|
271
|
+
if (stream.is_eof()) {
|
|
272
|
+
throw new ParseError("Unexpected EOF while parsing dictionary", stream.get_line());
|
|
273
|
+
}
|
|
274
|
+
while (true) {
|
|
275
|
+
const peek = stream.peek_char();
|
|
276
|
+
if (is_whitespace(peek)) {
|
|
277
|
+
stream.get_char();
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
if (stream.peek_char() === "}") {
|
|
283
|
+
get_token(stream);
|
|
284
|
+
return dict;
|
|
285
|
+
}
|
|
286
|
+
if (needComma) {
|
|
287
|
+
const token = get_token(stream);
|
|
288
|
+
if (token.type !== "COMMA") {
|
|
289
|
+
throw new ParseError("Expected '}' or ','", token.line);
|
|
290
|
+
}
|
|
291
|
+
needComma = false;
|
|
292
|
+
}
|
|
293
|
+
const keyToken = get_token(stream);
|
|
294
|
+
let key;
|
|
295
|
+
if (keyToken.type === "STRING") {
|
|
296
|
+
key = keyToken.value;
|
|
297
|
+
} else if (keyToken.type === "NUMBER") {
|
|
298
|
+
key = keyToken.value;
|
|
299
|
+
} else if (keyToken.type === "BOOLEAN") {
|
|
300
|
+
key = keyToken.value;
|
|
301
|
+
} else if (keyToken.type === "IDENTIFIER") {
|
|
302
|
+
key = keyToken.value;
|
|
303
|
+
} else {
|
|
304
|
+
throw new ParseError("Expected dictionary key", keyToken.line);
|
|
305
|
+
}
|
|
306
|
+
const colonToken = get_token(stream);
|
|
307
|
+
if (colonToken.type !== "COLON") {
|
|
308
|
+
throw new ParseError("Expected ':' after dictionary key", colonToken.line);
|
|
309
|
+
}
|
|
310
|
+
const value = parse_value(stream);
|
|
311
|
+
const keyStr = String(key);
|
|
312
|
+
dict[keyStr] = value;
|
|
313
|
+
needComma = true;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function parse_array(stream) {
|
|
317
|
+
const arr = [];
|
|
318
|
+
let needComma = false;
|
|
319
|
+
while (true) {
|
|
320
|
+
if (stream.is_eof()) {
|
|
321
|
+
throw new ParseError("Unexpected EOF while parsing array", stream.get_line());
|
|
322
|
+
}
|
|
323
|
+
while (true) {
|
|
324
|
+
const peek = stream.peek_char();
|
|
325
|
+
if (is_whitespace(peek)) {
|
|
326
|
+
stream.get_char();
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
if (stream.peek_char() === "]") {
|
|
332
|
+
get_token(stream);
|
|
333
|
+
return arr;
|
|
334
|
+
}
|
|
335
|
+
if (needComma) {
|
|
336
|
+
const token = get_token(stream);
|
|
337
|
+
if (token.type !== "COMMA") {
|
|
338
|
+
throw new ParseError("Expected ']' or ','", token.line);
|
|
339
|
+
}
|
|
340
|
+
needComma = false;
|
|
341
|
+
}
|
|
342
|
+
const value = parse_value(stream);
|
|
343
|
+
arr.push(value);
|
|
344
|
+
needComma = true;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
232
347
|
function parse_value(stream) {
|
|
233
348
|
const token = get_token(stream);
|
|
234
349
|
switch (token.type) {
|
|
@@ -238,6 +353,12 @@ function parse_value(stream) {
|
|
|
238
353
|
return token.value;
|
|
239
354
|
case "BOOLEAN":
|
|
240
355
|
return token.value;
|
|
356
|
+
case "BRACKET_OPEN": {
|
|
357
|
+
return parse_array(stream);
|
|
358
|
+
}
|
|
359
|
+
case "CURLY_BRACKET_OPEN": {
|
|
360
|
+
return parse_dictionary(stream);
|
|
361
|
+
}
|
|
241
362
|
case "IDENTIFIER": {
|
|
242
363
|
const ident = token.value;
|
|
243
364
|
if (ident === "Color") {
|
|
@@ -252,6 +373,9 @@ function parse_value(stream) {
|
|
|
252
373
|
throw new ParseError("Expected 2 arguments for Vector2 constructor", token.line);
|
|
253
374
|
}
|
|
254
375
|
return { x: args[0], y: args[1] };
|
|
376
|
+
} else if (ident === "PackedStringArray" || ident === "PoolStringArray" || ident === "StringArray") {
|
|
377
|
+
const args = parse_string_construct_args(stream);
|
|
378
|
+
return args;
|
|
255
379
|
} else {
|
|
256
380
|
throw new ParseError(`Unknown identifier: ${ident}`, token.line);
|
|
257
381
|
}
|