More Node-wrapping of Expression
This commit is contained in:
parent
846eeae04c
commit
821f321261
@ -120,7 +120,7 @@ pub enum ExpressionType {
|
|||||||
},
|
},
|
||||||
Call {
|
Call {
|
||||||
f: Box<Expression>,
|
f: Box<Expression>,
|
||||||
arguments: Vec<Expression>,
|
arguments: Vec<Node<Expression>>,
|
||||||
},
|
},
|
||||||
Index {
|
Index {
|
||||||
indexee: Box<Expression>,
|
indexee: Box<Expression>,
|
||||||
|
@ -607,6 +607,7 @@ impl Parser {
|
|||||||
let mut expr = self.index_expr()?;
|
let mut expr = self.index_expr()?;
|
||||||
while let LParen = self.peek() {
|
while let LParen = self.peek() {
|
||||||
let arguments = delimited!(self, LParen, expression, Comma, RParen);
|
let arguments = delimited!(self, LParen, expression, Comma, RParen);
|
||||||
|
let arguments = arguments.into_iter().map(|s| Node::new(s)).collect();
|
||||||
expr = Expression(ExpressionType::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect
|
expr = Expression(ExpressionType::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,7 +1297,7 @@ mod parse_tests {
|
|||||||
parse_test!("oi()", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] })]));
|
parse_test!("oi()", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] })]));
|
||||||
parse_test!("oi(a, 2 + 2)", AST(vec![exst!(Call
|
parse_test!("oi(a, 2 + 2)", AST(vec![exst!(Call
|
||||||
{ f: bx!(ex!(val!("oi"))),
|
{ f: bx!(ex!(val!("oi"))),
|
||||||
arguments: vec![ex!(val!("a")), ex!(binexp!("+", NatLiteral(2), NatLiteral(2)))]
|
arguments: vec![ex!(val!("a")).into(), ex!(binexp!("+", NatLiteral(2), NatLiteral(2))).into()]
|
||||||
})]));
|
})]));
|
||||||
parse_error!("a(b,,c)");
|
parse_error!("a(b,,c)");
|
||||||
|
|
||||||
@ -1543,7 +1544,7 @@ fn a(x) {
|
|||||||
type_anno: None,
|
type_anno: None,
|
||||||
body: vec![exst!(s "y")] }
|
body: vec![exst!(s "y")] }
|
||||||
)),
|
)),
|
||||||
arguments: vec![ex!(NatLiteral(1))] })]));
|
arguments: vec![ex!(NatLiteral(1)).into()] })]));
|
||||||
|
|
||||||
parse_test_wrap_ast! {
|
parse_test_wrap_ast! {
|
||||||
r#"\(x: Int): String { "q" }"#,
|
r#"\(x: Int): String { "q" }"#,
|
||||||
@ -1585,7 +1586,7 @@ fn a(x) {
|
|||||||
exst! {
|
exst! {
|
||||||
Call {
|
Call {
|
||||||
f: bx!(ex!(Call { f: bx!(ex!(val!("wahoo"))), arguments: vec![] })),
|
f: bx!(ex!(Call { f: bx!(ex!(val!("wahoo"))), arguments: vec![] })),
|
||||||
arguments: vec![ex!(s "3")],
|
arguments: vec![ex!(s "3").into()],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
@ -140,7 +140,7 @@ impl Expression {
|
|||||||
},
|
},
|
||||||
Call { f, arguments } => Expr::Call {
|
Call { f, arguments } => Expr::Call {
|
||||||
f: Box::new(f.reduce(symbol_table)),
|
f: Box::new(f.reduce(symbol_table)),
|
||||||
args: arguments.iter().map(|arg| arg.reduce(symbol_table)).collect(),
|
args: arguments.iter().map(|arg| arg.node().reduce(symbol_table)).collect(),
|
||||||
},
|
},
|
||||||
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()),
|
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()),
|
||||||
IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table),
|
IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table),
|
||||||
|
@ -166,7 +166,7 @@ impl<'a> TypeContext<'a> {
|
|||||||
IfExpression { discriminator, body } => self.infer_if_expr(discriminator, body)?,
|
IfExpression { discriminator, body } => self.infer_if_expr(discriminator, body)?,
|
||||||
Call { f, arguments } => {
|
Call { f, arguments } => {
|
||||||
let tf = self.infer_expr(f)?; //has to be an Arrow Type
|
let tf = self.infer_expr(f)?; //has to be an Arrow Type
|
||||||
let targ = self.infer_expr(&arguments[0])?; // TODO make this work with functions with more than one arg
|
let targ = self.infer_expr(&arguments[0].node())?; // TODO make this work with functions with more than one arg
|
||||||
match tf {
|
match tf {
|
||||||
Type::Arrow(t1, t2) => {
|
Type::Arrow(t1, t2) => {
|
||||||
self.unify(&t1.to_tvar(), &targ.to_tvar())?;
|
self.unify(&t1.to_tvar(), &targ.to_tvar())?;
|
||||||
|
Loading…
Reference in New Issue
Block a user