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