@@ -12,13 +12,15 @@ private enum TokenType
1212 Identifier ,
1313 Extends ,
1414 Super ,
15- LeftBracket ,
16- RightBracket ,
15+ LeftSquareBracket ,
16+ RightSquareBracket ,
17+ LeftAngleBracket ,
18+ RightAngleBracket ,
1719 Comma ,
1820 QuestionMark
1921 }
2022
21- private static readonly Regex _tokenizePattern = new ( @"\w+|<|>|,|\?" , RegexOptions . Compiled ) ;
23+ private static readonly Regex _tokenizePattern = new ( @"\w+|\[|\]| <|>|,|\?" , RegexOptions . Compiled ) ;
2224
2325 private static ( string , TokenType ) [ ] _tokens ;
2426 private static ( string text , TokenType type ) _token ;
@@ -41,7 +43,7 @@ internal static string ParseTypeName(string typename, Func<string, string> trans
4143 _sb . Clear ( ) ;
4244
4345 if ( TypeName ( ) && _token . type is TokenType . EndOfString )
44- {
46+ {
4547 // Otherwise we have extra tokens.
4648 return _sb . ToString ( ) ;
4749 }
@@ -59,8 +61,10 @@ private static (string, TokenType)[] Tokenize(string typeName)
5961 string s = match . Value ;
6062 tokens [ i ] = s switch
6163 {
62- "<" => ( s , TokenType . LeftBracket ) ,
63- ">" => ( s , TokenType . RightBracket ) ,
64+ "[" => ( s , TokenType . LeftSquareBracket ) ,
65+ "]" => ( s , TokenType . RightSquareBracket ) ,
66+ "<" => ( s , TokenType . LeftAngleBracket ) ,
67+ ">" => ( s , TokenType . RightAngleBracket ) ,
6468 "," => ( s , TokenType . Comma ) ,
6569 "?" => ( s , TokenType . QuestionMark ) ,
6670 "extends" => ( s , TokenType . Extends ) ,
@@ -84,7 +88,7 @@ private static bool TypeName()
8488 {
8589 _sb . Append ( _translate ( _token . text ) ) ;
8690 NextToken ( ) ;
87- if ( _token . type is TokenType . LeftBracket )
91+ if ( _token . type is TokenType . LeftAngleBracket )
8892 {
8993 _sb . Append ( "<" ) ;
9094 NextToken ( ) ;
@@ -96,7 +100,7 @@ private static bool TypeName()
96100 NextToken ( ) ;
97101 if ( ! TypeArgument ( ) ) return false ;
98102 }
99- if ( _token . type is TokenType . RightBracket )
103+ if ( _token . type is TokenType . RightAngleBracket )
100104 {
101105 _sb . Append ( ">" ) ;
102106 NextToken ( ) ;
@@ -117,12 +121,17 @@ private static bool TypeArgument()
117121 // TypeArgument = [ "?" [ "extends" | "super" ] ] TypeName.
118122 if ( _token . type is TokenType . QuestionMark )
119123 {
120- // C# does not have this. Ignore. We could fix it by replacing IList<T> by IList for example.
124+ _sb . Append ( "TWildcardTodo" ) ;
121125 NextToken ( ) ;
126+
122127 if ( _token . type is TokenType . Extends or TokenType . Super )
123128 {
124129 NextToken ( ) ;
125130 }
131+ else if ( _token . type is TokenType . RightAngleBracket )
132+ {
133+ return true ;
134+ }
126135 }
127136 return TypeName ( ) ;
128137 }
0 commit comments