*/
Json_Parse_Pairs(json);
- if(Parse_CurrentToken(json->state) != '}')
+ if(*json->state->pos != '}')
Parse_Error(json->state, PARSE_ERR_INVAL, ", or }");
Parse_Dedent(json->state);
break;
} while (Parse_NextToken(json->state) == ',');
- if(Parse_CurrentToken(json->state) != ']')
+ if(*json->state->pos != ']')
Parse_Error(json->state, PARSE_ERR_INVAL, ", or ]");
Parse_Dedent(json->state);
return NULL;
}
- switch(Parse_CurrentToken(json->state))
+ switch(Parse_NextToken(json->state))
{
case '{':
Json_Parse_Object(json);
// Skip to the next token. Advance the pointer at least 1 if we're not sitting on whitespace.
char Parse_NextToken(struct qparser_state_s *state)
{
- // Check if we will skip first.
- if(!Parse_SkipToToken(state))
- {
- // If not, advance the pointer.
+ if(!state->pos)
+ state->pos = state->buf;
+ else
Parse_Next(state, 1);
- // Ensure we didn't land on whitespace and skip that too.
- Parse_SkipToToken(state);
- }
- return *state->pos;
-}
-// Return the current token but skip comments.
-char Parse_CurrentToken(struct qparser_state_s *state)
-{
Parse_SkipToToken(state);
+
return *state->pos;
}
out = (qparser_state_t *)Z_Malloc(sizeof(qparser_state_t));
out->buf = in;
- out->pos = in;
+ out->pos = NULL;
out->line = 1;
out->col = 1;
out->depth = 0;
void Parse_Error(struct qparser_state_s *state, qparser_err_t error, const char *expected);
void Parse_Next(struct qparser_state_s *state, size_t count);
char Parse_NextToken(struct qparser_state_s *state);
-char Parse_CurrentToken(struct qparser_state_s *state);
qparser_state_t *Parse_New(const unsigned char *in);
qparser_state_t *Parse_LoadFile(const char *file);