utkrisht 0.1.0 → 0.1.1
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/package.json +1 -1
- package/readme.md +93 -77
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -20,35 +20,15 @@
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
23
|
-
> [!WARNING]
|
|
24
|
-
> Do not install this now, everything is broken and has errors.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Prerequisites
|
|
28
|
-
[Install Nim](https://nim-lang.org/install.html)
|
|
29
|
-
|
|
30
|
-
### Steps
|
|
31
|
-
Clone this repository
|
|
32
|
-
```
|
|
33
|
-
git clone https://github.com/LadyBeGood/utkrisht.git
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Compile the compiler
|
|
37
23
|
|
|
38
24
|
```bash
|
|
39
|
-
|
|
25
|
+
npm install -g utkrisht
|
|
40
26
|
```
|
|
41
|
-
|
|
42
|
-
(Optional) Clean up the repository after successful compilation:
|
|
43
|
-
```bash
|
|
44
|
-
rm -rf utkrisht
|
|
45
|
-
```
|
|
46
|
-
|
|
47
27
|
### Example usage
|
|
48
28
|
Compile a input.uki file to output.js file:
|
|
49
29
|
|
|
50
30
|
```bash
|
|
51
|
-
|
|
31
|
+
uki input.uki output.js
|
|
52
32
|
```
|
|
53
33
|
|
|
54
34
|
## Tutorial
|
|
@@ -76,7 +56,7 @@ You can document a variable by directly placing comments above it. These comment
|
|
|
76
56
|
# Divide 2 numbers
|
|
77
57
|
# - `a`: Numerator
|
|
78
58
|
# - `b`: Denominator
|
|
79
|
-
divide a, b
|
|
59
|
+
divide a, b ~ {
|
|
80
60
|
exit a / b
|
|
81
61
|
}
|
|
82
62
|
```
|
|
@@ -90,20 +70,48 @@ divide a, b: {
|
|
|
90
70
|
|
|
91
71
|
|
|
92
72
|
### Data types
|
|
93
|
-
Utkrisht has 5 data types
|
|
73
|
+
Utkrisht has **5 data types**.
|
|
94
74
|
|
|
95
|
-
| Data Type
|
|
96
|
-
|
|
97
|
-
| String | Value | Yes | Yes | No | No |
|
|
98
|
-
| Number | Value | Yes | No | No | No |
|
|
99
|
-
| Boolean | Value | Yes | No | No | No |
|
|
100
|
-
| Procedure | Reference | No | No | No | Yes |
|
|
101
|
-
| Structure | Reference | Yes | Yes | Yes | No |
|
|
75
|
+
| Data Type | Passed by | Clonable | iterable | Mutable | Callable | Hashable |
|
|
76
|
+
|---------------|-----------|----------|----------|---------|----------|-------------------|
|
|
77
|
+
| **String** | Value | Yes | Yes | No | No | Yes |
|
|
78
|
+
| **Number** | Value | Yes | No | No | No | Yes<sup>[1]</sup> |
|
|
79
|
+
| **Boolean** | Value | Yes | No | No | No | Yes |
|
|
80
|
+
| **Procedure** | Reference | No | No | No | Yes | Yes |
|
|
81
|
+
| **Structure** | Reference | Yes | Yes | Yes | No | Yes |
|
|
102
82
|
|
|
83
|
+
> [!NOTE]
|
|
84
|
+
> [1] All numbers including `nan` are hashable and can be used as keys.
|
|
85
|
+
> Structure uses the algorithm [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) to test keys for equivalnce.
|
|
86
|
+
> So `nan` is considered equal to `nan`.
|
|
103
87
|
|
|
104
88
|
#### String
|
|
105
|
-
|
|
89
|
+
Strings are used to store textual data.
|
|
90
|
+
|
|
91
|
+
Strings can be created using double quotes:
|
|
92
|
+
```
|
|
93
|
+
# Single line strings
|
|
94
|
+
"This is a single line string."
|
|
106
95
|
|
|
96
|
+
# Multi line string
|
|
97
|
+
"
|
|
98
|
+
This is a multiline string.
|
|
99
|
+
* These strings are allowed to span multiple lines.
|
|
100
|
+
* They need to be properly indented.
|
|
101
|
+
* Leading spaces, spaces and newline after starting quote and newline after ending quote are all trimmed off.
|
|
102
|
+
"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Special characters
|
|
106
|
+
| Character | Description |
|
|
107
|
+
|-----------|-----------------|
|
|
108
|
+
| `\n` | New Line |
|
|
109
|
+
| `\r` | Carriage Return |
|
|
110
|
+
| `\"` | Quote |
|
|
111
|
+
| `\\` | Backslash |
|
|
112
|
+
| `\t` | Tab |
|
|
113
|
+
|
|
114
|
+
A string is represented internally a sequence of UTF-16 code units, identical to JavaScript strings, and thus share the same quirks.
|
|
107
115
|
```
|
|
108
116
|
write length "😼" #> 2
|
|
109
117
|
write "😼".1 #> \ud83d
|
|
@@ -137,23 +145,23 @@ nan # stands for "not a number", but this is also a number
|
|
|
137
145
|
```
|
|
138
146
|
|
|
139
147
|
```
|
|
140
|
-
|
|
148
|
+
(123 = 123.0) #-> right
|
|
141
149
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
(0 = 0) #-> right
|
|
151
|
+
(-0 = -0) #-> right
|
|
152
|
+
(0 = -0) #-> right
|
|
145
153
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
154
|
+
(infinity = infinity) #-> right
|
|
155
|
+
(infinity = -infinity) #-> wrong
|
|
156
|
+
(-infinity = -infinity) #-> right
|
|
149
157
|
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
(nan = nan) #-> wrong (This is not a typo)
|
|
159
|
+
(nan != nan) #-> right (This is also not a typo)
|
|
152
160
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
161
|
+
is-finite 123 #-> right
|
|
162
|
+
is-finite infinity #-> wrong
|
|
163
|
+
is-finite -infinity #-> wrong
|
|
164
|
+
is-nan nan #-> right
|
|
157
165
|
```
|
|
158
166
|
|
|
159
167
|
```
|
|
@@ -178,16 +186,16 @@ Boolean literals are represented by the keywords `right` and `wrong`. There are
|
|
|
178
186
|
|
|
179
187
|
Keywords are predefined words used by the language to perform internal operations or represent built-in behavior.
|
|
180
188
|
|
|
181
|
-
Utkrisht has **
|
|
189
|
+
Utkrisht has **14 keywords**. None of them are reserved and may also be used as [identifiers](#identifiers).
|
|
182
190
|
|
|
183
|
-
| Keywords
|
|
184
|
-
|
|
185
|
-
| `right
|
|
186
|
-
| `when
|
|
187
|
-
| `loop
|
|
188
|
-
| `try
|
|
189
|
-
| `exit`
|
|
190
|
-
| `import
|
|
191
|
+
| Keywords | Description |
|
|
192
|
+
|-----------------------------|--------------------------|
|
|
193
|
+
| `right` `wrong` | Boolean literals |
|
|
194
|
+
| `when` `else` | Conditional branching |
|
|
195
|
+
| `loop` `with` `stop` `skip` | Looping and loop control |
|
|
196
|
+
| `try` `fix` | Error handling |
|
|
197
|
+
| `exit` `give` | Exiting from a procedure |
|
|
198
|
+
| `import` `export` | Module import and export |
|
|
191
199
|
|
|
192
200
|
|
|
193
201
|
|
|
@@ -209,11 +217,11 @@ Operators are symbols used to perform operations on values.
|
|
|
209
217
|
|---------------------------------------|-------------------------------------------|---------------------------------------------------------|
|
|
210
218
|
| `:` `=` | Infix | Variable declaration and reassignment |
|
|
211
219
|
| `+` `-` `*` `/` | Infix | Arithmetic operations |
|
|
212
|
-
| `=` `<` `>`
|
|
213
|
-
|
|
|
220
|
+
| `=` `<` `>` <br />`!=` `!<` `!>` | Infix | Comparison operations |
|
|
221
|
+
| `&` `\|` `!` | Infix (except `!`, which is prefix) | Logical operations |
|
|
214
222
|
| `_` | Infix | Range construction |
|
|
215
223
|
| `.` | Infix | Access operator |
|
|
216
|
-
|
|
|
224
|
+
| `!` | Postfix | Procedure call |
|
|
217
225
|
| `/` | Prefix | Module access operator |
|
|
218
226
|
| `@` | Prefix | Async operator |
|
|
219
227
|
| `$` | Prefix | Reactivity operator |
|
|
@@ -229,8 +237,8 @@ Separators are symbols used to divide syntactic elements without performing an o
|
|
|
229
237
|
| Separator | Separates |
|
|
230
238
|
|-----------|--------------------------------------------------------------|
|
|
231
239
|
| `,` | Arguments, Parameters, Properties |
|
|
232
|
-
|
|
|
233
|
-
|
|
|
240
|
+
| `!,` | Arguments (use default value for the parameter) |
|
|
241
|
+
| NewLine | Arguments, Parameters, Properties (non-terminating contexts) |
|
|
234
242
|
|
|
235
243
|
|
|
236
244
|
|
|
@@ -255,7 +263,7 @@ Terminators mark the end of a statement or declaration.
|
|
|
255
263
|
|
|
256
264
|
| Terminator | Terminates |
|
|
257
265
|
|------------|---------------------------------------------|
|
|
258
|
-
|
|
|
266
|
+
| NewLine | Statements, Comments (terminating contexts) |
|
|
259
267
|
| EndOfFile | Statements, Comments |
|
|
260
268
|
|
|
261
269
|
|
|
@@ -265,7 +273,7 @@ Identifiers are names given to different entities in Utkrisht to uniquely identi
|
|
|
265
273
|
|
|
266
274
|
```
|
|
267
275
|
# variables
|
|
268
|
-
message
|
|
276
|
+
message ~ "hi"
|
|
269
277
|
|
|
270
278
|
# structure keys
|
|
271
279
|
[name = "Uki"]
|
|
@@ -307,13 +315,13 @@ Variables are identifiers used to store data. All variables are mutable and can
|
|
|
307
315
|
|
|
308
316
|
|
|
309
317
|
|
|
310
|
-
Declare a variable using
|
|
318
|
+
Declare a variable using `~`
|
|
311
319
|
```
|
|
312
|
-
message
|
|
320
|
+
message ~ "Hello World"
|
|
313
321
|
```
|
|
314
322
|
Reassign a value using `=`
|
|
315
323
|
```
|
|
316
|
-
quantity
|
|
324
|
+
quantity ~ 34
|
|
317
325
|
|
|
318
326
|
quantity = 65
|
|
319
327
|
quantity = "high" # Data type of the value does not matter
|
|
@@ -323,24 +331,33 @@ quantity = "high" # Data type of the value does not matter
|
|
|
323
331
|
Control flow determines how execution proceeds through a program.
|
|
324
332
|
|
|
325
333
|
#### Conditionals
|
|
326
|
-
Conditionals control which
|
|
334
|
+
Conditionals control which block will be executed based on a **condition**. The condition must be a boolean value, Utkrisht does not have truthy or falsy values.
|
|
327
335
|
```
|
|
328
|
-
#
|
|
329
|
-
when age
|
|
330
|
-
write "You're an adult"
|
|
331
|
-
else age < 18
|
|
336
|
+
# Conditional statement
|
|
337
|
+
when age < 13
|
|
332
338
|
write "You're a child"
|
|
339
|
+
else age > 19
|
|
340
|
+
write "You're an adult"
|
|
333
341
|
else
|
|
334
|
-
write "You're
|
|
342
|
+
write "You're a teen"
|
|
335
343
|
|
|
336
344
|
|
|
337
|
-
#
|
|
338
|
-
status
|
|
345
|
+
# Multiline conditional expression
|
|
346
|
+
status ~
|
|
347
|
+
when age < 13
|
|
348
|
+
"child"
|
|
349
|
+
else age > 19
|
|
350
|
+
"adult"
|
|
351
|
+
else
|
|
352
|
+
"teen"
|
|
353
|
+
|
|
354
|
+
# Singleline conditional expression
|
|
355
|
+
status ~ when (age < 13) "child" else (age > 19) "adult" else "teen"
|
|
339
356
|
```
|
|
340
357
|
#### Loops
|
|
341
358
|
Loop is a data type sensitive construct. Therefore the behaviour of the loop depends upon the data type of the data following it.
|
|
342
359
|
```
|
|
343
|
-
# loop keyword followed
|
|
360
|
+
# loop keyword not followed by any data type
|
|
344
361
|
# loops infinitely
|
|
345
362
|
loop
|
|
346
363
|
write "hello"
|
|
@@ -363,7 +380,7 @@ loop 5 # loops 5 times
|
|
|
363
380
|
|
|
364
381
|
# loop keyword followed by a string or structure
|
|
365
382
|
# loops `length iterable` times
|
|
366
|
-
loop "uki" # loops 3 times because there are
|
|
383
|
+
loop "uki" # loops 3 times because there are 3 characters in "uki": "u", "k" and "i"
|
|
367
384
|
write "hello"
|
|
368
385
|
|
|
369
386
|
loop [id = 567, right, "orange"] # loops 3 times
|
|
@@ -477,15 +494,14 @@ A module can be imported using the `import` keyword followed by its path:
|
|
|
477
494
|
import utilities
|
|
478
495
|
import components/footer
|
|
479
496
|
import ../assets/icons
|
|
480
|
-
import routes/[home, notifications, profile]
|
|
481
497
|
```
|
|
482
498
|
When you write an import like `import abc`, the compiler looks for:
|
|
483
499
|
- a file named `abc.uki`, or
|
|
484
500
|
- a folder named `abc` that contains a file named `abc.uki`.
|
|
485
501
|
|
|
486
502
|
#### Export
|
|
487
|
-
Use the `export` keyword available to other modules:
|
|
503
|
+
Use the `export` keyword to make the variable available to other modules that import it:
|
|
488
504
|
```
|
|
489
|
-
export message
|
|
505
|
+
export message ~ "hi"
|
|
490
506
|
```
|
|
491
507
|
|