<commit_before>#include "lex.h"
#include "ast.h"
#include "parse.h"
#include "eval.h"
#include "lib/float.h"
#include "lib/number.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

/*
static sl_token_t*
token(sl_parse_state_t* ps)
{
    return &ps->tokens[ps->current_token - 1];
}
*/

static sl_token_t*
peek_token(sl_parse_state_t* ps)
{
    return &ps->tokens[ps->current_token];
}

static sl_token_t*
next_token(sl_parse_state_t* ps)
{
    return &ps->tokens[ps->current_token++];
}

static void
error(sl_parse_state_t* ps, char* fmt, ...)
{
    char buff[1024];
    va_list va;
    va_start(va, fmt);
    vsnprintf(buff, 1023, fmt, va);
    sl_throw_message2(ps->vm, ps->vm->lib.SyntaxError, buff);
}

static sl_token_t*
expect_token(sl_parse_state_t* ps, sl_token_type_t type)
{
    sl_token_t* tok = next_token(ps);
    if(tok->type != type) {
        error(ps, "Unexpected token: @TODO [expect_token]");
    }
    return tok;
}

static sl_node_base_t*
if_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
while_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
for_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
class_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
def_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
primary_expression(sl_parse_state_t* ps)
{
    sl_token_t* tok;
    switch(peek_token(ps)->type) {
        case SL_TOK_INTEGER:
            tok = next_token(ps);
            return sl_make_immediate_node(sl_number_parse(ps->vm, tok->as.str.buff, tok->as.str.len));
        case SL_TOK_FLOAT:
            return sl_make_immediate_node(sl_make_float(ps->vm, next_token(ps)->as.dbl));
        default:
            error(ps, "Unexpected token: @TODO [primary_expression]");
            return NULL;
    }
}

static sl_node_base_t*
call_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    return primary_expression(ps);
}

static sl_node_base_t*
power_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    return call_expression(ps);
}

static sl_node_base_t*
unary_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    return power_expression(ps);
}

static sl_node_base_t*
mul_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    return unary_expression(ps);
}

static sl_node_base_t*
add_expression(sl_parse_state_t* ps)
{
    sl_node_base_t* left = mul_expression(ps);
    sl_node_base_t* right;
    sl_token_t* tok;
    while(peek_token(ps)->type == SL_TOK_PLUS || peek_token(ps)->type == SL_TOK_MINUS) {
        tok = next_token(ps);<commit_msg>parse *, /, % properly<commit_after>#include "lex.h"
#include "ast.h"
#include "parse.h"
#include "eval.h"
#include "lib/float.h"
#include "lib/number.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

/*
static sl_token_t*
token(sl_parse_state_t* ps)
{
    return &ps->tokens[ps->current_token - 1];
}
*/

static sl_token_t*
peek_token(sl_parse_state_t* ps)
{
    return &ps->tokens[ps->current_token];
}

static sl_token_t*
next_token(sl_parse_state_t* ps)
{
    return &ps->tokens[ps->current_token++];
}

static void
error(sl_parse_state_t* ps, char* fmt, ...)
{
    char buff[1024];
    va_list va;
    va_start(va, fmt);
    vsnprintf(buff, 1023, fmt, va);
    sl_throw_message2(ps->vm, ps->vm->lib.SyntaxError, buff);
}

static sl_token_t*
expect_token(sl_parse_state_t* ps, sl_token_type_t type)
{
    sl_token_t* tok = next_token(ps);
    if(tok->type != type) {
        error(ps, "Unexpected token: @TODO [expect_token]");
    }
    return tok;
}

static sl_node_base_t*
if_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
while_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
for_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
class_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
def_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    (void)ps;
    return NULL;
}

static sl_node_base_t*
primary_expression(sl_parse_state_t* ps)
{
    sl_token_t* tok;
    switch(peek_token(ps)->type) {
        case SL_TOK_INTEGER:
            tok = next_token(ps);
            return sl_make_immediate_node(sl_number_parse(ps->vm, tok->as.str.buff, tok->as.str.len));
        case SL_TOK_FLOAT:
            return sl_make_immediate_node(sl_make_float(ps->vm, next_token(ps)->as.dbl));
        default:
            error(ps, "Unexpected token: @TODO [primary_expression]");
            return NULL;
    }
}

static sl_node_base_t*
call_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    return primary_expression(ps);
}

static sl_node_base_t*
power_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    return call_expression(ps);
}

static sl_node_base_t*
unary_expression(sl_parse_state_t* ps)
{
    /* @TODO */
    return power_expression(ps);
}

static sl_node_base_t*
mul_expression(sl_parse_state_t* ps)
{
    sl_node_base_t* left = unary_expression(ps);
    sl_node_base_t* right;
    sl_token_t* tok;
    char* id;
    while(peek_token(ps)->type == SL_TOK_TIMES || peek_token(ps)->type == SL_TOK_DIVIDE ||
            peek_token(ps)->type == SL_TOK_MOD) {
        tok = next_token(ps);
        right = unary_expression(ps);
        switch(tok->type) {
            case SL_TOK_TIMES:  id = "*"; break;
            case SL_TOK_DIVIDE: id = "/"; break;
            case SL_TOK_MOD:    id = "%"; break;
            default: /* wtf? */ break;
        }
        left = sl_make_send_node(ps, left, id, 1, &right);
    }
    return left;
}

static sl_node_base_t*
add_expression(sl_parse_state_t* ps)
{
    sl_node_base_t* left = mul_expression(ps);
    sl_node_base_t* right;
    sl_token_t* tok;
    while(peek_token(ps)->type == SL_TOK_PLUS || peek_token(ps)->type == SL_TOK_MINUS) {
        tok = next_token(ps);
{'fraction_non_alphanumeric': 0.13988964621876016, 'fraction_numerical': 0.0034079844206426485, 'mean_word_length': 3.453034682080925, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 49, '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': '1814795', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2478, 'n_words': 414}