Begin prototyping JsonDecode

This commit is contained in:
Jordan Bancino 2022-08-02 16:58:15 -04:00
parent 8d77846578
commit f48f7c088c

View file

@ -29,6 +29,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct JsonValue
{
@ -44,6 +45,31 @@ struct JsonValue
} as;
};
typedef enum JsonToken
{
TOKEN_UNKNOWN,
TOKEN_COLON,
TOKEN_COMMA,
TOKEN_OBJECT_OPEN,
TOKEN_OBJECT_CLOSE,
TOKEN_ARRAY_OPEN,
TOKEN_ARRAY_CLOSE,
TOKEN_STRING,
TOKEN_INTEGER,
TOKEN_FLOAT,
TOKEN_BOOLEAN,
TOKEN_NULL,
TOKEN_EOF
} JsonToken;
typedef struct JsonParserState
{
FILE *stream;
JsonToken tokenType;
char *token;
} JsonParserState;
JsonType
JsonValueType(JsonValue * value)
{
@ -386,6 +412,13 @@ JsonDecodeString(FILE * in)
while ((c = fgetc(in)) != EOF)
{
if (c <= 0x001F)
{
/* Bad byte; these must be escaped */
free(str);
return NULL;
}
switch (c)
{
case '"':
@ -615,3 +648,46 @@ JsonFree(HashMap * object)
HashMapFree(object);
}
static void
JsonConsumeWhitespace(JsonParserState * state)
{
int c;
while (isspace(c = fgetc(state->stream)));
ungetc(c, state->stream);
}
static void
JsonTokenSeek(JsonParserState * state)
{
}
static int
JsonExpect(JsonParserState * state, JsonToken token)
{
return state->tokenType == token;
}
static HashMap *
JsonDecodeObject(JsonParserState * state)
{
return NULL;
}
static Array *
JsonDecodeArray(JsonParserState * state)
{
return NULL;
}
HashMap *
JsonDecode(FILE * stream)
{
JsonParserState state;
state.stream = stream;
return JsonDecodeObject(&state);
}