[Syntax] Parse function call inside a binding
This commit is contained in:
parent
799cda1bf0
commit
c02e1c1f8e
@ -7,6 +7,7 @@ use crate::utils::Result3;
|
|||||||
|
|
||||||
pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<Binding, ()> {
|
pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<Binding, ()> {
|
||||||
let mut current_pos = pos;
|
let mut current_pos = pos;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* val/var keyword
|
* 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),
|
ParseResult::Ok(exp, next) => (exp, next),
|
||||||
_ => {
|
_ => {
|
||||||
return ParseResult::Err(SyntaxError {
|
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 {
|
let binding = if is_val {
|
||||||
Binding::Val(ValBinding {
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use super::{ast::Expression, ParseResult};
|
use super::{ast::Expression, functions::function_call, ParseResult};
|
||||||
use crate::lexic::token::{Token, TokenType};
|
use crate::lexic::token::{Token, TokenType};
|
||||||
|
|
||||||
/// An expression can be:
|
/// An expression can be:
|
||||||
@ -9,14 +9,12 @@ use crate::lexic::token::{Token, TokenType};
|
|||||||
/// - An identifier
|
/// - An identifier
|
||||||
/// - A function call
|
/// - A function call
|
||||||
pub fn try_parse(tokens: &Vec<Token>, pos: usize) -> ParseResult<Expression, ()> {
|
pub fn try_parse(tokens: &Vec<Token>, pos: usize) -> ParseResult<Expression, ()> {
|
||||||
/*
|
|
||||||
match function_call::try_parse(tokens, pos) {
|
match function_call::try_parse(tokens, pos) {
|
||||||
super::ParseResult::Ok(_, _) => todo!(),
|
super::ParseResult::Ok(function_call, next_pos) => {
|
||||||
super::ParseResult::Err(_) => todo!(),
|
return ParseResult::Ok::<_, ()>(Expression::FunctionCall(function_call), next_pos)
|
||||||
super::ParseResult::Mismatch(_) => todo!(),
|
}
|
||||||
super::ParseResult::Unmatched => todo!(),
|
_ => {}
|
||||||
}
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
match tokens.get(pos) {
|
match tokens.get(pos) {
|
||||||
Some(token) => match token.token_type {
|
Some(token) => match token.token_type {
|
||||||
|
Loading…
Reference in New Issue
Block a user