Override(path) syntax

This commit is contained in:
2026-06-09 12:30:22 +02:00
parent 20762a01bd
commit 0347892056
4 changed files with 21 additions and 8 deletions
+4 -1
View File
@@ -91,10 +91,13 @@ pub struct ClassConstructor {
pub body: Block,
}
#[derive(Debug, Clone, Serialize)]
pub struct Override(pub Option<ExprPath>);
#[derive(Debug, Clone, Serialize)]
pub struct FunctionDecl {
pub visibility: Visibility,
pub is_override: bool,
pub is_override: Option<Override>,
pub name: Identifier,
pub generics: GenericsDecl,
pub params: ParamList,
+1 -1
View File
@@ -325,7 +325,7 @@ trait_decl = {
// FUNCTIONS
// ======================================================
override_kw = { "override" }
override_kw = { "override" ~ ("(" ~ expr_path ~ ")")? }
function_decl = {
visibility? ~ override_kw? ~ "fn" ~ identifier ~ generics_decl? ~ "(" ~ method_args ~ ")" ~ type_expr? ~ (block | semicolon)
+11 -1
View File
@@ -13,7 +13,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
ast_ensure!(pair, Rule::function_decl => {
let mut inner = pair.into_inner();
let visibility = Visibility::try_from(&mut inner);
let is_override: AstResult<bool> = Ok(listen_rule(&mut inner, Rule::override_kw));
let is_override = consume_rule(&mut inner, Rule::override_kw).map(Override::try_from).transpose();
let name = Identifier::try_from(inner.next().unwrap());
let generics = consume_rule(&mut inner, Rule::generics_decl)
@@ -77,3 +77,13 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
})
}
}
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Override {
type Error = AstError<'a, Self>;
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
ast_ensure!(pair, Rule::override_kw => {
ast_expr!(Override(pair.into_inner().next().map(ExprPath::try_from).transpose()))
})
}
}