Override(path) syntax
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user