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,
|
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.
|
/// An AST node that represents an expression.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ExprNode {
|
pub enum ExprNode {
|
||||||
|
@ -189,4 +198,6 @@ pub enum ExprNode {
|
||||||
Get(GetExpr),
|
Get(GetExpr),
|
||||||
/// A set expression.
|
/// A set expression.
|
||||||
Set(SetExpr),
|
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(" = ");
|
dumper.current_line().push_str(" = ");
|
||||||
dump_expr_node(dumper, &set_expr.value);
|
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::Get(get_expr) => self.on_get_expression(es, get_expr),
|
||||||
ExprNode::Set(set_expr) => self.on_set_expression(es, set_expr),
|
ExprNode::Set(set_expr) => self.on_set_expression(es, set_expr),
|
||||||
|
ExprNode::Super(_) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,6 +485,8 @@ impl VarResolver for ExprNode {
|
||||||
.instance
|
.instance
|
||||||
.resolve(rs)
|
.resolve(rs)
|
||||||
.and_then(|_| set_expr.value.resolve(rs)),
|
.and_then(|_| set_expr.value.resolve(rs)),
|
||||||
|
|
||||||
|
ExprNode::Super(_) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue