Implement Access AST node
For name.value lookups
This commit is contained in:
parent
1c6545fb74
commit
f0e4b50c99
@ -196,6 +196,7 @@ pub enum ExpressionKind {
|
||||
WhileExpression { condition: Option<Box<Expression>>, body: Block },
|
||||
ForExpression { enumerators: Vec<Enumerator>, body: Box<ForBody> },
|
||||
Lambda { params: Vec<FormalParam>, type_anno: Option<TypeIdentifier>, body: Block },
|
||||
Access { name: Rc<String>, expr: Box<Expression> },
|
||||
ListLiteral(Vec<Expression>),
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,9 @@ pub fn walk_expression<V: ASTVisitor>(v: &mut V, expr: &Expression) {
|
||||
Lambda { params: _, type_anno: _, body } => {
|
||||
walk_block(v, body);
|
||||
}
|
||||
Access { name: _, expr } => {
|
||||
walk_expression(v, expr);
|
||||
}
|
||||
ListLiteral(exprs) =>
|
||||
for expr in exprs {
|
||||
walk_expression(v, expr);
|
||||
|
@ -120,6 +120,7 @@ fn render_expression(expr: &Expression, indent: usize, buf: &mut String) {
|
||||
newline(buf);
|
||||
do_indent(indent, buf);
|
||||
}
|
||||
Access { .. } => buf.push_str("<access-expr>"),
|
||||
ListLiteral(..) => buf.push_str("<list-literal>"),
|
||||
}
|
||||
buf.push(')');
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -203,11 +203,36 @@ fn operators() {
|
||||
|
||||
#[test]
|
||||
fn accessors() {
|
||||
/*
|
||||
assert_expr!("a.b");
|
||||
assert_expr!("a.b.c.d()");
|
||||
assert_expr!("a.b().c.d()");
|
||||
*/
|
||||
use ExpressionKind::*;
|
||||
|
||||
assert_expr!("a.b", expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) }));
|
||||
assert_expr!(
|
||||
"a.b.c",
|
||||
expr(Access {
|
||||
name: rc("c"),
|
||||
expr: bx(expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) }))
|
||||
})
|
||||
);
|
||||
assert_expr!(
|
||||
"a.b.c(3)",
|
||||
expr(Call {
|
||||
f: bx(expr(Access {
|
||||
name: rc("c"),
|
||||
expr: bx(expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) }))
|
||||
})),
|
||||
arguments: vec![InvocationArgument::Positional(expr(NatLiteral(3)))],
|
||||
})
|
||||
);
|
||||
assert_expr!(
|
||||
"a.b().c",
|
||||
expr(Access {
|
||||
name: rc("c"),
|
||||
expr: bx(expr(Call {
|
||||
f: bx(expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) })),
|
||||
arguments: vec![]
|
||||
}))
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -179,6 +179,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
||||
WhileExpression { .. } => Expression::ReductionError("While expr not implemented".to_string()),
|
||||
ForExpression { .. } => Expression::ReductionError("For expr not implemented".to_string()),
|
||||
ListLiteral { .. } => Expression::ReductionError("ListLiteral expr not implemented".to_string()),
|
||||
Access { .. } => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user