mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Implement support for "null" (and "nil") literals
--HG-- branch : dev
This commit is contained in:
@@ -170,6 +170,16 @@ namespace Orchard.Tests.Modules.Scripting {
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParserShouldUnderstandRelationalOperators7() {
|
||||
var tree = new Parser("null == null").Parse();
|
||||
CheckTree(tree, new object[] {
|
||||
"binop", TokenKind.EqualEqual,
|
||||
"const", null,
|
||||
"const", null,
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParserShouldUnderstandRelationalOperatorPrecedence() {
|
||||
var tree = new Parser("1 < 2 or 2 > 3 and !false").Parse();
|
||||
|
@@ -35,6 +35,8 @@ namespace Orchard.Tests.Modules.Scripting {
|
||||
public void LexerShouldProcessReservedWords() {
|
||||
TestReservedWord("true", true, TokenKind.True);
|
||||
TestReservedWord("false", false, TokenKind.False);
|
||||
TestReservedWord("nil", null, TokenKind.NullLiteral);
|
||||
TestReservedWord("null", null, TokenKind.NullLiteral);
|
||||
TestReservedWord("not", null, TokenKind.Not);
|
||||
TestReservedWord("and", null, TokenKind.And);
|
||||
TestReservedWord("or", null, TokenKind.Or);
|
||||
|
@@ -113,6 +113,7 @@ namespace Orchard.Scripting.Compiler {
|
||||
private AstNode ParsePrimaryExpression() {
|
||||
var token = _lexer.Token();
|
||||
switch (_lexer.Token().Kind) {
|
||||
case TokenKind.NullLiteral:
|
||||
case TokenKind.True:
|
||||
case TokenKind.False:
|
||||
case TokenKind.SingleQuotedStringLiteral:
|
||||
|
@@ -4,7 +4,7 @@ namespace Orchard.Scripting.Compiler {
|
||||
public abstract class PrimitiveType {
|
||||
public static PrimitiveType InstanceFor(object value) {
|
||||
if (value == null)
|
||||
return NilPrimitiveType.Instance;
|
||||
return NullPrimitiveType.Instance;
|
||||
if (value is bool)
|
||||
return BooleanPrimitiveType.Instance;
|
||||
if (value is int)
|
||||
@@ -82,11 +82,11 @@ namespace Orchard.Scripting.Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
public class NilPrimitiveType : PrimitiveType {
|
||||
private static NilPrimitiveType _instance;
|
||||
public class NullPrimitiveType : PrimitiveType {
|
||||
private static NullPrimitiveType _instance;
|
||||
|
||||
public static NilPrimitiveType Instance {
|
||||
get { return _instance ?? (_instance = new NilPrimitiveType()); }
|
||||
public static NullPrimitiveType Instance {
|
||||
get { return _instance ?? (_instance = new NullPrimitiveType()); }
|
||||
}
|
||||
|
||||
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) {
|
||||
|
@@ -25,6 +25,7 @@
|
||||
LessThan,
|
||||
LessThanEqual,
|
||||
GreaterThan,
|
||||
GreaterThanEqual
|
||||
GreaterThanEqual,
|
||||
NullLiteral
|
||||
}
|
||||
}
|
@@ -155,6 +155,9 @@ namespace Orchard.Scripting.Compiler {
|
||||
return CreateToken(TokenKind.And, null);
|
||||
case "not":
|
||||
return CreateToken(TokenKind.Not, null);
|
||||
case "null":
|
||||
case "nil":
|
||||
return CreateToken(TokenKind.NullLiteral, null);
|
||||
default:
|
||||
return CreateToken(TokenKind.Identifier, identifier);
|
||||
}
|
||||
|
Reference in New Issue
Block a user