diff --git a/src/ast.rs b/src/ast.rs index 8db7572..7f9d790 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -38,7 +38,7 @@ 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, + pub superclass: Option, /// The list of class members. pub members: Vec, } diff --git a/src/dumper.rs b/src/dumper.rs index 038cce8..0c15ef5 100644 --- a/src/dumper.rs +++ b/src/dumper.rs @@ -97,7 +97,9 @@ fn dump_statement(dumper: &mut Dumper, stmt: &StmtNode) { StmtNode::ClassDecl(decl) => { 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(&format!(" < {}", superclass.token.lexeme)); } dumper.current_line().push_str(" {"); if !decl.members.is_empty() { diff --git a/src/parser.rs b/src/parser.rs index eaf97fd..b9c8407 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -227,7 +227,10 @@ impl Parser { let name = self.consume_identifier("expected class name")?; let superclass = match self.expect(&[TokenType::Less]) { None => None, - Some(_) => Some(self.consume_identifier("expected superclass name")?), + Some(_) => Some(VariableExpr { + token: self.consume_identifier("expected superclass name")?.clone(), + id: self.make_id(), + }), }; self.consume(&TokenType::LeftBrace, "'{' expected")?;