Better support for userdata bound types

This commit is contained in:
Deukhoofd 2018-11-29 20:45:59 +01:00
parent 4fa0ad9f70
commit a4ad57e3f7
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 15 additions and 4 deletions

View File

@ -283,6 +283,13 @@ namespace Upsilon.Binder
{
return ((TableVariableSymbol)indexerVariable).Variables[fullStopIndexExpression.Index];
}
if (indexerVariable.Type == Type.UserData)
{
var bDefProperty = ((UserDataBoundTypeDefinition) ((FunctionParameterSymbol) indexerVariable)
.BoundTypeDefinition).Properties[fullStopIndexExpression.Index];
var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.ActualType);
return new FunctionParameterSymbol(fullStopIndexExpression.Index, boundDef);
}
}
return null;
}

View File

@ -495,13 +495,17 @@ namespace Upsilon.Parser
private ExpressionSyntax ParseFullStopIndexExpression(ExpressionSyntax expression)
{
var fullStop = MatchToken(SyntaxKind.FullStop);
var index = MatchToken(SyntaxKind.Identifier);
if (index is IdentifierToken identifier)
if (Current.Kind == SyntaxKind.Identifier)
{
return new FullStopIndexExpressionSyntax(expression, fullStop, identifier);
var index = NextToken();
return new FullStopIndexExpressionSyntax(expression, fullStop, (IdentifierToken) index);
}
_diagnostics.LogBadCharacter(expression.Span, SyntaxKind.Identifier);
return new BadExpressionSyntax();
// We'll still want to return a index expression, but we just express that the identifier is empty.
// This is helpful for tools, etc
return new FullStopIndexExpressionSyntax(expression, fullStop,
new IdentifierToken(string.Empty, fullStop.Span.End));
}
private ExpressionSyntax ParseParenthesizedExpression()