virtual keyword parsing and ast
This commit is contained in:
@@ -380,6 +380,7 @@ impl ClassProcessedData {
|
||||
column: constructor.column,
|
||||
item: FunctionDecl {
|
||||
visibility: constructor.item.visibility.clone(),
|
||||
is_virtual: false,
|
||||
is_override: None,
|
||||
name: Identifier(String::from("constructor")),
|
||||
generics: constructor.item.generics.clone(),
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user