Adds Nil
This commit is contained in:
parent
d34e5c85c7
commit
3efa6a6359
|
@ -0,0 +1,12 @@
|
|||
namespace Upsilon.BaseTypes
|
||||
{
|
||||
public class LuaNull : LuaType
|
||||
{
|
||||
public override Type Type => Type.Nil;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace Upsilon.Parser
|
|||
return SyntaxKind.ElseIfKeyword;
|
||||
case "else":
|
||||
return SyntaxKind.ElseKeyword;
|
||||
case "nil":
|
||||
return SyntaxKind.NilKeyword;
|
||||
default:
|
||||
return SyntaxKind.Identifier;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace Upsilon.Parser
|
|||
ThenKeyword,
|
||||
ElseIfKeyword,
|
||||
ElseKeyword,
|
||||
NilKeyword,
|
||||
|
||||
Identifier,
|
||||
|
||||
|
@ -52,6 +53,6 @@ namespace Upsilon.Parser
|
|||
BlockStatement,
|
||||
IfStatement,
|
||||
ElseIfStatement,
|
||||
ElseStatement
|
||||
ElseStatement,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue