Class items, struct items, enum items, mapping
This commit is contained in:
@@ -59,3 +59,9 @@ impl From<GenericDecl> for Generic {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Spanned<T> {
|
||||
pub fn get_comment(&self) -> String {
|
||||
format!("/* {}:{} */", self.line, self.column)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,29 +41,29 @@ pub enum TopLevelKind {
|
||||
visibility: Visibility,
|
||||
name: Identifier,
|
||||
generics: GenericsDecl,
|
||||
fields: Vec<EnumItem>,
|
||||
fields: Vec<Spanned<EnumItem>>,
|
||||
},
|
||||
StructDecl {
|
||||
visibility: Visibility,
|
||||
name: Identifier,
|
||||
generics: GenericsDecl,
|
||||
fields: Vec<FieldDecl>,
|
||||
fields: Vec<Spanned<FieldDecl>>,
|
||||
},
|
||||
FunctionDecl(FunctionDecl),
|
||||
ClassDecl {
|
||||
visibility: Visibility,
|
||||
name: Identifier,
|
||||
generics: GenericsDecl,
|
||||
fields: Vec<FieldDeclStmt>,
|
||||
constructor: ClassConstructor,
|
||||
fields: Vec<Spanned<FieldDeclStmt>>,
|
||||
constructor: Spanned<ClassConstructor>,
|
||||
items: Vec<ClassItem>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum ClassItem {
|
||||
Method(FunctionDecl),
|
||||
ImplDecl(ImplDecl),
|
||||
Method(Spanned<FunctionDecl>),
|
||||
ImplDecl(Spanned<ImplDecl>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Default)]
|
||||
|
||||
@@ -54,7 +54,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
||||
|
||||
fields: inner
|
||||
.next()
|
||||
.map(|pair| collect_recovered::<FieldDecl, FieldDecl>(pair.into_inner()))
|
||||
.map(|pair| collect_recovered(pair.into_inner()))
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default()),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user