Changed BNF grammar of call statements
To allow calling lambdas
This commit is contained in:
parent
08ca48b2ba
commit
e3671a579d
@ -52,14 +52,15 @@ type_params := '<' type_name (, type_name)* '>'
|
|||||||
|
|
||||||
expression := precedence_expr type_anno+
|
expression := precedence_expr type_anno+
|
||||||
precedence_expr := prefix_expr
|
precedence_expr := prefix_expr
|
||||||
prefix_expr := prefix_op primary
|
prefix_expr := prefix_op call_expr
|
||||||
prefix_op := '+' | '-' | '!' | '~'
|
prefix_op := '+' | '-' | '!' | '~'
|
||||||
|
call_expr := primary ( '(' expr_list ')' )*
|
||||||
primary := literal | paren_expr | if_expr | match_expr | for_expr | identifier_expr | curly_brace_expr
|
primary := literal | paren_expr | if_expr | match_expr | for_expr | identifier_expr | curly_brace_expr
|
||||||
curly_brace_expr := lambda_expr | anonymous_struct //TODO
|
curly_brace_expr := lambda_expr | anonymous_struct //TODO
|
||||||
lambda_expr := '{' '|' (formal_param ',')* '|' (type_anno)* (statement)* '}'
|
lambda_expr := '{' '|' (formal_param ',')* '|' (type_anno)* (statement)* '}'
|
||||||
paren_expr := LParen paren_inner RParen
|
paren_expr := LParen paren_inner RParen
|
||||||
paren_inner := (expression ',')*
|
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
|
literal := 'true' | 'false' | number_literal | STR_LITERAL
|
||||||
|
|
||||||
named_struct := IDENTIFIER record_block
|
named_struct := IDENTIFIER record_block
|
||||||
@ -77,7 +78,6 @@ pattern := identifier //TODO NOT DONE
|
|||||||
|
|
||||||
block := '{' (statement)* '}'
|
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)* | ε) ']'
|
index_expr := '[' (expression (',' (expression)* | ε) ']'
|
||||||
expr_list := expression (',' expression)* | ε
|
expr_list := expression (',' expression)* | ε
|
||||||
|
|
||||||
@ -579,10 +579,20 @@ impl Parser {
|
|||||||
ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr)),
|
ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr)),
|
||||||
None))
|
None))
|
||||||
},
|
},
|
||||||
_ => self.primary()
|
_ => self.call_expr()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
parse_method!(call_expr(&mut self) -> ParseResult<Expression> {
|
||||||
|
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<Expression> {
|
parse_method!(primary(&mut self) -> ParseResult<Expression> {
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
LCurlyBrace => self.curly_brace_expr(),
|
LCurlyBrace => self.curly_brace_expr(),
|
||||||
@ -641,12 +651,6 @@ impl Parser {
|
|||||||
let fields = self.record_block()?;
|
let fields = self.record_block()?;
|
||||||
Expression(NamedStruct { name: identifier, fields }, None)
|
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 => {
|
LSquareBracket => {
|
||||||
let indexers = self.index_expr()?;
|
let indexers = self.index_expr()?;
|
||||||
Expression(Index {
|
Expression(Index {
|
||||||
@ -669,10 +673,6 @@ impl Parser {
|
|||||||
Ok((field_name, value))
|
Ok((field_name, value))
|
||||||
});
|
});
|
||||||
|
|
||||||
parse_method!(call_expr(&mut self) -> ParseResult<Vec<Expression>> {
|
|
||||||
Ok(delimited!(self, LParen, ')', expression, Comma, RParen, '('))
|
|
||||||
});
|
|
||||||
|
|
||||||
parse_method!(index_expr(&mut self) -> ParseResult<Vec<Expression>> {
|
parse_method!(index_expr(&mut self) -> ParseResult<Vec<Expression>> {
|
||||||
Ok(delimited!(self, LSquareBracket, '[', expression, Comma, RSquareBracket, ']'))
|
Ok(delimited!(self, LSquareBracket, '[', expression, Comma, RSquareBracket, ']'))
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user