Support generic types

This commit is contained in:
Yoshi Askharoun
2025-01-27 23:28:44 -06:00
parent 7ad4ee68e0
commit 3e9e1fef0f
2 changed files with 32 additions and 2 deletions
+27
View File
@@ -72,6 +72,33 @@ public static partial class Lexer
typeName = typePrefixResult.Value;
}
// Capture generic types
var genericTypeStartPosition = input.Position;
var genericTypeMarkerResult = Parse.Char('`')(input);
input = genericTypeMarkerResult.Remainder;
if (genericTypeMarkerResult.WasSuccessful)
{
var genericTypeParameterCountResult = Parse.Number(input);
input = genericTypeParameterCountResult.Remainder;
if (!genericTypeParameterCountResult.WasSuccessful)
return Result.Failure<QualifiedTypeName>(input, "Invalid generic type", ["Expected a type parameter count"]);
var genericTypeParametersOpenBrace = Parse.Char('[')(input);
input = genericTypeParametersOpenBrace.Remainder;
if (genericTypeParametersOpenBrace.WasSuccessful)
{
var genericTypeParametersResult = Parse.AnyChar.Except(Parse.Chars('.', ']')).AtLeastOnce().Text()
.DelimitedBy(Parse.Char('.'))
.Until(Parse.Char(']'))(input);
input = genericTypeParametersResult.Remainder;
if (!genericTypeParametersResult.WasSuccessful)
return Result.Failure<QualifiedTypeName>(input, "Invalid generic type", ["Expected type parameters"]);
var genericTypeEndPosition = input.Position;
typeName += input.Source[genericTypeStartPosition..genericTypeEndPosition];
}
}
QualifiedTypeName qualifiedName = new(typePrefix, typeName)
{
Line = line,
+5 -2
View File
@@ -27,17 +27,20 @@ public class Assembly
.export Default 0 UI
.export Alt 0 UI
.import-ns assembly://UIX/Microsoft.Iris as iris
.import-type UI
.import-type Dictionary
.import-ns assembly://UIX/Microsoft.Iris as iris
.import-type iris:Command
.import-type String
.import-type ViewItem
.import-type Text
.import-type Color
.import-type Font
.import-type generic:List`1[System.String]
.import-mbrs UI{Locals, Content}
.import-mbrs Text{Color, Content, Font}
.import-mbrs SingletonModelItem`1[ZuneUI.TransportControls]{Instance}
.import-mthd List`1[System.Int32].Add(Int32)
.constant const0 = Color.str(255, 255, 0, 0)
.constant const1 = String.str(Howdy from Microsoft.Iris!)
@@ -79,7 +82,7 @@ Alt_locl:
_output.WriteLine(ast.ToString());
Assert.NotNull(ast);
Assert.Equal(22, ast.Directives.Count());
Assert.Equal(25, ast.Directives.Count());
Assert.Equal(24, ast.Code.Count());
}