aboutsummaryrefslogtreecommitdiff
path: root/doc/syntax.md
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 15:15:17 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 15:15:17 +0100
commit1cdeea8bd4be4dd55f4ab5d5d0c33586473e0cb1 (patch)
treeb6192300a54d7deed33164a9830ae077372677c9 /doc/syntax.md
parent09d398c748c2707918c9f531b91d161b08cb1163 (diff)
downloaduwu-lang-1cdeea8bd4be4dd55f4ab5d5d0c33586473e0cb1.tar.xz
Extend documentation
Diffstat (limited to 'doc/syntax.md')
-rw-r--r--doc/syntax.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/syntax.md b/doc/syntax.md
new file mode 100644
index 0000000..6ec3cfc
--- /dev/null
+++ b/doc/syntax.md
@@ -0,0 +1,35 @@
+## Syntax
+
+A module is made out of functions. Each function is made out of a name and exactly one expression, seperated by arbitrary whitespace.
+
+```
+function_name expression
+
+other_function_name
+ other_expression
+
+
+ weird_indent_function_name
+
+ weird_indent_expression
+
+```
+
+An expression is either of these:
+
+- Integer literal: `0`, `1`, `3245`
+- String literal: `"hello, world"`, `""`, `"this is
+a multiline
+string literal
+"`
+- Argument number: `$0`, `$1`, `$5`
+- Function reference: `&function_name`
+- Function call: `function_name(args)` or just `function_name`, where args is a comma-separated list of expressions.
+
+**Important:** When passing arguments to a function, these arguments are not passed directly as values, but rather as expressions. Each argument is evaulated as the called function accesses it. This means that you can have constructs that would cause infinite recursion in other languages - a good example for a usecase of that are conditions: `:bool:if(condition, if_true, else)` is just a regular function from the standard library. `if_true` is only evaluated if condition is truey, meaning that if condition is falsey and `if_true` is a function call, that function will not be called.
+
+Function name syntax:
+
+- `function`: Call `function` in the current module.
+- `path:to:module:function`: Call `function` in the module located at `path/to/module`. That path is relative to the path of the module calling the function. See module paths section under Invocation.
+- `:std_module:function`: Call `function` in the module `std_module` from the standard library.