plainscript-lang 1.0.3 → 1.0.36
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 +836 -188
- package/compiler/cli.js +68 -4
- package/compiler/dependency-detector.js +6 -2
- package/compiler/generator.js +737 -51
- package/compiler/lexer.js +12 -0
- package/compiler/parser.js +184 -14
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +32 -5
- package/docs/GAME-PROMPT.md +915 -0
- package/docs/PLAINSCRIPT-SPEC.md +264 -3
- package/docs/index.html +41 -33
- package/docs/logo-pln.jpg +0 -0
- package/docs/visualization-example.svg +32 -0
- package/docs/website/script.js +130 -1
- package/docs/website/style.css +253 -122
- package/examples/ai-providers.pln +1 -1
- package/examples/arrays.pln +1 -1
- package/examples/async-errors.pln +1 -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 +29 -0
- package/examples/browser-interactive/public/index.html +83 -0
- package/examples/browser-interactive/public/interactive.js +27 -0
- package/examples/browser-interactive/src/interactive.pln +34 -0
- package/examples/cache-and-jobs.pln +1 -1
- package/examples/cache-schedule.pln +1 -1
- package/examples/canvas-game/README.md +34 -0
- package/examples/canvas-game/public/game.js +131 -0
- package/examples/canvas-game/public/index.html +48 -0
- package/examples/canvas-game/src/game.pln +139 -0
- 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 +1 -1
- 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 +54 -0
- package/examples/javascript-library/package-lock.json +21 -0
- package/examples/javascript-library/package.json +8 -0
- package/examples/javascript-library/public/config.json +4 -0
- package/examples/javascript-library/public/index.html +40 -0
- package/examples/javascript-library/src/interop.pln +53 -0
- 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 +51 -0
- package/examples/three-dimensional/public/index.html +33 -0
- package/examples/three-dimensional/src/scene.pln +34 -0
- package/examples/visualization.pln +12 -0
- 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 +24 -2
- package/examples/whatsapp-bot/qr.pln +18 -2
- package/package.json +5 -3
- package/docs/logo.jpg +0 -0
package/compiler/lexer.js
CHANGED
|
@@ -411,6 +411,18 @@ function tokenize(source) {
|
|
|
411
411
|
continue;
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
+
// Hex number literal (0x... → decimal; supports colors like 0xRRGGBB)
|
|
415
|
+
if (source[i] === '0' && (source[i + 1] === 'x' || source[i + 1] === 'X')) {
|
|
416
|
+
let hex = '';
|
|
417
|
+
let j = i + 2;
|
|
418
|
+
while (j < source.length && /[0-9a-fA-F]/.test(source[j])) hex += source[j++];
|
|
419
|
+
if (hex) {
|
|
420
|
+
tokens.push({ type: TOKEN.NUMBER, value: Number.parseInt(hex, 16), line: tokenLine, col: tokenCol });
|
|
421
|
+
i = j;
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
414
426
|
// Number literal (may include decimal point or BigInt suffix 'n')
|
|
415
427
|
if (/[0-9]/.test(source[i])) {
|
|
416
428
|
let num = '';
|
package/compiler/parser.js
CHANGED
|
@@ -41,8 +41,10 @@ const NUMBER_WORDS = {
|
|
|
41
41
|
const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete'];
|
|
42
42
|
|
|
43
43
|
// Time units accepted by the "every <n> <unit>" statement, in milliseconds
|
|
44
|
-
// (used by the generator to build the interval directly).
|
|
44
|
+
// (used by the generator to build the interval directly). "every 16
|
|
45
|
+
// milliseconds" powers requestAnimationFrame-style loops.
|
|
45
46
|
const TIME_UNITS = {
|
|
47
|
+
millisecond: 1, milliseconds: 1,
|
|
46
48
|
second: 1000, seconds: 1000,
|
|
47
49
|
minute: 60 * 1000, minutes: 60 * 1000,
|
|
48
50
|
hour: 60 * 60 * 1000, hours: 60 * 60 * 1000,
|
|
@@ -401,6 +403,13 @@ function parse(tokens) {
|
|
|
401
403
|
peekAt(2).type === TOKEN.IDENTIFIER && TIME_UNITS[peekAt(2).value]) {
|
|
402
404
|
return parseEvery();
|
|
403
405
|
}
|
|
406
|
+
// v1.0.36 — every frame … done: requestAnimationFrame loop. "every" lexes
|
|
407
|
+
// as TOKEN.EACH; guard on the following "frame" identifier ("for every
|
|
408
|
+
// item in list" is intercepted by TOKEN.FOR above).
|
|
409
|
+
if (token.type === TOKEN.EACH && peekAt(1).type === TOKEN.IDENTIFIER &&
|
|
410
|
+
peekAt(1).value === 'frame') {
|
|
411
|
+
return parseEveryFrame();
|
|
412
|
+
}
|
|
404
413
|
if (token.type === TOKEN.WHILE) return parseWhile();
|
|
405
414
|
if (token.type === TOKEN.USE) return parseUse();
|
|
406
415
|
if (token.type === TOKEN.IMPORT || token.type === TOKEN.INCLUDE || token.type === TOKEN.LOAD ||
|
|
@@ -544,9 +553,12 @@ function parse(tokens) {
|
|
|
544
553
|
return { type: 'ReturnStatement', value };
|
|
545
554
|
}
|
|
546
555
|
|
|
547
|
-
// new expression: new ClassName(args)
|
|
556
|
+
// new expression: new ClassName(args). "new" is not a keyword, so
|
|
557
|
+
// parsePrimary intercepts it anywhere an expression appears; routing the
|
|
558
|
+
// statement-start form through parsePrimary keeps member chains after the
|
|
559
|
+
// constructor intact (new THREE.Scene().add(...)).
|
|
548
560
|
if (token.value === 'new' && peekAt(1).type !== TOKEN.BECOMES && peekAt(1).type !== TOKEN.LPAREN) {
|
|
549
|
-
return { type: 'ExpressionStatement', expression:
|
|
561
|
+
return { type: 'ExpressionStatement', expression: parsePrimary() };
|
|
550
562
|
}
|
|
551
563
|
|
|
552
564
|
// v1.2 — bot "<token>" / bot <expr>: creates the polling Telegram bot.
|
|
@@ -643,6 +655,22 @@ function parse(tokens) {
|
|
|
643
655
|
return parseEvery();
|
|
644
656
|
}
|
|
645
657
|
|
|
658
|
+
// v1.0.36 — every frame … done: requestAnimationFrame loop. Identifier
|
|
659
|
+
// mirror of the EACH dispatch above.
|
|
660
|
+
if (token.value === 'every' && peekAt(1).type === TOKEN.IDENTIFIER &&
|
|
661
|
+
peekAt(1).value === 'frame') {
|
|
662
|
+
return parseEveryFrame();
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// v1.0.36 — after <n> <unit>s … done: one-shot delayed execution.
|
|
666
|
+
// Contextual like "retry": "after becomes 5" and after(...) keep their
|
|
667
|
+
// ordinary meanings.
|
|
668
|
+
if (token.value === 'after' &&
|
|
669
|
+
tokenStartsValue(peekAt(1)) &&
|
|
670
|
+
peekAt(2).type === TOKEN.IDENTIFIER && TIME_UNITS[peekAt(2).value]) {
|
|
671
|
+
return parseAfter();
|
|
672
|
+
}
|
|
673
|
+
|
|
646
674
|
// v2.1.0 — schedule "<cron>" … done: run work on a cron schedule.
|
|
647
675
|
if (token.value === 'schedule' && peekAt(1).type === TOKEN.STRING) {
|
|
648
676
|
advance(); // schedule
|
|
@@ -686,6 +714,23 @@ function parse(tokens) {
|
|
|
686
714
|
return parseWhatsAppBot();
|
|
687
715
|
}
|
|
688
716
|
|
|
717
|
+
// v2.1.1 — pair whatsapp "<phone>": starts an on-demand WhatsApp pairing
|
|
718
|
+
// session for the given phone number. Used by hybrid bots where a
|
|
719
|
+
// Telegram command triggers a WhatsApp pairing flow.
|
|
720
|
+
// Accepts a string literal (validated at compile time) or any expression
|
|
721
|
+
// (e.g. a variable filled by regex matches[1]).
|
|
722
|
+
if (token.value === 'pair' &&
|
|
723
|
+
peekAt(1).type === TOKEN.IDENTIFIER && peekAt(1).value === 'whatsapp') {
|
|
724
|
+
advance(); // pair
|
|
725
|
+
advance(); // whatsapp
|
|
726
|
+
if (peek().type === TOKEN.STRING) {
|
|
727
|
+
const phone = advance().value;
|
|
728
|
+
return { type: 'WhatsAppPairStatement', phone: { type: 'StringLiteral', value: phone } };
|
|
729
|
+
}
|
|
730
|
+
const phoneExpr = parseExpression();
|
|
731
|
+
return { type: 'WhatsAppPairStatement', phone: phoneExpr };
|
|
732
|
+
}
|
|
733
|
+
|
|
689
734
|
// v2.1.1 — log message: prints the normalized message record inside an
|
|
690
735
|
// "on message" handler. Generation rejects it everywhere else with a
|
|
691
736
|
// teaching error.
|
|
@@ -696,6 +741,15 @@ function parse(tokens) {
|
|
|
696
741
|
return { type: 'WhatsAppLogStatement' };
|
|
697
742
|
}
|
|
698
743
|
|
|
744
|
+
// v2.14 — download "<path>": saves the current message's media (image,
|
|
745
|
+
// video, audio, document, sticker, …) to a file, inside an "on message"
|
|
746
|
+
// handler. Generation rejects it everywhere else with a teaching error.
|
|
747
|
+
if (token.value === 'download' && peekAt(1).type === TOKEN.STRING) {
|
|
748
|
+
advance(); // download
|
|
749
|
+
const filePath = advance().value;
|
|
750
|
+
return { type: 'WhatsAppDownloadStatement', filePath };
|
|
751
|
+
}
|
|
752
|
+
|
|
699
753
|
// v2.1.0 — broadcast <expr>: sends to every connected socket.
|
|
700
754
|
if (token.value === 'broadcast') {
|
|
701
755
|
advance(); // broadcast
|
|
@@ -1828,6 +1882,31 @@ function parseAsk() {
|
|
|
1828
1882
|
(nextToken.type === TOKEN.IDENTIFIER && (nextToken.value === 'nothing' || nextToken.value === 'socket'));
|
|
1829
1883
|
|
|
1830
1884
|
if (!isEventWhen) {
|
|
1885
|
+
// v1.0.36 — when <target> "<event>" happens [as <name>] … done binds a
|
|
1886
|
+
// DOM event listener: when button "click" happens => addEventListener.
|
|
1887
|
+
// Detection probes the target expression and commits only when a string
|
|
1888
|
+
// followed by "happens" is next; otherwise the tokens are replayed and
|
|
1889
|
+
// the block parses as the English-like if-condition "when <condition>".
|
|
1890
|
+
const savedPos = pos;
|
|
1891
|
+
try {
|
|
1892
|
+
const target = parseExpression();
|
|
1893
|
+
if (peek().type === TOKEN.STRING && peekAt(1).type === TOKEN.HAPPENS) {
|
|
1894
|
+
const eventStr = advance().value;
|
|
1895
|
+
advance(); // happens
|
|
1896
|
+
let paramName = null;
|
|
1897
|
+
if (peek().type === TOKEN.AS) {
|
|
1898
|
+
advance(); // as
|
|
1899
|
+
paramName = consume(TOKEN.IDENTIFIER,
|
|
1900
|
+
'Expected a parameter name after "as".\n\nExample:\n when button "click" happens as event').value;
|
|
1901
|
+
}
|
|
1902
|
+
const body = parseBody('"when happens" block');
|
|
1903
|
+
return { type: 'WhenTargetedStatement', target, event: eventStr, paramName, body };
|
|
1904
|
+
}
|
|
1905
|
+
} catch (_e) {
|
|
1906
|
+
// Not a targeted "when" — replay and fall through to the condition form.
|
|
1907
|
+
}
|
|
1908
|
+
pos = savedPos;
|
|
1909
|
+
|
|
1831
1910
|
const condition = parseCondition();
|
|
1832
1911
|
// Optional "then" keyword
|
|
1833
1912
|
if (peek().type === TOKEN.THEN) {
|
|
@@ -2898,7 +2977,18 @@ function parseAsk() {
|
|
|
2898
2977
|
|
|
2899
2978
|
const item = tryParseItemExpression();
|
|
2900
2979
|
if (item) return item;
|
|
2901
|
-
|
|
2980
|
+
// v1.0.36 — `new` works anywhere an expression is parsed (assignment
|
|
2981
|
+
// targets, call arguments, member chains). "new" is not a keyword, so this
|
|
2982
|
+
// identifier must be intercepted here; parseAtom would read it as a plain
|
|
2983
|
+
// Identifier and turn "new THREE.Scene()" into "new.THREE.Scene()".
|
|
2984
|
+
let node;
|
|
2985
|
+
if (peek().type === TOKEN.IDENTIFIER && peek().value === 'new' &&
|
|
2986
|
+
peekAt(1).type !== TOKEN.BECOMES && peekAt(1).type !== TOKEN.LPAREN) {
|
|
2987
|
+
advance(); // new
|
|
2988
|
+
node = parseNewExpressionCore();
|
|
2989
|
+
} else {
|
|
2990
|
+
node = parseAtom();
|
|
2991
|
+
}
|
|
2902
2992
|
while (true) {
|
|
2903
2993
|
if (peek().type === TOKEN.LBRACKET) {
|
|
2904
2994
|
advance();
|
|
@@ -3346,7 +3436,7 @@ function parseAsk() {
|
|
|
3346
3436
|
}
|
|
3347
3437
|
if (unitToken.type !== TOKEN.IDENTIFIER || !TIME_UNITS[unitToken.value]) {
|
|
3348
3438
|
throw new Error(makeError(
|
|
3349
|
-
'Expected a time unit after the number in "every".\n\nUnits: seconds, minutes, hours, days\n\nExample:\n every 5 minutes',
|
|
3439
|
+
'Expected a time unit after the number in "every".\n\nUnits: milliseconds, seconds, minutes, hours, days\n\nExample:\n every 5 minutes',
|
|
3350
3440
|
unitToken
|
|
3351
3441
|
));
|
|
3352
3442
|
}
|
|
@@ -3355,6 +3445,36 @@ function parseAsk() {
|
|
|
3355
3445
|
return { type: 'EveryStatement', count, unit, body };
|
|
3356
3446
|
}
|
|
3357
3447
|
|
|
3448
|
+
// v1.0.36 — every frame … done: a requestAnimationFrame loop whose body runs
|
|
3449
|
+
// once per animation frame. The next frame is scheduled after the body so it
|
|
3450
|
+
// always runs (t is the frame timestamp, like the DOM's rAF callback).
|
|
3451
|
+
function parseEveryFrame() {
|
|
3452
|
+
advance(); // every/each
|
|
3453
|
+
advance(); // frame
|
|
3454
|
+
const body = parseBody('"every frame" block');
|
|
3455
|
+
return { type: 'EveryFrameStatement', body };
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
// v1.0.36 — after <n> <unit>s … done: run work once after a delay.
|
|
3459
|
+
// after 5 seconds
|
|
3460
|
+
// show "butter!" ... done
|
|
3461
|
+
// The delay is a number expression ("after count seconds"); the unit is
|
|
3462
|
+
// consumed from TIME_UNITS so the generator can fold <n>*<unit> directly.
|
|
3463
|
+
function parseAfter() {
|
|
3464
|
+
advance(); // after
|
|
3465
|
+
const delay = parseExpression();
|
|
3466
|
+
const unitToken = peek();
|
|
3467
|
+
if (unitToken.type !== TOKEN.IDENTIFIER || !TIME_UNITS[unitToken.value]) {
|
|
3468
|
+
throw new Error(makeError(
|
|
3469
|
+
'Expected a time unit after the delay in "after".\n\nUnits: milliseconds, seconds, minutes, hours, days\n\nExample:\n after 5 seconds\n show "later"\n done',
|
|
3470
|
+
unitToken
|
|
3471
|
+
));
|
|
3472
|
+
}
|
|
3473
|
+
const unit = TIME_UNITS[advance().value];
|
|
3474
|
+
const body = parseBody('"after" block');
|
|
3475
|
+
return { type: 'AfterStatement', delay, unit, body };
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3358
3478
|
// v2.1.0 — websocket server on <port> … done
|
|
3359
3479
|
//
|
|
3360
3480
|
// websocket server on 8081
|
|
@@ -3431,6 +3551,7 @@ function parseAsk() {
|
|
|
3431
3551
|
|
|
3432
3552
|
let authFolder = null;
|
|
3433
3553
|
let login = null;
|
|
3554
|
+
let baileysModule = null;
|
|
3434
3555
|
const handlers = [];
|
|
3435
3556
|
|
|
3436
3557
|
while (peek().type !== TOKEN.DONE) {
|
|
@@ -3441,6 +3562,16 @@ function parseAsk() {
|
|
|
3441
3562
|
));
|
|
3442
3563
|
}
|
|
3443
3564
|
|
|
3565
|
+
// use baileys "<pkg>" — override the Baileys implementation package.
|
|
3566
|
+
// Default is @qwerty-xcv/baileys. Accepts any require-able package name,
|
|
3567
|
+
// so developers can pin a fork or the upstream @whiskeysockets/baileys.
|
|
3568
|
+
if (peek().type === TOKEN.USE && peekAt(1).value === 'baileys' && peekAt(2).type === TOKEN.STRING) {
|
|
3569
|
+
advance(); // use
|
|
3570
|
+
advance(); // baileys
|
|
3571
|
+
baileysModule = advance().value;
|
|
3572
|
+
continue;
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3444
3575
|
// auth "<folder>" — where WhatsApp session credentials persist.
|
|
3445
3576
|
if (peek().type === TOKEN.IDENTIFIER && peek().value === 'auth' &&
|
|
3446
3577
|
peekAt(1).type === TOKEN.STRING) {
|
|
@@ -3495,7 +3626,7 @@ function parseAsk() {
|
|
|
3495
3626
|
}
|
|
3496
3627
|
|
|
3497
3628
|
throw new Error(makeError(
|
|
3498
|
-
'A "whatsapp bot" block may only contain an "auth", a "login", and "on message" statements.\n\nExample:\n whatsapp bot\n auth "session"\n login qr\n\n on message\n log message\n done\n done',
|
|
3629
|
+
'A "whatsapp bot" block may only contain an "auth", a "login", a "use baileys", and "on message" statements.\n\nExample:\n whatsapp bot\n auth "session"\n use baileys "@qwerty-xcv/baileys"\n login qr\n\n on message\n log message\n done\n done',
|
|
3499
3630
|
peek()
|
|
3500
3631
|
));
|
|
3501
3632
|
}
|
|
@@ -3504,8 +3635,9 @@ function parseAsk() {
|
|
|
3504
3635
|
return {
|
|
3505
3636
|
type: 'WhatsAppBotStatement',
|
|
3506
3637
|
authFolder: authFolder || 'plainscript-whatsapp-auth',
|
|
3507
|
-
login: login
|
|
3638
|
+
login: login,
|
|
3508
3639
|
handlers,
|
|
3640
|
+
baileysModule,
|
|
3509
3641
|
};
|
|
3510
3642
|
}
|
|
3511
3643
|
|
|
@@ -3879,17 +4011,55 @@ function parseAsk() {
|
|
|
3879
4011
|
return { type: 'ClassDeclaration', name, superClass, body };
|
|
3880
4012
|
}
|
|
3881
4013
|
|
|
3882
|
-
// new ClassName(args)
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
4014
|
+
// new ClassName(args) — the constructor-call forms:
|
|
4015
|
+
// new Foo → new Foo()
|
|
4016
|
+
// new Foo(1, 2) → new Foo(1, 2)
|
|
4017
|
+
// new window.Thing(1, 2) → new window.Thing(1, 2)
|
|
4018
|
+
// new Foo().bar → new Foo().bar (postfix continues in parsePrimary)
|
|
4019
|
+
// Called with the "new" word already consumed. The callee is parsed as a
|
|
4020
|
+
// plain identifier plus a member chain so "new THREE.Scene(75)" binds the
|
|
4021
|
+
// argument list to the constructor — not to a member call.
|
|
4022
|
+
function parseNewExpressionCore() {
|
|
4023
|
+
const callee = parseNewCallee();
|
|
4024
|
+
let args = [];
|
|
3886
4025
|
if (peek().type === TOKEN.LPAREN) {
|
|
3887
4026
|
advance(); // (
|
|
3888
|
-
const { separator, args } = parseArgList();
|
|
4027
|
+
const { separator, args: parsedArgs } = parseArgList();
|
|
3889
4028
|
consume(TOKEN.RPAREN, 'Expected ")" to close the constructor call.');
|
|
3890
|
-
|
|
4029
|
+
if (separator) {
|
|
4030
|
+
throw new Error(makeError(
|
|
4031
|
+
'Constructor calls cannot use "to"/"from" arguments.\n\nExample:\n new THREE.PerspectiveCamera(75, 1.5, 0.1, 1000)',
|
|
4032
|
+
peek()
|
|
4033
|
+
));
|
|
4034
|
+
}
|
|
4035
|
+
args = parsedArgs;
|
|
3891
4036
|
}
|
|
3892
|
-
return { type: 'NewExpression', callee, args
|
|
4037
|
+
return { type: 'NewExpression', callee, args };
|
|
4038
|
+
}
|
|
4039
|
+
|
|
4040
|
+
// The constructor name after "new": an identifier with an optional member
|
|
4041
|
+
// chain. Deliberately narrower than parsePrimary — a call paren following
|
|
4042
|
+
// the callee belongs to the constructor, so it is never consumed here.
|
|
4043
|
+
function parseNewCallee() {
|
|
4044
|
+
const token = peek();
|
|
4045
|
+
if (token.type !== TOKEN.IDENTIFIER || token.value === 'new') {
|
|
4046
|
+
throw new Error(makeError(
|
|
4047
|
+
'Expected a class name after "new".\n\nExample:\n remember scene as new THREE.Scene()',
|
|
4048
|
+
token
|
|
4049
|
+
));
|
|
4050
|
+
}
|
|
4051
|
+
advance();
|
|
4052
|
+
let node = { type: 'Identifier', name: token.value };
|
|
4053
|
+
while (peek().type === TOKEN.DOT) {
|
|
4054
|
+
advance();
|
|
4055
|
+
const propToken = peek();
|
|
4056
|
+
if (propToken.type === TOKEN.EOF || !/^[A-Za-z_$]/.test(propToken.value)) {
|
|
4057
|
+
throw new Error(makeError('Expected a property name after "." in the constructor.', propToken));
|
|
4058
|
+
}
|
|
4059
|
+
advance();
|
|
4060
|
+
node = { type: 'MemberExpression', object: node, property: propToken.value };
|
|
4061
|
+
}
|
|
4062
|
+
return node;
|
|
3893
4063
|
}
|
|
3894
4064
|
|
|
3895
4065
|
// ── Program ────────────────────────────────────────────────────────────────
|
package/compiler/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# PlainScript 1.0.
|
|
1
|
+
# PlainScript 1.0.36 Capability Audit
|
|
2
2
|
|
|
3
3
|
This audit is based on what the compiler actually supports right now.
|
|
4
4
|
If `plainscript check` validates it, it's listed here.
|
|
@@ -18,6 +18,7 @@ If `plainscript check` validates it, it's listed here.
|
|
|
18
18
|
| For and while loops | Implemented | `for each ... done`, `while ... done` |
|
|
19
19
|
| Match and switch | Implemented | `match value against ... done` |
|
|
20
20
|
| Loop control | Implemented | `break`, `continue` |
|
|
21
|
+
| String verbs | Implemented | `lowercase`, `uppercase`, `split`, `join`, `trim`, `capitalize words` |
|
|
21
22
|
| Classes and `new` | Implemented | JavaScript-compatible class forms |
|
|
22
23
|
|
|
23
24
|
## Modules and Runtime
|
|
@@ -51,15 +52,37 @@ If `plainscript check` validates it, it's listed here.
|
|
|
51
52
|
| SQLite | Implemented | native and WebAssembly drivers |
|
|
52
53
|
| PostgreSQL generation | Implemented | `postgres connection` |
|
|
53
54
|
| SQL parameter binding | Implemented | `{variable}` placeholders |
|
|
55
|
+
| MongoDB | Implemented | `mongo connection`, insert, select, update, delete |
|
|
56
|
+
| MongoDB insert | Implemented | `insert into ... done` |
|
|
57
|
+
| MongoDB select | Implemented | `select from ... done` |
|
|
58
|
+
| MongoDB update | Implemented | `update ... set ... done` |
|
|
59
|
+
| MongoDB delete | Implemented | `delete from ... done` |
|
|
54
60
|
| Email | Implemented | `mail transport`, `send mail` |
|
|
55
61
|
| Schedules and jobs | Implemented | `every`, `schedule`, `run background` |
|
|
56
62
|
| WebSockets | Implemented | `websocket server` |
|
|
57
63
|
| Redis/in-memory cache | Implemented | `cache`, `cacheGet`, `cacheSet` |
|
|
58
64
|
| Telegram bots | Implemented | `bot`, message/callback handlers |
|
|
59
65
|
| AI providers | Implemented | `chat`, `chatWith`, `embedText`, provider presets |
|
|
60
|
-
| WhatsApp bots | Implemented | `whatsapp bot` |
|
|
66
|
+
| WhatsApp bots | Implemented | `whatsapp bot` (pairing/QR, message types, media download, custom Baileys) |
|
|
61
67
|
| OCR | Implemented | `ocr path of file as text` |
|
|
62
68
|
|
|
69
|
+
## Browser and Games
|
|
70
|
+
|
|
71
|
+
| Capability | Status | Current source form |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| Static serving | Implemented | `web app`, `serve folder "public"`, `reply file "public/index.html"` |
|
|
74
|
+
| Browser compile target | Implemented | `build game.pln -o public/game.js` (package-free `<script>` output) |
|
|
75
|
+
| Canvas 2D | Implemented | `canvas.getContext("2d")`, `fillStyle becomes ...`, `fillRect(...)` |
|
|
76
|
+
| DOM events | Implemented | `when <target> "<event>" happens as name` → `addEventListener` |
|
|
77
|
+
| Frame loops | Implemented | `every frame ... done`, rAF + delta time |
|
|
78
|
+
| Browser builtins | Implemented | `select`, `selectAll`, `parseHTML`, `localPoint`, `gamepads`, `droppedFiles` |
|
|
79
|
+
| Promise builtins | Implemented | `loadImage`, `loadAudio`, `fetchJson`, `fetchBytes`, `readDataUrl` (auto-awaited) |
|
|
80
|
+
| Audio | Implemented | `audioContext()`, `playTone(freq, seconds, options)` (user-gesture resume) |
|
|
81
|
+
| WebSocket client | Implemented | `new WebSocket(url)`, `when ws "message" happens`, `webSocketSend(ws, value)` |
|
|
82
|
+
| Persistence | Implemented | `localStorage.getItem/setItem`, `jsonEncode`, `jsonDecode` |
|
|
83
|
+
| JS library interop | Implemented | `use <pkg>`, `bring name from "pkg"`, `new Type(...)`, callbacks, `try/recover` |
|
|
84
|
+
| WebGL/WebGPU and libraries | Implemented | `webglContext`/`glShader`/`glProgram`/`glBuffer`, `new THREE.Scene()` etc. |
|
|
85
|
+
|
|
63
86
|
## Canonical Examples
|
|
64
87
|
|
|
65
88
|
Here are the example files that exercise each capability:
|
|
@@ -85,6 +108,10 @@ examples/cache-schedule.pln
|
|
|
85
108
|
examples/bots.pln
|
|
86
109
|
examples/ocr.pln
|
|
87
110
|
examples/testing.pln
|
|
111
|
+
examples/canvas-game/
|
|
112
|
+
examples/browser-interactive/
|
|
113
|
+
examples/three-dimensional/
|
|
114
|
+
examples/javascript-library/
|
|
88
115
|
examples/modules/
|
|
89
116
|
examples/football-backend/
|
|
90
117
|
examples/id-verification/
|
|
@@ -99,6 +126,6 @@ find examples -name '*.pln' -exec node compiler/cli.js check {} \;
|
|
|
99
126
|
|
|
100
127
|
## Version Info
|
|
101
128
|
|
|
102
|
-
The release label for this repo is `1.0.
|
|
103
|
-
package metadata, website,
|
|
104
|
-
versions are not tied to this label.
|
|
129
|
+
The release label for this repo is `1.0.36`. It covers the compiler,
|
|
130
|
+
package metadata, website, editor tooling, and browser/game documentation.
|
|
131
|
+
Third-party dependency versions are not tied to this label.
|