Parse empty arguments list

master
Araozu 2023-10-01 17:37:19 -05:00
parent 03b5a1b6de
commit c4d13e76bc
4 changed files with 43 additions and 5 deletions

View File

@ -2,5 +2,14 @@
#[derive(Debug)] #[derive(Debug)]
pub struct FunctionCall { pub struct FunctionCall {
identifier: Box<String> pub identifier: Box<String>
} }
#[derive(Debug)]
pub struct ArgumentsList {
pub arguments: Vec<Box<Argument>>
}
#[derive(Debug)]
pub enum Argument {}

View File

@ -1,21 +1,42 @@
use crate::{lexic::token::Token, syntax::{ParseResult, ast::functions::FunctionCall}}; use crate::{lexic::token::{Token, TokenType}, syntax::{ParseResult, ast::functions::FunctionCall, utils::parse_token_type}, error_handling::SyntaxError};
pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<FunctionCall, ()> { pub fn try_parse<'a>(tokens: &'a Vec<Token>, pos: usize) -> ParseResult<FunctionCall, ()> {
let mut current_pos = pos;
// Parse identifier
let (identifier, next_pos) = match parse_token_type(tokens, current_pos, TokenType::Identifier)
{
ParseResult::Ok(id, next) => (id, next),
ParseResult::Err(err) => return ParseResult::Err(err),
ParseResult::Mismatch(_) => {
return ParseResult::Unmatched;
}
ParseResult::Unmatched => {
return ParseResult::Unmatched;
}
};
current_pos = next_pos;
// Parse arguments list
todo!() ParseResult::Unmatched
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::lexic::get_tokens;
use super::*; use super::*;
#[test] #[test]
fn should_parse_1() { fn should_not_parse_identifier_alone() {
let tokens = get_tokens(&String::from("function_name")).unwrap();
let fun_decl = try_parse(&tokens, 0);
let ParseResult::Unmatched = fun_decl else {
panic!("Expected an unmatched result: {:?}", fun_decl);
};
} }
} }

View File

@ -1 +1,2 @@
pub mod function_call; pub mod function_call;
pub mod arguments_list;

View File

@ -30,9 +30,16 @@ pub enum SyntaxResult {
#[derive(Debug)] #[derive(Debug)]
pub enum ParseResult<A, B> { pub enum ParseResult<A, B> {
/// The parsing was a success
Ok(A, usize), Ok(A, usize),
/// The parsing failed past a point of no return.
///
/// For example, when parsing a function declaration
/// the `fun` token is found, but then no identifier
Err(SyntaxError), Err(SyntaxError),
/// A construct different from the one expected was found
Mismatch(B), Mismatch(B),
/// No construct was found
Unmatched, Unmatched,
} }