This commit is contained in:
Deukhoofd 2018-11-14 13:45:49 +01:00
parent d34e5c85c7
commit 3efa6a6359
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
6 changed files with 27 additions and 6 deletions

View File

@ -0,0 +1,12 @@
namespace Upsilon.BaseTypes
{
public class LuaNull : LuaType
{
public override Type Type => Type.Nil;
public override string ToString()
{
return "null";
}
}
}

View File

@ -110,11 +110,15 @@ namespace Upsilon.Binder
type = Type.Boolean;
outValue = new LuaBoolean(b);
break;
case null:
type = Type.Nil;
outValue = new LuaNull();
break;
default:
_diagnostics.LogUnknownType(e.Span);
break;
}
return new BoundLiteralExpression(outValue, type);
return new BoundLiteralExpression(outValue);
}
private BoundExpression BindParenthesizedExpression(ParenthesizedExpressionSyntax e)
@ -128,7 +132,7 @@ namespace Upsilon.Binder
if (!_scope.TryGetVariable(name, out var variable))
{
_diagnostics.LogUnknownVariable(e.Identifier.Span, name);
return new BoundLiteralExpression(null, Type.Nil);
return new BoundLiteralExpression(new LuaNull());
}
return new BoundVariableExpression(variable);

View File

@ -4,14 +4,13 @@ namespace Upsilon.Binder
{
public class BoundLiteralExpression : BoundExpression
{
public BoundLiteralExpression(LuaType value, Type type)
public BoundLiteralExpression(LuaType value)
{
Value = value;
Type = type;
}
public override BoundKind Kind => BoundKind.BoundLiteralExpression;
public override Type Type { get; }
public override Type Type => Value.Type;
public LuaType Value { get; }
}
}

View File

@ -181,6 +181,9 @@ namespace Upsilon.Parser
case SyntaxKind.Identifier:
var token = MatchToken(SyntaxKind.Identifier);
return new VariableExpressionSyntax((IdentifierToken) token);
case SyntaxKind.NilKeyword:
var nilToken = MatchToken(SyntaxKind.NilKeyword);
return new LiteralExpressionSyntax(nilToken, null);
default:
_diagnostics.LogBadCharacter(new TextSpan(_position, 1), SyntaxKind.Identifier);
NextToken();

View File

@ -28,6 +28,8 @@ namespace Upsilon.Parser
return SyntaxKind.ElseIfKeyword;
case "else":
return SyntaxKind.ElseKeyword;
case "nil":
return SyntaxKind.NilKeyword;
default:
return SyntaxKind.Identifier;
}

View File

@ -32,6 +32,7 @@ namespace Upsilon.Parser
ThenKeyword,
ElseIfKeyword,
ElseKeyword,
NilKeyword,
Identifier,
@ -52,6 +53,6 @@ namespace Upsilon.Parser
BlockStatement,
IfStatement,
ElseIfStatement,
ElseStatement
ElseStatement,
}
}