From f4f89b39b6b4103ed3eab3b3c4a14feae3cef647 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 6 Nov 2018 02:40:10 -0800 Subject: [PATCH] Handle nested function calls --- schala-lang/language/src/parsing.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index ad2c7a5..27b787b 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -586,13 +586,13 @@ impl Parser { #[recursive_descent_method] fn call_expr(&mut self) -> ParseResult { - let index = self.index_expr()?; - Ok(if let LParen = self.peek() { + let mut expr = self.index_expr()?; + while let LParen = self.peek() { let arguments = delimited!(self, LParen, expression, Comma, RParen); - Expression(ExpressionType::Call { f: bx!(index), arguments }, None) //TODO fix this none - } else { - index - }) + expr = Expression(ExpressionType::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect + } + + Ok(expr) } #[recursive_descent_method] @@ -1511,6 +1511,22 @@ fn a(x) { } } + #[test] + fn more_advanced_lambdas() { + parse_test! { + r#"fn wahoo() { let a = 10; \(x) { x + a } }; + wahoo()(3) "#, AST(vec![ + exst!(s r"fn wahoo() { let a = 10; \(x) { x + a } }"), + exst! { + Call { + f: bx!(ex!(Call { f: bx!(ex!(val!("wahoo"))), arguments: vec![] })), + arguments: vec![ex!(s "3")], + } + } + ]) + } + } + #[test] fn list_literals() { parse_test! {