public static JToken Translate(SyntaxValue v) { if (v.OnLiteral) { var l = v.Literal; if (l.OnNullValue) { return(new JValue()); } else if (l.OnBooleanValue) { return(new JValue(l.BooleanValue)); } else if (l.OnNumberValue) { return(new JValue(l.NumberValue)); } else if (l.OnStringValue) { return(new JValue(l.StringValue)); } else { throw new InvalidOperationException(); } } else if (v.OnObject) { return(new JObject(TranslateMembers(v.Object.Members))); } else if (v.OnArray) { return(new JArray(TranslateElements(v.Array.Elements))); } else { throw new InvalidOperationException(); } }
private static bool SyntaxEquals(SyntaxValue Left, SyntaxValue Right) { if (Left._Tag != Right._Tag) { return(false); } if (Left.OnLiteral) { return(SyntaxEquals(Left.Literal, Right.Literal)); } else if (Left.OnObject) { return(SyntaxEquals(Left.Object, Right.Object)); } else if (Left.OnArray) { return(SyntaxEquals(Left.Array, Right.Array)); } else { throw new InvalidOperationException(); } }
public ExternalNameOrSymbolReference(SyntaxValue<string> nameLiteral, SymbolType[] candidateTypes) : base(nameLiteral, candidateTypes) { Role = SymbolRole.ExternalNameOrSymbolReference; }
public ExternalName(SyntaxValue<string> nameLiteral, SymbolType type) : base(nameLiteral, SymbolRole.ExternalName, type) { }
public SymbolReference(SyntaxValue<string> nameLiteral, SymbolType type) : base(nameLiteral, SymbolRole.SymbolReference, type) { IsAmbiguous = false; IsQualifiedReference = false; }
public AmbiguousSymbolReference(SyntaxValue<string> nameLiteral, SymbolType[] candidateTypes) : base(nameLiteral, SymbolType.TO_BE_RESOLVED) { IsAmbiguous = true; CandidateTypes = candidateTypes; }
public SymbolInformation(SyntaxValue<string> nameLiteral, SymbolRole role, SymbolType type) { NameLiteral = nameLiteral; Role = role; Type = type; }
public SymbolDefinitionOrReference(SyntaxValue<string> nameLiteral, SymbolType type) : base(nameLiteral, SymbolRole.SymbolDefinitionOrReference, type) { }
public static void DoTest() { Assert(SyntaxEquals(TokenParse(@"""123abc\u0020\t\"""""), SyntaxRule.CreateLiteral(TokenLiteral.CreateStringValue("123abc \t\"")))); Assert(SyntaxEquals(TokenParse(@"0"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(0)))); Assert(SyntaxEquals(TokenParse(@"-1000"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(-1000)))); Assert(SyntaxEquals(TokenParse(@"0.0"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(0)))); Assert(SyntaxEquals(TokenParse(@"123.456"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(123.456)))); Assert(SyntaxEquals(TokenParse(@"-10.1"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(-10.1)))); Assert(SyntaxEquals(TokenParse(@"100.001e10"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(100.001e10)))); Assert(SyntaxEquals(TokenParse(@"-100.00e+10"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(-100.00e+10)))); Assert(SyntaxEquals(TokenParse(@"100.001e-10"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(100.001e-10)))); Assert(SyntaxEquals(TokenParse(@"1.23456789123456789123456789e10"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(1.23456789123456789123456789e10)))); Assert(SyntaxEquals(TokenParse(@"1.79769e+308"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(1.79769e+308)))); Assert(SyntaxEquals(TokenParse(@"-1.79769e+308"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(-1.79769e+308)))); Assert(SyntaxEquals(TokenParse(@"2.22507e-308"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(2.22507e-308)))); Assert(SyntaxEquals(TokenParse(@"-2.22507e-308"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNumberValue(-2.22507e-308)))); Assert(SyntaxEquals(TokenParse(@"null"), SyntaxRule.CreateLiteral(TokenLiteral.CreateNullValue()))); Assert(SyntaxEquals(TokenParse(@"false"), SyntaxRule.CreateLiteral(TokenLiteral.CreateBooleanValue(false)))); Assert(SyntaxEquals(TokenParse(@"true"), SyntaxRule.CreateLiteral(TokenLiteral.CreateBooleanValue(true)))); Assert(SyntaxEquals(TokenParse(@"{"), SyntaxRule.CreateLeftBrace())); Assert(SyntaxEquals(TokenParse(@"}"), SyntaxRule.CreateRightBrace())); Assert(SyntaxEquals(TokenParse(@"["), SyntaxRule.CreateLeftBracket())); Assert(SyntaxEquals(TokenParse(@"]"), SyntaxRule.CreateRightBracket())); Assert(SyntaxEquals(TokenParse(@":"), SyntaxRule.CreateColon())); Assert(SyntaxEquals(TokenParse(@","), SyntaxRule.CreateComma())); Assert(SyntaxEquals(TokenParse(" \t\r\n"), SyntaxRule.CreateWhitespace())); Assert(SyntaxEquals(SyntaxParse("null"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNullValue()))); Assert(SyntaxEquals(SyntaxParse("false"), SyntaxValue.CreateLiteral(TokenLiteral.CreateBooleanValue(false)))); Assert(SyntaxEquals(SyntaxParse("true"), SyntaxValue.CreateLiteral(TokenLiteral.CreateBooleanValue(true)))); Assert(SyntaxEquals(SyntaxParse("123"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(123)))); Assert(SyntaxEquals(SyntaxParse("\"123\""), SyntaxValue.CreateLiteral(TokenLiteral.CreateStringValue("123")))); Assert(SyntaxEquals(SyntaxParse(" null "), SyntaxValue.CreateLiteral(TokenLiteral.CreateNullValue()))); Assert(SyntaxEquals(SyntaxParse(" false "), SyntaxValue.CreateLiteral(TokenLiteral.CreateBooleanValue(false)))); Assert(SyntaxEquals(SyntaxParse(" true "), SyntaxValue.CreateLiteral(TokenLiteral.CreateBooleanValue(true)))); Assert(SyntaxEquals(SyntaxParse(" 123 "), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(123)))); Assert(SyntaxEquals(SyntaxParse(" \"123\" "), SyntaxValue.CreateLiteral(TokenLiteral.CreateStringValue("123")))); Assert(SyntaxEquals(SyntaxParse("{}"), SyntaxValue.CreateObject(new SyntaxObject { Members = Optional <SyntaxMembers> .Empty }))); Assert(SyntaxEquals(SyntaxParse("[]"), SyntaxValue.CreateArray(new SyntaxArray { Elements = Optional <SyntaxElements> .Empty }))); Assert(SyntaxEquals(SyntaxParse("{ }"), SyntaxValue.CreateObject(new SyntaxObject { Members = Optional <SyntaxMembers> .Empty }))); Assert(SyntaxEquals(SyntaxParse("[ ]"), SyntaxValue.CreateArray(new SyntaxArray { Elements = Optional <SyntaxElements> .Empty }))); Assert(SyntaxEquals(SyntaxParse(" { }"), SyntaxValue.CreateObject(new SyntaxObject { Members = Optional <SyntaxMembers> .Empty }))); Assert(SyntaxEquals(SyntaxParse(" [ ]"), SyntaxValue.CreateArray(new SyntaxArray { Elements = Optional <SyntaxElements> .Empty }))); Assert(SyntaxEquals(SyntaxParse(" { } "), SyntaxValue.CreateObject(new SyntaxObject { Members = Optional <SyntaxMembers> .Empty }))); Assert(SyntaxEquals(SyntaxParse(" [ ] "), SyntaxValue.CreateArray(new SyntaxArray { Elements = Optional <SyntaxElements> .Empty }))); Assert(SyntaxEquals(SyntaxParse("{\"key\":1}"), SyntaxValue.CreateObject(new SyntaxObject { Members = SyntaxMembers.CreateSingle(new Tuple <TokenLiteral, SyntaxValue>(TokenLiteral.CreateStringValue("key"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1)))) }))); Assert(SyntaxEquals(SyntaxParse("[1]"), SyntaxValue.CreateArray(new SyntaxArray { Elements = SyntaxElements.CreateSingle(SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1))) }))); Assert(SyntaxEquals(SyntaxParse("{ \"key\" : 1 }"), SyntaxValue.CreateObject(new SyntaxObject { Members = SyntaxMembers.CreateSingle(new Tuple <TokenLiteral, SyntaxValue>(TokenLiteral.CreateStringValue("key"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1)))) }))); Assert(SyntaxEquals(SyntaxParse("[ 1 ]"), SyntaxValue.CreateArray(new SyntaxArray { Elements = SyntaxElements.CreateSingle(SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1))) }))); Assert(SyntaxEquals(SyntaxParse("{\"key\":1,\"value\":2}"), SyntaxValue.CreateObject(new SyntaxObject { Members = SyntaxMembers.CreateMultiple(new Tuple <SyntaxMembers, TokenLiteral, SyntaxValue>(SyntaxMembers.CreateSingle(new Tuple <TokenLiteral, SyntaxValue>(TokenLiteral.CreateStringValue("key"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1)))), TokenLiteral.CreateStringValue("value"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(2)))) }))); Assert(SyntaxEquals(SyntaxParse("[1,2]"), SyntaxValue.CreateArray(new SyntaxArray { Elements = SyntaxElements.CreateMultiple(new Tuple <SyntaxElements, SyntaxValue>(SyntaxElements.CreateSingle(SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1))), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(2)))) }))); Assert(SyntaxEquals(SyntaxParse("{ \"key\" : 1, \"value\" : 2 }"), SyntaxValue.CreateObject(new SyntaxObject { Members = SyntaxMembers.CreateMultiple(new Tuple <SyntaxMembers, TokenLiteral, SyntaxValue>(SyntaxMembers.CreateSingle(new Tuple <TokenLiteral, SyntaxValue>(TokenLiteral.CreateStringValue("key"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1)))), TokenLiteral.CreateStringValue("value"), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(2)))) }))); Assert(SyntaxEquals(SyntaxParse("[ 1, 2 ]"), SyntaxValue.CreateArray(new SyntaxArray { Elements = SyntaxElements.CreateMultiple(new Tuple <SyntaxElements, SyntaxValue>(SyntaxElements.CreateSingle(SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(1))), SyntaxValue.CreateLiteral(TokenLiteral.CreateNumberValue(2)))) }))); }