MCPcopy Index your code
hub / github.com/IBM/Project_CodeNet / parse

Function parse

tools/json-graph/src/jgflib.c:217–256  ·  view source on GitHub ↗

Parse the JSON input (global) into an array of tokens. Returns the allocated token array. The number of tokens is passed back via num_tokens. */

Source from the content-addressed store, hash-verified

215 The number of tokens is passed back via num_tokens.
216*/
217static jsmntok_t *parse(int *num_tokens)
218{
219 jsmn_parser parser;
220 size_t nalloc = 1024; /* tokens allocated */
221 size_t nread = read_input();
222 int ntokens;
223 jsmntok_t *tokens;
224
225 if (debug)
226 fprintf(stderr, "(D): Parsing the input...\n");
227 jsmn_init(&parser);
228 tokens = malloc(nalloc * sizeof(tokens[0]));
229
230 restart: {
231 ntokens = jsmn_parse(&parser, input, nread, tokens, nalloc);
232 switch (ntokens) {
233 case JSMN_ERROR_NOMEM:
234 /* Reallocate and keep going. */
235 if (debug)
236 fprintf(stderr, "(D): Reallocating tokens array.\n");
237 nalloc <<= 1;
238 tokens = realloc((void *)tokens, nalloc * sizeof(tokens[0]));
239 goto restart;
240
241 case JSMN_ERROR_INVAL:
242 fprintf(stderr, "(E): Invalid character in input.\n");
243 exit(2);
244
245 case JSMN_ERROR_PART:
246 /* Should never happen! */
247 fprintf(stderr, "(E): Incomplete input, more bytes expected.\n");
248 exit(3);
249
250 default:
251 break;
252 }
253 }
254 *num_tokens = ntokens;
255 return tokens;
256}
257
258/** Returns string representation for JSON type. */
259static const char *type(jsmntype_t t)

Callers 2

jgf_parseFunction · 0.85
jsonml_parseFunction · 0.85

Calls 3

read_inputFunction · 0.85
jsmn_initFunction · 0.85
jsmn_parseFunction · 0.85

Tested by

no test coverage detected