aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-09-11 12:35:26 +0200
committerHimbeer <himbeer@disroot.org>2024-09-11 12:50:01 +0200
commit6e877c258f90c5ada9dc981b0b437aa61c510db4 (patch)
treed1451dd44c2419ec419fda3f91af71c028cbc1f7 /doc
parent1a8f37ba9d5a1f1e656f7aff4d75994c410e41b0 (diff)
Add module system to grammar
Diffstat (limited to 'doc')
-rw-r--r--doc/grammar.txt28
1 files changed, 15 insertions, 13 deletions
diff --git a/doc/grammar.txt b/doc/grammar.txt
index 77f5763..c78e2a6 100644
--- a/doc/grammar.txt
+++ b/doc/grammar.txt
@@ -1,12 +1,14 @@
root := toplevel*
-toplevel := externfunc | function | constant
+toplevel := import* ( externfunc | function | constant )
-function := [ "export" ] "func" IDENT "(" ( param ), ")" IDENT block
-param := IDENT type
+import := "import" IDENT [ NAME ] ";"
-externfunc := "extern" "func" IDENT "(" ( type ), ")" IDENT ";"
+function := [ "pub" ] [ "export" ] "func" NAME "(" ( param ), ")" type block
+param := NAME type
-constant := "const" IDENT "=" ( type | bool | INTEGER | FLOAT | STRING* ) ";"
+externfunc := "extern" "func" NAME "(" ( type ), ")" type ";"
+
+constant := [ "pub" ] "const" NAME "=" ( type | bool | INTEGER | FLOAT | STRING* ) ";"
block := "{" body* "}"
@@ -26,19 +28,19 @@ if := "if" expression block elseif* else*
elseif := "else" "if" expression block
else := "else" block
-for := [ ":" IDENT ] [ assignment ";" ] expression [ ";" assignment ] block
+for := [ ":" NAME ] [ assignment ";" ] expression [ ";" assignment ] block
return := "return" expression
-break := "break" ":" IDENT
-continue := "continue" ":" IDENT
+break := "break" ":" NAME
+continue := "continue" ":" NAME
-declaration := "let" [ "mut" ] IDENT "=" expression ";"
+declaration := "let" [ "mut" ] NAME "=" expression ";"
assignment := location "=" expression ";"
-location := IDENT ( index | field )* [ "*" ]
+location := NAME ( index | field )* [ "*" ]
index := "[" INTEGER "]"
-field := "." IDENT
+field := "." NAME
call := IDENT "(" ( expression ), ")"
@@ -55,9 +57,9 @@ float := "f32" | "f64"
array := "[" INTEGER "]" type
slice := "[]" type
struct := "struct" "{" fields "}"
-enum := "enum" [ expression ] "{" ( IDENT ), "}"
+enum := "enum" [ expression ] "{" ( NAME ), "}"
union := "union" [ type ] "{" fields "}"
-fields := ( IDENT type ),
+fields := ( NAME type ),
expression := equality | comparison
equality := comparison ( "==" | "!=" ) comparison