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.
- package/README.md +828 -209
- package/compiler/cli.js +68 -4
- package/compiler/generator.js +315 -0
- package/compiler/lexer.js +12 -0
- package/compiler/parser.js +144 -12
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +25 -4
- package/docs/GAME-PROMPT.md +915 -0
- package/docs/PLAINSCRIPT-SPEC.md +130 -1
- package/docs/index.html +21 -14
- package/docs/website/style.css +162 -195
- 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/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 +1 -1
- package/examples/whatsapp-bot/qr.pln +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Dropping into a JavaScript library
|
|
2
|
+
|
|
3
|
+
The full-interop showcase: import an npm package with `bring`, call members and
|
|
4
|
+
`new` constructors on it, pass PlainScript functions as native callbacks, and
|
|
5
|
+
optionally shape the scene with a JSON config fetched at runtime. This is the
|
|
6
|
+
**import path** — unlike `examples/three-dimensional`, which maps `THREE` to a
|
|
7
|
+
browser global, this file demands the package be bundled for the browser.
|
|
8
|
+
|
|
9
|
+
What the script exercises:
|
|
10
|
+
|
|
11
|
+
- `bring THREE from "three"` emits `require('three')` at the top of the build.
|
|
12
|
+
- `new THREE.Scene()`, `new THREE.WebGLRenderer()`, `new THREE.SphereGeometry(...)`
|
|
13
|
+
and `new THREE.Mesh(geo, mat)` fill a starfield of 150 primitives. Colors use
|
|
14
|
+
v1.0.36 hex literals (`0x40c463`), so the palette is legible at a glance.
|
|
15
|
+
- A resize callback `make fitWindow() ... done` passed straight to
|
|
16
|
+
`window.addEventListener("resize", fitWindow)`.
|
|
17
|
+
- `fetchJson("config.json")` (auto-awaiting) reads `{stars, color}` out of a
|
|
18
|
+
served file and re-sizes/re-colors the field. In `try ... recover as err ... done`
|
|
19
|
+
a failing fetch logs the error and falls back to the built-in defaults —
|
|
20
|
+
serve the folder over HTTP so the fetch succeeds, and you'll see the fallback
|
|
21
|
+
path fire if you ever open the page from `file://`.
|
|
22
|
+
- `every frame ... done` rotates the whole scene and calls `renderer.render(...)`.
|
|
23
|
+
- `show "..."` lines land in the browser console because `show` compiles to
|
|
24
|
+
`console.log`.
|
|
25
|
+
|
|
26
|
+
## Run
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
plainscript add three
|
|
30
|
+
npx plainscript build src/interop.pln -o public/interop.js
|
|
31
|
+
npx esbuild public/interop.js --bundle --outfile=public/interop.bundle.js
|
|
32
|
+
npx serve public
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Then open http://localhost:3000 (check the console). `index.html` already points
|
|
36
|
+
at `interop.bundle.js`.
|
|
37
|
+
|
|
38
|
+
`plainscript add <package>` installs a package into the current project and
|
|
39
|
+
saves it to `package.json` (`npm install <package> --save` under the hood). The
|
|
40
|
+
esbuild one-liner above is all the bundling the import path needs; vite or
|
|
41
|
+
rollup work equally well. Build twice — once by PlainScript, once by a bundler —
|
|
42
|
+
is the whole trick: PlainScript emits ordinary CommonJS `require()`s and the
|
|
43
|
+
bundler turns them into browser-safe modules.
|
|
44
|
+
|
|
45
|
+
`check` never needs the package installed: `npx plainscript check src` validates
|
|
46
|
+
imports from the source alone.
|
|
47
|
+
|
|
48
|
+
## What to tweak
|
|
49
|
+
|
|
50
|
+
Point `fetchJson` at a remote URL or drop a different `config.json` next to the
|
|
51
|
+
page. Anything you can reach with `fetch` — `fetchJson` returns
|
|
52
|
+
`{ok, status, data, text, parseError}` — is fair game, and the
|
|
53
|
+
`try ... recover` block shows the friendly-fallback pattern when the network
|
|
54
|
+
misbehaves.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "javascript-library",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "javascript-library",
|
|
9
|
+
"version": "0.1.0",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"three": "^0.185.1"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"node_modules/three": {
|
|
15
|
+
"version": "0.185.1",
|
|
16
|
+
"resolved": "https://registry.npmjs.org/three/-/three-0.185.1.tgz",
|
|
17
|
+
"integrity": "sha512-5aojFCXKwnjBRZvUnt3WFfEcvUJgkN5LlijRFN95hMy8WVkG4I0QNcJE+OuWvuJ0bOdStrbfXn0pkd6/QyiAlg==",
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>PlainScript Interop</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
background: #0d1117;
|
|
12
|
+
color: #e6edf3;
|
|
13
|
+
font-family: system-ui, "Segoe UI", sans-serif;
|
|
14
|
+
}
|
|
15
|
+
.note {
|
|
16
|
+
position: fixed;
|
|
17
|
+
bottom: 12px;
|
|
18
|
+
left: 50%;
|
|
19
|
+
transform: translateX(-50%);
|
|
20
|
+
width: 90%;
|
|
21
|
+
max-width: 640px;
|
|
22
|
+
padding: 8px 14px;
|
|
23
|
+
border-radius: 10px;
|
|
24
|
+
background: rgba(13, 17, 23, 0.75);
|
|
25
|
+
font-size: 13px;
|
|
26
|
+
color: #8b949e;
|
|
27
|
+
text-align: center;
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
<div class="note">
|
|
34
|
+
Fetching <code>config.json</code> from the server — serve the folder over HTTP
|
|
35
|
+
and the star count / color come from the file; otherwise the scene falls back
|
|
36
|
+
to the built-in defaults (check the console for the log lines).
|
|
37
|
+
</div>
|
|
38
|
+
<script src="interop.bundle.js"></script>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// PlainScript 1.0.36: drop into an npm library via import, callbacks, and fetch.
|
|
2
|
+
|
|
3
|
+
bring THREE from "three"
|
|
4
|
+
|
|
5
|
+
remember scene as new THREE.Scene()
|
|
6
|
+
remember camera as new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000)
|
|
7
|
+
remember renderer as new THREE.WebGLRenderer()
|
|
8
|
+
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
9
|
+
camera.position.z becomes 9
|
|
10
|
+
document.body.append(renderer.domElement)
|
|
11
|
+
|
|
12
|
+
make fitWindow()
|
|
13
|
+
camera.aspect becomes window.innerWidth / window.innerHeight
|
|
14
|
+
camera.updateProjectionMatrix()
|
|
15
|
+
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
16
|
+
done
|
|
17
|
+
|
|
18
|
+
window.addEventListener("resize", fitWindow)
|
|
19
|
+
|
|
20
|
+
remember starCount as 150
|
|
21
|
+
remember starColor as 0x40c463
|
|
22
|
+
|
|
23
|
+
try
|
|
24
|
+
remember cfg as fetchJson("config.json")
|
|
25
|
+
if cfg.ok is true
|
|
26
|
+
starCount becomes cfg.data.stars
|
|
27
|
+
starColor becomes cfg.data.color
|
|
28
|
+
otherwise
|
|
29
|
+
show "Config request returned status " + cfg.status
|
|
30
|
+
done
|
|
31
|
+
recover as err
|
|
32
|
+
show message of err
|
|
33
|
+
show "Falling back to the built-in starfield."
|
|
34
|
+
done
|
|
35
|
+
|
|
36
|
+
remember stars as []
|
|
37
|
+
for index n from 0 to starCount
|
|
38
|
+
remember shape as new THREE.SphereGeometry(0.05, 6, 6)
|
|
39
|
+
remember starMaterial as new THREE.MeshBasicMaterial({ color: starColor })
|
|
40
|
+
remember star as new THREE.Mesh(shape, starMaterial)
|
|
41
|
+
star.position.x becomes (Math.random() - 0.5) * 18
|
|
42
|
+
star.position.y becomes (Math.random() - 0.5) * 10
|
|
43
|
+
star.position.z becomes (Math.random() - 0.5) * 10
|
|
44
|
+
scene.add(star)
|
|
45
|
+
stars.push(star)
|
|
46
|
+
done
|
|
47
|
+
|
|
48
|
+
show "Starfield ready with " + starCount + " stars"
|
|
49
|
+
|
|
50
|
+
every frame
|
|
51
|
+
scene.rotation.y becomes scene.rotation.y + 0.002
|
|
52
|
+
renderer.render(scene, camera)
|
|
53
|
+
done
|
package/examples/json.pln
CHANGED
package/examples/loops.pln
CHANGED
package/examples/modules/app.pln
CHANGED
package/examples/mongo.pln
CHANGED
package/examples/objects.pln
CHANGED
package/examples/ocr.pln
CHANGED
package/examples/packages.pln
CHANGED
package/examples/records.pln
CHANGED
package/examples/rest-api.pln
CHANGED
package/examples/server.pln
CHANGED
package/examples/sqlite.pln
CHANGED
package/examples/start.pln
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// PlainScript 1.0.
|
|
1
|
+
// PlainScript 1.0.36: start command entry point.
|
|
2
2
|
show "PlainScript started"
|
package/examples/stdlib.pln
CHANGED
package/examples/testing.pln
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# WebGL 3D scene via the global THREE object
|
|
2
|
+
|
|
3
|
+
The canonical PlainScript path to 3D: the page loads **three.js from a CDN**
|
|
4
|
+
before the compiled script, so `src/scene.pln` just references the global
|
|
5
|
+
`THREE` object directly. The build is 100% dependency-free — the emitted file
|
|
6
|
+
contains no `require(...)` and needs no bundler, it only needs `THREE` to exist
|
|
7
|
+
in the page.
|
|
8
|
+
|
|
9
|
+
What the script exercises:
|
|
10
|
+
|
|
11
|
+
- `remember scene as new THREE.Scene()`, `new THREE.PerspectiveCamera(...)`,
|
|
12
|
+
`new THREE.WebGLRenderer()` and `renderer.setSize(...)`.
|
|
13
|
+
- `new THREE.BoxGeometry(...)`, `new THREE.MeshStandardMaterial({ color: 0x40c463 })`
|
|
14
|
+
and `new THREE.Mesh(geo, mat)` — v1.0.36 hex literals (`0xRRGGBB`) keep the
|
|
15
|
+
palette legible; the lights use `0xffffff`.
|
|
16
|
+
- A light rig with `new THREE.AmbientLight(...)` + `new THREE.DirectionalLight(...)`.
|
|
17
|
+
- `document.body.append(renderer.domElement)` mounts the WebGL canvas.
|
|
18
|
+
- A `when window "resize" happens` handler that updates the camera aspect ratio
|
|
19
|
+
and the renderer size.
|
|
20
|
+
- An `every frame ... done` `requestAnimationFrame` loop that rotates the cube
|
|
21
|
+
and calls `renderer.render(scene, camera)`.
|
|
22
|
+
|
|
23
|
+
## Run
|
|
24
|
+
|
|
25
|
+
No install, no bundler. Build, then open the page over a static server:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx plainscript build src/scene.pln -o public/scene.js
|
|
29
|
+
npx serve public
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then open http://localhost:3000.
|
|
33
|
+
|
|
34
|
+
## The alternative: importing three as a package
|
|
35
|
+
|
|
36
|
+
If you prefer the npm module instead of a CDN global, swap the `.pln` header for
|
|
37
|
+
|
|
38
|
+
```plainscript
|
|
39
|
+
bring THREE from "three"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`plainscript build` then emits `const THREE = require('three');` at the top, and
|
|
43
|
+
the browser needs that bundled:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
plainscript add three
|
|
47
|
+
npx esbuild public/scene.js --bundle --outfile=public/scene.bundle.js
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
and point `index.html` at the bundled file. The CDN-global route above exists
|
|
51
|
+
precisely so you can ship 3D without a bundler.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>PlainScript 3D</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
background: #0d1117;
|
|
12
|
+
color: #e6edf3;
|
|
13
|
+
font-family: system-ui, "Segoe UI", sans-serif;
|
|
14
|
+
}
|
|
15
|
+
.note {
|
|
16
|
+
position: fixed;
|
|
17
|
+
bottom: 12px;
|
|
18
|
+
left: 50%;
|
|
19
|
+
transform: translateX(-50%);
|
|
20
|
+
padding: 6px 14px;
|
|
21
|
+
border-radius: 999px;
|
|
22
|
+
background: rgba(13, 17, 23, 0.75);
|
|
23
|
+
font-size: 13px;
|
|
24
|
+
color: #8b949e;
|
|
25
|
+
pointer-events: none;
|
|
26
|
+
}
|
|
27
|
+
</style>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
|
|
31
|
+
<script src="scene.js"></script>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// PlainScript 1.0.36: a WebGL 3D scene using the global THREE object.
|
|
2
|
+
|
|
3
|
+
remember scene as new THREE.Scene()
|
|
4
|
+
remember camera as new THREE.PerspectiveCamera(75, 640 / 480, 0.1, 1000)
|
|
5
|
+
remember renderer as new THREE.WebGLRenderer()
|
|
6
|
+
renderer.setSize(640, 480)
|
|
7
|
+
camera.position.z becomes 5
|
|
8
|
+
|
|
9
|
+
remember geometry as new THREE.BoxGeometry(1, 1, 1)
|
|
10
|
+
remember material as new THREE.MeshStandardMaterial({ color: 0x40c463 })
|
|
11
|
+
remember cube as new THREE.Mesh(geometry, material)
|
|
12
|
+
scene.add(cube)
|
|
13
|
+
|
|
14
|
+
remember ambient as new THREE.AmbientLight(0xffffff)
|
|
15
|
+
remember sun as new THREE.DirectionalLight(0xffffff, 1)
|
|
16
|
+
sun.position.set(3, 5, 4)
|
|
17
|
+
scene.add(ambient)
|
|
18
|
+
scene.add(sun)
|
|
19
|
+
|
|
20
|
+
document.body.append(renderer.domElement)
|
|
21
|
+
|
|
22
|
+
make fitWindow()
|
|
23
|
+
camera.aspect becomes window.innerWidth / window.innerHeight
|
|
24
|
+
camera.updateProjectionMatrix()
|
|
25
|
+
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
26
|
+
done
|
|
27
|
+
|
|
28
|
+
window.addEventListener("resize", fitWindow)
|
|
29
|
+
|
|
30
|
+
every frame
|
|
31
|
+
cube.rotation.y becomes cube.rotation.y + 0.01
|
|
32
|
+
cube.rotation.x becomes cube.rotation.x + 0.005
|
|
33
|
+
renderer.render(scene, camera)
|
|
34
|
+
done
|
package/examples/web-api.pln
CHANGED
package/examples/web-app.pln
CHANGED
package/examples/websocket.pln
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plainscript-lang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"description": "PlainScript — an Intent-Oriented Programming Language. When even a simple sentence can be code.",
|
|
5
5
|
"main": "compiler/cli.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"plainscript": "./compiler/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "node tests/compiler.test.js && node tests/build.test.js && node tests/telegram.test.js && node tests/ocr.test.js && node tests/nesting.test.js && node tests/backend.test.js && node tests/runtime.test.js && node tests/acceptance.test.js && node tests/whatsapp.test.js && node tests/audit.test.js && node tests/sourcemap.test.js && node tests/modules.test.js && node tests/datastructures.test.js && node tests/docs.test.js && node tests/compat/language.test.js && node tests/compat/node.test.js && node tests/compat/binary.test.js && node tests/compat/errors.test.js && node tests/compat/async.test.js && node tests/compat/modules.test.js && node tests/compat/npm.test.js && node tests/compat/web.test.js && node tests/compat/real-world.test.js"
|
|
10
|
+
"test": "node tests/compiler.test.js && node tests/build.test.js && node tests/telegram.test.js && node tests/ocr.test.js && node tests/nesting.test.js && node tests/backend.test.js && node tests/runtime.test.js && node tests/browser.test.js && node tests/acceptance.test.js && node tests/whatsapp.test.js && node tests/audit.test.js && node tests/sourcemap.test.js && node tests/modules.test.js && node tests/datastructures.test.js && node tests/docs.test.js && node tests/compat/browser-interop.test.js && node tests/compat/language.test.js && node tests/compat/node.test.js && node tests/compat/binary.test.js && node tests/compat/errors.test.js && node tests/compat/async.test.js && node tests/compat/modules.test.js && node tests/compat/npm.test.js && node tests/compat/web.test.js && node tests/compat/real-world.test.js"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"compiler",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@qwerty-xcv/baileys": "^0.0.1",
|
|
46
46
|
"mongodb": "^7.6.0",
|
|
47
|
-
"tesseract.js": "^7.0.0"
|
|
47
|
+
"tesseract.js": "^7.0.0",
|
|
48
|
+
"three": "^0.185.1"
|
|
48
49
|
}
|
|
49
50
|
}
|