@@ -24,9 +24,9 @@ generic_placeholder = { ident ~ (":" ~ ident)? }
2424
2525state_ref = { ident | "*" }
2626
27- block_stmt = _{ if_stmt | while_stmt | for_stmt | match_stmt | fun_decl | struct_decl | enum_decl | unsafe_block | block }
27+ block_stmt = _{ if_stmt | while_stmt | for_stmt | match_stmt | fun_decl | destructor_decl | struct_decl | enum_decl | effect_decl | unsafe_block | block }
2828
29- simple_stmt = _{ (import_stmt | let_stmt | const_stmt | return_stmt | expr_stmt | break_stmt | continue_stmt | defer_stmt) ~ stmt_terminator? }
29+ simple_stmt = _{ (import_stmt | let_stmt | shorthand_let_stmt | const_stmt | return_stmt | expr_stmt | break_stmt | continue_stmt | defer_stmt) ~ stmt_terminator? }
3030
3131defer_stmt = { "defer" ~ (block | stmt) }
3232
@@ -50,7 +50,7 @@ sealed_keyword = { "sealed" }
5050
5151import_stmt = { "import" ~ string ~ stmt_terminator? }
5252package_stmt = { "package" ~ (ident ~ ("." ~ ident)*) ~ stmt_terminator? }
53- let_stmt = { mut_keyword? ~ var_type ~ ident ~ "=" ~ expr ~ stmt_terminator? }
53+ let_stmt = { "let" ~ mut_keyword? ~ ( var_type ~ ident ~ "=" | ident ~ ":=") ~ expr ~ stmt_terminator? }
5454shorthand_let_stmt = { mut_keyword? ~ ident ~ ":=" ~ expr ~ stmt_terminator? }
5555const_stmt = { "const" ~ var_type ~ ident ~ "=" ~ expr ~ stmt_terminator? }
5656return_stmt = { "return" ~ expr? ~ stmt_terminator? }
@@ -60,6 +60,17 @@ for_stmt = { "for" ~ atom ~ ":=" ~ expr ~ block ~ stmt_terminator? }
6060
6161stmt_ending = _{ "\n" | WHITESPACE* }
6262
63+ destructor_decl = {
64+ visibility_modifier? ~ "~" ~ ident ~ "(" ~ ")" ~ block ~ stmt_terminator?
65+ }
66+
67+ effect_decl = {
68+ visibility_modifier? ~ sealed_keyword? ~ "effect" ~ ident ~ permits_expr? ~ "(" ~ param_list ~ ")" ~ block
69+ }
70+
71+ effect_annotation = { "\\" ~ type_expr }
72+
73+
6374match_stmt = { "match" ~ expr ~ "{" ~ match_arm* ~ "}" ~ stmt_terminator? }
6475unsafe_block = { "unsafe" ~ block ~ stmt_terminator? }
6576expr_stmt = { expr ~ stmt_terminator? }
@@ -75,9 +86,9 @@ struct_decl = { visibility_modifier? ~ "struct" ~ ident ~ generic_params? ~ fiel
7586fun_decl = {
7687 visibility_modifier? ~ unsafe_modifier? ~
7788 (extern_modifier ~ string)? ~
78- (inline_keyword | noinline_keyword)? ~
89+ (comptime_keyword | inline_keyword | noinline_keyword)? ~ // can't inline a comptime/noinline function and vice versa
7990 var_type ~ ident ~
80- generic_params? ~ param_list ~ (block | arrow_expr)? ~ stmt_terminator?
91+ generic_params? ~ param_list ~ effect_annotation* ~ (block | arrow_expr)? ~ stmt_terminator?
8192}
8293
8394own_keyword = { "own" }
@@ -127,17 +138,21 @@ private_keyword = { "private" }
127138module_keyword = { "module" }
128139package_keyword = { "package" }
129140
141+ comptime_keyword = { "comptime" }
142+
130143mut_keyword = { "mut" }
131- keyword = _{ "true" | "false" | "if" | "else" | "while" | "return" | "for" | "enum" | "type" }
144+ keyword = _{ "true" | "false" | "if" | "else" | "while" | "return" | "for" | "enum" | "type" | "let" | "const" | "mut" | "struct" | "interface" | "impl" | "match" | "break" | "continue" | "unsafe" | "extern" | "inline" | "noinline" | "comptime" | "defer" | "import" | "package" | "this" }
132145
133146ident = @{ !keyword ~ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
134147number = @{ "-"? ~ ASCII_DIGIT+ }
148+ decimal = @{ "-"? ~ ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+ }
149+ char = @{ "'" ~ ("\\" ~ ANY | (!"'" ~ ANY)) ~ "'" }
135150string = @{ "\"" ~ string_inner* ~ "\"" }
136151string_inner = _{ "\\\"" | "\\\\" | (!"\"" ~ ANY) }
137152
138153expr = { assignment }
139154
140- assign_op = { "=" }
155+ assign_op = { ":=" | " =" }
141156compound_assign_op = {
142157 "+="
143158 | "-="
@@ -165,24 +180,24 @@ boolean = { "true" | "false" }
165180logic_or = { logic_and ~ ("||" ~ logic_and)* }
166181logic_and = { bit_or ~ ("&&" ~ bit_or)* }
167182
168- bit_or = { bit_xor ~ (( "|" ~ "=") ~ bit_xor)* }
169- bit_xor = { bit_and ~ (( "^" ~ "=") ~ bit_and)* }
170- bit_and = { equality ~ (( "&" ~ "=") ~ equality)* }
183+ bit_or = { bit_xor ~ ("|" ~ bit_xor)* }
184+ bit_xor = { bit_and ~ ("^" ~ bit_and)* }
185+ bit_and = { equality ~ ("&" ~ equality)* }
171186
172- equality = { comparison ~ (("==" | "~=") ~ comparison)* }
187+ equality = { comparison ~ (("==" | "!=" | " ~=") ~ comparison)* }
173188comparison = { shift ~ (comparison_operators ~ shift)* }
174189
175- operator_shift = { ( ">>>" ~ "=") | ( "<<<" ~ "=") | ( ">>" ~ "=") | ( "<<" ~ "=") }
190+ operator_shift = { ">>>" | "<<<" | ">>" | "<<" }
176191shift = { term ~ ((operator_shift) ~ term)* }
177192
178193term = { factor ~ (operator_add_sub ~ factor)* }
179194factor = { unary ~ (operator_mul_div ~ unary)* }
180195unary = { ("~" | "-" | "+")* ~ primary }
181196
182- operator_add_sub = { ( "+" ~ "=") | ( "-" ~ "=") }
183- operator_mul_div = { ( "*" ~ "=") | ( "/" ~ "=") | ( "%" ~ "=") }
197+ operator_add_sub = { "+" | "-" }
198+ operator_mul_div = { "*" | "/" | "%" }
184199
185- comparison_operators = { "<" | ">" | "<= " | ">= " | "~=" | "==" }
200+ comparison_operators = { "<= " | ">= " | "<" | ">" | "~=" | "! =" | "==" }
186201
187202primary = {
188203 atom ~ postfix
@@ -199,8 +214,11 @@ atom = _{ parenthesized_expr
199214 | class_initialization
200215 | boolean
201216 | array_literal
217+ | lambda_expr
202218 | ident
219+ | decimal
203220 | number
221+ | char
204222 | string
205223 | this_type }
206224
@@ -220,8 +238,8 @@ type_list = { var_type ~ ("," ~ var_type)* }
220238
221239nullable_suffix = { "?" }
222240
223- array_suffix = { "[" ~ atom ~ "]" }
224- basic_type = { (ident ~ ("<" ~ type_list ~ ">")?) | "i32" | "u32" | "f64" | "uf64" | "i64" | "u64" | "i128" | "u128" | "u8" | "i8" | "i16" | "u16" | "boolean" }
241+ array_suffix = { "[" ~ expr ~ "]" }
242+ basic_type = { (ident ~ ("<" ~ type_list ~ ">")?) | "i32" | "u32" | "f32" | " f64" | "uf32" | " uf64" | "i64" | "u64" | "i128" | "u128" | "u8" | "i8" | "i16" | "u16" | "boolean" | "char" | "str " }
225243
226244parenthesized_expr = { "(" ~ expr ~ ")" }
227245operator_pow = { "^" }
0 commit comments