plainscript-lang 1.0.0 → 1.0.2-latest

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 (106) hide show
  1. package/README.md +194 -729
  2. package/compiler/bundler.js +2 -2
  3. package/compiler/cli.js +182 -79
  4. package/compiler/dependency-detector.js +5 -0
  5. package/compiler/formatter.js +1 -1
  6. package/compiler/generator.js +1083 -206
  7. package/compiler/lexer.js +130 -54
  8. package/compiler/parser.js +1117 -156
  9. package/compiler/version.js +1 -1
  10. package/docs/CAPABILITY_GAP_AUDIT.md +98 -435
  11. package/docs/PLAINSCRIPT-SPEC.md +335 -0
  12. package/docs/index.html +103 -605
  13. package/docs/website/script.js +59 -943
  14. package/docs/website/style.css +74 -656
  15. package/examples/ai-providers.pln +7 -0
  16. package/examples/arrays.pln +4 -0
  17. package/examples/async-errors.pln +18 -0
  18. package/examples/auth-api.pln +9 -0
  19. package/examples/auth-sessions.pln +32 -0
  20. package/examples/basics.pln +14 -0
  21. package/examples/bots.pln +13 -0
  22. package/examples/cache-and-jobs.pln +7 -0
  23. package/examples/cache-schedule.pln +22 -0
  24. package/examples/collections.pln +15 -0
  25. package/examples/concurrency.pln +18 -0
  26. package/examples/conditions.pln +22 -0
  27. package/examples/database.pln +8 -0
  28. package/examples/day2.pln +7 -0
  29. package/examples/day3.pln +5 -0
  30. package/examples/deployment.pln +6 -0
  31. package/examples/email-send.pln +3 -0
  32. package/examples/error-handling.pln +7 -0
  33. package/examples/expressions.pln +7 -0
  34. package/examples/file-uploads.pln +10 -0
  35. package/examples/files-and-config.pln +6 -0
  36. package/examples/files.pln +12 -0
  37. package/examples/football-backend/{app.ps → app.pln} +22 -21
  38. package/examples/functions.pln +17 -0
  39. package/examples/hello.pln +2 -0
  40. package/examples/http-client.pln +3 -0
  41. package/examples/http.pln +11 -0
  42. package/examples/id-verification/{app.ps → app.pln} +5 -4
  43. package/examples/id-verification/make-sample-id.js +29 -42
  44. package/examples/json.pln +11 -0
  45. package/examples/loops.pln +18 -0
  46. package/examples/modules/app.pln +3 -0
  47. package/examples/modules/main.pln +4 -0
  48. package/examples/modules/math.pln +9 -0
  49. package/examples/mongo.pln +33 -0
  50. package/examples/objects.pln +4 -0
  51. package/examples/ocr.pln +22 -0
  52. package/examples/packages.pln +6 -0
  53. package/examples/record-kinds.pln +7 -0
  54. package/examples/records.pln +15 -0
  55. package/examples/rest-api-fetch.pln +10 -0
  56. package/examples/rest-api.pln +8 -0
  57. package/examples/scheduled-tasks.pln +4 -0
  58. package/examples/search-and-filter.pln +4 -0
  59. package/examples/server.pln +6 -0
  60. package/examples/sessions-and-cookies.pln +8 -0
  61. package/examples/sqlite.pln +23 -0
  62. package/examples/start.pln +2 -0
  63. package/examples/stdlib.pln +4 -0
  64. package/examples/telegram-ai-bot.pln +19 -0
  65. package/examples/telegram-bot.pln +6 -0
  66. package/examples/testing.pln +13 -0
  67. package/examples/web-api.pln +27 -0
  68. package/examples/web-app.pln +8 -0
  69. package/examples/websocket-server.pln +6 -0
  70. package/examples/websocket.pln +13 -0
  71. package/examples/whatsapp-bot/{pairing.ps → pairing.pln} +4 -5
  72. package/examples/whatsapp-bot/qr.pln +12 -0
  73. package/package.json +3 -2
  74. package/docs/PLINJS_SPEC.md +0 -1151
  75. package/examples/arrays.ps +0 -13
  76. package/examples/auth-api.ps +0 -56
  77. package/examples/cache-and-jobs.ps +0 -29
  78. package/examples/concurrency.ps +0 -49
  79. package/examples/database.ps +0 -41
  80. package/examples/day2.ps +0 -7
  81. package/examples/day3.ps +0 -11
  82. package/examples/deployment.ps +0 -12
  83. package/examples/email-send.ps +0 -22
  84. package/examples/error-handling.ps +0 -54
  85. package/examples/expressions.ps +0 -40
  86. package/examples/file-uploads.ps +0 -39
  87. package/examples/files-and-config.ps +0 -47
  88. package/examples/hello.ps +0 -3
  89. package/examples/http-client.ps +0 -44
  90. package/examples/loops.ps +0 -17
  91. package/examples/modules/app.ps +0 -16
  92. package/examples/modules/math.ps +0 -20
  93. package/examples/objects.ps +0 -12
  94. package/examples/record-kinds.ps +0 -43
  95. package/examples/rest-api-fetch.ps +0 -94
  96. package/examples/rest-api.ps +0 -68
  97. package/examples/scheduled-tasks.ps +0 -23
  98. package/examples/search-and-filter.ps +0 -34
  99. package/examples/server.ps +0 -25
  100. package/examples/sessions-and-cookies.ps +0 -54
  101. package/examples/start.ps +0 -2
  102. package/examples/stdlib.ps +0 -41
  103. package/examples/telegram-bot.ps +0 -42
  104. package/examples/web-app.ps +0 -20
  105. package/examples/websocket-server.ps +0 -27
  106. package/examples/whatsapp-bot/qr.ps +0 -8
@@ -1,68 +0,0 @@
1
- // PlainScript v2.1 — A real REST API
2
- //
3
- // Run with: plainscript run examples/rest-api.ps
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
-
19
- 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, ["name", "email"])
33
- remember count as length(missing)
34
- if count is greater 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
46
- 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) is greater than 0
54
- reply found[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
- done
67
-
68
- start 3000
@@ -1,23 +0,0 @@
1
- // PlainScript v2.1 — Scheduled and recurring tasks
2
- //
3
- // Run with: plainscript run examples/scheduled-tasks.ps
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: " + now()
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,34 +0,0 @@
1
- // PlainScript v1.0.0 — Functional transformations
2
- //
3
- // Run with: plainscript run examples/search-and-filter.ps
4
- //
5
- // gather / filter / total map, filter and reduce in place; match routes a
6
- // value to behaviour.
7
-
8
- remember scores as [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 [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,25 +0,0 @@
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"
25
- done
@@ -1,54 +0,0 @@
1
- // PlainScript v1.0.0 — Sessions, cookies and rate limiting
2
- //
3
- // Run with: plainscript run examples/sessions-and-cookies.ps
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
-
12
- 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"
21
- 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
26
- 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
- start 3000
package/examples/start.ps DELETED
@@ -1,2 +0,0 @@
1
- // PlainScript v1.0.1 — entry file for `plainscript start`
2
- show "Application started by PlainScript"
@@ -1,41 +0,0 @@
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 now as time()
8
- remember today as date()
9
- show now
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,42 +0,0 @@
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
9
- when someone sends "/start"
10
- reply "Welcome to the PlainScript bot!" with buttons
11
- "Help" -> "help"
12
- "About" -> "about"
13
- "Status" -> "status"
14
- done
15
- 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 now as date()
25
- reply "Current time: " + now
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
@@ -1,20 +0,0 @@
1
- // PlainScript v0.6 — Web App (Express shorthand)
2
-
3
- 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"
14
- reply json
15
- status is "ok"
16
- version is "0.6"
17
- done
18
- done
19
-
20
- start 3000
@@ -1,27 +0,0 @@
1
- // PlainScript v2.1 — WebSocket chat server
2
- //
3
- // Run with: plainscript run examples/websocket-server.ps
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
-
8
- 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"
@@ -1,8 +0,0 @@
1
- whatsapp bot
2
- auth "session"
3
- login qr
4
-
5
- on message
6
- log message
7
- done
8
- done