Fix undeclared lifetime and simplifed grammar #50

This commit is contained in:
2026-06-04 17:44:41 +02:00
parent a8717aa5c4
commit e571d98cd0
4 changed files with 7 additions and 17 deletions
+5 -9
View File
@@ -285,13 +285,9 @@ method_args = _{
((self_param ~ ("," ~ param_list)?) | param_list) ~ ","? ((self_param ~ ("," ~ param_list)?) | param_list) ~ ","?
} }
method = {
visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ (block | semicolon)
}
class_item = _{ class_item = _{
impl_decl impl_decl
| method | function_decl
} }
class_decl = { class_decl = {
@@ -302,11 +298,11 @@ class_decl = {
// IMPL // IMPL
// ====================================================== // ======================================================
impl_for_decl = { impl_for_decl = {
"impl" ~ generics_decl? ~ type_expr ~ "for" ~ type_expr ~ "{" ~ method* ~ "}" "impl" ~ generics_decl? ~ type_expr ~ "for" ~ type_expr ~ "{" ~ function_decl* ~ "}"
} }
impl_decl = { impl_decl = {
"impl" ~ generics_decl? ~ type_expr ~ "{" ~ method* ~ "}" "impl" ~ generics_decl? ~ type_expr ~ "{" ~ function_decl* ~ "}"
} }
// ====================================================== // ======================================================
@@ -315,7 +311,7 @@ impl_decl = {
trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* } trait_requirements = { ":" ~ type_expr_param ~ ("+" ~ type_expr_param)* }
trait_item = _{ trait_item = _{
method function_decl
} }
trait_decl = { trait_decl = {
@@ -327,7 +323,7 @@ trait_decl = {
// ====================================================== // ======================================================
function_decl = { function_decl = {
visibility? ~ type_expr ~ identifier ~ "(" ~ param_list ~ ")" ~ block visibility? ~ type_expr ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ (block | semicolon)
} }
// ====================================================== // ======================================================
+1 -1
View File
@@ -42,7 +42,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ClassItem {
Ok(ClassItem::ImplDecl(pair.try_into().get()?)) Ok(ClassItem::ImplDecl(pair.try_into().get()?))
} }
Rule::method => Ok(ClassItem::Method(pair.try_into().get()?)), Rule::function_decl => Ok(ClassItem::Method(pair.try_into().get()?)),
_ => AstError::bug_unimplemented(pair), _ => AstError::bug_unimplemented(pair),
} }
+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 => { ast_ensure!(pair, Rule::function_decl => {
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());
-6
View File
@@ -1,9 +1,3 @@
class Bro {
constructor() {}
void idk_man(i32 bro) {}
}
void main() { void main() {
test_package::hello(); test_package::hello();