~repos /plum

#treesitter#compiler#wasm

git clone https://pyrossh.dev/repos/plum.git

A statically typed, imperative programming language inspired by rust, python


7aecb8c7 pyrossh

1 year ago
docs
Files changed (1) hide show
  1. readme.md +65 -24
readme.md CHANGED
@@ -1,36 +1,49 @@
1
1
  # 👾 Pacos Programming Language
2
2
 
3
- A simple statically typed imperative programming language. Its main aim to be simple and easy to code correct programs. It takes inspiration for golang and ponylang. It comes packed with linting, formatting, test runner, language server, package management in-built.
3
+ A simple statically typed imperative programming language. Its main aim to be simple and easy to code correct programs. It takes inspiration for golang, ponylang, and dart. It comes packed with linting, formatting, test runner, language server, and package management in-built.
4
4
 
5
- The parser is written using tree-sitter syntax so has out of the box syntax highlighting support for helix and zed editor.
5
+ The compiler users the tree-sitter parser so has out of the box syntax highlighting support for helix and zed editor.
6
6
 
7
- Here is some sample syntax, enjoy 👾
7
+ Here is some sample code, please enjoy.
8
- ```
8
+ ```rs
9
9
  module lambda
10
10
 
11
11
  fn sum(a: int, b: int): int = a + b
12
12
 
13
- fn sum_list(series: list[int]): int =
13
+ fn sum_all(series: list[int]): int =
14
14
  series.reduce(0, |v| v + 1)
15
15
 
16
16
  fn fib(n: int): int =
17
17
  match n
18
18
  0 | 1 -> n
19
- else -> fib(n - 1) + fib(n - 2)
19
+ _ -> fib(n - 1) + fib(n - 2)
20
20
 
21
21
  fn fib(n: int): int =
22
- if n == 0 || n == 1 then
22
+ if n == 0 || n == 1
23
23
  n
24
24
  else
25
25
  fib(n - 1) + fib(n - 2)
26
- end
27
26
 
28
27
  fn factorial(n: int): int =
29
28
  match n
30
- 1 -> 1
29
+ a -> 1
31
30
  _ -> n * factorial(n - 1)
32
31
 
32
+ fn first_item(l: list[int]): int? =
33
+ l[0]
34
+
35
+ fn first_item(l: list[int]): int? =
36
+ match l
37
+ [] -> nil
38
+ [head, ...rest] -> head
39
+
40
+ fn first_item(l: list[int]): int? =
41
+ if l.size > 0
42
+ l[0]
43
+ else
44
+ nil
45
+
33
- fn to-celsius(f: float) =
46
+ fn to-celsius(f: float): float =
34
47
  (f - 32) * (5 / 9)
35
48
 
36
49
  record Cat(
@@ -102,7 +115,10 @@ bench("1231") |t, n|
102
115
  ## Language Reference
103
116
 
104
117
  **Keywords**
118
+
119
+ ```rs
105
- for,while,if,then,else,end,record,enum,fn,assert,when,match
120
+ for,while,if,else,record,enum,fn,assert,when,match,type
121
+ ```
106
122
 
107
123
  ### Types
108
124
  ```
@@ -167,7 +183,7 @@ A float represents a 64-bit floating point (52-bit mantissa) IEEE-754-2008 binar
167
183
  A str represents a slice of runes or unicode code points. It is encoded to UTF-8 by default.
168
184
  It supports interpolation of variables/values that implement the ToStr interface.
169
185
 
170
- ```
186
+ ```rs
171
187
  "Hello World"
172
188
  name := "Pacos"
173
189
  age := 1
@@ -178,14 +194,14 @@ println("Name ${name} age ${age}")
178
194
 
179
195
  **list**
180
196
 
181
- ```
197
+ ```rs
182
198
  a := [1, 2, 3] // list[int]
183
199
  b := [[1, 2], [3, 4], [5, 6]] // list[list[int]]
184
200
  ```
185
201
 
186
202
  **map**
187
203
 
188
- ```
204
+ ```rs
189
205
  tree = [
190
206
  value: "Fred",
191
207
  left: [
@@ -205,7 +221,8 @@ tree = [
205
221
 
206
222
 
207
223
  **Assignment statement**
224
+
208
- ```
225
+ ```rs
209
226
  low, mid, high := 0, 0, n.numItems
210
227
  x := 10
211
228
  y := 20
@@ -218,7 +235,7 @@ assoc_list["b"]
218
235
 
219
236
  **While statement**
220
237
 
221
- ```
238
+ ```rs
222
239
  while low < high
223
240
  mid = (low + high) / 2
224
241
  low = cmp > 0 > mid + 1 : low
@@ -233,7 +250,8 @@ else |err|
233
250
  ```
234
251
 
235
252
  **For statement**
253
+
236
- ```
254
+ ```rs
237
255
  for players_list |value|
238
256
  if value == 0
239
257
  continue
@@ -267,17 +285,17 @@ fn range(start: int, end: int, cb: (v: T) -> IterateResult) =
267
285
  range(0, 5, |v| =>
268
286
  sum3 += v
269
287
  )
270
- ```
271
288
 
272
289
  // Iterate over multiple objects.
273
290
  // All lengths must be equal at the start of the loop, otherwise detectable
274
291
  // illegal behavior occurs.
275
292
  for items, items2 |i, j|
276
293
  count += i + j
294
+ ```
277
295
 
278
296
  **When expression/statement**
279
297
 
280
- ```
298
+ ```rs
281
299
  when
282
300
  cmp > 0 -> low = mid + 1
283
301
  cmp < 0 -> high = mid
@@ -289,33 +307,56 @@ Bitwise operators (>>, <<, &, |, ~, etc.)
289
307
  Comparison operators (<, >, ==, etc.)
290
308
 
291
309
  **if expression/statement**
310
+
311
+ ```rs
292
312
  if (a) |value| {
293
313
  try expect(value == 0);
294
314
  } else |err| {
295
315
  _ = err;
296
316
  unreachable;
297
317
  }
318
+ ```
298
319
 
299
320
  ### Conditional operators
300
321
 
301
322
  **not operator**
323
+
324
+ ```
302
325
  !a
303
326
  !true
327
+ ```
304
328
 
305
329
  **ternary operator**
330
+
331
+ ```
306
332
  x ? x : y
333
+ ```
307
334
 
308
335
  **safe navigation operator**
336
+
337
+ ```
309
338
  a?.b?.c?.d
339
+ ```
340
+
341
+ **Safe index operator**
342
+ ```
343
+ array?[1]
344
+ ```
310
345
 
311
346
  **elvis operator**
347
+
348
+ ```
312
349
  x ?: y
350
+ ```
313
351
 
314
352
  **elvis assignment operator**
315
- atomicNumber ?= 2
316
353
 
354
+ ```
317
- **Range operator**
355
+ atomic_number ?= 2
318
- for 5..10 |i|:
356
+ ```
319
357
 
320
- **Safe index operator**
358
+ **Range operator**
359
+ ```
360
+ for 5..10 |i|
321
- array?[1]
361
+ println(i)
362
+ ```