mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 07:56:06 +02:00
Fix some mistakes in the language reference
This commit is contained in:
+11
-12
@@ -26,19 +26,18 @@ Execution proceeds top-to-bottom unless a control-flow statement changes the lin
|
|||||||
|
|
||||||
## Basic rules
|
## Basic rules
|
||||||
|
|
||||||
- Lines are trimmed of leading and trailing whitespace before execution.
|
- Scripts are plain text files with the `.ynt` extension.
|
||||||
- Blank lines are silently skipped.
|
- Each non-empty line is one statement. There are no multi-line expressions.
|
||||||
- Lines starting with `#` are comments and are silently skipped.
|
- Leading and trailing whitespace on each line is ignored.
|
||||||
- Variable interpolation uses `${name}` and is evaluated before the statement runs.
|
- Lines starting with `#` are comments. Inline comments are not supported. Everything after the keyword is treated as its argument.
|
||||||
- Special characters inside string literals are encoded internally and decoded on output - this is transparent to scripts.
|
- `${variable}` anywhere in a line is replaced with the variable's value before the statement runs.
|
||||||
|
- Text wrapped in double quotes (`"..."`) is a string literal. Its contents are not matched as keywords and support escape sequences like `\n` and `\t`.
|
||||||
---
|
|
||||||
|
|
||||||
## Comments
|
## Comments
|
||||||
|
|
||||||
```ynt
|
```ynt
|
||||||
# This is a comment.
|
# This is a comment.
|
||||||
print_line Hello # inline comments are NOT supported - everything after print_line is the argument
|
print_line Hello # inline comments are NOT supported. Everything after print_line is the argument
|
||||||
```
|
```
|
||||||
|
|
||||||
Only whole-line comments (lines whose first non-whitespace character is `#`) are supported.
|
Only whole-line comments (lines whose first non-whitespace character is `#`) are supported.
|
||||||
@@ -222,7 +221,7 @@ Adjacent sign characters (`++`, `--`, `-+`, `+-`) are normalised before evaluati
|
|||||||
```ynt
|
```ynt
|
||||||
var x = 3
|
var x = 3
|
||||||
var y = 4
|
var y = 4
|
||||||
var sum = ${x} + ${y} calc # 7
|
var sum = ${x} + ${y} calc # 7
|
||||||
var expr = 2 + 3 * 4 calc # 14 (* before +)
|
var expr = 2 + 3 * 4 calc # 14 (* before +)
|
||||||
var parens = (2 + 3) * 4 calc # 20
|
var parens = (2 + 3) * 4 calc # 20
|
||||||
var power = 2 ^ 10 calc # 1024
|
var power = 2 ^ 10 calc # 1024
|
||||||
@@ -311,7 +310,7 @@ goto <name>
|
|||||||
```
|
```
|
||||||
|
|
||||||
`label` marks a target. `goto` performs an unconditional jump to that label.
|
`label` marks a target. `goto` performs an unconditional jump to that label.
|
||||||
At the top level, labels are file-scoped — you can jump to any label in the file. Inside a function, labels are restricted to the current function; you cannot jump to a label outside the calling function.
|
At the top level, labels are file-scoped, you can jump to any label in the file. Inside a function, labels are restricted to the current function; you cannot jump to a label outside the calling function.
|
||||||
|
|
||||||
```ynt
|
```ynt
|
||||||
label loop:
|
label loop:
|
||||||
@@ -598,7 +597,7 @@ print_line Main thread continues.
|
|||||||
#### Recommended pattern
|
#### Recommended pattern
|
||||||
|
|
||||||
Use a direct function call with `task`, and terminate inside that function with `exit`.
|
Use a direct function call with `task`, and terminate inside that function with `exit`.
|
||||||
This keeps the worker logic isolated and avoids `goto` scaffolding.
|
This keeps the worker logic isolated.
|
||||||
|
|
||||||
```ynt
|
```ynt
|
||||||
call background_job task
|
call background_job task
|
||||||
@@ -606,7 +605,7 @@ print_line Main thread keeps going
|
|||||||
|
|
||||||
func background_job:
|
func background_job:
|
||||||
print_line Work in background
|
print_line Work in background
|
||||||
exit
|
exit
|
||||||
```
|
```
|
||||||
|
|
||||||
This works well for task-only worker flows. In non-task/shared flows, prefer `return` if you want
|
This works well for task-only worker flows. In non-task/shared flows, prefer `return` if you want
|
||||||
|
|||||||
Reference in New Issue
Block a user