plainscript-lang 1.0.0 → 1.0.2-rfc
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 +157 -150
- package/compiler/bundler.js +2 -2
- package/compiler/cli.js +172 -65
- package/compiler/formatter.js +1 -1
- package/compiler/generator.js +905 -184
- package/compiler/lexer.js +128 -54
- package/compiler/parser.js +1075 -155
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +131 -30
- package/docs/PLAINSCRIPT-SPEC.md +584 -0
- package/docs/index.html +48 -52
- package/docs/website/script.js +110 -24
- package/docs/website/style.css +4 -4
- package/examples/arrays.pln +12 -0
- package/examples/{auth-api.ps → auth-api.pln} +3 -3
- package/examples/{cache-and-jobs.ps → cache-and-jobs.pln} +1 -1
- package/examples/{concurrency.ps → concurrency.pln} +8 -8
- package/examples/{database.ps → database.pln} +1 -1
- package/examples/{deployment.ps → deployment.pln} +2 -2
- package/examples/{email-send.ps → email-send.pln} +1 -1
- package/examples/{error-handling.ps → error-handling.pln} +8 -7
- package/examples/{expressions.ps → expressions.pln} +1 -1
- package/examples/{file-uploads.ps → file-uploads.pln} +4 -4
- package/examples/{files-and-config.ps → files-and-config.pln} +4 -4
- package/examples/football-backend/{app.ps → app.pln} +2 -2
- package/examples/{http-client.ps → http-client.pln} +18 -18
- package/examples/id-verification/{app.ps → app.pln} +1 -1
- package/examples/{loops.ps → loops.pln} +2 -3
- package/examples/modules/{app.ps → app.pln} +4 -4
- package/examples/modules/{math.ps → math.pln} +1 -1
- package/examples/{record-kinds.ps → record-kinds.pln} +4 -4
- package/examples/{rest-api-fetch.ps → rest-api-fetch.pln} +1 -1
- package/examples/{rest-api.ps → rest-api.pln} +5 -5
- package/examples/{scheduled-tasks.ps → scheduled-tasks.pln} +2 -2
- package/examples/{search-and-filter.ps → search-and-filter.pln} +5 -5
- package/examples/{sessions-and-cookies.ps → sessions-and-cookies.pln} +2 -2
- package/examples/start.pln +2 -0
- package/examples/{stdlib.ps → stdlib.pln} +2 -2
- package/examples/{telegram-bot.ps → telegram-bot.pln} +2 -2
- package/examples/{websocket-server.ps → websocket-server.pln} +1 -1
- package/package.json +2 -2
- package/docs/PLINJS_SPEC.md +0 -1151
- package/examples/arrays.ps +0 -13
- package/examples/start.ps +0 -2
- /package/examples/{day2.ps → day2.pln} +0 -0
- /package/examples/{day3.ps → day3.pln} +0 -0
- /package/examples/{hello.ps → hello.pln} +0 -0
- /package/examples/{objects.ps → objects.pln} +0 -0
- /package/examples/{server.ps → server.pln} +0 -0
- /package/examples/{web-app.ps → web-app.pln} +0 -0
- /package/examples/whatsapp-bot/{pairing.ps → pairing.pln} +0 -0
- /package/examples/whatsapp-bot/{qr.ps → qr.pln} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — runtime dependency and deployment example
|
|
2
2
|
//
|
|
3
3
|
// `plainscript build` and `plainscript run` detect express from `web app` and install it
|
|
4
|
-
// when it is missing. `plainscript start` builds src/app.
|
|
4
|
+
// when it is missing. `plainscript start` builds src/app.pln by default.
|
|
5
5
|
|
|
6
6
|
web app
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// PlainScript v2.1 — Sending email
|
|
2
2
|
//
|
|
3
|
-
// Run with: MAIL_PASS=secret plainscript run examples/email-send.
|
|
3
|
+
// Run with: MAIL_PASS=secret plainscript run examples/email-send.pln
|
|
4
4
|
//
|
|
5
5
|
// Configure the outgoing transport once, then send as many mails as you
|
|
6
6
|
// like. Credentials come from the environment — never hardcode them.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — Robust error handling
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/error-handling.
|
|
3
|
+
// Run with: plainscript run examples/error-handling.pln
|
|
4
4
|
//
|
|
5
5
|
// Shows deterministic recovery: typed "recover" blocks, silent swallowing,
|
|
6
6
|
// and automatic retries with backoff for flaky operations.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
make parseSettings(raw)
|
|
9
9
|
remember settings as jsonDecode(raw)
|
|
10
10
|
if settings is empty
|
|
11
|
-
give
|
|
11
|
+
give record with theme "light" done
|
|
12
12
|
otherwise
|
|
13
13
|
give settings
|
|
14
14
|
done
|
|
@@ -20,15 +20,16 @@ try
|
|
|
20
20
|
show theme of settings
|
|
21
21
|
recover as err
|
|
22
22
|
show "falling back: " + message of err
|
|
23
|
-
remember settings as
|
|
23
|
+
remember settings as record with theme "dark" done
|
|
24
24
|
show theme of settings
|
|
25
25
|
done
|
|
26
26
|
|
|
27
|
-
//
|
|
27
|
+
// Typed recover clauses can select errors by name
|
|
28
28
|
try
|
|
29
29
|
remember parsed as jsonDecode("also not json")
|
|
30
30
|
recover when err catches "SyntaxError"
|
|
31
31
|
show "JSON parse error caught: " + message of err
|
|
32
|
+
done
|
|
32
33
|
recover as err
|
|
33
34
|
show "some other error: " + message of err
|
|
34
35
|
done
|
|
@@ -40,7 +41,7 @@ done
|
|
|
40
41
|
show "survived the failed read"
|
|
41
42
|
|
|
42
43
|
// Automatic retry with a delay
|
|
43
|
-
remember logs as
|
|
44
|
+
remember logs as list
|
|
44
45
|
make fetchStatus()
|
|
45
46
|
add("trying…" to logs)
|
|
46
47
|
give read("status.db.json")
|
|
@@ -51,4 +52,4 @@ retry 3 times every 1 second
|
|
|
51
52
|
show body
|
|
52
53
|
done
|
|
53
54
|
|
|
54
|
-
show length(logs)
|
|
55
|
+
show length(logs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — File uploads
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/file-uploads.
|
|
3
|
+
// Run with: plainscript run examples/file-uploads.pln
|
|
4
4
|
// Then try:
|
|
5
5
|
// curl -F photo=@some-image.png http://localhost:3000/upload
|
|
6
6
|
// curl -F doc=@notes.txt http://localhost:3000/upload-many
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
web app
|
|
12
12
|
|
|
13
|
-
accept uploads limit "5 MB" allow
|
|
13
|
+
accept uploads limit "5 MB" allow list with "image/png", "image/jpeg", "text/plain"
|
|
14
14
|
|
|
15
15
|
route post "/upload"
|
|
16
16
|
remember file as upload("file")
|
|
@@ -36,4 +36,4 @@ route post "/upload-many"
|
|
|
36
36
|
done
|
|
37
37
|
done
|
|
38
38
|
|
|
39
|
-
start 3000
|
|
39
|
+
start 3000
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — File I/O, YAML and environment configuration
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/files-and-config.
|
|
3
|
+
// Run with: plainscript run examples/files-and-config.pln
|
|
4
4
|
//
|
|
5
5
|
// Writes and reads files, walks a folder, round-trips YAML and applies a
|
|
6
6
|
// .env file. Everything is deterministic and dependency-free.
|
|
@@ -22,7 +22,7 @@ show walkFolder("example-output")
|
|
|
22
22
|
|
|
23
23
|
remember settings as
|
|
24
24
|
app is "plainscript"
|
|
25
|
-
limits is
|
|
25
|
+
limits is record with requests 100 and window "hour" done
|
|
26
26
|
done
|
|
27
27
|
|
|
28
28
|
remember encoded as yamlEncode(settings)
|
|
@@ -44,4 +44,4 @@ show jsonDecode(backup)
|
|
|
44
44
|
deleteFile("example-output/greeting.txt")
|
|
45
45
|
deleteFile("example-output/log.txt")
|
|
46
46
|
deleteFolder("example-output")
|
|
47
|
-
show "cleanup done"
|
|
47
|
+
show "cleanup done"
|
|
@@ -55,9 +55,9 @@ route get "/teams"
|
|
|
55
55
|
done
|
|
56
56
|
|
|
57
57
|
route post "/teams"
|
|
58
|
-
remember missing as validate(body of request,
|
|
58
|
+
remember missing as validate(body of request, list with "name")
|
|
59
59
|
remember problems as length(missing)
|
|
60
|
-
if problems
|
|
60
|
+
if problems more than 0
|
|
61
61
|
status 400
|
|
62
62
|
reply missing
|
|
63
63
|
otherwise
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — HTTP client: every method, headers and timeouts
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/http-client.
|
|
3
|
+
// Run with: plainscript run examples/http-client.pln
|
|
4
4
|
//
|
|
5
5
|
// Uses the public JSONPlaceholder API. Every call returns a record with
|
|
6
6
|
// ok / status / headers / data; JSON bodies are parsed automatically.
|
|
@@ -10,27 +10,27 @@ remember users as get "https://jsonplaceholder.typicode.com/users" timeout 8000
|
|
|
10
10
|
show "GET users -> " + text(status of users) + ", count " + text(length(data of users))
|
|
11
11
|
|
|
12
12
|
// POST an inline object, sent as JSON
|
|
13
|
-
remember created as post "https://jsonplaceholder.typicode.com/posts" with
|
|
14
|
-
title
|
|
15
|
-
userId
|
|
16
|
-
|
|
13
|
+
remember created as post "https://jsonplaceholder.typicode.com/posts" with record with
|
|
14
|
+
title "Hello from PlainScript" and
|
|
15
|
+
userId 1
|
|
16
|
+
done
|
|
17
17
|
show "POST -> status " + text(status of created)
|
|
18
18
|
if ok of created is true
|
|
19
19
|
show "new post id " + text(id of data of created)
|
|
20
20
|
done
|
|
21
21
|
|
|
22
22
|
// PUT replaces the whole resource
|
|
23
|
-
remember replaced as put "https://jsonplaceholder.typicode.com/posts/1" with
|
|
24
|
-
title
|
|
25
|
-
body
|
|
26
|
-
userId
|
|
27
|
-
|
|
23
|
+
remember replaced as put "https://jsonplaceholder.typicode.com/posts/1" with record with
|
|
24
|
+
title "Updated" and
|
|
25
|
+
body "new body" and
|
|
26
|
+
userId 1
|
|
27
|
+
done
|
|
28
28
|
show "PUT -> status " + text(status of replaced)
|
|
29
29
|
|
|
30
30
|
// PATCH merges into the resource
|
|
31
|
-
remember patched as patch "https://jsonplaceholder.typicode.com/posts/1" with
|
|
32
|
-
title
|
|
33
|
-
|
|
31
|
+
remember patched as patch "https://jsonplaceholder.typicode.com/posts/1" with record with
|
|
32
|
+
title "Patched title"
|
|
33
|
+
done
|
|
34
34
|
show "PATCH -> status " + text(status of patched)
|
|
35
35
|
|
|
36
36
|
// DELETE
|
|
@@ -38,7 +38,7 @@ remember removed as delete "https://jsonplaceholder.typicode.com/posts/1"
|
|
|
38
38
|
show "DELETE -> ok " + text(ok of removed)
|
|
39
39
|
|
|
40
40
|
// Custom headers and error surfacing
|
|
41
|
-
remember guarded as get "https://api.example.com/private" headers
|
|
42
|
-
Authorization
|
|
43
|
-
|
|
44
|
-
show "guard called? " + text(ok of guarded) + " (status " + text(status of guarded) + ")"
|
|
41
|
+
remember guarded as get "https://api.example.com/private" headers record with
|
|
42
|
+
Authorization "Bearer test"
|
|
43
|
+
done timeout 3000
|
|
44
|
+
show "guard called? " + text(ok of guarded) + " (status " + text(status of guarded) + ")"
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
remember players as
|
|
1
|
+
remember players as list with
|
|
2
2
|
"Haaland",
|
|
3
3
|
"Foden",
|
|
4
4
|
"Rodri"
|
|
5
|
-
]
|
|
6
5
|
|
|
7
6
|
for each player in players
|
|
8
7
|
show player
|
|
@@ -10,7 +9,7 @@ done
|
|
|
10
9
|
|
|
11
10
|
remember count as 0
|
|
12
11
|
|
|
13
|
-
while count
|
|
12
|
+
while count fewer than 3
|
|
14
13
|
count becomes count + 1
|
|
15
14
|
done
|
|
16
15
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — Importing your own modules
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/modules/app.
|
|
3
|
+
// Run with: plainscript run examples/modules/app.pln
|
|
4
4
|
//
|
|
5
5
|
// Files are compiled in dependency order (deepest first), so the helpers in
|
|
6
|
-
// math.
|
|
6
|
+
// math.pln are visible here before app.pln runs.
|
|
7
7
|
|
|
8
|
-
import "./math.
|
|
8
|
+
import "./math.pln"
|
|
9
9
|
|
|
10
10
|
show PI // 3.14
|
|
11
11
|
show double(21) // 42
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// PlainScript
|
|
1
|
+
// PlainScript v2.1 — Record kinds, generators and the test DSL
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/record-kinds.
|
|
3
|
+
// Run with: plainscript run examples/record-kinds.pln
|
|
4
4
|
//
|
|
5
5
|
// Defines a schema, builds instances, composes records, streams values from
|
|
6
6
|
// generators, and verifies behaviour with the built-in test runner.
|
|
@@ -18,7 +18,7 @@ show title of fav
|
|
|
18
18
|
show pages of fav
|
|
19
19
|
show rating of fav
|
|
20
20
|
|
|
21
|
-
remember extended as merge(fav,
|
|
21
|
+
remember extended as merge(fav, record with author "Ada" done)
|
|
22
22
|
show author of extended
|
|
23
23
|
show fieldsOf(extended)
|
|
24
24
|
|
|
@@ -40,4 +40,4 @@ make makeTitles(catalog)
|
|
|
40
40
|
done
|
|
41
41
|
done
|
|
42
42
|
|
|
43
|
-
show spread of makeTitles(
|
|
43
|
+
show spread of makeTitles(list with fav, extended)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// PlainScript v2.1 — A real REST API
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/rest-api.
|
|
3
|
+
// Run with: plainscript run examples/rest-api.pln
|
|
4
4
|
// Try: curl http://localhost:3000/api/users
|
|
5
5
|
//
|
|
6
6
|
// Demonstrates method routes, route groups, CORS, request validation,
|
|
@@ -29,9 +29,9 @@ group "/api"
|
|
|
29
29
|
done
|
|
30
30
|
|
|
31
31
|
route post "/users"
|
|
32
|
-
remember missing as validate(body of request,
|
|
32
|
+
remember missing as validate(body of request, list with "name", "email")
|
|
33
33
|
remember count as length(missing)
|
|
34
|
-
if count
|
|
34
|
+
if count more than 0
|
|
35
35
|
status 400
|
|
36
36
|
reply missing
|
|
37
37
|
otherwise
|
|
@@ -50,8 +50,8 @@ group "/api"
|
|
|
50
50
|
remember found as query
|
|
51
51
|
SELECT * FROM users WHERE id = {id}
|
|
52
52
|
done
|
|
53
|
-
if length(found)
|
|
54
|
-
reply found
|
|
53
|
+
if length(found) more than 0
|
|
54
|
+
reply found at position 0
|
|
55
55
|
otherwise
|
|
56
56
|
status 404
|
|
57
57
|
reply "not found"
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// PlainScript v2.1 — Scheduled and recurring tasks
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/scheduled-tasks.
|
|
3
|
+
// Run with: plainscript run examples/scheduled-tasks.pln
|
|
4
4
|
//
|
|
5
5
|
// "every" covers simple intervals; "schedule" accepts any standard cron
|
|
6
6
|
// expression (powered by croner).
|
|
7
7
|
|
|
8
8
|
// A heartbeat every 30 seconds
|
|
9
9
|
every 30 seconds
|
|
10
|
-
show "Heartbeat: " +
|
|
10
|
+
show "Heartbeat: " + time()
|
|
11
11
|
done
|
|
12
12
|
|
|
13
13
|
// Any standard cron expression
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — Functional transformations
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/search-and-filter.
|
|
3
|
+
// Run with: plainscript run examples/search-and-filter.pln
|
|
4
4
|
//
|
|
5
5
|
// gather / filter / total map, filter and reduce in place; match routes a
|
|
6
6
|
// value to behaviour.
|
|
7
7
|
|
|
8
|
-
remember scores as
|
|
8
|
+
remember scores as list with 70, 45, 92, 38, 60
|
|
9
9
|
|
|
10
10
|
gather each score in scores giving score + 5
|
|
11
11
|
show scores // [ 75, 50, 97, 43, 65 ]
|
|
@@ -13,7 +13,7 @@ show scores // [ 75, 50, 97, 43, 65 ]
|
|
|
13
13
|
filter each score in scores when score is at least 60
|
|
14
14
|
show scores // [ 75, 97, 65 ]
|
|
15
15
|
|
|
16
|
-
remember prices as
|
|
16
|
+
remember prices as list with 19.99, 4.99, 29.99
|
|
17
17
|
total each price in prices giving price
|
|
18
18
|
show prices // 54.97
|
|
19
19
|
|
|
@@ -31,4 +31,4 @@ done
|
|
|
31
31
|
match pattern "^([0-9]+)$" in "2026" as digits
|
|
32
32
|
if digits is not empty
|
|
33
33
|
show "matched digits: " + first of digits
|
|
34
|
-
done
|
|
34
|
+
done
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// PlainScript v1.0.
|
|
1
|
+
// PlainScript v1.0.2 — Sessions, cookies and rate limiting
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/sessions-and-cookies.
|
|
3
|
+
// Run with: plainscript run examples/sessions-and-cookies.pln
|
|
4
4
|
// Then try:
|
|
5
5
|
// curl -c cookies.txt -b cookies.txt http://localhost:3000/login
|
|
6
6
|
// curl -c cookies.txt -b cookies.txt http://localhost:3000/profile
|
|
@@ -21,8 +21,8 @@ done
|
|
|
21
21
|
|
|
22
22
|
// Status command
|
|
23
23
|
when someone sends "/status"
|
|
24
|
-
remember
|
|
25
|
-
reply "Current time: " +
|
|
24
|
+
remember currentDate as date()
|
|
25
|
+
reply "Current time: " + currentDate
|
|
26
26
|
done
|
|
27
27
|
|
|
28
28
|
// Callback handlers for the inline keyboard buttons
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// PlainScript v2.1 — WebSocket chat server
|
|
2
2
|
//
|
|
3
|
-
// Run with: plainscript run examples/websocket-server.
|
|
3
|
+
// Run with: plainscript run examples/websocket-server.pln
|
|
4
4
|
// Then connect any ws client to ws://localhost:8080 and start typing.
|
|
5
5
|
// Every message a client sends is echoed back to it and broadcast to
|
|
6
6
|
// everyone else.
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plainscript-lang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2-rfc",
|
|
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/backend.test.js && node tests/runtime.test.js && node tests/acceptance.test.js && node tests/whatsapp.test.js && node tests/audit.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/acceptance.test.js && node tests/whatsapp.test.js && node tests/audit.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",
|