fn parse_global_declaration(&mut self) -> Result<Option<Box<ASTnode>>, Box<dyn Error>> {
        match self.current_token_type()? {
            TokenType::STRUCT => {
                self.parse_struct_definition()?;
                Ok(None)
            }
            TokenType::ENUM => {
                self.parse_enum_definition()?;
                Ok(None)
            }
            _ => {
                // TODO: Handle composite types
                let (data_type, _) = self.parse_type()?;
                let ident = self.match_token(TokenType::IDENT)?;

                match &self.current_token {
                    Some(tok) => match tok.token_type {
                        TokenType::LPAREN => {
                            let tree = self.parse_func_declaration(ident, data_type)?;
                            Ok(Some(tree))
                        }
                        TokenType::SEMI | TokenType::COMMA => {
                            self.parse_global_scalar_declaration(data_type, ident)?;
                            Ok(None)
                        }
                        TokenType::LBRACKET => {
                            self.parse_global_array_declaration(data_type, ident)?;
                            Ok(None)
                        }
                        _ => Err(
                            format!("Syntax error, unexpected '{}' found", tok.token_type).into(),
                        ),
                    },
                    None => {
                        panic!(
                            "Unexpected error: No more tokens found in parse_global_declaration."
                        );
                    }
                }
            }
        }
    }
// Parse a global declaration and maybe return an ASTnode.
// Global var declarations do not yield ASTNodes
Parse a global declaration and maybe return an ASTnode.
Global var declarations do not yield ASTNodes
Parse a global declaration and maybe return an ASTnode . Global var declarations do not yield ASTNodes
fn parse_global_declaration(&mut self) -> Result<Option<Box<ASTnode>>, Box<dyn Error>> {
        match self.current_token_type()? {
            TokenType::STRUCT => {
                self.parse_struct_definition()?;
                Ok(None)
            }
            TokenType::ENUM => {
                self.parse_enum_definition()?;
                Ok(None)
            }
            _ => {
                // TODO: Handle composite types
                let (data_type, _) = self.parse_type()?;
                let ident = self.match_token(TokenType::IDENT)?;
                match &self.current_token {
                    Some(tok) => match tok.token_type {
                        TokenType::LPAREN => {
                            let tree = self.parse_func_declaration(ident, data_type)?;
                            Ok(Some(tree))
                        }
                        TokenType::SEMI | TokenType::COMMA => {
                            self.parse_global_scalar_declaration(data_type, ident)?;
                            Ok(None)
                        }
                        TokenType::LBRACKET => {
                            self.parse_global_array_declaration(data_type, ident)?;
                            Ok(None)
                        }
                        _ => Err(
                            format!("Syntax error, unexpected '{}' found", tok.token_type).into(),
                        ),
                    },
                    None => {
                        panic!(
                            "Unexpected error: No more tokens found in parse_global_declaration."
                        );
                    }
                }
            }
        }
    }
fn parse_global_declaration ( & mut self ) -> Result < Option < Box < ASTnode > > , Box < dyn Error > > { match self . current_token_type ( ) ? { TokenType :: STRUCT => { self . parse_struct_definition ( ) ? ; Ok ( None ) } TokenType :: ENUM => { self . parse_enum_definition ( ) ? ; Ok ( None ) } _ => { // TODO: Handle composite types let ( data_type , _ ) = self . parse_type ( ) ? ; let ident = self . match_token ( TokenType :: IDENT ) ? ; match & self . current_token { Some ( tok ) => match tok . token_type { TokenType :: LPAREN => { let tree = self . parse_func_declaration ( ident , data_type ) ? ; Ok ( Some ( tree ) ) } TokenType :: SEMI | TokenType :: COMMA => { self . parse_global_scalar_declaration ( data_type , ident ) ? ; Ok ( None ) } TokenType :: LBRACKET => { self . parse_global_array_declaration ( data_type , ident ) ? ; Ok ( None ) } _ => Err ( format ! ( " " tok token_type ) . into ( ) , ) , } , None => { panic ! ( " " ) ; } } } } }
Parse a global declaration and maybe return an ASTnode.
Parse a global declaration and maybe return an ASTnode .
&mut self