<commit_before>#include <stdlib.h>
#include <string.h>
#include "structures.h"
#include "constants.h"

void build_array(struct Value_array * array, struct Tokens * tokens){
    while(tokens->tokens[tokens->counter].type != 'e'){
        tokens->counter++;
        if (tokens->counter >= tokens->length) {
            ERROR("Unbalanced array");
        }
        if(tokens->tokens[tokens->counter].type == 's'){
            struct Value * val = malloc(sizeof(struct Value));
            val->type = 's';
            val->data.str = string_copy_stack(&tokens->tokens[tokens->counter].data);
            array->values[array->size] = val;
            array->size++;
        }
        else if(tokens->tokens[tokens->counter].type == 'n'){
            struct Value * val = malloc(sizeof(struct Value));
            if(string_contains(dot_const, &tokens->tokens[tokens->counter].data)){
                float content = atof(tokens->tokens[tokens->counter].data.body);
                val->type='f';
                val->data.fl=content;
            } else {
                long content = atol(tokens->tokens[tokens->counter].data.body);
                val->type='l';
                val->data.ln=content;
            }
            array->values[array->size] = val;
            array->size++;
        }
        else if(tokens->tokens[tokens->counter].type == 'k'){
            struct Value * val = malloc(sizeof(struct Value));
            val->type = 'k';
            
            val->data.str = string_copy_stack(&tokens->tokens[tokens->counter].data);
            array->values[array->size] = val;
            array->size++;
        }
        else if(tokens->tokens[tokens->counter].type == 'b'){
            struct Value * val = malloc(sizeof(struct Value));
            val->type = 'a';
            val->data.array = malloc(sizeof(struct Value_array));
            val->data.array->size = 0;
            build_array(val->data.array, tokens);
            array->values[array->size] = val;
            array->size++;
            // to advance beyond the inner closing bracket, otherwise it
            // will cause the outer array to stop building
            tokens->counter++;
        }
    }
}<commit_msg>Fix array parsing<commit_after>#include <stdlib.h>
#include <string.h>
#include "structures.h"
#include "constants.h"
#include "base_util.h"

void build_array(struct Value_array * array, struct Tokens * tokens){
    char c;
    while ((c = tokens->tokens[++tokens->counter].type) != 'e'){
        if (tokens->counter >= tokens->length) {
            ERROR("Unbalanced array");
        }
        if(c == 's'){
            struct Value * val = malloc(sizeof(struct Value));
            val->type = 's';
            val->data.str = string_copy_stack(&tokens->tokens[tokens->counter].data);
            array->values[array->size] = val;
            array->size++;
        }
        else if(c == 'n'){
            struct Value * val = malloc(sizeof(struct Value));
            if(string_contains(dot_const, &tokens->tokens[tokens->counter].data)){
                float content = atof(tokens->tokens[tokens->counter].data.body);
                val->type='f';
                val->data.fl=content;
            } else {
                long content = atol(tokens->tokens[tokens->counter].data.body);
                val->type='l';
                val->data.ln=content;
            }
            array->values[array->size] = val;
            array->size++;
        }
        else if(c == 'k'){
            struct Value * val = malloc(sizeof(struct Value));
            val->type = 'k';
            
            val->data.str = string_copy_stack(&tokens->tokens[tokens->counter].data);
            array->values[array->size] = val;
            array->size++;
        }
        else if(c == 'b'){
            struct Value * val = malloc(sizeof(struct Value));
            val->type = 'a';
            val->data.array = malloc(sizeof(struct Value_array));
            val->data.array->size = 0;
            build_array(val->data.array, tokens);
            array->values[array->size] = val;
            array->size++;
        } else if (c == 0) {
            //pass
        } else {
            for (int i = 0; i <= tokens->counter; i++) {
                struct String s = tokens->tokens[i].data;
                printf("%i \"", i);
                printf(s.length == 0 ? "" : s.body);
                printf("\" '%c' '%i'\n", tokens->tokens[i].type, (int) tokens->tokens[i].type);
            }
            ERROR("Invalid token type in array: '%c'", c);
        }
    }
}
{'fraction_non_alphanumeric': 0.16301969365426697, 'fraction_numerical': 0.0010940919037199124, 'mean_word_length': 1.7770352369380316, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5059897', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1258, 'n_words': 252}