plainscript-lang 1.0.36 → 1.0.362
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/README.md +252 -20
- package/compiler/bundler.js +4 -4
- package/compiler/cli.js +18 -18
- package/compiler/dependency-detector.js +34 -22
- package/compiler/generator.js +326 -196
- package/compiler/lexer.js +49 -39
- package/compiler/parser.js +552 -181
- package/compiler/sourcemap.js +1 -1
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +2 -2
- package/docs/FB-PROMPT.md +524 -0
- package/docs/GAME-PROMPT.md +56 -55
- package/docs/PLAINSCRIPT-SPEC.md +16 -15
- package/docs/index.html +13 -6
- package/docs/website/script.js +1 -1
- package/docs/website/style.css +3 -3
- package/examples/ai-providers.pln +1 -1
- package/examples/arrays.pln +1 -1
- package/examples/async-errors.pln +2 -1
- package/examples/auth-api.pln +1 -1
- package/examples/auth-sessions.pln +1 -1
- package/examples/basics.pln +1 -1
- package/examples/bots.pln +1 -1
- package/examples/browser-interactive/README.md +3 -3
- package/examples/browser-interactive/src/interactive.pln +1 -1
- package/examples/cache-and-jobs.pln +1 -1
- package/examples/cache-schedule.pln +1 -1
- package/examples/canvas-game/README.md +4 -4
- package/examples/canvas-game/src/game.pln +1 -1
- package/examples/collections.pln +1 -1
- package/examples/concurrency.pln +1 -1
- package/examples/conditions.pln +1 -1
- package/examples/database.pln +1 -1
- package/examples/day2.pln +1 -1
- package/examples/day3.pln +1 -1
- package/examples/deployment.pln +1 -1
- package/examples/email-send.pln +1 -1
- package/examples/error-handling.pln +3 -2
- package/examples/expressions.pln +1 -1
- package/examples/file-uploads.pln +1 -1
- package/examples/files-and-config.pln +1 -1
- package/examples/files.pln +1 -1
- package/examples/football-backend/app.pln +1 -1
- package/examples/functions.pln +1 -1
- package/examples/hello.pln +1 -1
- package/examples/http-client.pln +1 -1
- package/examples/http.pln +1 -1
- package/examples/id-verification/app.pln +1 -1
- package/examples/javascript-library/README.md +6 -6
- package/examples/javascript-library/public/index.html +1 -1
- package/examples/javascript-library/src/interop.pln +1 -1
- package/examples/json.pln +1 -1
- package/examples/loops.pln +1 -1
- package/examples/modules/app.pln +1 -1
- package/examples/modules/main.pln +1 -1
- package/examples/modules/math.pln +1 -1
- package/examples/mongo.pln +1 -1
- package/examples/objects.pln +1 -1
- package/examples/ocr.pln +1 -1
- package/examples/packages.pln +1 -1
- package/examples/record-kinds.pln +1 -1
- package/examples/records.pln +1 -1
- package/examples/rest-api-fetch.pln +1 -1
- package/examples/rest-api.pln +1 -1
- package/examples/scheduled-tasks.pln +1 -1
- package/examples/search-and-filter.pln +1 -1
- package/examples/server.pln +1 -1
- package/examples/sessions-and-cookies.pln +1 -1
- package/examples/sqlite.pln +1 -1
- package/examples/start.pln +1 -1
- package/examples/stdlib.pln +1 -1
- package/examples/string-verbs.pln +1 -1
- package/examples/telegram-ai-bot.pln +1 -1
- package/examples/telegram-bot.pln +1 -1
- package/examples/testing.pln +1 -1
- package/examples/three-dimensional/README.md +2 -2
- package/examples/three-dimensional/src/scene.pln +1 -1
- package/examples/web-api.pln +1 -1
- package/examples/web-app.pln +1 -1
- package/examples/websocket-server.pln +1 -1
- package/examples/websocket.pln +1 -1
- package/examples/whatsapp-bot/pairing.pln +2 -2
- package/examples/whatsapp-bot/qr.pln +2 -2
- package/package.json +11 -12
package/compiler/lexer.js
CHANGED
|
@@ -15,6 +15,7 @@ const TOKEN = {
|
|
|
15
15
|
ELSE: 'ELSE', // alias for otherwise
|
|
16
16
|
DONE: 'DONE',
|
|
17
17
|
END: 'END', // alias for done
|
|
18
|
+
DO: 'DO', // block-bodied lambda opener: (x) do ... done
|
|
18
19
|
GREATER: 'GREATER',
|
|
19
20
|
LESS: 'LESS',
|
|
20
21
|
THAN: 'THAN',
|
|
@@ -33,11 +34,14 @@ const TOKEN = {
|
|
|
33
34
|
EVERY: 'EVERY', // alias: "for every item in list"
|
|
34
35
|
IN: 'IN',
|
|
35
36
|
WHILE: 'WHILE',
|
|
37
|
+
REPEAT: 'REPEAT', // Natural intent repeat loop: repeat 5 times, repeat with x in list, repeat while, repeat until
|
|
38
|
+
UNTIL: 'UNTIL', // Natural intent repeat until <condition>
|
|
39
|
+
LOG_KW: 'LOG_KW', // alias for show: "log 'hello'"
|
|
36
40
|
USE: 'USE',
|
|
37
41
|
IMPORT: 'IMPORT',
|
|
38
42
|
INCLUDE: 'INCLUDE', // alias for import: "include "./file.pln""
|
|
39
43
|
LOAD: 'LOAD', // alias for import: "load "./file.pln""
|
|
40
|
-
// v0.3
|
|
44
|
+
// v0.3 - Express runtime
|
|
41
45
|
WHEN: 'WHEN',
|
|
42
46
|
SOMEONE: 'SOMEONE',
|
|
43
47
|
VISITS: 'VISITS',
|
|
@@ -54,7 +58,7 @@ const TOKEN = {
|
|
|
54
58
|
SERVE_STATIC: 'SERVE_STATIC', // alias for serve folder
|
|
55
59
|
SERVE_PUBLIC: 'SERVE_PUBLIC', // alias for serve folder
|
|
56
60
|
FOLDER: 'FOLDER',
|
|
57
|
-
// v0.6
|
|
61
|
+
// v0.6 - Extended comparisons
|
|
58
62
|
ABOVE: 'ABOVE',
|
|
59
63
|
BELOW: 'BELOW',
|
|
60
64
|
AT: 'AT',
|
|
@@ -70,14 +74,14 @@ const TOKEN = {
|
|
|
70
74
|
WITH: 'WITH',
|
|
71
75
|
BETWEEN: 'BETWEEN',
|
|
72
76
|
AND: 'AND',
|
|
73
|
-
OR: 'OR', // v2.1.1
|
|
74
|
-
INSTANCEOF: 'INSTANCEOF', // v1.0.2
|
|
75
|
-
// v0.6
|
|
77
|
+
OR: 'OR', // v2.1.1 - logical or in conditions
|
|
78
|
+
INSTANCEOF: 'INSTANCEOF', // v1.0.2 - instanceof condition
|
|
79
|
+
// v0.6 - Express DX
|
|
76
80
|
WEB: 'WEB',
|
|
77
81
|
ROUTE_KW: 'ROUTE_KW',
|
|
78
82
|
START_KW: 'START_KW',
|
|
79
83
|
RUN_ON: 'RUN_ON', // alias for start: "run on port 3000"
|
|
80
|
-
// v0.6
|
|
84
|
+
// v0.6 - SQLite DX
|
|
81
85
|
DATABASE_KW: 'DATABASE_KW',
|
|
82
86
|
CONNECT_DB: 'CONNECT_DB', // alias for database: "connect database "app.db""
|
|
83
87
|
USE_DATABASE: 'USE_DATABASE', // alias for database: "use database "app.db""
|
|
@@ -89,7 +93,7 @@ const TOKEN = {
|
|
|
89
93
|
SQL_BODY: 'SQL_BODY', // raw SQL collected between a block keyword and "done"
|
|
90
94
|
ASK: 'ASK', // interactive input: ask name / ask "prompt" as name
|
|
91
95
|
PROMPT: 'PROMPT', // alias for ask: 'prompt "name?" as name'
|
|
92
|
-
OCR_KW: 'OCR_KW', // v2.0.1
|
|
96
|
+
OCR_KW: 'OCR_KW', // v2.0.1 - ocr "<image>" as <name> [using "<lang>"]
|
|
93
97
|
PACKAGE: 'PACKAGE', // bare npm package name after "use" (may contain -, _, ., /, @)
|
|
94
98
|
GATHER: 'GATHER', // gather each item in list giving expr (functional map)
|
|
95
99
|
FILTER_KW: 'FILTER_KW', // filter each item in list when condition (functional filter)
|
|
@@ -102,10 +106,10 @@ const TOKEN = {
|
|
|
102
106
|
EMIT: 'EMIT', // emit "event.name" with data (event emitter)
|
|
103
107
|
HAPPENS: 'HAPPENS', // when "event.name" happens as data (event listener)
|
|
104
108
|
CATCHES: 'CATCHES', // recover when err catches "TypeError" (typed error recovery)
|
|
105
|
-
// v1.0.1
|
|
109
|
+
// v1.0.1 - generators. "yield" is a JavaScript reserved word, so it becomes a
|
|
106
110
|
// real keyword token (a variable named `yield` is illegal in JS anyway).
|
|
107
111
|
YIELD: 'YIELD',
|
|
108
|
-
// v2.3
|
|
112
|
+
// v2.3 - English-like syntax keywords
|
|
109
113
|
TO: 'TO', // "to add a and b together" function syntax
|
|
110
114
|
TOGETHER: 'TOGETHER', // function block terminator alternative
|
|
111
115
|
BE: 'BE', // "let x be 5" alternative to "let x is 5"
|
|
@@ -117,43 +121,44 @@ const TOKEN = {
|
|
|
117
121
|
LIST_WITH: 'LIST_WITH', // "list with 1, 2, 3" alternative to "[1, 2, 3]"
|
|
118
122
|
RECORD_WITH: 'RECORD_WITH', // "record with name 'Alice'" alternative to object literal
|
|
119
123
|
// Punctuation
|
|
120
|
-
LBRACE: 'LBRACE', // {
|
|
124
|
+
LBRACE: 'LBRACE', // { - inline object literal (v1.2)
|
|
121
125
|
RBRACE: 'RBRACE', // }
|
|
122
|
-
COLON: 'COLON', // :
|
|
123
|
-
ARROW: 'ARROW', // ->
|
|
126
|
+
COLON: 'COLON', // : - inline object property separator (v1.2)
|
|
127
|
+
ARROW: 'ARROW', // -> - Telegram inline keyboard button (v1.2)
|
|
124
128
|
LPAREN: 'LPAREN',
|
|
125
129
|
RPAREN: 'RPAREN',
|
|
126
130
|
LBRACKET: 'LBRACKET',
|
|
127
131
|
RBRACKET: 'RBRACKET',
|
|
128
132
|
COMMA: 'COMMA',
|
|
129
133
|
DOT: 'DOT',
|
|
130
|
-
OPTIONAL_CHAIN: 'OPTIONAL_CHAIN', // ?.
|
|
131
|
-
NULLISH_COALESCE: 'NULLISH_COALESCE', // ??
|
|
132
|
-
POWER: 'POWER', // **
|
|
134
|
+
OPTIONAL_CHAIN: 'OPTIONAL_CHAIN', // ?. - optional chaining
|
|
135
|
+
NULLISH_COALESCE: 'NULLISH_COALESCE', // ?? - nullish coalescing
|
|
136
|
+
POWER: 'POWER', // ** - exponentiation
|
|
133
137
|
PLUS: 'PLUS',
|
|
134
|
-
MINUS: 'MINUS', // v2.1.1
|
|
135
|
-
STAR: 'STAR', // v2.1.1
|
|
136
|
-
SLASH: 'SLASH', // v2.1.1
|
|
137
|
-
PERCENT: 'PERCENT', // v2.1.1
|
|
138
|
-
SPREAD: 'SPREAD', // ...
|
|
139
|
-
REST: 'REST', // ...
|
|
138
|
+
MINUS: 'MINUS', // v2.1.1 - subtraction / unary minus
|
|
139
|
+
STAR: 'STAR', // v2.1.1 - multiplication
|
|
140
|
+
SLASH: 'SLASH', // v2.1.1 - division
|
|
141
|
+
PERCENT: 'PERCENT', // v2.1.1 - remainder (modulo)
|
|
142
|
+
SPREAD: 'SPREAD', // ... - spread operator
|
|
143
|
+
REST: 'REST', // ... - rest parameter
|
|
140
144
|
LOGICAL_OR_ASSIGN: 'LOGICAL_OR_ASSIGN', // ||=
|
|
141
145
|
LOGICAL_AND_ASSIGN: 'LOGICAL_AND_ASSIGN', // &&=
|
|
142
146
|
NULLISH_ASSIGN: 'NULLISH_ASSIGN', // ??=
|
|
147
|
+
PLUS_ASSIGN: 'PLUS_ASSIGN', // ++= (increment-assign, x += v)
|
|
143
148
|
// Literals & identifiers
|
|
144
149
|
IDENTIFIER: 'IDENTIFIER',
|
|
145
150
|
STRING: 'STRING',
|
|
146
151
|
NUMBER: 'NUMBER',
|
|
147
|
-
TRUE_KW: 'TRUE_KW', // v2.1.1
|
|
148
|
-
FALSE_KW: 'FALSE_KW', // v2.1.1
|
|
149
|
-
NULL_KW: 'NULL_KW', // v2.1.1
|
|
150
|
-
UNDEFINED_KW: 'UNDEFINED_KW', // v2.2.0
|
|
152
|
+
TRUE_KW: 'TRUE_KW', // v2.1.1 - boolean literal true
|
|
153
|
+
FALSE_KW: 'FALSE_KW', // v2.1.1 - boolean literal false
|
|
154
|
+
NULL_KW: 'NULL_KW', // v2.1.1 - null literal
|
|
155
|
+
UNDEFINED_KW: 'UNDEFINED_KW', // v2.2.0 - undefined literal
|
|
151
156
|
BIGINT: 'BIGINT', // BigInt literal (e.g., 42n)
|
|
152
157
|
TEMPLATE_STRING: 'TEMPLATE_STRING', // backtick-delimited string with interpolation
|
|
153
158
|
SYMBOL_KW: 'SYMBOL_KW', // symbol keyword
|
|
154
159
|
DEBUGGER_KW: 'DEBUGGER_KW', // debugger keyword
|
|
155
160
|
IMPORT_META: 'IMPORT_META', // import.meta
|
|
156
|
-
// v2.4
|
|
161
|
+
// v2.4 - Near-English intent-oriented syntax (single-word keywords)
|
|
157
162
|
RAISES: 'RAISES', // "raise expr" throw alternative
|
|
158
163
|
CHOOSING: 'CHOOSING', // "choosing cond then a otherwise b" ternary
|
|
159
164
|
USES: 'USES', // "x uses a, b together" function call
|
|
@@ -176,6 +181,7 @@ const KEYWORDS = {
|
|
|
176
181
|
else: TOKEN.ELSE,
|
|
177
182
|
done: TOKEN.DONE,
|
|
178
183
|
end: TOKEN.END,
|
|
184
|
+
do: TOKEN.DO, // block-bodied lambda opener: (x) do ... done
|
|
179
185
|
greater: TOKEN.GREATER,
|
|
180
186
|
less: TOKEN.LESS,
|
|
181
187
|
than: TOKEN.THAN,
|
|
@@ -215,7 +221,7 @@ const KEYWORDS = {
|
|
|
215
221
|
serve_static: TOKEN.SERVE_STATIC,
|
|
216
222
|
serve_public: TOKEN.SERVE_PUBLIC,
|
|
217
223
|
folder: TOKEN.FOLDER,
|
|
218
|
-
// v0.6
|
|
224
|
+
// v0.6 - comparisons
|
|
219
225
|
above: TOKEN.ABOVE,
|
|
220
226
|
below: TOKEN.BELOW,
|
|
221
227
|
at: TOKEN.AT,
|
|
@@ -233,25 +239,25 @@ const KEYWORDS = {
|
|
|
233
239
|
instanceof: TOKEN.INSTANCEOF,
|
|
234
240
|
now: TOKEN.NOW,
|
|
235
241
|
back: TOKEN.BACK,
|
|
236
|
-
// v2.1.1
|
|
242
|
+
// v2.1.1 - literal keywords. These were previously plain identifiers that
|
|
237
243
|
// passed through to generated JavaScript; making them explicit tokens gives
|
|
238
244
|
// them first-class AST nodes and deterministic diagnostics.
|
|
239
245
|
true: TOKEN.TRUE_KW,
|
|
240
246
|
false: TOKEN.FALSE_KW,
|
|
241
247
|
null: TOKEN.NULL_KW,
|
|
242
248
|
undefined: TOKEN.UNDEFINED_KW,
|
|
243
|
-
// v0.6
|
|
249
|
+
// v0.6 - Express DX
|
|
244
250
|
web: TOKEN.WEB,
|
|
245
251
|
route: TOKEN.ROUTE_KW,
|
|
246
252
|
start: TOKEN.START_KW,
|
|
247
253
|
run_on: TOKEN.RUN_ON,
|
|
248
|
-
// v0.6
|
|
254
|
+
// v0.6 - SQLite DX
|
|
249
255
|
database: TOKEN.DATABASE_KW,
|
|
250
256
|
connect_db: TOKEN.CONNECT_DB,
|
|
251
257
|
use_database: TOKEN.USE_DATABASE,
|
|
252
258
|
ask: TOKEN.ASK,
|
|
253
259
|
prompt: TOKEN.PROMPT,
|
|
254
|
-
// v2.0.1
|
|
260
|
+
// v2.0.1 - OCR capability
|
|
255
261
|
ocr: TOKEN.OCR_KW,
|
|
256
262
|
// IOPL-native features
|
|
257
263
|
gather: TOKEN.GATHER,
|
|
@@ -268,7 +274,7 @@ const KEYWORDS = {
|
|
|
268
274
|
yield: TOKEN.YIELD,
|
|
269
275
|
symbol: TOKEN.SYMBOL_KW,
|
|
270
276
|
debugger: TOKEN.DEBUGGER_KW,
|
|
271
|
-
// v2.3
|
|
277
|
+
// v2.3 - English-like syntax keywords
|
|
272
278
|
to: TOKEN.TO,
|
|
273
279
|
together: TOKEN.TOGETHER,
|
|
274
280
|
be: TOKEN.BE,
|
|
@@ -279,12 +285,16 @@ const KEYWORDS = {
|
|
|
279
285
|
divided_by: TOKEN.DIVIDED_BY_WORD,
|
|
280
286
|
list_with: TOKEN.LIST_WITH,
|
|
281
287
|
record_with: TOKEN.RECORD_WITH,
|
|
282
|
-
// v2.4
|
|
288
|
+
// v2.4 - Near-English intent-oriented syntax (single-word keywords)
|
|
283
289
|
raise: TOKEN.RAISES,
|
|
284
290
|
raises: TOKEN.RAISES,
|
|
285
291
|
choosing: TOKEN.CHOOSING,
|
|
286
292
|
uses: TOKEN.USES,
|
|
287
293
|
fills: TOKEN.FILLS,
|
|
294
|
+
// Natural language intent keywords
|
|
295
|
+
repeat: TOKEN.REPEAT,
|
|
296
|
+
until: TOKEN.UNTIL,
|
|
297
|
+
log: TOKEN.LOG_KW,
|
|
288
298
|
};
|
|
289
299
|
|
|
290
300
|
// Keywords that introduce raw SQL blocks (content up to "done" is collected verbatim).
|
|
@@ -298,7 +308,7 @@ const SQL_BLOCK_WORDS = {
|
|
|
298
308
|
|
|
299
309
|
// Decode one escape sequence inside a double-quoted string, starting at
|
|
300
310
|
// source[index] (the backslash). Returns [decodedText, charsConsumed].
|
|
301
|
-
// Supported: \n \t \r \0 \\ \" \'
|
|
311
|
+
// Supported: \n \t \r \0 \\ \" \' - any other escaped character is kept as
|
|
302
312
|
// itself (JavaScript-style leniency), so "\q" means "q".
|
|
303
313
|
function decodeEscape(source, index) {
|
|
304
314
|
const next = source[index + 1];
|
|
@@ -345,7 +355,7 @@ function tokenize(source) {
|
|
|
345
355
|
pendingUse = false;
|
|
346
356
|
continue;
|
|
347
357
|
}
|
|
348
|
-
pendingUse = false; // not a package start
|
|
358
|
+
pendingUse = false; // not a package start - tokenize normally
|
|
349
359
|
}
|
|
350
360
|
|
|
351
361
|
// String literal. Normal escapes are decoded here (\n, \t, \r, \\, \",
|
|
@@ -380,7 +390,7 @@ function tokenize(source) {
|
|
|
380
390
|
}
|
|
381
391
|
|
|
382
392
|
// Backtick string (template literal): preserves whitespace and supports
|
|
383
|
-
// interpolation. Scanning is escape-aware
|
|
393
|
+
// interpolation. Scanning is escape-aware - a backslash escapes the next
|
|
384
394
|
// character verbatim (\` does not close the string, \\ stays a backslash,
|
|
385
395
|
// \$ guards ${ from interpolating) while ordinary characters, real
|
|
386
396
|
// newlines and ${expr} pass through untouched for the generator to emit.
|
|
@@ -478,7 +488,7 @@ function tokenize(source) {
|
|
|
478
488
|
tokens.push({ type: TOKEN.SQL_BODY, value: sql.trimEnd(), line: tokenLine, col: tokenCol });
|
|
479
489
|
tokens.push({ type: TOKEN.DONE, value: 'done', line, col: col() });
|
|
480
490
|
}
|
|
481
|
-
// else: stays on same line
|
|
491
|
+
// else: stays on same line - parsed normally by the parser as kwType + next tokens
|
|
482
492
|
continue;
|
|
483
493
|
}
|
|
484
494
|
|
|
@@ -504,9 +514,9 @@ function tokenize(source) {
|
|
|
504
514
|
if (source[i] === '?' && source[i + 1] === '?') { tokens.push({ type: TOKEN.NULLISH_COALESCE, value: '??', line: tokenLine, col: tokenCol }); i += 2; continue; }
|
|
505
515
|
if (source[i] === '.' && source[i + 1] === '.' && source[i + 2] === '.') { tokens.push({ type: TOKEN.SPREAD, value: '...', line: tokenLine, col: tokenCol }); i += 3; continue; }
|
|
506
516
|
if (source[i] === '.') { tokens.push({ type: TOKEN.DOT, value: '.', line: tokenLine, col: tokenCol }); i++; continue; }
|
|
507
|
-
if (source[i] === '+' && source[i + 1] === '+' && source[i + 2] === '=') { tokens.push({ type: TOKEN.
|
|
517
|
+
if (source[i] === '+' && source[i + 1] === '+' && source[i + 2] === '=') { tokens.push({ type: TOKEN.PLUS_ASSIGN, value: '++=', line: tokenLine, col: tokenCol }); i += 3; continue; }
|
|
508
518
|
if (source[i] === '+') { tokens.push({ type: TOKEN.PLUS, value: '+', line: tokenLine, col: tokenCol }); i++; continue; }
|
|
509
|
-
// v2.1.1
|
|
519
|
+
// v2.1.1 - arithmetic. "->" is matched first so it never becomes MINUS.
|
|
510
520
|
if (source[i] === '-' && source[i + 1] === '>') { tokens.push({ type: TOKEN.ARROW, value: '->', line: tokenLine, col: tokenCol }); i += 2; continue; }
|
|
511
521
|
if (source[i] === '-') { tokens.push({ type: TOKEN.MINUS, value: '-', line: tokenLine, col: tokenCol }); i++; continue; }
|
|
512
522
|
if (source[i] === '*' && source[i + 1] === '*') { tokens.push({ type: TOKEN.POWER, value: '**', line: tokenLine, col: tokenCol }); i += 2; continue; }
|