Fix minor grammar

This commit is contained in:
2026-05-05 16:06:32 +02:00
parent 31821300c6
commit f4944103ac
2 changed files with 18 additions and 12 deletions
+12 -11
View File
@@ -12,10 +12,11 @@ string_lit = { "\"" ~ inner_str ~ "\"" }
inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* } inner_str = @{ (!"\"" ~ ("\\\"" | ANY))* }
static_path = { identifier ~ ("::" ~ identifier)* } static_path = { identifier ~ ("::" ~ identifier)* }
export = { "public" } export = { "public" }
mutable = { "mut" } mutable = { "mut" }
sharp = _{ "#" } sharp = _{ "#" }
var_decl = { type_expr ~ mutable? ~ identifier } var_decl = { type_expr ~ mutable? ~ identifier }
semicolon = { ";" }
// ================= TOP LEVEL ================= // ================= TOP LEVEL =================
@@ -74,17 +75,17 @@ statement = _{
// --- basic statements --- // --- basic statements ---
expr_stmt = { expr ~ ";" } expr_stmt = { expr ~ semicolon }
return_stmt = { "return" ~ expr? ~ ";" } return_stmt = { "return" ~ expr? ~ semicolon }
break_stmt = { "break" ~ ";" } break_stmt = { "break" ~ semicolon }
continue_stmt = { "continue" ~ ";" } continue_stmt = { "continue" ~ semicolon }
var_decl_statement = { var_decl ~ ("=" ~ expr)? ~ ";" } var_decl_statement = { var_decl ~ ("=" ~ expr)? ~ semicolon }
assign_statement = { expr ~ "=" ~ expr ~ ";" } assign_statement = { expr ~ "=" ~ expr ~ semicolon }
else_if = { "else" ~ "if" ~ "(" ~ expr ~ ")" ~ statement } else_if = { "else" ~ "if" ~ "(" ~ expr ~ ")" ~ statement }
@@ -135,7 +136,7 @@ macro_call_px = { "!" ~ "(" ~ macro_inner_v* ~ ")" }
struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ ","? ~ "}" } struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ ","? ~ "}" }
index_px = { "[" ~ expr ~ "]" } index_px = { "[" ~ expr ~ "]" }
binary_px = { bin_op ~ expr } binary_px = { bin_op ~ expr }
bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" } bin_op = { "<=" | ">=" | "==" | "!=" | "+" | "-" | "*" | "/" | "%" | "<" | ">" }
struct_field_decl = { identifier ~ ":" ~ expr } struct_field_decl = { identifier ~ ":" ~ expr }
prefix = { prefix = {
+6 -1
View File
@@ -7,7 +7,7 @@ public struct ApiCall {
} }
void main() { void main() {
ApiCall call = ApiCall { x: 10, y: 12 }; ApiCall mut call = ApiCall { x: 10, y: 12 };
if (call.x == 20) { if (call.x == 20) {
println!("= 20"); println!("= 20");
@@ -19,5 +19,10 @@ void main() {
println!("= unknown"); println!("= unknown");
} }
while (call.x <= 40) {
call.x = call.x - 1;
println!("while");
}
println!("{call:?}"); println!("{call:?}");
} }