From 488b9859920ee06ec2cbc4e4eb5e98c3880b160d Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Thu, 23 Apr 2026 19:04:01 +0200 Subject: [PATCH] Struct init grammar --- parser/src/grammar.pest | 13 ++++++++----- parser/src/script_grammar.pest | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index 058b782..331b703 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -105,15 +105,18 @@ primary = { postfix = { field_px | call_px + | struct_px | index_px | binary_px } -field_px = { "." ~ identifier } -call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } -index_px = { "[" ~ expr ~ "]" } -binary_px = { bin_op ~ expr } -bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" } +field_px = { "." ~ identifier } +call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } +struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ "}" } +index_px = { "[" ~ expr ~ "]" } +binary_px = { bin_op ~ expr } +bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" } +struct_field_decl = { identifier ~ ":" ~ expr } expr = { primary ~ postfix* diff --git a/parser/src/script_grammar.pest b/parser/src/script_grammar.pest index 4cc1a94..5ba90bc 100644 --- a/parser/src/script_grammar.pest +++ b/parser/src/script_grammar.pest @@ -105,15 +105,18 @@ primary = { postfix = { field_px | call_px + | struct_px | index_px | binary_px } -field_px = { "." ~ identifier } -call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } -index_px = { "[" ~ expr ~ "]" } -binary_px = { bin_op ~ expr } -bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" } +field_px = { "." ~ identifier } +call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } +struct_px = { "{" ~ (struct_field_decl ~ ("," ~ struct_field_decl)*)? ~ "}" } +index_px = { "[" ~ expr ~ "]" } +binary_px = { bin_op ~ expr } +bin_op = { "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" } +struct_field_decl = { identifier ~ ":" ~ expr } expr = { primary ~ postfix*