From 5ddfc132e71044ab9b18b13ec3ce61aa2e23b5b5 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 6 Mar 2018 00:38:33 -0800 Subject: [PATCH] Changed BNF grammar of call statements To allow calling lambdas --- src/schala_lang/parsing.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 36192ef..2ff9dc7 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -52,14 +52,15 @@ type_params := '<' type_name (, type_name)* '>' expression := precedence_expr type_anno+ precedence_expr := prefix_expr -prefix_expr := prefix_op primary +prefix_expr := prefix_op call_expr prefix_op := '+' | '-' | '!' | '~' +call_expr := primary ( '(' expr_list ')' )* primary := literal | paren_expr | if_expr | match_expr | for_expr | identifier_expr | curly_brace_expr curly_brace_expr := lambda_expr | anonymous_struct //TODO lambda_expr := '{' '|' (formal_param ',')* '|' (type_anno)* (statement)* '}' paren_expr := LParen paren_inner RParen paren_inner := (expression ',')* -identifier_expr := named_struct | call_expr | index_expr | IDENTIFIER +identifier_expr := named_struct | index_expr | IDENTIFIER literal := 'true' | 'false' | number_literal | STR_LITERAL named_struct := IDENTIFIER record_block @@ -77,7 +78,6 @@ pattern := identifier //TODO NOT DONE block := '{' (statement)* '}' -call_expr := IDENTIFIER '(' expr_list ')' //TODO maybe make this optional? or no, have a bare identifier meant to be used as method taken care of in eval index_expr := '[' (expression (',' (expression)* | ε) ']' expr_list := expression (',' expression)* | ε @@ -579,10 +579,20 @@ impl Parser { ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr)), None)) }, - _ => self.primary() + _ => self.call_expr() } }); + parse_method!(call_expr(&mut self) -> ParseResult { + let primary = self.primary()?; + Ok(if let LParen = self.peek() { + let arguments = delimited!(self, LParen, ')', expression, Comma, RParen, '('); + Expression(ExpressionType::Call { f: bx!(primary), arguments }, None) //TODO fix this none + } else { + primary + }) + }); + parse_method!(primary(&mut self) -> ParseResult { match self.peek() { LCurlyBrace => self.curly_brace_expr(), @@ -641,12 +651,6 @@ impl Parser { let fields = self.record_block()?; Expression(NamedStruct { name: identifier, fields }, None) }, - LParen => { - let arguments = self.call_expr()?; - //TODO make this be more general - let f = bx!(Expression(Value(identifier), None)); - Expression(Call { f, arguments }, None) - }, LSquareBracket => { let indexers = self.index_expr()?; Expression(Index { @@ -669,10 +673,6 @@ impl Parser { Ok((field_name, value)) }); - parse_method!(call_expr(&mut self) -> ParseResult> { - Ok(delimited!(self, LParen, ')', expression, Comma, RParen, '(')) - }); - parse_method!(index_expr(&mut self) -> ParseResult> { Ok(delimited!(self, LSquareBracket, '[', expression, Comma, RSquareBracket, ']')) });