Macro calls

This commit is contained in:
2026-05-04 19:43:49 +02:00
parent c717a57f99
commit c083a547d7
5 changed files with 17 additions and 1 deletions
+1
View File
@@ -66,6 +66,7 @@ pub enum TopLevel {
pub enum Postfix { pub enum Postfix {
FieldAccess(String), FieldAccess(String),
Call(Vec<Expression>), Call(Vec<Expression>),
MacroCall(String),
StructCall(HashMap<String, Expression>), StructCall(HashMap<String, Expression>),
Index(Expression), Index(Expression),
Binary(BinaryOp, Expression), Binary(BinaryOp, Expression),
+7
View File
@@ -79,6 +79,11 @@ path_type = { static_path ~ ("<" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ">")? }
ref_type = { mutable? ~ "*" } ref_type = { mutable? ~ "*" }
type_expr = { (path_type | tuple_type) ~ ref_type* } type_expr = { (path_type | tuple_type) ~ ref_type* }
macro_inner_v = {
"(" ~ macro_inner_v* ~ ")"
| (!("(" | ")") ~ ANY)
}
primary = { primary = {
integer integer
| float | float
@@ -90,6 +95,7 @@ primary = {
postfix = { postfix = {
field_px field_px
| call_px | call_px
| macro_call_px
| struct_px | struct_px
| index_px | index_px
| binary_px | binary_px
@@ -97,6 +103,7 @@ postfix = {
field_px = { "." ~ identifier } field_px = { "." ~ identifier }
call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } call_px = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
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 }
+2
View File
@@ -362,6 +362,8 @@ impl From<pest::iterators::Pair<'_, Rule>> for Postfix {
Postfix::Binary(op, Expression::from(inner.next().unwrap())) Postfix::Binary(op, Expression::from(inner.next().unwrap()))
} }
Rule::macro_call_px => Postfix::MacroCall(pair.into_inner().as_str().to_string()),
_ => unimplemented!("Postfix parsing not implemented yet {:?}", pair.as_rule()), _ => unimplemented!("Postfix parsing not implemented yet {:?}", pair.as_rule()),
} }
} }
+4
View File
@@ -144,6 +144,10 @@ impl PostfixChain for [Postfix] {
format!("{}({})", result, args) format!("{}({})", result, args)
} }
Postfix::MacroCall(inner) => {
format!("{}!({})", result, inner)
}
Postfix::StructCall(fields) => { Postfix::StructCall(fields) => {
let fields = fields let fields = fields
.iter() .iter()
+3 -1
View File
@@ -1 +1,3 @@
i32 add(i32* a, i32* b) {} void main() {
println!("Hello, World!");
}