[Syntax] Parse function call inside a binding

master
Araozu 2023-11-04 06:52:46 -05:00
parent 799cda1bf0
commit c02e1c1f8e
2 changed files with 11 additions and 10 deletions

View File

@ -7,6 +7,7 @@ use crate::utils::Result3;
pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<Binding, ()> {
let mut current_pos = pos;
/*
* val/var keyword
*/
@ -80,8 +81,9 @@ pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<Binding,
});
}
};
current_pos += 1;
let (expression, _next) = match expression::try_parse(tokens, current_pos + 1) {
let (expression, next_pos) = match expression::try_parse(tokens, current_pos) {
ParseResult::Ok(exp, next) => (exp, next),
_ => {
return ParseResult::Err(SyntaxError {
@ -91,6 +93,7 @@ pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<Binding,
});
}
};
current_pos = next_pos;
let binding = if is_val {
Binding::Val(ValBinding {
@ -106,7 +109,7 @@ pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<Binding,
})
};
ParseResult::Ok(binding, current_pos + 2)
ParseResult::Ok(binding, current_pos)
}
#[cfg(test)]

View File

@ -1,4 +1,4 @@
use super::{ast::Expression, ParseResult};
use super::{ast::Expression, functions::function_call, ParseResult};
use crate::lexic::token::{Token, TokenType};
/// An expression can be:
@ -9,14 +9,12 @@ use crate::lexic::token::{Token, TokenType};
/// - An identifier
/// - A function call
pub fn try_parse(tokens: &Vec<Token>, pos: usize) -> ParseResult<Expression, ()> {
/*
match function_call::try_parse(tokens, pos) {
super::ParseResult::Ok(_, _) => todo!(),
super::ParseResult::Err(_) => todo!(),
super::ParseResult::Mismatch(_) => todo!(),
super::ParseResult::Unmatched => todo!(),
super::ParseResult::Ok(function_call, next_pos) => {
return ParseResult::Ok::<_, ()>(Expression::FunctionCall(function_call), next_pos)
}
*/
_ => {}
};
match tokens.get(pos) {
Some(token) => match token.token_type {