Fix methods #58 and #55

This commit is contained in:
2026-06-04 17:38:49 +02:00
parent 20d9641dda
commit a8717aa5c4
3 changed files with 14 additions and 7 deletions
+5 -6
View File
@@ -281,8 +281,12 @@ self_param = {
"self" ~ mutable? ~ deref_px? "self" ~ mutable? ~ deref_px?
} }
method_args = _{
((self_param ~ ("," ~ param_list)?) | param_list) ~ ","?
}
method = { method = {
visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ self_param? ~ ("," ~ param_list)? ~ ")" ~ block visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ (block | semicolon)
} }
class_item = _{ class_item = _{
@@ -310,13 +314,8 @@ impl_decl = {
// ====================================================== // ======================================================
trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* } trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* }
method_no_body = {
visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ self_param? ~ ("," ~ param_list)? ~ ")" ~ semicolon
}
trait_item = _{ trait_item = _{
method method
| method_no_body
} }
trait_decl = { trait_decl = {
+1 -1
View File
@@ -10,7 +10,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
type Error = AstError<'a, Self>; type Error = AstError<'a, Self>;
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> { fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
ast_ensure!(pair, Rule::function_decl, Rule::method, Rule::method_no_body => { ast_ensure!(pair, Rule::function_decl, Rule::method => {
let mut inner = pair.into_inner(); let mut inner = pair.into_inner();
let visibility = Visibility::try_from(&mut inner); let visibility = Visibility::try_from(&mut inner);
let return_type = TypeExpr::try_from(inner.next().unwrap()); let return_type = TypeExpr::try_from(inner.next().unwrap());
+8
View File
@@ -1,3 +1,11 @@
class Bro {
constructor() {}
void idk_man(i32 bro) {}
}
void main() { void main() {
test_package::hello(); test_package::hello();
let idk = Bro::new();
} }