plainscript-lang 1.0.1 → 1.0.2

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 (52) hide show
  1. package/README.md +154 -147
  2. package/compiler/bundler.js +2 -2
  3. package/compiler/cli.js +58 -58
  4. package/compiler/formatter.js +1 -1
  5. package/compiler/generator.js +753 -67
  6. package/compiler/lexer.js +127 -53
  7. package/compiler/parser.js +953 -151
  8. package/compiler/version.js +1 -1
  9. package/docs/CAPABILITY_GAP_AUDIT.md +130 -29
  10. package/docs/PLAINSCRIPT-SPEC.md +584 -0
  11. package/docs/index.html +33 -42
  12. package/docs/website/script.js +110 -24
  13. package/docs/website/style.css +4 -4
  14. package/examples/arrays.pln +12 -0
  15. package/examples/{auth-api.ps → auth-api.pln} +3 -3
  16. package/examples/{cache-and-jobs.ps → cache-and-jobs.pln} +1 -1
  17. package/examples/{concurrency.ps → concurrency.pln} +8 -8
  18. package/examples/{database.ps → database.pln} +1 -1
  19. package/examples/{deployment.ps → deployment.pln} +2 -2
  20. package/examples/{email-send.ps → email-send.pln} +1 -1
  21. package/examples/{error-handling.ps → error-handling.pln} +8 -7
  22. package/examples/{expressions.ps → expressions.pln} +1 -1
  23. package/examples/{file-uploads.ps → file-uploads.pln} +4 -4
  24. package/examples/{files-and-config.ps → files-and-config.pln} +4 -4
  25. package/examples/football-backend/{app.ps → app.pln} +2 -2
  26. package/examples/{http-client.ps → http-client.pln} +18 -18
  27. package/examples/id-verification/{app.ps → app.pln} +1 -1
  28. package/examples/{loops.ps → loops.pln} +2 -3
  29. package/examples/modules/{app.ps → app.pln} +4 -4
  30. package/examples/modules/{math.ps → math.pln} +1 -1
  31. package/examples/{record-kinds.ps → record-kinds.pln} +4 -4
  32. package/examples/{rest-api-fetch.ps → rest-api-fetch.pln} +1 -1
  33. package/examples/{rest-api.ps → rest-api.pln} +5 -5
  34. package/examples/{scheduled-tasks.ps → scheduled-tasks.pln} +2 -2
  35. package/examples/{search-and-filter.ps → search-and-filter.pln} +5 -5
  36. package/examples/{sessions-and-cookies.ps → sessions-and-cookies.pln} +2 -2
  37. package/examples/start.pln +2 -0
  38. package/examples/{stdlib.ps → stdlib.pln} +2 -2
  39. package/examples/{telegram-bot.ps → telegram-bot.pln} +2 -2
  40. package/examples/{websocket-server.ps → websocket-server.pln} +1 -1
  41. package/package.json +1 -1
  42. package/docs/PLINJS_SPEC.md +0 -1151
  43. package/examples/arrays.ps +0 -13
  44. package/examples/start.ps +0 -2
  45. /package/examples/{day2.ps → day2.pln} +0 -0
  46. /package/examples/{day3.ps → day3.pln} +0 -0
  47. /package/examples/{hello.ps → hello.pln} +0 -0
  48. /package/examples/{objects.ps → objects.pln} +0 -0
  49. /package/examples/{server.ps → server.pln} +0 -0
  50. /package/examples/{web-app.ps → web-app.pln} +0 -0
  51. /package/examples/whatsapp-bot/{pairing.ps → pairing.pln} +0 -0
  52. /package/examples/whatsapp-bot/{qr.ps → qr.pln} +0 -0
@@ -1,6 +1,6 @@
1
- // PlainScript v1.0.1 — Robust error handling
1
+ // PlainScript v1.0.2 — Robust error handling
2
2
  //
3
- // Run with: plainscript run examples/error-handling.ps
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 { theme: "light" }
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 { theme: "dark" }
23
+ remember settings as record with theme "dark" done
24
24
  show theme of settings
25
25
  done
26
26
 
27
- // Multiple typed recover clauses win on error name
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
1
  // PlainScript v1.1 — PlainScript Expressions Examples
2
2
 
3
- remember players as ["Haaland", "Foden", "Rodri"]
3
+ remember players as list with "Haaland", "Foden", "Rodri"
4
4
 
5
5
  // Items
6
6
  show first player from players
@@ -1,6 +1,6 @@
1
- // PlainScript v1.0.1 — File uploads
1
+ // PlainScript v1.0.2 — File uploads
2
2
  //
3
- // Run with: plainscript run examples/file-uploads.ps
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 ["image/png", "image/jpeg", "text/plain"]
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 — File I/O, YAML and environment configuration
1
+ // PlainScript v1.0.2 — File I/O, YAML and environment configuration
2
2
  //
3
- // Run with: plainscript run examples/files-and-config.ps
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 { requests: 100, window: "hour" }
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, ["name"])
58
+ remember missing as validate(body of request, list with "name")
59
59
  remember problems as length(missing)
60
- if problems is greater than 0
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 — HTTP client: every method, headers and timeouts
1
+ // PlainScript v1.0.2 — HTTP client: every method, headers and timeouts
2
2
  //
3
- // Run with: plainscript run examples/http-client.ps
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: "Hello from PlainScript",
15
- userId: 1
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: "Updated",
25
- body: "new body",
26
- userId: 1
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: "Patched 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: "Bearer test"
43
- } timeout 3000
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,5 +1,5 @@
1
1
  web app
2
- accept uploads limit "5 MB" allow ["image/png", "image/jpeg"] folder "uploads"
2
+ accept uploads limit "5 MB" allow list with "image/png", "image/jpeg" folder "uploads"
3
3
 
4
4
  route post "/verify"
5
5
  remember found as uploads("id")
@@ -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 is less than 3
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 — Importing your own modules
1
+ // PlainScript v1.0.2 — Importing your own modules
2
2
  //
3
- // Run with: plainscript run examples/modules/app.ps
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.ps are visible here before app.ps runs.
6
+ // math.pln are visible here before app.pln runs.
7
7
 
8
- import "./math.ps"
8
+ import "./math.pln"
9
9
 
10
10
  show PI // 3.14
11
11
  show double(21) // 42
@@ -1,4 +1,4 @@
1
- // PlainScript v1.0.1 — reusable module, imported by app.ps
1
+ // PlainScript v1.0.2 — reusable module, imported by app.pln
2
2
 
3
3
  remember PI as 3.14
4
4
 
@@ -1,6 +1,6 @@
1
- // PlainScript v1.0.1 — Record kinds, generators and the test DSL
1
+ // PlainScript v2.1 — Record kinds, generators and the test DSL
2
2
  //
3
- // Run with: plainscript run examples/record-kinds.ps
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, { author: "Ada" })
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([fav, extended])
43
+ show spread of makeTitles(list with fav, extended)
@@ -53,7 +53,7 @@ done
53
53
  route get "/api/search"
54
54
  remember q as query("q")
55
55
  remember limit as query("limit")
56
- remember results as []
56
+ remember results as list
57
57
  reply json
58
58
  q is q
59
59
  limit is limit
@@ -1,6 +1,6 @@
1
1
  // PlainScript v2.1 — A real REST API
2
2
  //
3
- // Run with: plainscript run examples/rest-api.ps
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, ["name", "email"])
32
+ remember missing as validate(body of request, list with "name", "email")
33
33
  remember count as length(missing)
34
- if count is greater than 0
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) is greater than 0
54
- reply found[0]
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.ps
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: " + now()
10
+ show "Heartbeat: " + time()
11
11
  done
12
12
 
13
13
  // Any standard cron expression
@@ -1,11 +1,11 @@
1
- // PlainScript v1.0.1 — Functional transformations
1
+ // PlainScript v1.0.2 — Functional transformations
2
2
  //
3
- // Run with: plainscript run examples/search-and-filter.ps
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 [70, 45, 92, 38, 60]
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 [19.99, 4.99, 29.99]
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 — Sessions, cookies and rate limiting
1
+ // PlainScript v1.0.2 — Sessions, cookies and rate limiting
2
2
  //
3
- // Run with: plainscript run examples/sessions-and-cookies.ps
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
@@ -0,0 +1,2 @@
1
+ // PlainScript v1.0.2 — entry file for `plainscript start`
2
+ show "Application started by PlainScript"
@@ -4,9 +4,9 @@
4
4
  print("Hello from print!")
5
5
 
6
6
  // time and date
7
- remember now as time()
7
+ remember currentTime as time()
8
8
  remember today as date()
9
- show now
9
+ show currentTime
10
10
  show today
11
11
 
12
12
  // JSON encoding and decoding
@@ -21,8 +21,8 @@ done
21
21
 
22
22
  // Status command
23
23
  when someone sends "/status"
24
- remember now as date()
25
- reply "Current time: " + now
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.ps
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,6 +1,6 @@
1
1
  {
2
2
  "name": "plainscript-lang",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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": {