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
+1
View File
@@ -380,6 +380,7 @@ impl ClassProcessedData {
column: constructor.column, column: constructor.column,
item: FunctionDecl { item: FunctionDecl {
visibility: constructor.item.visibility.clone(), visibility: constructor.item.visibility.clone(),
is_virtual: false,
is_override: None, is_override: None,
name: Identifier(String::from("constructor")), name: Identifier(String::from("constructor")),
generics: constructor.item.generics.clone(), generics: constructor.item.generics.clone(),
+3 -3
View File
@@ -107,12 +107,13 @@ pub struct Override(pub Option<ExprPath>);
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub struct FunctionDecl { pub struct FunctionDecl {
pub visibility: Visibility, pub visibility: Visibility,
pub is_override: Option<Override>, pub is_virtual: bool,
pub return_type: Option<TypeExpr>,
pub name: Identifier, pub name: Identifier,
pub generics: GenericsDecl, pub generics: GenericsDecl,
pub self_param: Option<(bool, Option<Identifier>, bool)>, pub self_param: Option<(bool, Option<Identifier>, bool)>,
pub params: ParamList, pub params: ParamList,
pub return_type: Option<TypeExpr>, pub is_override: Option<Override>,
pub body: Option<Block>, pub body: Option<Block>,
} }
@@ -129,7 +130,6 @@ pub struct FieldDecl {
pub visibility: Visibility, pub visibility: Visibility,
pub type_: TypeExpr, pub type_: TypeExpr,
pub name: Identifier, pub name: Identifier,
// pub tuple_names: Vec<Identifier>,
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
+4 -1
View File
@@ -36,6 +36,7 @@ keyword = {
| "override" | "override"
| "const" | "const"
| "type" | "type"
| "virtual"
} }
identifier = @{ identifier = @{
@@ -373,10 +374,12 @@ trait_decl = {
// FUNCTIONS // FUNCTIONS
// ====================================================== // ======================================================
virtual_kw = { "virtual" }
override_kw = { "override" ~ ("(" ~ expr_path ~ ")")? } override_kw = { "override" ~ ("(" ~ expr_path ~ ")")? }
function_decl = { 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 mut inner = pair.into_inner();
let visibility = Visibility::try_from(&mut 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) let return_type = consume_rule(&mut inner, Rule::type_expr)
.map(TypeExpr::try_from) .map(TypeExpr::try_from)
.transpose()?; .transpose()?;
@@ -45,12 +47,13 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
Ok(Self { Ok(Self {
visibility: visibility, visibility: visibility,
is_override: is_override, is_virtual: is_virtual,
return_type: return_type, return_type: return_type,
name: name, name: name,
generics: generics, generics: generics,
self_param: self_param, self_param: self_param,
params: params, params: params,
is_override: is_override,
body: body, body: body,
}) })
}) })