virtual keyword parsing and ast

This commit is contained in:
2026-07-09 06:23:04 +02:00
parent 442d1e66a8
commit 0d2199ee3a
4 changed files with 12 additions and 5 deletions
+3 -3
View File
@@ -107,12 +107,13 @@ pub struct Override(pub Option<ExprPath>);
#[derive(Debug, Clone, Serialize)]
pub struct FunctionDecl {
pub visibility: Visibility,
pub is_override: Option<Override>,
pub is_virtual: bool,
pub return_type: Option<TypeExpr>,
pub name: Identifier,
pub generics: GenericsDecl,
pub self_param: Option<(bool, Option<Identifier>, bool)>,
pub params: ParamList,
pub return_type: Option<TypeExpr>,
pub is_override: Option<Override>,
pub body: Option<Block>,
}
@@ -129,7 +130,6 @@ pub struct FieldDecl {
pub visibility: Visibility,
pub type_: TypeExpr,
pub name: Identifier,
// pub tuple_names: Vec<Identifier>,
}
#[derive(Debug, Clone, Serialize)]
+4 -1
View File
@@ -36,6 +36,7 @@ keyword = {
| "override"
| "const"
| "type"
| "virtual"
}
identifier = @{
@@ -373,10 +374,12 @@ trait_decl = {
// FUNCTIONS
// ======================================================
virtual_kw = { "virtual" }
override_kw = { "override" ~ ("(" ~ expr_path ~ ")")? }
function_decl = {
visibility? ~ ("void" | type_expr) ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ override_kw? ~ (block | semicolon)
visibility? ~ virtual_kw? ~ ("void" | type_expr) ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ override_kw? ~ (block | semicolon)
}
// ======================================================
+4 -1
View File
@@ -14,6 +14,8 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
let mut inner = pair.into_inner();
let visibility = Visibility::try_from(&mut inner)?;
let is_virtual = listen_rule(&mut inner, Rule::virtual_kw);
let return_type = consume_rule(&mut inner, Rule::type_expr)
.map(TypeExpr::try_from)
.transpose()?;
@@ -45,12 +47,13 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
Ok(Self {
visibility: visibility,
is_override: is_override,
is_virtual: is_virtual,
return_type: return_type,
name: name,
generics: generics,
self_param: self_param,
params: params,
is_override: is_override,
body: body,
})
})