コード例 #1
0
ファイル: MyJson.cs プロジェクト: CompilerKit/CodeWalk
 JsonElement TryCatchNumber(string str)
 {
     JsonElement element = new JsonElement();
     long numInteger;
     double numDouble;
     decimal numDecimal;
     if (Int64.TryParse(str, out numInteger))
     {
         return new JsonElement(numInteger);
     }
     else if (Double.TryParse(str, out numDouble))
     {
         return new JsonElement(numDouble);
     }
     else if (Decimal.TryParse(str, out numDecimal))
     {
         return new JsonElement(numDecimal);
     }
     else
     {
         element.SetValueType(JsonValueType.Error);
         return element;
     }
 }
コード例 #2
0
ファイル: MyJson.cs プロジェクト: CompilerKit/CodeWalk
 JsonElement ReadJsonElement()
 {
     JsonElement element = new JsonElement();
     switch (CurrentChar)
     {
         case '"': //read string
             element.SetValue(GetString());
             break;
         case 'n': //try read null
             if (GetStringUtilSpaceOrComma() == "null")
             {
                 element = new JsonElement(null);
                 break;
             }
             element.SetValueType(JsonValueType.Error);
             break;
         case 't': //try read true
             if (GetStringUtilSpaceOrComma() == "true")
             {
                 element = new JsonElement(true);
                 break;
             }
             element.SetValueType(JsonValueType.Error);
             break;
         case 'f': //try read false
             if (GetStringUtilSpaceOrComma() == "false")
             {
                 element = new JsonElement(false);
                 break;
             }
             element.SetValueType(JsonValueType.Error);
             break;
         default: //try read number or error
             element = TryCatchNumber(GetStringUtilSpaceOrComma());
             break;
     }
     if (element.ValueType == JsonValueType.Error)
     {
         throw new Exception("Something wrong");
     }
     return element;
 }
コード例 #3
0
ファイル: AstCsToJson.cs プロジェクト: CompilerKit/CodeWalk
 JsonValue GetModifiers(IEnumerable<CSharpModifierToken> modifierTokens)
 {
     List<CSharpModifierToken> modifierList = new List<CSharpModifierToken>();
     foreach (CSharpModifierToken modifier in modifierTokens)
     {
         modifierList.Add(modifier);
     }
     int count = modifierList.Count;
     int lastIndex = count - 1;
     if (count > 1)
     {
         JsonArray modifierArr = new JsonArray();
         modifierArr.Comment = "GetModifiers";
         for (int i = 0; i < count; i++)
         {
             modifierList[i].AcceptVisitor(this);
             modifierArr.AddJsonValue(Pop());
         }
         return modifierArr;
     }
     else if (count == 1)
     {
         modifierList[0].AcceptVisitor(this);
         return Pop();
     }
     else//count = 0;
     {
         JsonElement nullElement = new JsonElement();
         nullElement.SetValue(null);
         return nullElement;
     }
 }
コード例 #4
0
ファイル: MyJson.cs プロジェクト: CompilerKit/CodeWalk
 public void VisitJsonElement(JsonElement jsonElement)
 {
     if (jsonElement == null)
     {
         VisitNull();
         return;
     }
     switch (jsonElement.ValueType)
     {
         case JsonValueType.String:
             Write('"' + jsonElement.ElementValue + '"');
             break;
         case JsonValueType.Number:
         case JsonValueType.Boolean:
         case JsonValueType.Null:
             Write(jsonElement.ElementValue);
             break;
         default:
             throw new Exception("Not element");
     }
 }
コード例 #5
0
ファイル: AstCsToJson.cs プロジェクト: CompilerKit/CodeWalk
        public void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode)
        {
            tokennodeCounter++;
            if (tokennodeCounter == 26)
            {

            }
            CSharpModifierToken mod = cSharpTokenNode as CSharpModifierToken;
            if (mod != null)
            {
                JsonElement element = new JsonElement();
                element.SetValue(CSharpModifierToken.GetModifierName(mod.Modifier));
                Push(element);
            }
            else
            {
                throw new NotSupportedException("Should never visit individual tokens");
            }
        }