Updated the parser implementation
This commit is contained in:
		| @@ -16,9 +16,9 @@ | ||||
|       "main", | ||||
|       "src/main.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/main.c", | ||||
|     "output": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/main" | ||||
|     "directory": "/Users/abdelrahman/dev/personal/say-it-in-json", | ||||
|     "file": "/Users/abdelrahman/dev/personal/say-it-in-json/src/main.c", | ||||
|     "output": "/Users/abdelrahman/dev/personal/say-it-in-json/main" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
| @@ -37,9 +37,9 @@ | ||||
|       "main", | ||||
|       "src/dstring/dstring.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/dstring/dstring.c", | ||||
|     "output": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/main" | ||||
|     "directory": "/Users/abdelrahman/dev/personal/say-it-in-json", | ||||
|     "file": "/Users/abdelrahman/dev/personal/say-it-in-json/src/dstring/dstring.c", | ||||
|     "output": "/Users/abdelrahman/dev/personal/say-it-in-json/main" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
| @@ -58,9 +58,9 @@ | ||||
|       "main", | ||||
|       "src/json_entities/json_entities.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/json_entities/json_entities.c", | ||||
|     "output": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/main" | ||||
|     "directory": "/Users/abdelrahman/dev/personal/say-it-in-json", | ||||
|     "file": "/Users/abdelrahman/dev/personal/say-it-in-json/src/json_entities/json_entities.c", | ||||
|     "output": "/Users/abdelrahman/dev/personal/say-it-in-json/main" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
| @@ -79,9 +79,9 @@ | ||||
|       "main", | ||||
|       "src/lexer/lexer.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/lexer/lexer.c", | ||||
|     "output": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/main" | ||||
|     "directory": "/Users/abdelrahman/dev/personal/say-it-in-json", | ||||
|     "file": "/Users/abdelrahman/dev/personal/say-it-in-json/src/lexer/lexer.c", | ||||
|     "output": "/Users/abdelrahman/dev/personal/say-it-in-json/main" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
| @@ -100,373 +100,8 @@ | ||||
|       "main", | ||||
|       "src/parser/parser.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/parser/parser.c", | ||||
|     "output": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/main" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
|       "/usr/bin/clang-16", | ||||
|       "-cc1", | ||||
|       "-triple", | ||||
|       "x86_64-redhat-linux-gnu", | ||||
|       "-emit-obj", | ||||
|       "-mrelax-all", | ||||
|       "-disable-free", | ||||
|       "-clear-ast-before-backend", | ||||
|       "-disable-llvm-verifier", | ||||
|       "-discard-value-names", | ||||
|       "-main-file-name", | ||||
|       "-mrelocation-model", | ||||
|       "static", | ||||
|       "-mframe-pointer=all", | ||||
|       "-fmath-errno", | ||||
|       "-ffp-contract=on", | ||||
|       "-fno-rounding-math", | ||||
|       "-mconstructor-aliases", | ||||
|       "-funwind-tables=2", | ||||
|       "-target-cpu", | ||||
|       "x86-64", | ||||
|       "-tune-cpu", | ||||
|       "generic", | ||||
|       "-mllvm", | ||||
|       "-treat-scalable-fixed-error-as-warning", | ||||
|       "-debug-info-kind=constructor", | ||||
|       "-dwarf-version=4", | ||||
|       "-debugger-tuning=gdb", | ||||
|       "-fcoverage-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-resource-dir", | ||||
|       "/usr/lib64/clang/16", | ||||
|       "-I", | ||||
|       "include", | ||||
|       "-I", | ||||
|       "include/dstring", | ||||
|       "-I", | ||||
|       "include/json_entities", | ||||
|       "-I", | ||||
|       "include/lexer", | ||||
|       "-I", | ||||
|       "include/parser", | ||||
|       "-internal-isystem", | ||||
|       "/usr/lib64/clang/16/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/local/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/usr/include", | ||||
|       "-Wall", | ||||
|       "-Werror", | ||||
|       "-pedantic", | ||||
|       "-fdebug-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-ferror-limit", | ||||
|       "19", | ||||
|       "-fgnuc-version=4.2.1", | ||||
|       "-fcolor-diagnostics", | ||||
|       "-faddrsig", | ||||
|       "-D__GCC_HAVE_DWARF2_CFI_ASM=1", | ||||
|       "-x", | ||||
|       "c", | ||||
|       "-o", | ||||
|       "/tmp/main-f4c98b.o", | ||||
|       "src/main.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/main.c", | ||||
|     "output": "/tmp/main-f4c98b.o" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
|       "/usr/bin/clang-16", | ||||
|       "-cc1", | ||||
|       "-triple", | ||||
|       "x86_64-redhat-linux-gnu", | ||||
|       "-emit-obj", | ||||
|       "-mrelax-all", | ||||
|       "-disable-free", | ||||
|       "-clear-ast-before-backend", | ||||
|       "-disable-llvm-verifier", | ||||
|       "-discard-value-names", | ||||
|       "-main-file-name", | ||||
|       "-mrelocation-model", | ||||
|       "static", | ||||
|       "-mframe-pointer=all", | ||||
|       "-fmath-errno", | ||||
|       "-ffp-contract=on", | ||||
|       "-fno-rounding-math", | ||||
|       "-mconstructor-aliases", | ||||
|       "-funwind-tables=2", | ||||
|       "-target-cpu", | ||||
|       "x86-64", | ||||
|       "-tune-cpu", | ||||
|       "generic", | ||||
|       "-mllvm", | ||||
|       "-treat-scalable-fixed-error-as-warning", | ||||
|       "-debug-info-kind=constructor", | ||||
|       "-dwarf-version=4", | ||||
|       "-debugger-tuning=gdb", | ||||
|       "-fcoverage-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-resource-dir", | ||||
|       "/usr/lib64/clang/16", | ||||
|       "-I", | ||||
|       "include", | ||||
|       "-I", | ||||
|       "include/dstring", | ||||
|       "-I", | ||||
|       "include/json_entities", | ||||
|       "-I", | ||||
|       "include/lexer", | ||||
|       "-I", | ||||
|       "include/parser", | ||||
|       "-internal-isystem", | ||||
|       "/usr/lib64/clang/16/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/local/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/usr/include", | ||||
|       "-Wall", | ||||
|       "-Werror", | ||||
|       "-pedantic", | ||||
|       "-fdebug-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-ferror-limit", | ||||
|       "19", | ||||
|       "-fgnuc-version=4.2.1", | ||||
|       "-fcolor-diagnostics", | ||||
|       "-faddrsig", | ||||
|       "-D__GCC_HAVE_DWARF2_CFI_ASM=1", | ||||
|       "-x", | ||||
|       "c", | ||||
|       "-o", | ||||
|       "/tmp/dstring-431798.o", | ||||
|       "src/dstring/dstring.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/dstring/dstring.c", | ||||
|     "output": "/tmp/dstring-431798.o" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
|       "/usr/bin/clang-16", | ||||
|       "-cc1", | ||||
|       "-triple", | ||||
|       "x86_64-redhat-linux-gnu", | ||||
|       "-emit-obj", | ||||
|       "-mrelax-all", | ||||
|       "-disable-free", | ||||
|       "-clear-ast-before-backend", | ||||
|       "-disable-llvm-verifier", | ||||
|       "-discard-value-names", | ||||
|       "-main-file-name", | ||||
|       "-mrelocation-model", | ||||
|       "static", | ||||
|       "-mframe-pointer=all", | ||||
|       "-fmath-errno", | ||||
|       "-ffp-contract=on", | ||||
|       "-fno-rounding-math", | ||||
|       "-mconstructor-aliases", | ||||
|       "-funwind-tables=2", | ||||
|       "-target-cpu", | ||||
|       "x86-64", | ||||
|       "-tune-cpu", | ||||
|       "generic", | ||||
|       "-mllvm", | ||||
|       "-treat-scalable-fixed-error-as-warning", | ||||
|       "-debug-info-kind=constructor", | ||||
|       "-dwarf-version=4", | ||||
|       "-debugger-tuning=gdb", | ||||
|       "-fcoverage-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-resource-dir", | ||||
|       "/usr/lib64/clang/16", | ||||
|       "-I", | ||||
|       "include", | ||||
|       "-I", | ||||
|       "include/dstring", | ||||
|       "-I", | ||||
|       "include/json_entities", | ||||
|       "-I", | ||||
|       "include/lexer", | ||||
|       "-I", | ||||
|       "include/parser", | ||||
|       "-internal-isystem", | ||||
|       "/usr/lib64/clang/16/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/local/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/usr/include", | ||||
|       "-Wall", | ||||
|       "-Werror", | ||||
|       "-pedantic", | ||||
|       "-fdebug-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-ferror-limit", | ||||
|       "19", | ||||
|       "-fgnuc-version=4.2.1", | ||||
|       "-fcolor-diagnostics", | ||||
|       "-faddrsig", | ||||
|       "-D__GCC_HAVE_DWARF2_CFI_ASM=1", | ||||
|       "-x", | ||||
|       "c", | ||||
|       "-o", | ||||
|       "/tmp/json_entities-e4ee72.o", | ||||
|       "src/json_entities/json_entities.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/json_entities/json_entities.c", | ||||
|     "output": "/tmp/json_entities-e4ee72.o" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
|       "/usr/bin/clang-16", | ||||
|       "-cc1", | ||||
|       "-triple", | ||||
|       "x86_64-redhat-linux-gnu", | ||||
|       "-emit-obj", | ||||
|       "-mrelax-all", | ||||
|       "-disable-free", | ||||
|       "-clear-ast-before-backend", | ||||
|       "-disable-llvm-verifier", | ||||
|       "-discard-value-names", | ||||
|       "-main-file-name", | ||||
|       "-mrelocation-model", | ||||
|       "static", | ||||
|       "-mframe-pointer=all", | ||||
|       "-fmath-errno", | ||||
|       "-ffp-contract=on", | ||||
|       "-fno-rounding-math", | ||||
|       "-mconstructor-aliases", | ||||
|       "-funwind-tables=2", | ||||
|       "-target-cpu", | ||||
|       "x86-64", | ||||
|       "-tune-cpu", | ||||
|       "generic", | ||||
|       "-mllvm", | ||||
|       "-treat-scalable-fixed-error-as-warning", | ||||
|       "-debug-info-kind=constructor", | ||||
|       "-dwarf-version=4", | ||||
|       "-debugger-tuning=gdb", | ||||
|       "-fcoverage-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-resource-dir", | ||||
|       "/usr/lib64/clang/16", | ||||
|       "-I", | ||||
|       "include", | ||||
|       "-I", | ||||
|       "include/dstring", | ||||
|       "-I", | ||||
|       "include/json_entities", | ||||
|       "-I", | ||||
|       "include/lexer", | ||||
|       "-I", | ||||
|       "include/parser", | ||||
|       "-internal-isystem", | ||||
|       "/usr/lib64/clang/16/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/local/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/usr/include", | ||||
|       "-Wall", | ||||
|       "-Werror", | ||||
|       "-pedantic", | ||||
|       "-fdebug-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-ferror-limit", | ||||
|       "19", | ||||
|       "-fgnuc-version=4.2.1", | ||||
|       "-fcolor-diagnostics", | ||||
|       "-faddrsig", | ||||
|       "-D__GCC_HAVE_DWARF2_CFI_ASM=1", | ||||
|       "-x", | ||||
|       "c", | ||||
|       "-o", | ||||
|       "/tmp/lexer-b434f8.o", | ||||
|       "src/lexer/lexer.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/lexer/lexer.c", | ||||
|     "output": "/tmp/lexer-b434f8.o" | ||||
|   }, | ||||
|   { | ||||
|     "arguments": [ | ||||
|       "/usr/bin/clang-16", | ||||
|       "-cc1", | ||||
|       "-triple", | ||||
|       "x86_64-redhat-linux-gnu", | ||||
|       "-emit-obj", | ||||
|       "-mrelax-all", | ||||
|       "-disable-free", | ||||
|       "-clear-ast-before-backend", | ||||
|       "-disable-llvm-verifier", | ||||
|       "-discard-value-names", | ||||
|       "-main-file-name", | ||||
|       "-mrelocation-model", | ||||
|       "static", | ||||
|       "-mframe-pointer=all", | ||||
|       "-fmath-errno", | ||||
|       "-ffp-contract=on", | ||||
|       "-fno-rounding-math", | ||||
|       "-mconstructor-aliases", | ||||
|       "-funwind-tables=2", | ||||
|       "-target-cpu", | ||||
|       "x86-64", | ||||
|       "-tune-cpu", | ||||
|       "generic", | ||||
|       "-mllvm", | ||||
|       "-treat-scalable-fixed-error-as-warning", | ||||
|       "-debug-info-kind=constructor", | ||||
|       "-dwarf-version=4", | ||||
|       "-debugger-tuning=gdb", | ||||
|       "-fcoverage-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-resource-dir", | ||||
|       "/usr/lib64/clang/16", | ||||
|       "-I", | ||||
|       "include", | ||||
|       "-I", | ||||
|       "include/dstring", | ||||
|       "-I", | ||||
|       "include/json_entities", | ||||
|       "-I", | ||||
|       "include/lexer", | ||||
|       "-I", | ||||
|       "include/parser", | ||||
|       "-internal-isystem", | ||||
|       "/usr/lib64/clang/16/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/local/include", | ||||
|       "-internal-isystem", | ||||
|       "/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/include", | ||||
|       "-internal-externc-isystem", | ||||
|       "/usr/include", | ||||
|       "-Wall", | ||||
|       "-Werror", | ||||
|       "-pedantic", | ||||
|       "-fdebug-compilation-dir=/home/abdelrahman/dev_work/say_it_in_json", | ||||
|       "-ferror-limit", | ||||
|       "19", | ||||
|       "-fgnuc-version=4.2.1", | ||||
|       "-fcolor-diagnostics", | ||||
|       "-faddrsig", | ||||
|       "-D__GCC_HAVE_DWARF2_CFI_ASM=1", | ||||
|       "-x", | ||||
|       "c", | ||||
|       "-o", | ||||
|       "/tmp/parser-2c05fe.o", | ||||
|       "src/parser/parser.c" | ||||
|     ], | ||||
|     "directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json", | ||||
|     "file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/parser/parser.c", | ||||
|     "output": "/tmp/parser-2c05fe.o" | ||||
|     "directory": "/Users/abdelrahman/dev/personal/say-it-in-json", | ||||
|     "file": "/Users/abdelrahman/dev/personal/say-it-in-json/src/parser/parser.c", | ||||
|     "output": "/Users/abdelrahman/dev/personal/say-it-in-json/main" | ||||
|   } | ||||
| ] | ||||
|   | ||||
| @@ -17,32 +17,58 @@ void parse_token(token_t token) { | ||||
|  | ||||
|     value.collection->type = JCOLL_OBJECT; | ||||
|     value.collection->size = 0; | ||||
|     value.collection->first_child = NULL; | ||||
|     value.collection->begin = NULL; | ||||
|     value.collection->end = NULL; | ||||
|  | ||||
|     if (!current) { | ||||
|       current = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->type = JENTITY_SINGLE; | ||||
|       current->value = value; | ||||
|     } else if (current->type == JENTITY_PAIR && | ||||
|                current->pair.value.type == JVAL_EMPTY) { | ||||
|       current->pair.value = value; | ||||
|       current->parent = NULL; | ||||
|       current->next = NULL; | ||||
|     } else { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_SINGLE; | ||||
|       current->next->value = value; | ||||
|       current->next->parent = current->parent; | ||||
|       jcoll_t *collection = NULL; | ||||
|  | ||||
|       current = current->next; | ||||
|       if (current->type == JENTITY_SINGLE) { | ||||
|         collection = current->value.collection; | ||||
|       } else { | ||||
|         collection = current->pair.value.collection; | ||||
|       } | ||||
|  | ||||
|       if (!(collection->end)) { | ||||
|         collection->begin = collection->end = | ||||
|             (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|         collection->end->type = JENTITY_SINGLE; | ||||
|         collection->end->value = value; | ||||
|         collection->end->parent = current; | ||||
|         collection->end->next = NULL; | ||||
|  | ||||
|         current = collection->end; | ||||
|       } else { | ||||
|         if (collection->end->type == JENTITY_PAIR && | ||||
|             collection->end->pair.value.type == JVAL_EMPTY) { | ||||
|           collection->end->pair.value = value; | ||||
|  | ||||
|           current = collection->end; | ||||
|         } else { | ||||
|           jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|           entity->type = JENTITY_SINGLE; | ||||
|           entity->value = value; | ||||
|           entity->parent = current; | ||||
|           entity->next = NULL; | ||||
|  | ||||
|           collection->end->next = entity; | ||||
|  | ||||
|           collection->end = entity; | ||||
|  | ||||
|           current = entity; | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     break; | ||||
|   } | ||||
|   case TK_R_BRACE: | ||||
|     if (current->parent) { | ||||
|       current = current->parent; | ||||
|     } | ||||
|  | ||||
|     break; | ||||
|   case TK_L_BRACKET: { | ||||
|     jval_t value = (jval_t){ | ||||
|         .type = JVAL_COLLECTION, | ||||
| @@ -51,25 +77,59 @@ void parse_token(token_t token) { | ||||
|  | ||||
|     value.collection->type = JCOLL_ARRAY; | ||||
|     value.collection->size = 0; | ||||
|     value.collection->first_child = NULL; | ||||
|     value.collection->begin = NULL; | ||||
|     value.collection->end = NULL; | ||||
|  | ||||
|     if (!current) { | ||||
|       current = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->type = JENTITY_SINGLE; | ||||
|       current->value = value; | ||||
|     } else if (current->type == JENTITY_PAIR && | ||||
|                current->pair.value.type == JVAL_EMPTY) { | ||||
|       current->pair.value = value; | ||||
|       current->parent = NULL; | ||||
|       current->next = NULL; | ||||
|     } else { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_SINGLE; | ||||
|       current->next->value = value; | ||||
|       current->next->parent = current->parent; | ||||
|       jcoll_t *collection = NULL; | ||||
|  | ||||
|       current = current->next; | ||||
|       if (current->type == JENTITY_SINGLE) { | ||||
|         collection = current->value.collection; | ||||
|       } else { | ||||
|         collection = current->pair.value.collection; | ||||
|       } | ||||
|  | ||||
|       if (!(collection->end)) { | ||||
|         collection->begin = collection->end = | ||||
|             (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|         collection->end->type = JENTITY_SINGLE; | ||||
|         collection->end->value = value; | ||||
|         collection->end->parent = current; | ||||
|         collection->end->next = current; | ||||
|  | ||||
|         current = collection->end; | ||||
|       } else { | ||||
|         if (collection->end->type == JENTITY_PAIR && | ||||
|             collection->end->pair.value.type == JVAL_EMPTY) { | ||||
|           collection->end->pair.value = value; | ||||
|  | ||||
|           current = collection->end; | ||||
|         } else { | ||||
|           jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|           entity->type = JENTITY_SINGLE; | ||||
|           entity->value = value; | ||||
|           entity->parent = current; | ||||
|           entity->next = NULL; | ||||
|  | ||||
|           collection->end->next = entity; | ||||
|  | ||||
|           collection->end = entity; | ||||
|  | ||||
|           current = entity; | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     break; | ||||
|   } | ||||
|   case TK_R_BRACE: | ||||
|   case TK_R_BRACKET: | ||||
|     if (current->parent) { | ||||
|       current = current->parent; | ||||
| @@ -79,28 +139,37 @@ void parse_token(token_t token) { | ||||
|   case TK_NULL: { | ||||
|     jval_t value = (jval_t){.type = JVAL_NULL, .null_val = NULL}; | ||||
|  | ||||
|     if (current->type == JENTITY_PAIR && | ||||
|         current->pair.value.type == JVAL_EMPTY) { | ||||
|       current->pair.value = value; | ||||
|     } else if (current->type == JENTITY_SINGLE && | ||||
|                current->value.type == JVAL_COLLECTION && | ||||
|                current->value.collection->type == JCOLL_ARRAY && | ||||
|                !(current->value.collection->first_child)) { | ||||
|       current->value.collection->first_child = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|     jcoll_t *collection = NULL; | ||||
|  | ||||
|       current->value.collection->first_child->type = JENTITY_SINGLE; | ||||
|       current->value.collection->first_child->value = value; | ||||
|       current->value.collection->first_child->parent = current; | ||||
|  | ||||
|       current = current->value.collection->first_child; | ||||
|     if (current->type == JENTITY_SINGLE) { | ||||
|       collection = current->value.collection; | ||||
|     } else { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_SINGLE; | ||||
|       current->next->value = value; | ||||
|       current->next->parent = current->parent; | ||||
|       collection = current->pair.value.collection; | ||||
|     } | ||||
|  | ||||
|       current = current->next; | ||||
|     if (!(collection->end)) { | ||||
|       collection->begin = collection->end = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       collection->end->type = JENTITY_SINGLE; | ||||
|       collection->end->value = value; | ||||
|       collection->end->parent = current; | ||||
|       collection->end->next = NULL; | ||||
|     } else { | ||||
|       if (collection->end->type == JENTITY_PAIR && | ||||
|           collection->end->pair.value.type == JVAL_EMPTY) { | ||||
|         collection->end->pair.value = value; | ||||
|       } else { | ||||
|         jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|         entity->type = JENTITY_SINGLE; | ||||
|         entity->value = value; | ||||
|         entity->parent = current; | ||||
|         entity->next = NULL; | ||||
|  | ||||
|         collection->end->next = entity; | ||||
|  | ||||
|         collection->end = entity; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     break; | ||||
| @@ -109,28 +178,37 @@ void parse_token(token_t token) { | ||||
|     jval_t value = | ||||
|         (jval_t){.type = JVAL_BOOLEAN, .boolean = token.value.boolean}; | ||||
|  | ||||
|     if (current->type == JENTITY_PAIR && | ||||
|         current->pair.value.type == JVAL_EMPTY) { | ||||
|       current->pair.value = value; | ||||
|     } else if (current->type == JENTITY_SINGLE && | ||||
|                current->value.type == JVAL_COLLECTION && | ||||
|                current->value.collection->type == JCOLL_ARRAY && | ||||
|                !(current->value.collection->first_child)) { | ||||
|       current->value.collection->first_child = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|     jcoll_t *collection = NULL; | ||||
|  | ||||
|       current->value.collection->first_child->type = JENTITY_SINGLE; | ||||
|       current->value.collection->first_child->value = value; | ||||
|       current->value.collection->first_child->parent = current; | ||||
|  | ||||
|       current = current->value.collection->first_child; | ||||
|     if (current->type == JENTITY_SINGLE) { | ||||
|       collection = current->value.collection; | ||||
|     } else { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_SINGLE; | ||||
|       current->next->value = value; | ||||
|       current->next->parent = current->parent; | ||||
|       collection = current->pair.value.collection; | ||||
|     } | ||||
|  | ||||
|       current = current->next; | ||||
|     if (!(collection->end)) { | ||||
|       collection->begin = collection->end = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       collection->end->type = JENTITY_SINGLE; | ||||
|       collection->end->value = value; | ||||
|       collection->end->parent = current; | ||||
|       collection->end->next = NULL; | ||||
|     } else { | ||||
|       if (collection->end->type == JENTITY_PAIR && | ||||
|           collection->end->pair.value.type == JVAL_EMPTY) { | ||||
|         collection->end->pair.value = value; | ||||
|       } else { | ||||
|         jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|         entity->type = JENTITY_SINGLE; | ||||
|         entity->value = value; | ||||
|         entity->parent = current; | ||||
|         entity->next = NULL; | ||||
|  | ||||
|         collection->end->next = entity; | ||||
|  | ||||
|         collection->end = entity; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     break; | ||||
| @@ -138,56 +216,73 @@ void parse_token(token_t token) { | ||||
|   case TK_STR_KEY: { | ||||
|     jval_t value = (jval_t){.type = JVAL_EMPTY, .null_val = NULL}; | ||||
|  | ||||
|     if (current->type == JENTITY_PAIR) { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_PAIR; | ||||
|       current->next->pair.key = dstr_from_string(token.value.string); | ||||
|       current->next->pair.value = value; | ||||
|       current->next->parent = current->parent; | ||||
|     jcoll_t *collection = NULL; | ||||
|  | ||||
|       current = current->next; | ||||
|     } else if (current->type == JENTITY_SINGLE && | ||||
|                current->value.type == JVAL_COLLECTION && | ||||
|                !(current->value.collection->first_child)) { | ||||
|       current->value.collection->first_child = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|       current->value.collection->first_child->type = JENTITY_PAIR; | ||||
|       current->value.collection->first_child->pair.key = | ||||
|           dstr_from_string(token.value.string); | ||||
|       current->value.collection->first_child->pair.value = value; | ||||
|       current->value.collection->first_child->parent = current; | ||||
|  | ||||
|       current = current->value.collection->first_child; | ||||
|     if (current->type == JENTITY_SINGLE) { | ||||
|       collection = current->value.collection; | ||||
|     } else { | ||||
|       collection = current->pair.value.collection; | ||||
|     } | ||||
|  | ||||
|     if (!(collection->end)) { | ||||
|       collection->begin = collection->end = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       collection->end->type = JENTITY_PAIR; | ||||
|       collection->end->pair.key = dstr_from_string(token.value.string); | ||||
|       collection->end->pair.value = value; | ||||
|       collection->end->parent = current; | ||||
|       collection->end->next = NULL; | ||||
|     } else { | ||||
|       jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|       entity->type = JENTITY_PAIR; | ||||
|       entity->pair.key = dstr_from_string(token.value.string); | ||||
|       entity->pair.value = value; | ||||
|       entity->parent = current; | ||||
|       entity->next = NULL; | ||||
|  | ||||
|       collection->end->next = entity; | ||||
|  | ||||
|       collection->end = entity; | ||||
|     } | ||||
|  | ||||
|     break; | ||||
|   } | ||||
|   case TK_STR_VAL: { | ||||
|     jval_t value = (jval_t){.type = JVAL_STRING, | ||||
|                             .string = dstr_from_string(token.value.string)}; | ||||
|  | ||||
|     if (current->type == JENTITY_PAIR && | ||||
|         current->pair.value.type == JVAL_EMPTY) { | ||||
|       current->pair.value = value; | ||||
|     } else if (current->type == JENTITY_SINGLE && | ||||
|                current->value.type == JVAL_COLLECTION && | ||||
|                current->value.collection->type == JCOLL_ARRAY && | ||||
|                !(current->value.collection->first_child)) { | ||||
|       current->value.collection->first_child = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|     jcoll_t *collection = NULL; | ||||
|  | ||||
|       current->value.collection->first_child->type = JENTITY_SINGLE; | ||||
|       current->value.collection->first_child->value = value; | ||||
|       current->value.collection->first_child->parent = current; | ||||
|  | ||||
|       current = current->value.collection->first_child; | ||||
|     if (current->type == JENTITY_SINGLE) { | ||||
|       collection = current->value.collection; | ||||
|     } else { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_SINGLE; | ||||
|       current->next->value = value; | ||||
|       current->next->parent = current->parent; | ||||
|       collection = current->pair.value.collection; | ||||
|     } | ||||
|  | ||||
|       current = current->next; | ||||
|     if (!(collection->end)) { | ||||
|       collection->begin = collection->end = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       collection->end->type = JENTITY_SINGLE; | ||||
|       collection->end->value = value; | ||||
|       collection->end->parent = current; | ||||
|       collection->end->next = NULL; | ||||
|     } else { | ||||
|       if (collection->end->type == JENTITY_PAIR && | ||||
|           collection->end->pair.value.type == JVAL_EMPTY) { | ||||
|         collection->end->pair.value = value; | ||||
|       } else { | ||||
|         jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|         entity->type = JENTITY_SINGLE; | ||||
|         entity->value = value; | ||||
|         entity->parent = current; | ||||
|         entity->next = NULL; | ||||
|  | ||||
|         collection->end->next = entity; | ||||
|  | ||||
|         collection->end = entity; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     break; | ||||
| @@ -196,28 +291,37 @@ void parse_token(token_t token) { | ||||
|     jval_t value = | ||||
|         (jval_t){.type = JVAL_INTEGER, .num_int = token.value.num_int}; | ||||
|  | ||||
|     if (current->type == JENTITY_PAIR && | ||||
|         current->pair.value.type == JVAL_EMPTY) { | ||||
|       current->pair.value = value; | ||||
|     } else if (current->type == JENTITY_SINGLE && | ||||
|                current->value.type == JVAL_COLLECTION && | ||||
|                current->value.collection->type == JCOLL_ARRAY && | ||||
|                !(current->value.collection->first_child)) { | ||||
|       current->value.collection->first_child = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|     jcoll_t *collection = NULL; | ||||
|  | ||||
|       current->value.collection->first_child->type = JENTITY_SINGLE; | ||||
|       current->value.collection->first_child->value = value; | ||||
|       current->value.collection->first_child->parent = current; | ||||
|  | ||||
|       current = current->value.collection->first_child; | ||||
|     if (current->type == JENTITY_SINGLE) { | ||||
|       collection = current->value.collection; | ||||
|     } else { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_SINGLE; | ||||
|       current->next->value = value; | ||||
|       current->next->parent = current->parent; | ||||
|       collection = current->pair.value.collection; | ||||
|     } | ||||
|  | ||||
|       current = current->next; | ||||
|     if (!(collection->end)) { | ||||
|       collection->begin = collection->end = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       collection->end->type = JENTITY_SINGLE; | ||||
|       collection->end->value = value; | ||||
|       collection->end->parent = current; | ||||
|       collection->end->next = NULL; | ||||
|     } else { | ||||
|       if (collection->end->type == JENTITY_PAIR && | ||||
|           collection->end->pair.value.type == JVAL_EMPTY) { | ||||
|         collection->end->pair.value = value; | ||||
|       } else { | ||||
|         jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|         entity->type = JENTITY_SINGLE; | ||||
|         entity->value = value; | ||||
|         entity->parent = current; | ||||
|         entity->next = NULL; | ||||
|  | ||||
|         collection->end->next = entity; | ||||
|  | ||||
|         collection->end = entity; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     break; | ||||
| @@ -226,28 +330,37 @@ void parse_token(token_t token) { | ||||
|     jval_t value = | ||||
|         (jval_t){.type = JVAL_DOUBLE, .num_dbl = token.value.num_frac}; | ||||
|  | ||||
|     if (current->type == JENTITY_PAIR && | ||||
|         current->pair.value.type == JVAL_EMPTY) { | ||||
|       current->pair.value = value; | ||||
|     } else if (current->type == JENTITY_SINGLE && | ||||
|                current->value.type == JVAL_COLLECTION && | ||||
|                current->value.collection->type == JCOLL_ARRAY && | ||||
|                !(current->value.collection->first_child)) { | ||||
|       current->value.collection->first_child = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|     jcoll_t *collection = NULL; | ||||
|  | ||||
|       current->value.collection->first_child->type = JENTITY_SINGLE; | ||||
|       current->value.collection->first_child->value = value; | ||||
|       current->value.collection->first_child->parent = current; | ||||
|  | ||||
|       current = current->value.collection->first_child; | ||||
|     if (current->type == JENTITY_SINGLE) { | ||||
|       collection = current->value.collection; | ||||
|     } else { | ||||
|       current->next = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       current->next->type = JENTITY_SINGLE; | ||||
|       current->next->value = value; | ||||
|       current->next->parent = current->parent; | ||||
|       collection = current->pair.value.collection; | ||||
|     } | ||||
|  | ||||
|       current = current->next; | ||||
|     if (!(collection->end)) { | ||||
|       collection->begin = collection->end = | ||||
|           (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|       collection->end->type = JENTITY_SINGLE; | ||||
|       collection->end->value = value; | ||||
|       collection->end->parent = current; | ||||
|       collection->end->parent = NULL; | ||||
|     } else { | ||||
|       if (collection->end->type == JENTITY_PAIR && | ||||
|           collection->end->pair.value.type == JVAL_EMPTY) { | ||||
|         collection->end->pair.value = value; | ||||
|       } else { | ||||
|         jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t)); | ||||
|  | ||||
|         entity->type = JENTITY_SINGLE; | ||||
|         entity->value = value; | ||||
|         entity->parent = current; | ||||
|         entity->next = NULL; | ||||
|  | ||||
|         collection->end->next = entity; | ||||
|  | ||||
|         collection->end = entity; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     break; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user