@@ -835,85 +835,17 @@ def parse_type(type_str)
835835 return nil unless type_str
836836
837837 type_str = type_str . strip
838+ return nil if type_str . empty?
838839
839- # Use ParserCombinator::TypeParser for proper array shorthand support
840- # Falls back to legacy parsing if TypeParser is not available
840+ # Use ParserCombinator::TypeParser for all type parsing
841+ # Supports: simple types, generics, array shorthand, union, intersection, function types
841842 @type_parser ||= TRuby ::ParserCombinator ::TypeParser . new
842843 result = @type_parser . parse ( type_str )
843844 return result [ :type ] if result [ :success ]
844845
845- # Legacy parsing fallback
846-
847- # Union type
848- if type_str . include? ( "|" )
849- types = type_str . split ( "|" ) . map { |t | parse_type ( t . strip ) }
850- return UnionType . new ( types : types )
851- end
852-
853- # Intersection type
854- if type_str . include? ( "&" )
855- types = type_str . split ( "&" ) . map { |t | parse_type ( t . strip ) }
856- return IntersectionType . new ( types : types )
857- end
858-
859- # Nullable type
860- if type_str . end_with? ( "?" )
861- inner = parse_type ( type_str [ 0 ..-2 ] )
862- return NullableType . new ( inner_type : inner )
863- end
864-
865- # Generic type
866- if type_str . include? ( "<" ) && type_str . include? ( ">" )
867- match = type_str . match ( /^(\w +)<(.+)>$/ )
868- if match
869- base = match [ 1 ]
870- args = parse_generic_args ( match [ 2 ] )
871- return GenericType . new ( base : base , type_args : args )
872- end
873- end
874-
875- # Function type
876- if type_str . include? ( "->" )
877- match = type_str . match ( /^\( (.*)?\) \s *->\s *(.+)$/ )
878- if match
879- param_types = match [ 1 ] ? match [ 1 ] . split ( "," ) . map { |t | parse_type ( t . strip ) } : [ ]
880- return_type = parse_type ( match [ 2 ] )
881- return FunctionType . new ( param_types : param_types , return_type : return_type )
882- end
883- end
884-
885- # Simple type
846+ # Fallback for unparseable types - return as SimpleType
886847 SimpleType . new ( name : type_str )
887848 end
888-
889- def parse_generic_args ( args_str )
890- args = [ ]
891- current = ""
892- depth = 0
893-
894- args_str . each_char do |char |
895- case char
896- when "<"
897- depth += 1
898- current += char
899- when ">"
900- depth -= 1
901- current += char
902- when ","
903- if depth . zero?
904- args << parse_type ( current . strip )
905- current = ""
906- else
907- current += char
908- end
909- else
910- current += char
911- end
912- end
913-
914- args << parse_type ( current . strip ) unless current . empty?
915- args
916- end
917849 end
918850
919851 #==========================================================================
0 commit comments