<commit_before>/** 
  * parse.c
  * Lake Scheme
  *
  * Copyright 2011 <NAME>
  * MIT License
  *
  */

#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dlist.h"
#include "int.h"
#include "lake.h"
#include "list.h"
#include "parse.h"
#include "string.h"
#include "sym.h"

struct context {
    char *s;
    size_t n;
    size_t i;
    size_t mark;
};
typedef struct context Ctx;

static void warn_trailing(Ctx *ctx)
{
    if (ctx->i < ctx->n) {
        char *trailing = ctx->s + ctx->i;
        printf("warning: ignoring %d trailing chars: %s\n", (int)(ctx->n - ctx->i), trailing);
    }
}

static LakeVal *_parse_expr(Ctx *ctx);

LakeVal *parse_expr(char *s, size_t n)
{
    Ctx ctx = { s, n, 0, 0 };
    LakeVal *result = _parse_expr(&ctx);
    warn_trailing(&ctx);
    return result;
}

LakeList *parse_exprs(char *s, size_t n)
{
    Ctx ctx = { s, n, 0, 0 };
    LakeList *results = list_make();
    LakeVal *result;
    while (ctx.i < ctx.n) {
        result = _parse_expr(&ctx);
        if (result && result != VAL(PARSE_ERR)) {
            list_append(results, result);
        }
        else {
            list_free(results);
            return NULL;
        }
    }
    warn_trailing(&ctx);
    return results;
}

static int maybe_spaces(Ctx *ctx);

static char peek(Ctx *ctx)
{
    if (ctx->i < ctx->n) return ctx->s[ctx->i];
    return PARSE_EOF;
}

LakeList *parse_naked_list(char *s, size_t n)
{
    Ctx ctx = { s, n, 0, 0 };
    LakeList *list = list_make();
    char c;
    maybe_spaces(&ctx);<commit_msg>don't warn about trailing comments during parsing<commit_after>/** 
  * parse.c
  * Lake Scheme
  *
  * Copyright 2011 <NAME>
  * MIT License
  *
  */

#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dlist.h"
#include "int.h"
#include "lake.h"
#include "list.h"
#include "parse.h"
#include "string.h"
#include "sym.h"

struct context {
    char *s;
    size_t n;
    size_t i;
    size_t mark;
};
typedef struct context Ctx;

static LakeVal *_parse_expr(Ctx *ctx);
static int maybe_spaces(Ctx *ctx);

static char peek(Ctx *ctx)
{
    if (ctx->i < ctx->n) return ctx->s[ctx->i];
    return PARSE_EOF;
}

static void warn_trailing(Ctx *ctx)
{
    maybe_spaces(ctx);
    /* don't warn about trailing comments */
    if (ctx->i < ctx->n && peek(ctx) != ';') {
        char *trailing = ctx->s + ctx->i;
        printf("warning: ignoring %d trailing chars: %s\n", (int)(ctx->n - ctx->i), trailing);
    }
}

LakeVal *parse_expr(char *s, size_t n)
{
    Ctx ctx = { s, n, 0, 0 };
    LakeVal *result = _parse_expr(&ctx);
    warn_trailing(&ctx);
    return result;
}

LakeList *parse_exprs(char *s, size_t n)
{
    Ctx ctx = { s, n, 0, 0 };
    LakeList *results = list_make();
    LakeVal *result;
    while (ctx.i < ctx.n) {
        result = _parse_expr(&ctx);
        if (result && result != VAL(PARSE_ERR)) {
            list_append(results, result);
        }
        else {
            list_free(results);
            return NULL;
        }
    }
    warn_trailing(&ctx);
    return results;
}

LakeList *parse_naked_list(char *s, size_t n)
{
    Ctx ctx = { s, n, 0, 0 };
    LakeList *list = list_make();
    char c;
    maybe_spaces(&ctx);
{'fraction_non_alphanumeric': 0.15878900216249614, 'fraction_numerical': 0.006178560395427865, 'mean_word_length': 2.6138392857142856, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, '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': '4838537', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1242, 'n_words': 316}