plainscript-lang 1.0.2-rfc → 1.0.3-beta

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 (67) hide show
  1. package/README.md +194 -736
  2. package/compiler/cli.js +13 -17
  3. package/compiler/generator.js +93 -21
  4. package/compiler/version.js +1 -1
  5. package/docs/CAPABILITY_GAP_AUDIT.md +98 -536
  6. package/docs/PLAINSCRIPT-SPEC.md +308 -557
  7. package/docs/index.html +101 -599
  8. package/docs/website/script.js +59 -1029
  9. package/docs/website/style.css +74 -656
  10. package/examples/ai-providers.pln +7 -0
  11. package/examples/arrays.pln +4 -12
  12. package/examples/async-errors.pln +18 -0
  13. package/examples/auth-api.pln +3 -50
  14. package/examples/auth-sessions.pln +32 -0
  15. package/examples/basics.pln +14 -0
  16. package/examples/bots.pln +13 -0
  17. package/examples/cache-and-jobs.pln +6 -28
  18. package/examples/cache-schedule.pln +22 -0
  19. package/examples/collections.pln +15 -0
  20. package/examples/concurrency.pln +12 -43
  21. package/examples/conditions.pln +22 -0
  22. package/examples/database.pln +6 -39
  23. package/examples/day2.pln +6 -6
  24. package/examples/day3.pln +4 -10
  25. package/examples/deployment.pln +3 -9
  26. package/examples/email-send.pln +3 -22
  27. package/examples/error-handling.pln +6 -54
  28. package/examples/expressions.pln +7 -40
  29. package/examples/file-uploads.pln +5 -34
  30. package/examples/files-and-config.pln +5 -46
  31. package/examples/files.pln +12 -0
  32. package/examples/football-backend/app.pln +21 -20
  33. package/examples/functions.pln +17 -0
  34. package/examples/hello.pln +2 -3
  35. package/examples/http-client.pln +3 -44
  36. package/examples/http.pln +11 -0
  37. package/examples/id-verification/app.pln +4 -3
  38. package/examples/id-verification/make-sample-id.js +29 -42
  39. package/examples/json.pln +11 -0
  40. package/examples/loops.pln +13 -11
  41. package/examples/modules/app.pln +3 -16
  42. package/examples/modules/main.pln +4 -0
  43. package/examples/modules/math.pln +5 -16
  44. package/examples/objects.pln +3 -11
  45. package/examples/ocr.pln +22 -0
  46. package/examples/packages.pln +6 -0
  47. package/examples/record-kinds.pln +6 -42
  48. package/examples/records.pln +15 -0
  49. package/examples/rest-api-fetch.pln +6 -90
  50. package/examples/rest-api.pln +5 -65
  51. package/examples/scheduled-tasks.pln +4 -23
  52. package/examples/search-and-filter.pln +4 -34
  53. package/examples/server.pln +5 -24
  54. package/examples/sessions-and-cookies.pln +4 -50
  55. package/examples/sqlite.pln +23 -0
  56. package/examples/start.pln +2 -2
  57. package/examples/stdlib.pln +4 -41
  58. package/examples/telegram-ai-bot.pln +19 -0
  59. package/examples/telegram-bot.pln +4 -40
  60. package/examples/testing.pln +13 -0
  61. package/examples/web-api.pln +27 -0
  62. package/examples/web-app.pln +4 -16
  63. package/examples/websocket-server.pln +5 -26
  64. package/examples/websocket.pln +13 -0
  65. package/examples/whatsapp-bot/pairing.pln +4 -5
  66. package/examples/whatsapp-bot/qr.pln +7 -3
  67. package/package.json +2 -2
@@ -1,68 +1,8 @@
1
- // PlainScript v2.1 — A real REST API
2
- //
3
- // Run with: plainscript run examples/rest-api.pln
4
- // Try: curl http://localhost:3000/api/users
5
- //
6
- // Demonstrates method routes, route groups, CORS, request validation,
7
- // path/query/header accessors, status codes and a SQLite database.
8
-
9
- database "rest-api-demo.db"
10
-
11
- execute
12
- CREATE TABLE IF NOT EXISTS users (
13
- id INTEGER PRIMARY KEY AUTOINCREMENT,
14
- name TEXT,
15
- email TEXT
16
- )
17
- done
18
-
1
+ // PlainScript 1.0.3-beta: JSON REST route.
19
2
  web app
20
- allow cors
21
-
22
- group "/api"
23
-
24
- route get "/users"
25
- remember users as query
26
- SELECT * FROM users
27
- done
28
- reply users
29
- done
30
-
31
- route post "/users"
32
- remember missing as validate(body of request, list with "name", "email")
33
- remember count as length(missing)
34
- if count more than 0
35
- status 400
36
- reply missing
37
- otherwise
38
- remember who as body of request.name
39
- remember mail as body of request.email
40
- insert
41
- INSERT INTO users (name, email) VALUES ({who}, {mail})
42
- done
43
- status 201
44
- reply "created"
45
- done
3
+ route get "/api/status"
4
+ reply json
5
+ status is "ok"
46
6
  done
47
-
48
- route get "/users/:id"
49
- remember id as param("id")
50
- remember found as query
51
- SELECT * FROM users WHERE id = {id}
52
- done
53
- if length(found) more than 0
54
- reply found at position 0
55
- otherwise
56
- status 404
57
- reply "not found"
58
- done
59
- done
60
-
61
- done
62
-
63
- route get "/health"
64
- remember token as header("x-token")
65
- reply "ok"
66
7
  done
67
-
68
- start 3000
8
+ start 3000
@@ -1,23 +1,4 @@
1
- // PlainScript v2.1 — Scheduled and recurring tasks
2
- //
3
- // Run with: plainscript run examples/scheduled-tasks.pln
4
- //
5
- // "every" covers simple intervals; "schedule" accepts any standard cron
6
- // expression (powered by croner).
7
-
8
- // A heartbeat every 30 seconds
9
- every 30 seconds
10
- show "Heartbeat: " + time()
11
- done
12
-
13
- // Any standard cron expression
14
- schedule "*/5 * * * *"
15
- show "Five minutes have passed"
16
- done
17
-
18
- // Nightly cleanup at 2 AM
19
- schedule "0 2 * * *"
20
- show "Running the nightly cleanup"
21
- done
22
-
23
- show "Scheduled tasks registered — press Ctrl+C to stop"
1
+ // PlainScript 1.0.3-beta: recurring task.
2
+ schedule "0 * * * *"
3
+ show "hourly task"
4
+ done
@@ -1,34 +1,4 @@
1
- // PlainScript v1.0.2 — Functional transformations
2
- //
3
- // Run with: plainscript run examples/search-and-filter.pln
4
- //
5
- // gather / filter / total map, filter and reduce in place; match routes a
6
- // value to behaviour.
7
-
8
- remember scores as list with 70, 45, 92, 38, 60
9
-
10
- gather each score in scores giving score + 5
11
- show scores // [ 75, 50, 97, 43, 65 ]
12
-
13
- filter each score in scores when score is at least 60
14
- show scores // [ 75, 97, 65 ]
15
-
16
- remember prices as list with 19.99, 4.99, 29.99
17
- total each price in prices giving price
18
- show prices // 54.97
19
-
20
- // Pattern matching
21
- remember day as "wed"
22
-
23
- match day against
24
- "mon" -> show "Start of the week"
25
- "wed" -> show "Middle of the week"
26
- "fri" -> show "Almost there"
27
- otherwise -> show "Another day"
28
- done
29
-
30
- // Regex matching extracts a group into a variable
31
- match pattern "^([0-9]+)$" in "2026" as digits
32
- if digits is not empty
33
- show "matched digits: " + first of digits
34
- done
1
+ // PlainScript 1.0.3-beta: collection filtering.
2
+ remember values as list with 1, 2, 3
3
+ remember found as first item from values
4
+ show found
@@ -1,25 +1,6 @@
1
- use express
2
-
3
- remember app as express()
4
-
5
- serve folder "public"
6
-
7
- when someone visits "/"
8
- reply "Hello from PlainScript!"
9
- done
10
-
11
- when someone visits "/about"
12
- reply "This server is written in PlainScript."
13
- done
14
-
15
- when someone visits "/api/status"
16
- reply json
17
- status is "ok"
18
- language is "PlainScript"
19
- version is "0.3"
20
- done
21
- done
22
-
23
- listen on 3000
24
- show "Server running at http://localhost:3000"
1
+ // PlainScript 1.0.3-beta: minimal server.
2
+ web app
3
+ route get "/"
4
+ reply "Hello from PlainScript"
25
5
  done
6
+ start 3000
@@ -1,54 +1,8 @@
1
- // PlainScript v1.0.2 — Sessions, cookies and rate limiting
2
- //
3
- // Run with: plainscript run examples/sessions-and-cookies.pln
4
- // Then try:
5
- // curl -c cookies.txt -b cookies.txt http://localhost:3000/login
6
- // curl -c cookies.txt -b cookies.txt http://localhost:3000/profile
7
- // curl -c cookies.txt -b cookies.txt http://localhost:3000/logout
8
- //
9
- // The app shows login/logout flow backed by signed sessions, preference
10
- // cookies, and a per-IP rate limit.
11
-
1
+ // PlainScript 1.0.3-beta: sessions and cookies.
12
2
  web app
13
-
14
- limit requests to 100 per minute
15
- enable sessions "a-long-random-secret-minimum"
16
-
17
- allow cors
18
-
19
- route get "/login"
20
- user of session of request becomes "ada"
3
+ enable sessions "session-secret"
4
+ route get "/"
21
5
  set cookie "theme" to "dark" expires in 7 days
22
- reply json
23
- welcome is true
24
- who is user of session of request
25
- done
6
+ reply "ready"
26
7
  done
27
-
28
- route get "/profile"
29
- remember who as user of session of request
30
- if who is empty
31
- status 401
32
- reply "Please log in first via /login"
33
- otherwise
34
- reply json
35
- user is who
36
- theme is cookie("theme")
37
- done
38
- done
39
- done
40
-
41
- route post "/logout"
42
- destroy session
43
- clear cookie "theme"
44
- reply "Logged out. Goodbye!"
45
- done
46
-
47
- when nothing matches
48
- status 404
49
- reply json
50
- error is "no such road"
51
- done
52
- done
53
-
54
8
  start 3000
@@ -0,0 +1,23 @@
1
+ // PlainScript 1.0.3-beta: SQLite, SQL blocks, parameters, and transactions.
2
+
3
+ database "plain-script-demo.db" using "wasm"
4
+ remember personName as "Ada"
5
+
6
+ execute
7
+ CREATE TABLE IF NOT EXISTS people (name TEXT, age INTEGER)
8
+ done
9
+
10
+ insert
11
+ INSERT INTO people (name, age) VALUES ({personName}, 36)
12
+ done
13
+
14
+ remember people as query
15
+ SELECT name, age FROM people ORDER BY name
16
+ done
17
+ show people
18
+
19
+ transaction
20
+ update
21
+ UPDATE people SET age = 37 WHERE name = {personName}
22
+ done
23
+ done
@@ -1,2 +1,2 @@
1
- // PlainScript v1.0.2 — entry file for `plainscript start`
2
- show "Application started by PlainScript"
1
+ // PlainScript 1.0.3-beta: start command entry point.
2
+ show "PlainScript started"
@@ -1,41 +1,4 @@
1
- // PlainScript v0.6 — Standard Library Examples
2
-
3
- // print (alias for show, compiled to console.log)
4
- print("Hello from print!")
5
-
6
- // time and date
7
- remember currentTime as time()
8
- remember today as date()
9
- show currentTime
10
- show today
11
-
12
- // JSON encoding and decoding
13
- remember user as
14
- name is "Ayokunle"
15
- age is 17
16
- done
17
-
18
- remember encoded as jsonEncode(user)
19
- show encoded
20
-
21
- remember decoded as jsonDecode(encoded)
22
- show decoded
23
-
24
- // Environment variables
25
- remember nodeEnv as env("NODE_ENV")
26
- show nodeEnv
27
-
28
- // File operations
29
- writeFile("hello.txt", "Hello from PlainScript!")
30
- remember exists as fileExists("hello.txt")
31
- show exists
32
-
33
- remember content as readFile("hello.txt")
34
- show content
35
-
36
- // UUID
37
- remember id as uuid()
38
- show id
39
-
40
- // exit (commented out so this example can run fully)
41
- // exit(0)
1
+ // PlainScript 1.0.3-beta: standard library helpers.
2
+ remember text as trim(" PlainScript ")
3
+ remember digest as sha256(text)
4
+ show digest
@@ -0,0 +1,19 @@
1
+ // PlainScript 1.0.3-beta: fixed and provider-backed Telegram replies.
2
+
3
+ bot env("TELEGRAM_BOT_TOKEN")
4
+
5
+ when someone sends "/start"
6
+ reply "Welcome. Use /status or /ask <question>."
7
+ done
8
+
9
+ when someone sends "/status"
10
+ reply "All systems are operational."
11
+ done
12
+
13
+ when someone sends matching "/ask (.+)"
14
+ telegramCall("sendChatAction", {chat_id: chatId, action: "typing"})
15
+ remember answer as chatWith("groq", "llama-3.3-70b-versatile", message)
16
+ reply answer
17
+ done
18
+
19
+ start telegram bot
@@ -1,42 +1,6 @@
1
- // Telegram bot with buttons and callbacks
2
- //
3
- // Creates a polling Telegram bot that answers commands and handles
4
- // inline keyboard callbacks.
5
-
6
- bot env("BOT_TOKEN")
7
-
8
- // Start command: welcome message with an inline keyboard
1
+ // PlainScript 1.0.3-beta: Telegram bot.
2
+ bot env("TELEGRAM_BOT_TOKEN")
9
3
  when someone sends "/start"
10
- reply "Welcome to the PlainScript bot!" with buttons
11
- "Help" -> "help"
12
- "About" -> "about"
13
- "Status" -> "status"
14
- done
4
+ reply "Welcome"
15
5
  done
16
-
17
- // Help command
18
- when someone sends "/help"
19
- reply "Available commands:\n/start - Show menu\n/help - Show this help\n/status - Bot status"
20
- done
21
-
22
- // Status command
23
- when someone sends "/status"
24
- remember currentDate as date()
25
- reply "Current time: " + currentDate
26
- done
27
-
28
- // Callback handlers for the inline keyboard buttons
29
- when someone clicks "help"
30
- reply "This bot demonstrates the Telegram integration."
31
- done
32
-
33
- when someone clicks "about"
34
- reply "Built with PlainScript - an Intent-Oriented Programming Language."
35
- done
36
-
37
- when someone clicks "status"
38
- reply "The bot is running."
39
- done
40
-
41
- // Boot long polling
42
- start telegram bot
6
+ start telegram bot
@@ -0,0 +1,13 @@
1
+ // PlainScript 1.0.3-beta: the native test DSL.
2
+
3
+ make add(a, b)
4
+ give a + b
5
+ done
6
+
7
+ test "addition works"
8
+ check add(2, 3) equals 5
9
+ done
10
+
11
+ test "text contains a word"
12
+ check "PlainScript" contains "Script"
13
+ done
@@ -0,0 +1,27 @@
1
+ // PlainScript 1.0.3-beta: web apps, routes, JSON, and status codes.
2
+
3
+ web app
4
+ allow cors
5
+
6
+ route get "/health"
7
+ reply json
8
+ ok is true
9
+ service is "plain-script"
10
+ done
11
+ done
12
+
13
+ route post "/echo"
14
+ remember incoming as body of request
15
+ reply json
16
+ received is incoming
17
+ done
18
+ done
19
+
20
+ when nothing matches
21
+ status 404
22
+ reply json
23
+ error is "not found"
24
+ done
25
+ done
26
+
27
+ start 0
@@ -1,20 +1,8 @@
1
- // PlainScript v0.6 — Web App (Express shorthand)
2
-
1
+ // PlainScript 1.0.3-beta: web application.
3
2
  web app
4
-
5
- route "/"
6
- reply "Hello from PlainScript!"
7
- done
8
-
9
- route "/about"
10
- reply "About PlainScript"
11
- done
12
-
13
- route "/api/status"
3
+ route get "/health"
14
4
  reply json
15
- status is "ok"
16
- version is "0.6"
5
+ ok is true
17
6
  done
18
7
  done
19
-
20
- start 3000
8
+ start 3000
@@ -1,27 +1,6 @@
1
- // PlainScript v2.1 — WebSocket chat server
2
- //
3
- // Run with: plainscript run examples/websocket-server.pln
4
- // Then connect any ws client to ws://localhost:8080 and start typing.
5
- // Every message a client sends is echoed back to it and broadcast to
6
- // everyone else.
7
-
1
+ // PlainScript 1.0.3-beta: WebSocket server.
8
2
  websocket server on 8080
9
-
10
- when socket connects
11
- send socket "Welcome to the PlainScript chat server!"
12
- broadcast "Someone new joined the chat"
13
- done
14
-
15
- when socket sends message
16
- show "Got: " + message
17
- send socket "You said: " + message
18
- broadcast message
19
- done
20
-
21
- when socket disconnects
22
- broadcast "Someone left the chat"
23
- done
24
-
25
- done
26
-
27
- show "Chat server listening on port 8080"
3
+ when socket connects
4
+ send socket "connected"
5
+ done
6
+ done
@@ -0,0 +1,13 @@
1
+ // PlainScript 1.0.3-beta: WebSocket server handlers.
2
+
3
+ websocket server on 8080
4
+ when socket connects
5
+ send socket "connected"
6
+ done
7
+ when socket sends message
8
+ broadcast message
9
+ done
10
+ when socket disconnects
11
+ show "socket closed"
12
+ done
13
+ done
@@ -1,17 +1,16 @@
1
+ // PlainScript 1.0.3-beta: WhatsApp pairing login.
2
+
1
3
  whatsapp bot
2
- auth "session"
4
+ auth "plain-script-whatsapp"
3
5
  login pairing "2348012345678"
4
-
5
6
  on message
6
7
  log message
7
-
8
8
  if message.text is "/start"
9
9
  reply "Welcome!"
10
10
  done
11
-
12
11
  if message.text is "/help"
13
12
  reply `Available commands:
14
13
  /start /help`
15
14
  done
16
15
  done
17
- done
16
+ done
@@ -1,8 +1,12 @@
1
+ // PlainScript 1.0.3-beta: WhatsApp QR login.
2
+
1
3
  whatsapp bot
2
- auth "session"
4
+ auth "plain-script-whatsapp"
3
5
  login qr
4
-
5
6
  on message
6
7
  log message
8
+ if message.text is "/start"
9
+ reply "Welcome"
10
+ done
7
11
  done
8
- done
12
+ done
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "plainscript-lang",
3
- "version": "1.0.2-rfc",
3
+ "version": "1.0.3-beta",
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/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/acceptance.test.js && node tests/whatsapp.test.js && node tests/audit.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"
11
11
  },
12
12
  "files": [
13
13
  "compiler",