AST - Added superclass field
This commit is contained in:
parent
680c4b249d
commit
164e7952bd
3 changed files with 12 additions and 2 deletions
|
@ -37,6 +37,8 @@ pub struct ClassMemberDecl {
|
|||
pub struct ClassDecl {
|
||||
/// The token that represents the name of the class.
|
||||
pub name: Token,
|
||||
/// The token indicating the name of the parent class, if any.
|
||||
pub superclass: Option<Token>,
|
||||
/// The list of class members.
|
||||
pub members: Vec<ClassMemberDecl>,
|
||||
}
|
||||
|
|
|
@ -95,7 +95,11 @@ fn dump_statement(dumper: &mut Dumper, stmt: &StmtNode) {
|
|||
}
|
||||
|
||||
StmtNode::ClassDecl(decl) => {
|
||||
dumper.add_line(format!("class {} {{", decl.name.lexeme));
|
||||
dumper.add_line(format!("class {}", decl.name.lexeme));
|
||||
if let Some(superclass) = &decl.superclass {
|
||||
dumper.current_line().push_str(&format!(" < {}", superclass.lexeme));
|
||||
}
|
||||
dumper.current_line().push_str(" {");
|
||||
if !decl.members.is_empty() {
|
||||
dumper.depth += 1;
|
||||
for member in decl.members.iter() {
|
||||
|
|
|
@ -257,7 +257,11 @@ impl Parser {
|
|||
}
|
||||
self.consume(&TokenType::RightBrace, "'}' expected")?;
|
||||
|
||||
Ok(StmtNode::ClassDecl(ClassDecl { name, members }))
|
||||
Ok(StmtNode::ClassDecl(ClassDecl {
|
||||
name,
|
||||
superclass: None,
|
||||
members,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Parse the following rule:
|
||||
|
|
Loading…
Reference in a new issue