plainscript-lang 1.0.35 → 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.
Files changed (87) hide show
  1. package/README.md +828 -209
  2. package/compiler/cli.js +68 -4
  3. package/compiler/generator.js +315 -0
  4. package/compiler/lexer.js +12 -0
  5. package/compiler/parser.js +144 -12
  6. package/compiler/version.js +1 -1
  7. package/docs/CAPABILITY_GAP_AUDIT.md +25 -4
  8. package/docs/GAME-PROMPT.md +915 -0
  9. package/docs/PLAINSCRIPT-SPEC.md +130 -1
  10. package/docs/index.html +21 -14
  11. package/docs/website/style.css +162 -195
  12. package/examples/ai-providers.pln +1 -1
  13. package/examples/arrays.pln +1 -1
  14. package/examples/async-errors.pln +1 -1
  15. package/examples/auth-api.pln +1 -1
  16. package/examples/auth-sessions.pln +1 -1
  17. package/examples/basics.pln +1 -1
  18. package/examples/bots.pln +1 -1
  19. package/examples/browser-interactive/README.md +29 -0
  20. package/examples/browser-interactive/public/index.html +83 -0
  21. package/examples/browser-interactive/public/interactive.js +27 -0
  22. package/examples/browser-interactive/src/interactive.pln +34 -0
  23. package/examples/cache-and-jobs.pln +1 -1
  24. package/examples/cache-schedule.pln +1 -1
  25. package/examples/canvas-game/README.md +34 -0
  26. package/examples/canvas-game/public/game.js +131 -0
  27. package/examples/canvas-game/public/index.html +48 -0
  28. package/examples/canvas-game/src/game.pln +139 -0
  29. package/examples/collections.pln +1 -1
  30. package/examples/concurrency.pln +1 -1
  31. package/examples/conditions.pln +1 -1
  32. package/examples/database.pln +1 -1
  33. package/examples/day2.pln +1 -1
  34. package/examples/day3.pln +1 -1
  35. package/examples/deployment.pln +1 -1
  36. package/examples/email-send.pln +1 -1
  37. package/examples/error-handling.pln +1 -1
  38. package/examples/expressions.pln +1 -1
  39. package/examples/file-uploads.pln +1 -1
  40. package/examples/files-and-config.pln +1 -1
  41. package/examples/files.pln +1 -1
  42. package/examples/football-backend/app.pln +1 -1
  43. package/examples/functions.pln +1 -1
  44. package/examples/hello.pln +1 -1
  45. package/examples/http-client.pln +1 -1
  46. package/examples/http.pln +1 -1
  47. package/examples/id-verification/app.pln +1 -1
  48. package/examples/javascript-library/README.md +54 -0
  49. package/examples/javascript-library/package-lock.json +21 -0
  50. package/examples/javascript-library/package.json +8 -0
  51. package/examples/javascript-library/public/config.json +4 -0
  52. package/examples/javascript-library/public/index.html +40 -0
  53. package/examples/javascript-library/src/interop.pln +53 -0
  54. package/examples/json.pln +1 -1
  55. package/examples/loops.pln +1 -1
  56. package/examples/modules/app.pln +1 -1
  57. package/examples/modules/main.pln +1 -1
  58. package/examples/modules/math.pln +1 -1
  59. package/examples/mongo.pln +1 -1
  60. package/examples/objects.pln +1 -1
  61. package/examples/ocr.pln +1 -1
  62. package/examples/packages.pln +1 -1
  63. package/examples/record-kinds.pln +1 -1
  64. package/examples/records.pln +1 -1
  65. package/examples/rest-api-fetch.pln +1 -1
  66. package/examples/rest-api.pln +1 -1
  67. package/examples/scheduled-tasks.pln +1 -1
  68. package/examples/search-and-filter.pln +1 -1
  69. package/examples/server.pln +1 -1
  70. package/examples/sessions-and-cookies.pln +1 -1
  71. package/examples/sqlite.pln +1 -1
  72. package/examples/start.pln +1 -1
  73. package/examples/stdlib.pln +1 -1
  74. package/examples/string-verbs.pln +1 -1
  75. package/examples/telegram-ai-bot.pln +1 -1
  76. package/examples/telegram-bot.pln +1 -1
  77. package/examples/testing.pln +1 -1
  78. package/examples/three-dimensional/README.md +51 -0
  79. package/examples/three-dimensional/public/index.html +33 -0
  80. package/examples/three-dimensional/src/scene.pln +34 -0
  81. package/examples/web-api.pln +1 -1
  82. package/examples/web-app.pln +1 -1
  83. package/examples/websocket-server.pln +1 -1
  84. package/examples/websocket.pln +1 -1
  85. package/examples/whatsapp-bot/pairing.pln +1 -1
  86. package/examples/whatsapp-bot/qr.pln +1 -1
  87. package/package.json +4 -3
@@ -1,4 +1,4 @@
1
- # PlainScript 1.0.35 language specification
1
+ # PlainScript 1.0.36 language specification
2
2
 
3
3
  This reference covers the syntax implemented by `compiler/lexer.js` and
4
4
  `compiler/parser.js`. The runtime it generates lives in
@@ -442,6 +442,134 @@ Chart options may include `width`, `height`, `background`, `foreground`,
442
442
  `grid`, `accent`, and `muted`. Image values are strings, so they can also be
443
443
  returned from a route or inserted into HTML.
444
444
 
445
+ ## Browser and games
446
+
447
+ PlainScript compiles to Plain JavaScript that runs in modern browsers. A
448
+ `web app` can serve the page itself, or you compile a `.pln` to `game.js` and
449
+ serve it with any static host. The tested workflows are:
450
+
451
+ 1. **Static**, served by PlainScript — `web app` + `serve folder "public"` +
452
+ a `reply file` route that returns `index.html`:
453
+
454
+ ```plainscript
455
+ web app
456
+ serve folder "public"
457
+ route get "/"
458
+ reply file "public/index.html"
459
+ done
460
+ start 8000
461
+ ```
462
+
463
+ 2. **Static**, any host — `node compiler/cli.js build game.pln -o public/game.js`
464
+ and include `<script src="game.js">` after the canvas and any CDN globals.
465
+
466
+ Canvas apps use the same value/property interop as everything else — canvas
467
+ state is assigned with `becomes`, then a draw call runs:
468
+
469
+ ```plainscript
470
+ remember canvas as document.getElementById("game")
471
+ remember ctx as canvas.getContext("2d")
472
+ ctx.fillStyle becomes "#0d1117"
473
+ ctx.fillRect(0, 0, 320, 240)
474
+ ```
475
+
476
+ Animation is `requestAnimationFrame`. Two native loop forms: `every frame`
477
+ (timing-agnostic) and an explicit rAF callback with delta seconds for
478
+ frame-rate-independent movement — see `docs/GAME-PROMPT.md` for the canonical
479
+ `dt` idiom. Input uses the DOM event form; `when <target> "<event>" happens`
480
+ becomes `addEventListener`, and reading a key map uses a boolean comparison:
481
+
482
+ ```plainscript
483
+ remember keys as {}
484
+ when document "keydown" happens as ke
485
+ keys[ke.key] becomes true
486
+ done
487
+ when document "keyup" happens as ke
488
+ keys[ke.key] becomes false
489
+ done
490
+
491
+ if keys["ArrowLeft"] is true
492
+ player.x becomes player.x - 4
493
+ done
494
+ ```
495
+
496
+ Browser builtins are either direct helpers or auto-awaited promises — no
497
+ `await` is written for the loaders:
498
+
499
+ - `select("canvas")` / `selectAll(".card")` / `parseHTML("<div>...</div>")`
500
+ - `loadImage(url)` → `Image`; `loadAudio(url)` → `Audio` element
501
+ - `fetchJson(url)` → `{ok, status, data, text, parseError}`; `fetchBytes(url)`
502
+ → `{ok, status, data: Uint8Array}`
503
+ - `readDataUrl(file)` → a `data:` URL string for a `File` (from
504
+ `droppedFiles(event)` or a file input)
505
+ - `audioContext()` + `playTone(frequency, seconds, options)` — start from a
506
+ user-gesture handler (`ctx.resume()`)
507
+ - `localPoint(event, canvas)` maps client to canvas coordinates
508
+ - `gamepads()` returns connected pads; `droppedFiles(event)` reads drag-drop
509
+ - WebSockets: client side uses `new WebSocket(url)` with `when ws "message"
510
+ happens`, and `webSocketSend(ws, value)` sends strings as-is or
511
+ JSON-stringifies anything else
512
+ - Persistence is direct interop: `localStorage.getItem(...)` /
513
+ `setItem` plus `jsonEncode` / `jsonDecode` (JSON is a builtin data type)
514
+
515
+ WebGL runs through the WebGL2 canvas API (`webglContext(canvas)`, `glShader`,
516
+ `glProgram`, `glBuffer` — all protected by teaching errors) or a library such
517
+ as Three.js constructed interop-style with `new`. WebGPU is available via its
518
+ canvas API.
519
+ A detailed, expanding guide for browser games lives in
520
+ `docs/GAME-PROMPT.md`.
521
+
522
+ ## JavaScript interop
523
+
524
+ `.pln` files are JavaScript; any JS API is reachable without sugar. Importing
525
+ uses `use` (bare npm name, bound lowercase) or `bring name from "pkg"`:
526
+
527
+ ```plainscript
528
+ use matter
529
+ bring THREE from "three"
530
+ remember engine as matter.Engine.create()
531
+ remember scene as new THREE.Scene()
532
+ ```
533
+
534
+ Call anything — member chains need no special syntax, and there is no wrapper
535
+ around values:
536
+
537
+ ```plainscript
538
+ crypto.createHash("sha256").update("abc").digest("hex")
539
+ mesh.scale.set(2, 2, 2)
540
+ ```
541
+
542
+ Construct with `new Type(args)` — as a statement, in `remember`, as an
543
+ argument, or bare without parens (`new Enemy`). A `make` function reference is
544
+ a first-class value — pass it as a callback:
545
+
546
+ ```plainscript
547
+ make fitWindow()
548
+ camera.aspect becomes window.innerWidth / window.innerHeight
549
+ camera.updateProjectionMatrix()
550
+ done
551
+ window.addEventListener("resize", fitWindow)
552
+ ```
553
+
554
+ Promises are awaited with `await` / `wait for`; errors follow the `try` /
555
+ `recover as err` / `finally` idiom, never `.then` chaining:
556
+
557
+ ```plainscript
558
+ try
559
+ remember response as await fetch("/api/state")
560
+ remember data as await response.json()
561
+ show data
562
+ recover as err
563
+ show message of err
564
+ done
565
+ ```
566
+
567
+ Typed arrays construct and index like anything else
568
+ (`new Uint8Array(64)`, `buffer[0] becomes 255`). The generated file adds
569
+ `require()` only for `use`/`bring`, and ends with a guarded `module.exports`
570
+ tail so the same output works as a browser `<script>` and under Node. The
571
+ comprehensive guide is `docs/GAME-PROMPT.md`.
572
+
445
573
  ## Native tests
446
574
 
447
575
  ```plainscript
@@ -457,6 +585,7 @@ Assertions are `equals`, `is`, `contains`, and `raises`.
457
585
  ```text
458
586
  plainscript check [target]
459
587
  plainscript build [file.pln]
588
+ plainscript build <file.pln> -o <output.js>
460
589
  plainscript run <file.pln>
461
590
  plainscript start
462
591
  plainscript fmt <file.pln>
package/docs/index.html CHANGED
@@ -3,13 +3,13 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <meta name="description" content="PlainScript 1.0.35 language reference and examples">
6
+ <meta name="description" content="PlainScript 1.0.36 language reference and examples">
7
7
  <meta name="theme-color" content="#070c16">
8
- <title>PlainScript 1.0.35</title>
8
+ <title>PlainScript 1.0.36</title>
9
9
 
10
10
  <link rel="preconnect" href="https://fonts.googleapis.com">
11
11
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
12
- <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@500&display=swap" rel="stylesheet">
12
+ <link href="https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,400;6..72,500&family=Public+Sans:wght@400;500&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
13
13
  <link rel="stylesheet" href="website/style.css">
14
14
  </head>
15
15
  <body>
@@ -21,7 +21,7 @@
21
21
  <a class="nav-logo" href="#">
22
22
  <img class="nav-logo-image" src="logo-pln.jpg" alt="">
23
23
  <span>PlainScript</span>
24
- <span class="logo-ver">1.0.35</span>
24
+ <span class="logo-ver">1.0.36</span>
25
25
  </a>
26
26
  <button class="nav-toggle" id="nav-toggle" aria-label="Toggle navigation" aria-expanded="false" aria-controls="nav-links">
27
27
  <span class="nav-toggle-bar"></span>
@@ -40,17 +40,24 @@
40
40
  <main>
41
41
  <section class="hero">
42
42
  <div class="container hero-content">
43
- <p class="hero-badge" data-reveal>1.0.35: Node.js programming for everyone</p>
44
- <h1 class="hero-title">Code that reads like plain English.</h1>
45
- <p class="hero-lead">Write what you want in plain words. PlainScript turns it into JavaScript — simple, readable, and easy to check.</p>
46
- <div class="hero-actions">
47
- <a class="button button-primary" href="#quickstart">Start building</a>
48
- <a class="button button-secondary" href="#library">Browse examples</a>
49
- </div>
50
- <pre class="code-window"><code>remember name as "Ada"
43
+ <div class="hero-grid">
44
+ <div class="hero-headline-block">
45
+ <p class="hero-badge" data-reveal>an intent-oriented language for node.js</p>
46
+ <h1 class="hero-title"><span class="kw">remember</span> the sentence <span class="kw">as</span> the program.<br><span class="kw">show</span> the result <span class="kw">when</span> the meaning is clear.</h1>
47
+ <p class="hero-lead">Write what you want in plain words. PlainScript checks it, then turns it into readable JavaScript — no boilerplate, no hidden steps.</p>
48
+ <div class="hero-actions">
49
+ <span class="hero-install-label">install</span>
50
+ <a class="button" href="#quickstart">npx plainscript new hello</a>
51
+ </div>
52
+ </div>
53
+ <div class="hero-panel">
54
+ <p class="hero-panel-label">terminal</p>
55
+ <pre class="code-window"><code>remember name as "Ada"
51
56
  if name contains "A"
52
57
  show `Hello, ${name}!`
53
58
  done</code></pre>
59
+ </div>
60
+ </div>
54
61
  </div>
55
62
  </section>
56
63
 
@@ -103,7 +110,7 @@ npm start</code></pre>
103
110
  <div class="container">
104
111
  <p class="section-tag" data-reveal>Feature library</p>
105
112
  <h2 class="section-title" data-reveal>Examples you can try today.</h2>
106
- <p class="section-lead">These snippets use the PlainScript 1.0.35 grammar.</p>
113
+ <p class="section-lead">These snippets use the PlainScript 1.0.36 grammar.</p>
107
114
  <div class="library-toolbar" data-reveal>
108
115
  <label class="sr-only" for="lib-search">Search examples</label>
109
116
  <input id="lib-search" class="lib-search-input" type="search" placeholder="Search examples">
@@ -132,7 +139,7 @@ npm start</code></pre>
132
139
  </main>
133
140
 
134
141
  <footer class="site-footer">
135
- <div class="container footer-bottom"><span>PlainScript</span><span>1.0.35</span></div>
142
+ <div class="container footer-bottom"><span>PlainScript</span><span>1.0.36</span></div>
136
143
  </footer>
137
144
 
138
145
  <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>