diff --git a/src/syntax/ast/functions.rs b/src/syntax/ast/functions.rs index 0cda11b..0a731d1 100644 --- a/src/syntax/ast/functions.rs +++ b/src/syntax/ast/functions.rs @@ -2,5 +2,14 @@ #[derive(Debug)] pub struct FunctionCall { - identifier: Box + pub identifier: Box } + + +#[derive(Debug)] +pub struct ArgumentsList { + pub arguments: Vec> +} + +#[derive(Debug)] +pub enum Argument {} diff --git a/src/syntax/functions/function_call.rs b/src/syntax/functions/function_call.rs index 1ea864d..1e841c2 100644 --- a/src/syntax/functions/function_call.rs +++ b/src/syntax/functions/function_call.rs @@ -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, pos: usize) -> ParseResult { + 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)] mod tests { + use crate::lexic::get_tokens; use super::*; #[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); + }; } } diff --git a/src/syntax/functions/mod.rs b/src/syntax/functions/mod.rs index 7799ff1..1b867ec 100644 --- a/src/syntax/functions/mod.rs +++ b/src/syntax/functions/mod.rs @@ -1 +1,2 @@ -pub mod function_call; \ No newline at end of file +pub mod function_call; +pub mod arguments_list; diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 7676466..0807513 100755 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -30,9 +30,16 @@ pub enum SyntaxResult { #[derive(Debug)] pub enum ParseResult { + /// The parsing was a success 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), + /// A construct different from the one expected was found Mismatch(B), + /// No construct was found Unmatched, }