aboutsummaryrefslogtreecommitdiff
path: root/test/sexp.c
blob: 45e74a4ff66f82ae39537b68dd4571f78f2fee4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <string.h>

#define ANY_SEXP_IMPLEMENT
//#define ANY_SEXP_NO_BOXING
//#define ANY_SEXP_NO_STRING
#include "any_sexp.h"

int main()
{
    const char *s = "(a b c (sub list) ())\n"
                    "(another lispy thingy)\n"
                    "() id ciao 20 a1020|x|3a\n"
                    ";comm\n3433 ;s\n"
                    "'symbol 'another 'a\n"
                    "'(a b c z) '('a) ''x  \"escape \\\"inside the string\"\n"
                    "\"string very long sus\" (\"a\" \"b\")\n"
                    "10 -20 30 41 -22345 123456789 '1\n";

    any_sexp_reader_t reader;
    any_sexp_reader_string_t string;
    any_sexp_reader_string_init(&reader, &string, s, strlen(s));

    any_sexp_t sexp = any_sexp_read(&reader);
    while (!ANY_SEXP_IS_ERROR(sexp)) {
        //printf("  %d   ", any_sexp_print(sexp));
        any_sexp_print(sexp);
        putchar('\n');
        any_sexp_free_list(sexp);
        sexp = any_sexp_read(&reader);
    }

    any_sexp_t pair = any_sexp_cons(any_sexp_number(1), any_sexp_number(2));
    any_sexp_print(pair);
    putchar('\n');

    any_sexp_t ap = any_sexp_append(any_sexp_cons(any_sexp_number(3), ANY_SEXP_NIL),
                                    any_sexp_cons(pair, ANY_SEXP_NIL));

    any_sexp_print(ap);
    putchar('\n');
    any_sexp_free_list(ap);

    //printf("%zu\n", sizeof(any_sexp_t));

    return 0;
}