Commit 89d948a3 authored by Chris Müller's avatar Chris Müller
Browse files

add general list parsing based on linked-lists

parent 5fa49f55
......@@ -112,7 +112,7 @@ int org_cherry_env_add(struct org_cherry_symbollist*
extern struct org_cherry_symbollist* org_cherry_global_symbollist;
extern struct org_cherry_value* org_cherry_symbol_emptylist;
extern struct org_cherry_value* org_cherry_emptylist;
extern struct org_cherry_value* org_cherry_true;
extern struct org_cherry_value* org_cherry_false;
extern struct org_cherry_value* org_cherry_symbol_quote;
......
......@@ -665,7 +665,37 @@ org_cherry_token_length(struct org_cherry_context* context)
static struct org_cherry_value*
org_cherry_read_pair(struct org_cherry_context* context)
{
const byte_t* pos;
enum org_cherry_tok tok;
struct org_cherry_value* head;
struct org_cherry_value* tail;
pos = org_cherry_pos(context);
tok = org_cherry_lex(context);
if(tok == TOK_ROUNDRIGHTBRACE)
return org_cherry_emptylist;
org_cherry_rewind(context, pos);
head = org_cherry_read(context);
pos = org_cherry_pos(context);
tok = org_cherry_lex(context);
if(tok == TOK_DOT) {
tail = org_cherry_read(context);
if(org_cherry_lex(context) != TOK_ROUNDRIGHTBRACE) {
org_cherry_error(context, "No trailing right parenthesis in improper list literal");
}
return (struct org_cherry_value*) org_cherry_list_cons(head, tail);
}
org_cherry_rewind(context, pos);
tail = org_cherry_read_pair(context);
return (struct org_cherry_value*) org_cherry_list_cons(head, tail);
}
struct org_cherry_value*
......
......@@ -27,7 +27,7 @@
// ----------------------------------------------------------------------------
struct org_cherry_symbollist* org_cherry_global_symbollist;
struct org_cherry_value* org_cherry_symbol_emptylist;
struct org_cherry_value* org_cherry_emptylist;
struct org_cherry_value* org_cherry_true;
struct org_cherry_value* org_cherry_false;
......@@ -297,8 +297,8 @@ org_cherry_initialize(struct org_cherry_pair* arguments)
org_cherry_false->meta.type = CY_BOOLEAN;
org_cherry_false->boolean_value = 0;
org_cherry_symbol_emptylist = org_cherry_value_alloc();
org_cherry_symbol_emptylist->meta.type = CY_EMPTYLIST;
org_cherry_emptylist = org_cherry_value_alloc();
org_cherry_emptylist->meta.type = CY_EMPTYLIST;
org_cherry_symbol_quote = org_cherry_symbol("quote");
org_cherry_symbol_define = org_cherry_symbol("define");
......
......@@ -21,7 +21,7 @@
static void test_initialization(const_pointer data)
{
assert(IS_NULL(org_cherry_symbol_emptylist));
assert(IS_NULL(org_cherry_emptylist));
assert(IS_BOOLEAN(org_cherry_true));
assert(IS_BOOLEAN(org_cherry_false));
assert(IS_SYMBOL(org_cherry_symbol_quote));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment