JangSing / JSON_Parser

JSON Parser (Mini Project for Test Driven Development)
0 stars 0 forks source link

jsonParse() should have its own data #2

Open chaosAD opened 9 years ago

chaosAD commented 9 years ago

In

typedef struct {
  ListElement *head;
  ListElement *tail;
  int length;
  ListState state;
} LinkedList;

please remove ListState state. Rename ListState to JsonState. Instead of polluting your LinkedList with Json information, create the following in JSON.h:

typedef struct {
  LinkedList data;
  JsonState state;
} JsonObject;

which uses LinkedList to store JSON data.

Your jsonParse function should look like void jsonParse(JsonObject *json). It takes in the JSON object which keeps all the information.

Create JsonObject in JsonObject *createJsonObject().

chaosAD commented 9 years ago

After seeing problem in your design, I suggest the following:

typedef struct {
  JsonState state;
} JsonObject;

typedef struct {
  TokenType type;
  uint32_t startColumn;
  uint32_t length;
  char *symbol;
  Arity arity;
  LinkedList *list;
} JsonToken;    

Now your jsonParse function should look like Token *jsonParse(JsonObject *json). It returns { token, which is a JsonToken. The declaration of JsonToken should be placed int Token.h.

The only difference between ordinary Token and JsonToken is token[] field is replaced with list. So the JsonToken has symbol = '{'.