ecere/ECONParser: parse json. econ is a superset of json.
[sdk] / ecere / src / sys / JSON.ec
index 79cac0f..f2d97b7 100644 (file)
@@ -31,7 +31,7 @@ public enum SetBool : uint
 };
 
 
-public class eCONParser : JSONParser
+public class ECONParser : JSONParser
 {
    eCON = true;
 }
@@ -182,7 +182,7 @@ private:
             }
          }
       }
-      else if(isalpha(ch))
+      else if(isalpha(ch) || ch == '_')
       {
          if(eCON)
          {
@@ -247,7 +247,7 @@ private:
          {
             char buffer[256];
             int c = 0;
-            while(c < sizeof(buffer)-1 && isalpha(ch))
+            while(c < sizeof(buffer)-1 && (isalpha(ch) || isdigit(ch) || ch == '_'))
             {
                buffer[c++] = ch;
                if(!f.Getc(&ch)) break;
@@ -507,7 +507,7 @@ private:
                break;
             }
          }
-         else if(ch == '\"' || (!comment && ch && !isalpha(ch)))
+         else if(ch == '\"' || (!comment && ch && !isalpha(ch) && !isdigit(ch) && ch != '_'))
          {
             if(quoted && ch == '\"' && wasQuoted)
                *wasQuoted = true;
@@ -526,7 +526,7 @@ private:
          *string = CopyString(buffer.array);
       }
       delete buffer;
-      if(ch != ',' && ch != '}' && ch != ';' && ch != '/' && ch != '=')
+      if(ch != ',' && ch != '}' && ch != ';' && ch != '/' && ch != '=' && ch != ':')
          ch = 0;
       return result;
    }
@@ -587,7 +587,7 @@ private:
                         lineComment = false;
                      else if(comment && pch == '*' && ch == '/')
                         comment = false;
-                     else if(ch == '=' || ch == ';' || ch == ',' || ch == '}')
+                     else if(ch == '=' || ch == ':' || ch == ';' || ch == ',' || ch == ']' || ch == '}')
                      {
                         ch = 0;
                         seekback = -1;
@@ -684,8 +684,10 @@ private:
                {
                   SkipEmpty();
                   prop = null; member = null;
-                  if(ch == '=')
+                  if(ch == '=' || ch == ':')
                   {
+                     if(wasQuoted)
+                        string[0] = (char)tolower(string[0]);
                      while(1)
                      {
                         eClass_FindNextMember(objectType, &curClass, &curMember, subMemberStack, &subMemberStackPos);
@@ -724,7 +726,7 @@ private:
                   }
                   else
                   {
-                     if(ch == '=')
+                     if(ch == '=' || ch == ':')
                         PrintLn("Warning: member ", string, " not found in class ", (String)objectType.name);
                      else
                         PrintLn("Warning: default member assignment: no more members");
@@ -785,12 +787,12 @@ private:
                      ch = 0;
                      SkipEmpty();
                   }
-                  if(eCON && ch != '=')
+                  if(eCON && ch != '=' && ch != ':')
                   {
                      f.Seek(seek-1, start);
                      ch = 0;
                   }
-                  if(ch == (eCON ? '=' : ':') || (eCON && type && (prop || member)))
+                  if((ch == ':' || (eCON && ch == '=')) || (eCON && type && (prop || member)))
                   {
                      JSONResult itemResult = GetValue(type, value);
                      if(itemResult != syntaxError)