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;
|
type = Type.Boolean;
|
||||||
outValue = new LuaBoolean(b);
|
outValue = new LuaBoolean(b);
|
||||||
break;
|
break;
|
||||||
|
case null:
|
||||||
|
type = Type.Nil;
|
||||||
|
outValue = new LuaNull();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
_diagnostics.LogUnknownType(e.Span);
|
_diagnostics.LogUnknownType(e.Span);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return new BoundLiteralExpression(outValue, type);
|
return new BoundLiteralExpression(outValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BoundExpression BindParenthesizedExpression(ParenthesizedExpressionSyntax e)
|
private BoundExpression BindParenthesizedExpression(ParenthesizedExpressionSyntax e)
|
||||||
|
@ -128,7 +132,7 @@ namespace Upsilon.Binder
|
||||||
if (!_scope.TryGetVariable(name, out var variable))
|
if (!_scope.TryGetVariable(name, out var variable))
|
||||||
{
|
{
|
||||||
_diagnostics.LogUnknownVariable(e.Identifier.Span, name);
|
_diagnostics.LogUnknownVariable(e.Identifier.Span, name);
|
||||||
return new BoundLiteralExpression(null, Type.Nil);
|
return new BoundLiteralExpression(new LuaNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BoundVariableExpression(variable);
|
return new BoundVariableExpression(variable);
|
||||||
|
|
|
@ -4,14 +4,13 @@ namespace Upsilon.Binder
|
||||||
{
|
{
|
||||||
public class BoundLiteralExpression : BoundExpression
|
public class BoundLiteralExpression : BoundExpression
|
||||||
{
|
{
|
||||||
public BoundLiteralExpression(LuaType value, Type type)
|
public BoundLiteralExpression(LuaType value)
|
||||||
{
|
{
|
||||||
Value = value;
|
Value = value;
|
||||||
Type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override BoundKind Kind => BoundKind.BoundLiteralExpression;
|
public override BoundKind Kind => BoundKind.BoundLiteralExpression;
|
||||||
public override Type Type { get; }
|
public override Type Type => Value.Type;
|
||||||
public LuaType Value { get; }
|
public LuaType Value { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -181,6 +181,9 @@ namespace Upsilon.Parser
|
||||||
case SyntaxKind.Identifier:
|
case SyntaxKind.Identifier:
|
||||||
var token = MatchToken(SyntaxKind.Identifier);
|
var token = MatchToken(SyntaxKind.Identifier);
|
||||||
return new VariableExpressionSyntax((IdentifierToken) token);
|
return new VariableExpressionSyntax((IdentifierToken) token);
|
||||||
|
case SyntaxKind.NilKeyword:
|
||||||
|
var nilToken = MatchToken(SyntaxKind.NilKeyword);
|
||||||
|
return new LiteralExpressionSyntax(nilToken, null);
|
||||||
default:
|
default:
|
||||||
_diagnostics.LogBadCharacter(new TextSpan(_position, 1), SyntaxKind.Identifier);
|
_diagnostics.LogBadCharacter(new TextSpan(_position, 1), SyntaxKind.Identifier);
|
||||||
NextToken();
|
NextToken();
|
||||||
|
|
|
@ -28,6 +28,8 @@ namespace Upsilon.Parser
|
||||||
return SyntaxKind.ElseIfKeyword;
|
return SyntaxKind.ElseIfKeyword;
|
||||||
case "else":
|
case "else":
|
||||||
return SyntaxKind.ElseKeyword;
|
return SyntaxKind.ElseKeyword;
|
||||||
|
case "nil":
|
||||||
|
return SyntaxKind.NilKeyword;
|
||||||
default:
|
default:
|
||||||
return SyntaxKind.Identifier;
|
return SyntaxKind.Identifier;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace Upsilon.Parser
|
||||||
ThenKeyword,
|
ThenKeyword,
|
||||||
ElseIfKeyword,
|
ElseIfKeyword,
|
||||||
ElseKeyword,
|
ElseKeyword,
|
||||||
|
NilKeyword,
|
||||||
|
|
||||||
Identifier,
|
Identifier,
|
||||||
|
|
||||||
|
@ -52,6 +53,6 @@ namespace Upsilon.Parser
|
||||||
BlockStatement,
|
BlockStatement,
|
||||||
IfStatement,
|
IfStatement,
|
||||||
ElseIfStatement,
|
ElseIfStatement,
|
||||||
ElseStatement
|
ElseStatement,
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue