Commits

Serge A. Zaitsev  committed 667de06

Design: primitive type implemented as a replacement to boolean/number/null. String tokens point to the unquoted string

  • Participants
  • Parent commits 0fd4fd3

Comments (0)

Files changed (4)

-CFLAGS=-Wall -std=c89 -g
+CFLAGS=-Wall -std=c89 -g -O2
 
 OBJS=jsmn.o demo.o
 
 
 	len = obj->end - obj->start;
 
-	printf("[%d,%d]\t", obj->start, obj->end);
+	printf("[%3d,%3d]\t", obj->start, obj->end);
 
 	char *type;
 	switch (obj->type) {
-		case JSON_OTHER:
-			type = "(?)";
-			break;
-		case JSON_NUMBER:
-			type = "(N)";
+		case JSON_PRIMITIVE:
+			type = "(.)";
 			break;
 		case JSON_STRING:
-			type = "(S)";
+			type = "(s)";
 			break;
 		case JSON_ARRAY:
 			type = "(A)";
 	r = jsmn_parse(&parser);
 	if (r < 0) {
 		printf("error %d at pos %d: %s\n", r, parser.pos, &js[parser.pos]);
-		exit(EXIT_FAILURE);
 	}
 
 	for (i = 0; i<NUM_TOKENS; i++) {
 	for (i = 0; i < parser->num_tokens; i++) {
 		parser->tokens[i].start = -1;
 		parser->tokens[i].end = -1;
-		parser->tokens[i].type = JSON_OTHER;
+		parser->tokens[i].type = JSON_PRIMITIVE;
 	}
 }
 
 
 	js = parser->js;
 
-	token = jsmn_start_token(parser, JSON_NUMBER);
+	token = jsmn_start_token(parser, JSON_PRIMITIVE);
 
 	for (; js[parser->pos] != '\0'; parser->pos++) {
 		switch (js[parser->pos]) {
 	return JSMN_ERROR_PART;
 }
 
-
 static int jsmn_parse_string(jsmn_parser *parser) {
 	const char *js;
 	jsontok_t *token;
 	return JSMN_ERROR_PART;
 }
 
-
 jsmnerr_t jsmn_parse(jsmn_parser *parser) {
 	const char *js;
 	jsontype_t type;
 			case '}': case ']':
 				type = (c == '}' ? JSON_OBJECT : JSON_ARRAY);
 				token = jsmn_end_token(parser, type);
+				token->end++;
 				break;
 			case '-': case '0': case '1' : case '2': case '3' : case '4':
 			case '5': case '6': case '7' : case '8': case '9':
  * 	o Other primitive: boolean (true/false) or null
  */
 typedef enum {
-	JSON_OTHER = 0,
+	JSON_PRIMITIVE = 0,
 	JSON_OBJECT = 1,
 	JSON_ARRAY = 2,
-	JSON_STRING = 3,
-	JSON_NUMBER = 4
+	JSON_STRING = 3
 } jsontype_t;
 
 typedef enum {