Parsing call expressions
This commit is contained in:
parent
dfc89e5060
commit
5dd1cd79ff
@ -548,8 +548,11 @@ impl Parser {
|
|||||||
let identifier = self.identifier()?;
|
let identifier = self.identifier()?;
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
LParen => {
|
LParen => {
|
||||||
let call = self.call_expr()?;
|
let call_params = self.call_expr()?;
|
||||||
unimplemented!()
|
Ok(Expression::Call {
|
||||||
|
name: identifier,
|
||||||
|
params: call_params,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
LSquareBracket => {
|
LSquareBracket => {
|
||||||
let indexers = self.index_expr()?;
|
let indexers = self.index_expr()?;
|
||||||
@ -562,8 +565,21 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_expr(&mut self) -> ParseResult<Expression> {
|
fn call_expr(&mut self) -> ParseResult<Vec<Expression>> {
|
||||||
unimplemented!()
|
let mut exprs = Vec::new();
|
||||||
|
expect!(self, LParen, "Expected '('");
|
||||||
|
loop {
|
||||||
|
if let RParen = self.peek() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exprs.push(self.expression()?);
|
||||||
|
match self.peek() {
|
||||||
|
Comma => { self.next(); },
|
||||||
|
_ => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect!(self, RParen, "Expected ')'");
|
||||||
|
Ok(exprs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index_expr(&mut self) -> ParseResult<Vec<Expression>> {
|
fn index_expr(&mut self) -> ParseResult<Vec<Expression>> {
|
||||||
@ -745,6 +761,11 @@ mod parse_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parsing_functions() {
|
fn parsing_functions() {
|
||||||
parse_test!("fn oi()", AST(vec![Declaration(FuncDecl { name: rc!(oi), params: vec![] })]));
|
parse_test!("fn oi()", AST(vec![Declaration(FuncDecl { name: rc!(oi), params: vec![] })]));
|
||||||
|
parse_test!("oi()", AST(vec![Expression(Call { name: rc!(oi), params: vec![] })]));
|
||||||
|
parse_test!("oi(a, 2 + 2)", AST(vec![Expression(Call
|
||||||
|
{ name: rc!(oi),
|
||||||
|
params: vec![var!("a"), binexp!(op!("+"), IntLiteral(2), IntLiteral(2))]
|
||||||
|
})]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user