From 0e710b3bc6b4b0521c41820f609eed80c0b5ec87 Mon Sep 17 00:00:00 2001 From: Denis Merigoux Date: Mon, 7 Mar 2022 18:13:27 +0100 Subject: [PATCH] Complete syntax reflecting the AST --- src/language/syntax.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/language/syntax.md b/src/language/syntax.md index afce746..06e2891 100644 --- a/src/language/syntax.md +++ b/src/language/syntax.md @@ -3,28 +3,49 @@ ``` P ::= [i]\* Program items i ::= array!(t, μ, n) Array type declaration where n is a natural number + | nat_mod!(t, n) Modular integer | fn f([d]+) -> μ b Function declaration + | type t = enum { [c(μ)]+ } Enum declaration (with constructors) + | type t = struct([μ]+) Struct declaration (without named fields) + | const x: μ = e Constant declaration + | use crate::* External crate import d ::= x: τ Function argument -μ ::= unit|bool|int Base types +μ ::= unit|bool|u8|U8|i8|I8... Base types | Seq<μ> Sequence + | String Strings | ([μ]+) Tuple + | unit Unit type + | t Named type τ ::= μ Plain type | &μ Immutable reference b ::= {[s;]+} Block -s ::= let x: τ = e Let binding +p ::= x Variable pattern + | ([p]+) Tuple pattern + | t (p) Struct constructor pattern + | _ Wildcard pattern +s ::= let p: τ = e Let binding + | let mut p: τ = e Mutable let binding | x = e Variable reassignment + | x = e? Variable reassignment with error catching + | let p: τ = e? Let binding with error catching | if e then b (else b) Conditional statements + | c(e) Enum injection + | match e { [c(p) => e]+ } Pattern matching | for x in e..e b For loop (integers only) | e Return expression | b Statement block e ::= ()|true|false Unit and boolean literals | n Integer literal + | "..." String literal + | t([e]+) Array literal + | e as μ Integer casting | x Variable + | () Unit | f([a]+) Function call + | if e then e else e Conditional expression | e ⊙ e Binary operations | ⊘ e Unary operations | ([e]+) Tuple constructor - | e.(n) Tuple field access where n is a natural number | x[e] Array or sequence index a ::= e Linear argument | &e Call-site borrowing