plainscript-lang 1.0.0 → 1.0.2-latest

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.
Files changed (106) hide show
  1. package/README.md +194 -729
  2. package/compiler/bundler.js +2 -2
  3. package/compiler/cli.js +182 -79
  4. package/compiler/dependency-detector.js +5 -0
  5. package/compiler/formatter.js +1 -1
  6. package/compiler/generator.js +1083 -206
  7. package/compiler/lexer.js +130 -54
  8. package/compiler/parser.js +1117 -156
  9. package/compiler/version.js +1 -1
  10. package/docs/CAPABILITY_GAP_AUDIT.md +98 -435
  11. package/docs/PLAINSCRIPT-SPEC.md +335 -0
  12. package/docs/index.html +103 -605
  13. package/docs/website/script.js +59 -943
  14. package/docs/website/style.css +74 -656
  15. package/examples/ai-providers.pln +7 -0
  16. package/examples/arrays.pln +4 -0
  17. package/examples/async-errors.pln +18 -0
  18. package/examples/auth-api.pln +9 -0
  19. package/examples/auth-sessions.pln +32 -0
  20. package/examples/basics.pln +14 -0
  21. package/examples/bots.pln +13 -0
  22. package/examples/cache-and-jobs.pln +7 -0
  23. package/examples/cache-schedule.pln +22 -0
  24. package/examples/collections.pln +15 -0
  25. package/examples/concurrency.pln +18 -0
  26. package/examples/conditions.pln +22 -0
  27. package/examples/database.pln +8 -0
  28. package/examples/day2.pln +7 -0
  29. package/examples/day3.pln +5 -0
  30. package/examples/deployment.pln +6 -0
  31. package/examples/email-send.pln +3 -0
  32. package/examples/error-handling.pln +7 -0
  33. package/examples/expressions.pln +7 -0
  34. package/examples/file-uploads.pln +10 -0
  35. package/examples/files-and-config.pln +6 -0
  36. package/examples/files.pln +12 -0
  37. package/examples/football-backend/{app.ps → app.pln} +22 -21
  38. package/examples/functions.pln +17 -0
  39. package/examples/hello.pln +2 -0
  40. package/examples/http-client.pln +3 -0
  41. package/examples/http.pln +11 -0
  42. package/examples/id-verification/{app.ps → app.pln} +5 -4
  43. package/examples/id-verification/make-sample-id.js +29 -42
  44. package/examples/json.pln +11 -0
  45. package/examples/loops.pln +18 -0
  46. package/examples/modules/app.pln +3 -0
  47. package/examples/modules/main.pln +4 -0
  48. package/examples/modules/math.pln +9 -0
  49. package/examples/mongo.pln +33 -0
  50. package/examples/objects.pln +4 -0
  51. package/examples/ocr.pln +22 -0
  52. package/examples/packages.pln +6 -0
  53. package/examples/record-kinds.pln +7 -0
  54. package/examples/records.pln +15 -0
  55. package/examples/rest-api-fetch.pln +10 -0
  56. package/examples/rest-api.pln +8 -0
  57. package/examples/scheduled-tasks.pln +4 -0
  58. package/examples/search-and-filter.pln +4 -0
  59. package/examples/server.pln +6 -0
  60. package/examples/sessions-and-cookies.pln +8 -0
  61. package/examples/sqlite.pln +23 -0
  62. package/examples/start.pln +2 -0
  63. package/examples/stdlib.pln +4 -0
  64. package/examples/telegram-ai-bot.pln +19 -0
  65. package/examples/telegram-bot.pln +6 -0
  66. package/examples/testing.pln +13 -0
  67. package/examples/web-api.pln +27 -0
  68. package/examples/web-app.pln +8 -0
  69. package/examples/websocket-server.pln +6 -0
  70. package/examples/websocket.pln +13 -0
  71. package/examples/whatsapp-bot/{pairing.ps → pairing.pln} +4 -5
  72. package/examples/whatsapp-bot/qr.pln +12 -0
  73. package/package.json +3 -2
  74. package/docs/PLINJS_SPEC.md +0 -1151
  75. package/examples/arrays.ps +0 -13
  76. package/examples/auth-api.ps +0 -56
  77. package/examples/cache-and-jobs.ps +0 -29
  78. package/examples/concurrency.ps +0 -49
  79. package/examples/database.ps +0 -41
  80. package/examples/day2.ps +0 -7
  81. package/examples/day3.ps +0 -11
  82. package/examples/deployment.ps +0 -12
  83. package/examples/email-send.ps +0 -22
  84. package/examples/error-handling.ps +0 -54
  85. package/examples/expressions.ps +0 -40
  86. package/examples/file-uploads.ps +0 -39
  87. package/examples/files-and-config.ps +0 -47
  88. package/examples/hello.ps +0 -3
  89. package/examples/http-client.ps +0 -44
  90. package/examples/loops.ps +0 -17
  91. package/examples/modules/app.ps +0 -16
  92. package/examples/modules/math.ps +0 -20
  93. package/examples/objects.ps +0 -12
  94. package/examples/record-kinds.ps +0 -43
  95. package/examples/rest-api-fetch.ps +0 -94
  96. package/examples/rest-api.ps +0 -68
  97. package/examples/scheduled-tasks.ps +0 -23
  98. package/examples/search-and-filter.ps +0 -34
  99. package/examples/server.ps +0 -25
  100. package/examples/sessions-and-cookies.ps +0 -54
  101. package/examples/start.ps +0 -2
  102. package/examples/stdlib.ps +0 -41
  103. package/examples/telegram-bot.ps +0 -42
  104. package/examples/web-app.ps +0 -20
  105. package/examples/websocket-server.ps +0 -27
  106. package/examples/whatsapp-bot/qr.ps +0 -8
package/compiler/lexer.js CHANGED
@@ -4,33 +4,55 @@
4
4
  const TOKEN = {
5
5
  // Core keywords (v0.1–v0.4)
6
6
  REMEMBER: 'REMEMBER',
7
+ LET: 'LET', // alias for remember: "let x is 5"
7
8
  SHOW: 'SHOW',
9
+ PRINT: 'PRINT', // alias for show
10
+ DISPLAY: 'DISPLAY', // alias for show
8
11
  AS: 'AS',
12
+ IS: 'IS', // used for both "let x is 5" and comparisons
9
13
  IF: 'IF',
10
14
  OTHERWISE: 'OTHERWISE',
15
+ ELSE: 'ELSE', // alias for otherwise
11
16
  DONE: 'DONE',
12
- IS: 'IS',
17
+ END: 'END', // alias for done
13
18
  GREATER: 'GREATER',
14
19
  LESS: 'LESS',
15
20
  THAN: 'THAN',
16
21
  MAKE: 'MAKE',
22
+ DEFINE: 'DEFINE', // alias for make: "define add(a, b)"
23
+ FUNCTION: 'FUNCTION', // alias for make: "function add(a, b)"
17
24
  GIVE: 'GIVE',
25
+ RETURN: 'RETURN', // alias for give
26
+ GIVE_BACK: 'GIVE_BACK', // alias for give: "give back a + b"
18
27
  BECOMES: 'BECOMES',
28
+ IS_NOW: 'IS_NOW', // alias for becomes: "x is now 10"
29
+ SET_TO: 'SET_TO', // alias for becomes: "set x to 10"
30
+ CHANGE_TO: 'CHANGE_TO', // alias for becomes: "change x to 10"
19
31
  FOR: 'FOR',
20
- EACH: 'EACH', // also used for "every" alias
32
+ EACH: 'EACH', // also used for "every" alias
33
+ EVERY: 'EVERY', // alias: "for every item in list"
21
34
  IN: 'IN',
22
35
  WHILE: 'WHILE',
23
36
  USE: 'USE',
24
37
  IMPORT: 'IMPORT',
38
+ INCLUDE: 'INCLUDE', // alias for import: "include "./file.pln""
39
+ LOAD: 'LOAD', // alias for import: "load "./file.pln""
25
40
  // v0.3 — Express runtime
26
41
  WHEN: 'WHEN',
27
42
  SOMEONE: 'SOMEONE',
28
43
  VISITS: 'VISITS',
29
44
  LISTEN: 'LISTEN',
45
+ START_ON: 'START_ON', // alias for listen: "start on port 3000"
46
+ SERVE_ON: 'SERVE_ON', // alias for listen: "serve on port 3000"
30
47
  ON: 'ON',
31
48
  REPLY: 'REPLY',
49
+ RESPOND: 'RESPOND', // alias for reply
50
+ SEND_BACK: 'SEND_BACK', // alias for reply
32
51
  JSON_KW: 'JSON_KW',
52
+ FILE_KW: 'FILE_KW', // for "reply file" and "serve file"
33
53
  SERVE: 'SERVE',
54
+ SERVE_STATIC: 'SERVE_STATIC', // alias for serve folder
55
+ SERVE_PUBLIC: 'SERVE_PUBLIC', // alias for serve folder
34
56
  FOLDER: 'FOLDER',
35
57
  // v0.6 — Extended comparisons
36
58
  ABOVE: 'ABOVE',
@@ -41,28 +63,32 @@ const TOKEN = {
41
63
  NOT: 'NOT',
42
64
  EMPTY: 'EMPTY',
43
65
  CONTAINS: 'CONTAINS',
66
+ NOW: 'NOW', // for "is now" assignment
67
+ BACK: 'BACK', // for "give back" return
44
68
  STARTS: 'STARTS',
45
69
  ENDS: 'ENDS',
46
70
  WITH: 'WITH',
47
71
  BETWEEN: 'BETWEEN',
48
72
  AND: 'AND',
49
- OR: 'OR', // v2.1.1 — logical or in conditions
73
+ OR: 'OR', // v2.1.1 — logical or in conditions
74
+ INSTANCEOF: 'INSTANCEOF', // v1.0.2 — instanceof condition
50
75
  // v0.6 — Express DX
51
76
  WEB: 'WEB',
52
77
  ROUTE_KW: 'ROUTE_KW',
53
78
  START_KW: 'START_KW',
79
+ RUN_ON: 'RUN_ON', // alias for start: "run on port 3000"
54
80
  // v0.6 — SQLite DX
55
81
  DATABASE_KW: 'DATABASE_KW',
82
+ CONNECT_DB: 'CONNECT_DB', // alias for database: "connect database "app.db""
83
+ USE_DATABASE: 'USE_DATABASE', // alias for database: "use database "app.db""
56
84
  QUERY_KW: 'QUERY_KW',
57
85
  INSERT_KW: 'INSERT_KW',
58
86
  UPDATE_KW: 'UPDATE_KW',
59
87
  DELETE_KW: 'DELETE_KW',
60
88
  EXECUTE_KW: 'EXECUTE_KW',
61
- SQL_BODY: 'SQL_BODY', // raw SQL collected between a block keyword and "done"
62
- // v1.1.1 — JavaScript Gateway (RFC-0011)
63
- JAVASCRIPT_KW: 'JAVASCRIPT_KW', // the "javascript" keyword introducing a raw JS block
64
- JS_BODY: 'JS_BODY', // raw JavaScript collected between "javascript" and "done"
89
+ SQL_BODY: 'SQL_BODY', // raw SQL collected between a block keyword and "done"
65
90
  ASK: 'ASK', // interactive input: ask name / ask "prompt" as name
91
+ PROMPT: 'PROMPT', // alias for ask: 'prompt "name?" as name'
66
92
  OCR_KW: 'OCR_KW', // v2.0.1 — ocr "<image>" as <name> [using "<lang>"]
67
93
  PACKAGE: 'PACKAGE', // bare npm package name after "use" (may contain -, _, ., /, @)
68
94
  GATHER: 'GATHER', // gather each item in list giving expr (functional map)
@@ -76,9 +102,20 @@ const TOKEN = {
76
102
  EMIT: 'EMIT', // emit "event.name" with data (event emitter)
77
103
  HAPPENS: 'HAPPENS', // when "event.name" happens as data (event listener)
78
104
  CATCHES: 'CATCHES', // recover when err catches "TypeError" (typed error recovery)
79
- // v1.0.0 — generators. "yield" is a JavaScript reserved word, so it becomes a
105
+ // v1.0.1 — generators. "yield" is a JavaScript reserved word, so it becomes a
80
106
  // real keyword token (a variable named `yield` is illegal in JS anyway).
81
107
  YIELD: 'YIELD',
108
+ // v2.3 — English-like syntax keywords
109
+ TO: 'TO', // "to add a and b together" function syntax
110
+ TOGETHER: 'TOGETHER', // function block terminator alternative
111
+ BE: 'BE', // "let x be 5" alternative to "let x is 5"
112
+ THEN: 'THEN', // "when ... then" alternative
113
+ PLUS_WORD: 'PLUS_WORD', // "a plus b" alternative to "a + b"
114
+ MINUS_WORD: 'MINUS_WORD', // "a minus b" alternative to "a - b"
115
+ TIMES_WORD: 'TIMES_WORD', // "a times b" alternative to "a * b"
116
+ DIVIDED_BY_WORD: 'DIVIDED_BY_WORD', // "a divided by b" alternative to "a / b"
117
+ LIST_WITH: 'LIST_WITH', // "list with 1, 2, 3" alternative to "[1, 2, 3]"
118
+ RECORD_WITH: 'RECORD_WITH', // "record with name 'Alice'" alternative to object literal
82
119
  // Punctuation
83
120
  LBRACE: 'LBRACE', // { — inline object literal (v1.2)
84
121
  RBRACE: 'RBRACE', // }
@@ -90,11 +127,19 @@ const TOKEN = {
90
127
  RBRACKET: 'RBRACKET',
91
128
  COMMA: 'COMMA',
92
129
  DOT: 'DOT',
130
+ OPTIONAL_CHAIN: 'OPTIONAL_CHAIN', // ?. — optional chaining
131
+ NULLISH_COALESCE: 'NULLISH_COALESCE', // ?? — nullish coalescing
132
+ POWER: 'POWER', // ** — exponentiation
93
133
  PLUS: 'PLUS',
94
134
  MINUS: 'MINUS', // v2.1.1 — subtraction / unary minus
95
135
  STAR: 'STAR', // v2.1.1 — multiplication
96
136
  SLASH: 'SLASH', // v2.1.1 — division
97
137
  PERCENT: 'PERCENT', // v2.1.1 — remainder (modulo)
138
+ SPREAD: 'SPREAD', // ... — spread operator
139
+ REST: 'REST', // ... — rest parameter
140
+ LOGICAL_OR_ASSIGN: 'LOGICAL_OR_ASSIGN', // ||=
141
+ LOGICAL_AND_ASSIGN: 'LOGICAL_AND_ASSIGN', // &&=
142
+ NULLISH_ASSIGN: 'NULLISH_ASSIGN', // ??=
98
143
  // Literals & identifiers
99
144
  IDENTIFIER: 'IDENTIFIER',
100
145
  STRING: 'STRING',
@@ -102,7 +147,17 @@ const TOKEN = {
102
147
  TRUE_KW: 'TRUE_KW', // v2.1.1 — boolean literal true
103
148
  FALSE_KW: 'FALSE_KW', // v2.1.1 — boolean literal false
104
149
  NULL_KW: 'NULL_KW', // v2.1.1 — null literal
150
+ UNDEFINED_KW: 'UNDEFINED_KW', // v2.2.0 — undefined literal
151
+ BIGINT: 'BIGINT', // BigInt literal (e.g., 42n)
105
152
  TEMPLATE_STRING: 'TEMPLATE_STRING', // backtick-delimited string with interpolation
153
+ SYMBOL_KW: 'SYMBOL_KW', // symbol keyword
154
+ DEBUGGER_KW: 'DEBUGGER_KW', // debugger keyword
155
+ IMPORT_META: 'IMPORT_META', // import.meta
156
+ // v2.4 — Near-English intent-oriented syntax (single-word keywords)
157
+ RAISES: 'RAISES', // "raise expr" throw alternative
158
+ CHOOSING: 'CHOOSING', // "choosing cond then a otherwise b" ternary
159
+ USES: 'USES', // "x uses a, b together" function call
160
+ FILLS: 'FILLS', // "fill x with a, b together" function call
106
161
  // End of input
107
162
  EOF: 'EOF',
108
163
  };
@@ -110,18 +165,30 @@ const TOKEN = {
110
165
  const KEYWORDS = {
111
166
  // Core
112
167
  remember: TOKEN.REMEMBER,
168
+ let: TOKEN.LET,
113
169
  show: TOKEN.SHOW,
170
+ print: TOKEN.PRINT,
171
+ display: TOKEN.DISPLAY,
114
172
  as: TOKEN.AS,
173
+ is: TOKEN.IS,
115
174
  if: TOKEN.IF,
116
175
  otherwise: TOKEN.OTHERWISE,
176
+ else: TOKEN.ELSE,
117
177
  done: TOKEN.DONE,
118
- is: TOKEN.IS,
178
+ end: TOKEN.END,
119
179
  greater: TOKEN.GREATER,
120
180
  less: TOKEN.LESS,
121
181
  than: TOKEN.THAN,
122
182
  make: TOKEN.MAKE,
183
+ define: TOKEN.DEFINE,
184
+ function: TOKEN.FUNCTION,
123
185
  give: TOKEN.GIVE,
186
+ return: TOKEN.RETURN,
187
+ give_back: TOKEN.GIVE_BACK,
124
188
  becomes: TOKEN.BECOMES,
189
+ is_now: TOKEN.IS_NOW,
190
+ set_to: TOKEN.SET_TO,
191
+ change_to: TOKEN.CHANGE_TO,
125
192
  for: TOKEN.FOR,
126
193
  each: TOKEN.EACH,
127
194
  every: TOKEN.EACH, // alias: "for every" = "for each"
@@ -129,15 +196,24 @@ const KEYWORDS = {
129
196
  while: TOKEN.WHILE,
130
197
  use: TOKEN.USE,
131
198
  import: TOKEN.IMPORT,
199
+ include: TOKEN.INCLUDE,
200
+ load: TOKEN.LOAD,
132
201
  // v0.3
133
202
  when: TOKEN.WHEN,
134
203
  someone: TOKEN.SOMEONE,
135
204
  visits: TOKEN.VISITS,
136
205
  listen: TOKEN.LISTEN,
206
+ start_on: TOKEN.START_ON,
207
+ serve_on: TOKEN.SERVE_ON,
137
208
  on: TOKEN.ON,
138
209
  reply: TOKEN.REPLY,
210
+ respond: TOKEN.RESPOND,
211
+ send_back: TOKEN.SEND_BACK,
139
212
  json: TOKEN.JSON_KW,
213
+ file: TOKEN.FILE_KW,
140
214
  serve: TOKEN.SERVE,
215
+ serve_static: TOKEN.SERVE_STATIC,
216
+ serve_public: TOKEN.SERVE_PUBLIC,
141
217
  folder: TOKEN.FOLDER,
142
218
  // v0.6 — comparisons
143
219
  above: TOKEN.ABOVE,
@@ -154,21 +230,27 @@ const KEYWORDS = {
154
230
  between: TOKEN.BETWEEN,
155
231
  and: TOKEN.AND,
156
232
  or: TOKEN.OR,
233
+ instanceof: TOKEN.INSTANCEOF,
234
+ now: TOKEN.NOW,
235
+ back: TOKEN.BACK,
157
236
  // v2.1.1 — literal keywords. These were previously plain identifiers that
158
237
  // passed through to generated JavaScript; making them explicit tokens gives
159
238
  // them first-class AST nodes and deterministic diagnostics.
160
239
  true: TOKEN.TRUE_KW,
161
240
  false: TOKEN.FALSE_KW,
162
241
  null: TOKEN.NULL_KW,
242
+ undefined: TOKEN.UNDEFINED_KW,
163
243
  // v0.6 — Express DX
164
244
  web: TOKEN.WEB,
165
245
  route: TOKEN.ROUTE_KW,
166
246
  start: TOKEN.START_KW,
247
+ run_on: TOKEN.RUN_ON,
167
248
  // v0.6 — SQLite DX
168
249
  database: TOKEN.DATABASE_KW,
169
- // v1.1.1 — JavaScript Gateway (RFC-0011)
170
- javascript: TOKEN.JAVASCRIPT_KW,
250
+ connect_db: TOKEN.CONNECT_DB,
251
+ use_database: TOKEN.USE_DATABASE,
171
252
  ask: TOKEN.ASK,
253
+ prompt: TOKEN.PROMPT,
172
254
  // v2.0.1 — OCR capability
173
255
  ocr: TOKEN.OCR_KW,
174
256
  // IOPL-native features
@@ -184,6 +266,25 @@ const KEYWORDS = {
184
266
  happens: TOKEN.HAPPENS,
185
267
  catches: TOKEN.CATCHES,
186
268
  yield: TOKEN.YIELD,
269
+ symbol: TOKEN.SYMBOL_KW,
270
+ debugger: TOKEN.DEBUGGER_KW,
271
+ // v2.3 — English-like syntax keywords
272
+ to: TOKEN.TO,
273
+ together: TOKEN.TOGETHER,
274
+ be: TOKEN.BE,
275
+ then: TOKEN.THEN,
276
+ plus: TOKEN.PLUS_WORD,
277
+ minus: TOKEN.MINUS_WORD,
278
+ times: TOKEN.TIMES_WORD,
279
+ divided_by: TOKEN.DIVIDED_BY_WORD,
280
+ list_with: TOKEN.LIST_WITH,
281
+ record_with: TOKEN.RECORD_WITH,
282
+ // v2.4 — Near-English intent-oriented syntax (single-word keywords)
283
+ raise: TOKEN.RAISES,
284
+ raises: TOKEN.RAISES,
285
+ choosing: TOKEN.CHOOSING,
286
+ uses: TOKEN.USES,
287
+ fills: TOKEN.FILLS,
187
288
  };
188
289
 
189
290
  // Keywords that introduce raw SQL blocks (content up to "done" is collected verbatim).
@@ -310,11 +411,17 @@ function tokenize(source) {
310
411
  continue;
311
412
  }
312
413
 
313
- // Number literal (may include decimal point)
414
+ // Number literal (may include decimal point or BigInt suffix 'n')
314
415
  if (/[0-9]/.test(source[i])) {
315
416
  let num = '';
316
417
  while (i < source.length && /[0-9.]/.test(source[i])) num += source[i++];
317
- tokens.push({ type: TOKEN.NUMBER, value: Number(num), line: tokenLine, col: tokenCol });
418
+ // Check for BigInt suffix
419
+ if (i < source.length && source[i] === 'n') {
420
+ i++; // consume 'n'
421
+ tokens.push({ type: TOKEN.BIGINT, value: BigInt(num), line: tokenLine, col: tokenCol });
422
+ } else {
423
+ tokens.push({ type: TOKEN.NUMBER, value: Number(num), line: tokenLine, col: tokenCol });
424
+ }
318
425
  continue;
319
426
  }
320
427
 
@@ -363,47 +470,6 @@ function tokenize(source) {
363
470
  continue;
364
471
  }
365
472
 
366
- // "javascript" introduces a raw JavaScript block: collect every line
367
- // verbatim until a line whose trimmed content is exactly "done".
368
- // This mirrors the SQL block behaviour so the lexer never has to
369
- // understand the JavaScript grammar inside the block.
370
- if (word === 'javascript') {
371
- tokens.push({ type: TOKEN.JAVASCRIPT_KW, value: word, line: tokenLine, col: tokenCol });
372
-
373
- let j = i;
374
- while (j < source.length && (source[j] === ' ' || source[j] === '\t')) j++;
375
-
376
- if (j >= source.length || source[j] === '\n' || source[j] === '\r') {
377
- // Raw block mode — advance past the newline and collect until "done"
378
- i = j;
379
- if (i < source.length && source[i] === '\n') { i++; line++; lineStart = i; }
380
-
381
- let js = '';
382
- while (i < source.length) {
383
- const lineEnd = source.indexOf('\n', i);
384
- const realEnd = lineEnd === -1 ? source.length : lineEnd;
385
- const lineText = source.slice(i, realEnd);
386
- const trimmed = lineText.trim();
387
-
388
- if (trimmed === 'done') {
389
- i = realEnd < source.length ? realEnd + 1 : realEnd;
390
- if (realEnd < source.length) { line++; lineStart = i; }
391
- break;
392
- }
393
-
394
- js += lineText + '\n';
395
- i = realEnd < source.length ? realEnd + 1 : realEnd;
396
- if (realEnd < source.length) { line++; lineStart = i; }
397
- }
398
-
399
- tokens.push({ type: TOKEN.JS_BODY, value: js.trimEnd(), line: tokenLine, col: tokenCol });
400
- tokens.push({ type: TOKEN.DONE, value: 'done', line, col: col() });
401
- }
402
- // else: "javascript" on its own line is followed by a value —
403
- // parsed normally by the parser (used as a remembered value).
404
- continue;
405
- }
406
-
407
473
  const type = Object.prototype.hasOwnProperty.call(KEYWORDS, word)
408
474
  ? KEYWORDS[word]
409
475
  : TOKEN.IDENTIFIER;
@@ -421,14 +487,24 @@ function tokenize(source) {
421
487
  if (source[i] === '[') { tokens.push({ type: TOKEN.LBRACKET, value: '[', line: tokenLine, col: tokenCol }); i++; continue; }
422
488
  if (source[i] === ']') { tokens.push({ type: TOKEN.RBRACKET, value: ']', line: tokenLine, col: tokenCol }); i++; continue; }
423
489
  if (source[i] === ',') { tokens.push({ type: TOKEN.COMMA, value: ',', line: tokenLine, col: tokenCol }); i++; continue; }
490
+ if (source[i] === '?' && source[i + 1] === '.') { tokens.push({ type: TOKEN.OPTIONAL_CHAIN, value: '?.', line: tokenLine, col: tokenCol }); i += 2; continue; }
491
+ if (source[i] === '?' && source[i + 1] === '?' && source[i + 2] === '=') { tokens.push({ type: TOKEN.NULLISH_ASSIGN, value: '??=', line: tokenLine, col: tokenCol }); i += 3; continue; }
492
+ if (source[i] === '?' && source[i + 1] === '?') { tokens.push({ type: TOKEN.NULLISH_COALESCE, value: '??', line: tokenLine, col: tokenCol }); i += 2; continue; }
493
+ if (source[i] === '.' && source[i + 1] === '.' && source[i + 2] === '.') { tokens.push({ type: TOKEN.SPREAD, value: '...', line: tokenLine, col: tokenCol }); i += 3; continue; }
424
494
  if (source[i] === '.') { tokens.push({ type: TOKEN.DOT, value: '.', line: tokenLine, col: tokenCol }); i++; continue; }
495
+ if (source[i] === '+' && source[i + 1] === '+' && source[i + 2] === '=') { tokens.push({ type: TOKEN.LOGICAL_AND_ASSIGN, value: '++=', line: tokenLine, col: tokenCol }); i += 3; continue; }
425
496
  if (source[i] === '+') { tokens.push({ type: TOKEN.PLUS, value: '+', line: tokenLine, col: tokenCol }); i++; continue; }
426
497
  // v2.1.1 — arithmetic. "->" is matched first so it never becomes MINUS.
427
498
  if (source[i] === '-' && source[i + 1] === '>') { tokens.push({ type: TOKEN.ARROW, value: '->', line: tokenLine, col: tokenCol }); i += 2; continue; }
428
499
  if (source[i] === '-') { tokens.push({ type: TOKEN.MINUS, value: '-', line: tokenLine, col: tokenCol }); i++; continue; }
500
+ if (source[i] === '*' && source[i + 1] === '*') { tokens.push({ type: TOKEN.POWER, value: '**', line: tokenLine, col: tokenCol }); i += 2; continue; }
429
501
  if (source[i] === '*') { tokens.push({ type: TOKEN.STAR, value: '*', line: tokenLine, col: tokenCol }); i++; continue; }
430
502
  if (source[i] === '/') { tokens.push({ type: TOKEN.SLASH, value: '/', line: tokenLine, col: tokenCol }); i++; continue; }
431
503
  if (source[i] === '%') { tokens.push({ type: TOKEN.PERCENT, value: '%', line: tokenLine, col: tokenCol }); i++; continue; }
504
+ if (source[i] === '|' && source[i + 1] === '|' && source[i + 2] === '=') { tokens.push({ type: TOKEN.LOGICAL_OR_ASSIGN, value: '||=', line: tokenLine, col: tokenCol }); i += 3; continue; }
505
+ if (source[i] === '&' && source[i + 1] === '&' && source[i + 2] === '=') { tokens.push({ type: TOKEN.LOGICAL_AND_ASSIGN, value: '&&=', line: tokenLine, col: tokenCol }); i += 3; continue; }
506
+ if (source[i] === '|') { i++; continue; } // lone | not supported
507
+ if (source[i] === '&') { i++; continue; } // lone & not supported
432
508
 
433
509
  throw new Error(
434
510
  `Line ${line}, Column ${col()}: Unexpected character "${source[i]}". PlainScript only uses letters, numbers, strings, and known symbols.`