diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index 26a7994..549e5dc 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -281,8 +281,12 @@ self_param = { "self" ~ mutable? ~ deref_px? } +method_args = _{ + ((self_param ~ ("," ~ param_list)?) | param_list) ~ ","? +} + method = { - visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ self_param? ~ ("," ~ param_list)? ~ ")" ~ block + visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ (block | semicolon) } class_item = _{ @@ -310,13 +314,8 @@ impl_decl = { // ====================================================== trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* } -method_no_body = { - visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ self_param? ~ ("," ~ param_list)? ~ ")" ~ semicolon -} - trait_item = _{ method - | method_no_body } trait_decl = { diff --git a/crates/parser/src/parser/items/function.rs b/crates/parser/src/parser/items/function.rs index 2b52253..65da84f 100644 --- a/crates/parser/src/parser/items/function.rs +++ b/crates/parser/src/parser/items/function.rs @@ -10,7 +10,7 @@ impl<'a> TryFrom> for FunctionDecl { type Error = AstError<'a, Self>; fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result { - 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 visibility = Visibility::try_from(&mut inner); let return_type = TypeExpr::try_from(inner.next().unwrap()); diff --git a/mist-test/src/main.mist b/mist-test/src/main.mist index 1a14ec9..759a8fe 100644 --- a/mist-test/src/main.mist +++ b/mist-test/src/main.mist @@ -1,3 +1,11 @@ +class Bro { + constructor() {} + + void idk_man(i32 bro) {} +} + void main() { test_package::hello(); + + let idk = Bro::new(); }