@@ -501,14 +501,55 @@ impl<'a> StatementParser for ParserBase<'a> {
501501 }
502502
503503 fn parse_type ( & mut self ) -> Result < Type , String > {
504- // 首先检查是否是指针类型
504+ // 首先检查是否是指针类型或数组类型
505505 if let Some ( token) = self . peek ( ) {
506506 if token == "?" && self . peek_ahead ( 1 ) == Some ( & "*" . to_string ( ) ) {
507507 // 可选指针类型 ?*Type
508508 return self . parse_pointer_type ( ) ;
509509 } else if token == "*" {
510510 // 普通指针类型 *Type
511511 return self . parse_pointer_type ( ) ;
512+ } else if token == "[" {
513+ // 数组类型或函数指针数组类型: []int 或 []*fn(int, int) : int
514+ self . consume ( ) ; // 消费 "["
515+ self . expect ( "]" ) ?; // 期望 "]"
516+
517+ if self . peek ( ) == Some ( & "*" . to_string ( ) ) {
518+ self . consume ( ) ; // 消费 "*"
519+
520+ if self . peek ( ) == Some ( & "fn" . to_string ( ) ) {
521+ // 函数指针数组类型: []*fn(int, int) : int
522+ self . consume ( ) ; // 消费 "fn"
523+ self . expect ( "(" ) ?;
524+
525+ let mut param_types = Vec :: new ( ) ;
526+ if self . peek ( ) != Some ( & ")" . to_string ( ) ) {
527+ loop {
528+ param_types. push ( self . parse_type ( ) ?) ;
529+ if self . peek ( ) != Some ( & "," . to_string ( ) ) {
530+ break ;
531+ }
532+ self . consume ( ) ; // 消费 ","
533+ }
534+ }
535+
536+ self . expect ( ")" ) ?;
537+ self . expect ( ":" ) ?;
538+ let return_type = Box :: new ( self . parse_type ( ) ?) ;
539+
540+ let func_ptr_type = Type :: FunctionPointer ( param_types, return_type) ;
541+ return Ok ( Type :: Array ( Box :: new ( func_ptr_type) ) ) ;
542+ } else {
543+ // 指针数组类型: []*int
544+ let target_type = Box :: new ( self . parse_type ( ) ?) ;
545+ let ptr_type = Type :: Pointer ( target_type) ;
546+ return Ok ( Type :: Array ( Box :: new ( ptr_type) ) ) ;
547+ }
548+ } else {
549+ // 普通数组类型: []int
550+ let element_type = Box :: new ( self . parse_type ( ) ?) ;
551+ return Ok ( Type :: Array ( element_type) ) ;
552+ }
512553 }
513554 }
514555
0 commit comments