AST - "Super expressions" (references to superclass methods)
This commit is contained in:
parent
896b0deef7
commit
2a8230ac80
4 changed files with 19 additions and 0 deletions
11
src/ast.rs
11
src/ast.rs
|
@ -134,6 +134,15 @@ pub struct VariableExpr {
|
|||
pub id: usize,
|
||||
}
|
||||
|
||||
/// A reference to a method in the superclass.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SuperExpr {
|
||||
/// The 'super' token itself
|
||||
pub keyword: Token,
|
||||
/// The identifier that contains the method name
|
||||
pub method: Token,
|
||||
}
|
||||
|
||||
/// An AST node that represents an expression.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ExprNode {
|
||||
|
@ -189,4 +198,6 @@ pub enum ExprNode {
|
|||
Get(GetExpr),
|
||||
/// A set expression.
|
||||
Set(SetExpr),
|
||||
/// A reference to a method in the superclass
|
||||
Super(SuperExpr),
|
||||
}
|
||||
|
|
|
@ -283,6 +283,11 @@ fn dump_expr_node(dumper: &mut Dumper, expr: &ExprNode) {
|
|||
dumper.current_line().push_str(" = ");
|
||||
dump_expr_node(dumper, &set_expr.value);
|
||||
}
|
||||
|
||||
ExprNode::Super(super_expr) => {
|
||||
dumper.current_line().push_str("super.");
|
||||
dumper.current_line().push_str(&super_expr.method.lexeme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -389,6 +389,7 @@ impl Interpretable for ExprNode {
|
|||
}
|
||||
ExprNode::Get(get_expr) => self.on_get_expression(es, get_expr),
|
||||
ExprNode::Set(set_expr) => self.on_set_expression(es, set_expr),
|
||||
ExprNode::Super(_) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -485,6 +485,8 @@ impl VarResolver for ExprNode {
|
|||
.instance
|
||||
.resolve(rs)
|
||||
.and_then(|_| set_expr.value.resolve(rs)),
|
||||
|
||||
ExprNode::Super(_) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue