plainscript-lang 1.0.362 → 1.1.0
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 +394 -54
- package/compiler/bundler.js +78 -3
- package/compiler/cli.js +239 -30
- package/compiler/formatter.js +21 -1
- package/compiler/generator.js +453 -107
- package/compiler/ir.js +62 -0
- package/compiler/lexer.js +42 -7
- package/compiler/lsp.js +290 -0
- package/compiler/parser.js +820 -113
- package/compiler/type-checker.js +440 -0
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +19 -3
- package/docs/GAME-PROMPT.md +3 -3
- package/docs/PLAINSCRIPT-GRAMMAR.md +317 -0
- package/docs/PLAINSCRIPT-SPEC.md +264 -5
- package/docs/V1.1-TYPED-COLLECTIONS-DESIGN.md +220 -0
- package/docs/index.html +5 -5
- package/docs/website/script.js +1 -1
- package/examples/ai-memory-cli.pln +221 -0
- package/examples/ai-memory.json +1 -0
- 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 +1 -1
- 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 +1 -1
- package/examples/canvas-game/src/game.pln +1 -1
- package/examples/collections.pln +1 -1
- package/examples/compound-assignments.pln +24 -0
- package/examples/concurrency.pln +2 -2
- 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-manager-cli.pln +51 -0
- 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/interactive-cli.pln +34 -0
- package/examples/javascript-library/README.md +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/memoize-demo.pln +31 -0
- 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/normalization-forms.pln +22 -0
- package/examples/objects.pln +1 -1
- package/examples/ocr.pln +1 -1
- package/examples/packages.pln +1 -1
- package/examples/random-cli.pln +32 -0
- 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/run-in-parallel.pln +25 -0
- 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/stats-cli.pln +29 -0
- package/examples/stdlib.pln +1 -1
- package/examples/string-helpers.pln +23 -0
- package/examples/string-verbs.pln +1 -1
- package/examples/telegram-ai-bot.pln +1 -1
- package/examples/telegram-bot.pln +1 -1
- package/examples/terminal-cli.pln +11 -0
- package/examples/testing.pln +1 -1
- package/examples/three-dimensional/README.md +1 -1
- package/examples/three-dimensional/src/scene.pln +1 -1
- package/examples/todo-cli.pln +98 -0
- package/examples/typed-collections.pln +21 -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 +13 -4
package/examples/deployment.pln
CHANGED
package/examples/email-send.pln
CHANGED
package/examples/expressions.pln
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — a small file manager CLI.
|
|
2
|
+
// Usage:
|
|
3
|
+
// plainscript run examples/file-manager-cli.pln list
|
|
4
|
+
// plainscript run examples/file-manager-cli.pln copy readme.md readme-backup.md
|
|
5
|
+
// plainscript run examples/file-manager-cli.pln remove readme-backup.md
|
|
6
|
+
// plainscript run examples/file-manager-cli.pln archive old-logs
|
|
7
|
+
|
|
8
|
+
make showHelp()
|
|
9
|
+
show "file-manager-cli.pln <list|copy|remove|archive> <path...>"
|
|
10
|
+
done
|
|
11
|
+
|
|
12
|
+
make main()
|
|
13
|
+
remember argv as args()
|
|
14
|
+
if count of argv is 0
|
|
15
|
+
showHelp()
|
|
16
|
+
exit(0)
|
|
17
|
+
done
|
|
18
|
+
remember command as argv at position 0
|
|
19
|
+
if command is "list"
|
|
20
|
+
show listFolder(".")
|
|
21
|
+
otherwise if command is "copy"
|
|
22
|
+
if count of argv is at least 3
|
|
23
|
+
copyFile(argv at position 1, argv at position 2)
|
|
24
|
+
show "copied " + argv at position 1 + " to " + argv at position 2
|
|
25
|
+
otherwise
|
|
26
|
+
show "usage: ... copy <from> <to>"
|
|
27
|
+
done
|
|
28
|
+
otherwise if command is "remove"
|
|
29
|
+
if count of argv is at least 2
|
|
30
|
+
deleteFile(argv at position 1)
|
|
31
|
+
show "removed " + argv at position 1
|
|
32
|
+
otherwise
|
|
33
|
+
show "usage: ... remove <file>"
|
|
34
|
+
done
|
|
35
|
+
otherwise if command is "archive"
|
|
36
|
+
if count of argv is at least 2
|
|
37
|
+
archiveEntry(argv at position 1)
|
|
38
|
+
otherwise
|
|
39
|
+
show "usage: ... archive <path>"
|
|
40
|
+
done
|
|
41
|
+
otherwise
|
|
42
|
+
showHelp()
|
|
43
|
+
done
|
|
44
|
+
done
|
|
45
|
+
|
|
46
|
+
make archiveEntry(path)
|
|
47
|
+
moveFile(path, path + "-archive")
|
|
48
|
+
show "archived " + path + " as " + path + "-archive"
|
|
49
|
+
done
|
|
50
|
+
|
|
51
|
+
main()
|
package/examples/files.pln
CHANGED
package/examples/functions.pln
CHANGED
package/examples/hello.pln
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// PlainScript 1.0.
|
|
1
|
+
// PlainScript 1.0.363: hello world.
|
|
2
2
|
show "Hello, PlainScript!"
|
package/examples/http-client.pln
CHANGED
package/examples/http.pln
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — an interactive terminal menu.
|
|
2
|
+
// Usage: plainscript run examples/interactive-cli.pln
|
|
3
|
+
// Runs a loop of `ask`, `confirm`, and `choose` prompts. When given the
|
|
4
|
+
// non-interactive flag it self-drives with seeded answers (for tests).
|
|
5
|
+
|
|
6
|
+
make playOnce(seedMode)
|
|
7
|
+
if seedMode is true
|
|
8
|
+
show "seeded: " + choose("Pick a color", ["red", "green", "blue"])
|
|
9
|
+
otherwise
|
|
10
|
+
ask "What is your name? " as guest
|
|
11
|
+
show "hello, " + guest
|
|
12
|
+
remember ok as confirm("Shall we continue")
|
|
13
|
+
if ok is true
|
|
14
|
+
show "choice: " + choose("Drink?", ["tea", "coffee", "juice"])
|
|
15
|
+
otherwise
|
|
16
|
+
show "ok, maybe next time"
|
|
17
|
+
done
|
|
18
|
+
done
|
|
19
|
+
done
|
|
20
|
+
|
|
21
|
+
make main()
|
|
22
|
+
remember argv as args()
|
|
23
|
+
if count of argv is at least 1 and argv at position 0 is "seeded"
|
|
24
|
+
playOnce(true)
|
|
25
|
+
otherwise
|
|
26
|
+
if count of argv is at least 1
|
|
27
|
+
show "usage: ... [seeded]"
|
|
28
|
+
exit(1)
|
|
29
|
+
done
|
|
30
|
+
playOnce(false)
|
|
31
|
+
done
|
|
32
|
+
done
|
|
33
|
+
|
|
34
|
+
main()
|
|
@@ -11,7 +11,7 @@ What the script exercises:
|
|
|
11
11
|
- `bring THREE from "three"` emits `require('three')` at the top of the build.
|
|
12
12
|
- `new THREE.Scene()`, `new THREE.WebGLRenderer()`, `new THREE.SphereGeometry(...)`
|
|
13
13
|
and `new THREE.Mesh(geo, mat)` fill a starfield of 150 primitives. Colors use
|
|
14
|
-
v1.0.
|
|
14
|
+
v1.0.363 hex literals (`0x40c463`), so the palette is legible at a glance.
|
|
15
15
|
- A resize callback `make fitWindow() ... done` passed straight to
|
|
16
16
|
`window.addEventListener("resize", fitWindow)`.
|
|
17
17
|
- `fetchJson("config.json")` (auto-awaiting) reads `{stars, color}` out of a
|
package/examples/json.pln
CHANGED
package/examples/loops.pln
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — memoization and the new statistics/vector primitives.
|
|
2
|
+
|
|
3
|
+
make slowSquare(n)
|
|
4
|
+
give n * n
|
|
5
|
+
done
|
|
6
|
+
|
|
7
|
+
remember fastSquare as memoize(slowSquare)
|
|
8
|
+
show fastSquare(9)
|
|
9
|
+
show fastSquare(9)
|
|
10
|
+
|
|
11
|
+
// A memoized recursive function still uses `make` + `yield`-free bodies:
|
|
12
|
+
make expensiveSum(n)
|
|
13
|
+
if n is at most 0
|
|
14
|
+
give 0
|
|
15
|
+
done
|
|
16
|
+
give n + expensiveSum(n - 1)
|
|
17
|
+
done
|
|
18
|
+
show expensiveSum(10)
|
|
19
|
+
|
|
20
|
+
// Vector primitives.
|
|
21
|
+
remember a as [1, 2, 3]
|
|
22
|
+
remember b as [4, 5, 6]
|
|
23
|
+
show "dot: " + dotProduct(a, b)
|
|
24
|
+
show "length of a: " + magnitude(a)
|
|
25
|
+
show "unit of a: " + join(normalize(a), ", ")
|
|
26
|
+
|
|
27
|
+
remember data as [2, 4, 4, 4, 5, 5, 7, 9]
|
|
28
|
+
show "mean: " + mean(data)
|
|
29
|
+
show "median: " + median(data)
|
|
30
|
+
show "variance: " + round(variance(data) * 100) / 100
|
|
31
|
+
show "deviation: " + round(deviation(data) * 100) / 100
|
package/examples/modules/app.pln
CHANGED
package/examples/mongo.pln
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — the three declaration forms are one grammar.
|
|
2
|
+
// `let x is ...`, `let x be ...`, and `remember x as ...` compile to the
|
|
3
|
+
// same JavaScript; mix them freely and const/generalize them.
|
|
4
|
+
// A `make function` body that uses `yield` compiles to a generator function.
|
|
5
|
+
|
|
6
|
+
let a is 5
|
|
7
|
+
let b be 6
|
|
8
|
+
remember c as 7
|
|
9
|
+
show a + b + c
|
|
10
|
+
|
|
11
|
+
let celsius be 21
|
|
12
|
+
remember fahrenheit as celsius * 9 / 5 + 32
|
|
13
|
+
show "69.8 degrees computed: " + fahrenheit
|
|
14
|
+
|
|
15
|
+
let tick be 1
|
|
16
|
+
tick is now 2
|
|
17
|
+
show tick
|
|
18
|
+
|
|
19
|
+
let name be "ada"
|
|
20
|
+
name becomes "ada lovelace"
|
|
21
|
+
name change to "Ada Lovelace"
|
|
22
|
+
show name
|
package/examples/objects.pln
CHANGED
package/examples/ocr.pln
CHANGED
package/examples/packages.pln
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — randomness without repeats and weighted picks.
|
|
2
|
+
// Usage:
|
|
3
|
+
// plainscript run examples/random-cli.pln
|
|
4
|
+
// plainscript run examples/random-cli.pln 20
|
|
5
|
+
|
|
6
|
+
make rollDice(sides)
|
|
7
|
+
give randomInteger(1, sides)
|
|
8
|
+
done
|
|
9
|
+
|
|
10
|
+
make main()
|
|
11
|
+
remember argv as args()
|
|
12
|
+
remember rolls as 6
|
|
13
|
+
if count of argv is at least 1
|
|
14
|
+
rolls becomes parseInt(argv at position 0, 10)
|
|
15
|
+
done
|
|
16
|
+
show "rolling a d6 " + rolls + " times:"
|
|
17
|
+
remember i as 0
|
|
18
|
+
remember sum as 0
|
|
19
|
+
while i is less than rolls
|
|
20
|
+
sum += rollDice(6)
|
|
21
|
+
i += 1
|
|
22
|
+
done
|
|
23
|
+
show "sum of rolls: " + sum
|
|
24
|
+
show "one die: " + rollDice(6)
|
|
25
|
+
show "coin: " + randomChoice(["heads", "tails"])
|
|
26
|
+
show "lucky card: " + randomChoice(["Ace", "King", "Queen", "Jack"])
|
|
27
|
+
show "weighted loot: " + weightedChoice(["common", "rare", "legendary"], [0.7, 0.25, 0.05])
|
|
28
|
+
show "shuffled deck: " + join(shuffle(["A", "2", "3", "4", "5"]), " ")
|
|
29
|
+
show "three of ten: " + join(sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3), " ")
|
|
30
|
+
done
|
|
31
|
+
|
|
32
|
+
main()
|
package/examples/records.pln
CHANGED
package/examples/rest-api.pln
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — Promise.all-style concurrency with a named result.
|
|
2
|
+
// `run in parallel ... done as <name>` starts every call at once and collects
|
|
3
|
+
// the value of each statement into the named list, preserving order.
|
|
4
|
+
|
|
5
|
+
make square(n)
|
|
6
|
+
give n * n
|
|
7
|
+
done
|
|
8
|
+
|
|
9
|
+
make cube(n)
|
|
10
|
+
give n * n * n
|
|
11
|
+
done
|
|
12
|
+
|
|
13
|
+
run in parallel
|
|
14
|
+
square(3)
|
|
15
|
+
cube(3)
|
|
16
|
+
square(4)
|
|
17
|
+
done as results
|
|
18
|
+
|
|
19
|
+
show "results: " + join(results, ", ")
|
|
20
|
+
|
|
21
|
+
remember acc as 0
|
|
22
|
+
for each value in results
|
|
23
|
+
acc += value
|
|
24
|
+
done
|
|
25
|
+
show "sum: " + acc
|
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.363: start command entry point.
|
|
2
2
|
show "PlainScript started"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — statistics over an arbitrary sample.
|
|
2
|
+
// Usage:
|
|
3
|
+
// plainscript run examples/stats-cli.pln 2 4 4 4 5 5 7 9
|
|
4
|
+
// New primitives: mean, median, variance, deviation, plus sort/first/last.
|
|
5
|
+
|
|
6
|
+
make toNumbers(raw)
|
|
7
|
+
remember numbers as []
|
|
8
|
+
for each item in raw
|
|
9
|
+
push(numbers, parseFloat(item))
|
|
10
|
+
done
|
|
11
|
+
give numbers
|
|
12
|
+
done
|
|
13
|
+
|
|
14
|
+
make report(numbers)
|
|
15
|
+
if count of numbers is 0
|
|
16
|
+
show "no numbers given; using the default sample"
|
|
17
|
+
numbers becomes [2, 4, 4, 4, 5, 5, 7, 9]
|
|
18
|
+
done
|
|
19
|
+
remember ordered as sort(numbers)
|
|
20
|
+
show "count: " + count of numbers
|
|
21
|
+
show "mean: " + round(mean(numbers) * 100) / 100
|
|
22
|
+
show "median: " + median(numbers)
|
|
23
|
+
show "variance: " + round(variance(numbers) * 100) / 100
|
|
24
|
+
show "deviation: " + round(deviation(numbers) * 100) / 100
|
|
25
|
+
show "lowest: " + first(ordered)
|
|
26
|
+
show "highest: " + last(ordered)
|
|
27
|
+
done
|
|
28
|
+
|
|
29
|
+
report(toNumbers(args()))
|
package/examples/stdlib.pln
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — string helpers including the new parsing verbs.
|
|
2
|
+
// parseBoolean / characters / toUpperCase / toLowerCase / split / join.
|
|
3
|
+
|
|
4
|
+
remember raw as "true"
|
|
5
|
+
show parseBoolean(raw)
|
|
6
|
+
|
|
7
|
+
remember messy as " PlainScript "
|
|
8
|
+
show "[" + trim(messy) + "]"
|
|
9
|
+
show toUpperCase("whisper")
|
|
10
|
+
show toLowerCase("LOUD")
|
|
11
|
+
|
|
12
|
+
remember sentence as "the quick brown fox"
|
|
13
|
+
remember chars as characters("abc")
|
|
14
|
+
show "first char: " + chars at position 0
|
|
15
|
+
show "words: " + count of split(sentence, " ")
|
|
16
|
+
|
|
17
|
+
remember yesCount as 0
|
|
18
|
+
for each token in split("yes,no,1,off,true", ",")
|
|
19
|
+
if parseBoolean(token) is true
|
|
20
|
+
yesCount += 1
|
|
21
|
+
done
|
|
22
|
+
done
|
|
23
|
+
show "truthy tokens: " + yesCount
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// PlainScript 1.0.363 — terminal and process primitives.
|
|
2
|
+
// `terminalWidth()`, `terminalHeight()`, `clearTerminal()` and `stderr(...)`
|
|
3
|
+
// are CLI helpers. Error text goes to stderr so stdout stays clean.
|
|
4
|
+
|
|
5
|
+
stderr("starting terminal census")
|
|
6
|
+
show "width: " + terminalWidth()
|
|
7
|
+
show "height: " + terminalHeight()
|
|
8
|
+
stderr("clearing screen")
|
|
9
|
+
clearTerminal()
|
|
10
|
+
show "screen cleared"
|
|
11
|
+
stderr("done")
|
package/examples/testing.pln
CHANGED
|
@@ -11,7 +11,7 @@ What the script exercises:
|
|
|
11
11
|
- `remember scene as new THREE.Scene()`, `new THREE.PerspectiveCamera(...)`,
|
|
12
12
|
`new THREE.WebGLRenderer()` and `renderer.setSize(...)`.
|
|
13
13
|
- `new THREE.BoxGeometry(...)`, `new THREE.MeshStandardMaterial({ color: 0x40c463 })`
|
|
14
|
-
and `new THREE.Mesh(geo, mat)` - v1.0.
|
|
14
|
+
and `new THREE.Mesh(geo, mat)` - v1.0.363 hex literals (`0xRRGGBB`) keep the
|
|
15
15
|
palette legible; the lights use `0xffffff`.
|
|
16
16
|
- A light rig with `new THREE.AmbientLight(...)` + `new THREE.DirectionalLight(...)`.
|
|
17
17
|
- `document.body.append(renderer.domElement)` mounts the WebGL canvas.
|