svalue_t* read_scm(source_t source_code) { size_t nbytes = read(STDIN_FILENO, source_code, 111000); if (nbytes == 0) { exit(EXIT_FAILURE); } token_stream toks = tokenize(source_code, 0, nbytes); token_t current_tok; while (toks.length > 0) { current_tok = peek_token(&toks); switch (current_tok.token_type) { case SYMBOL: printf("symbol: %s\n", current_tok.token.symbol); break; case IDENTIFIER: printf("identifer: %s\n", current_tok.token.identifier); break; case INTEGER: printf("integer: %s\n", current_tok.token.integer); break; case FLOATING: printf("floating: %s\n", current_tok.token.floating); break; case QUOTE: printf("quote: '\n"); break; case WSPACE: printf("whitespace\n"); break; case PAREN: printf("paren: %s\n", current_tok.token.parenthesis); break; case EMPTY: printf("this should not be empty\n"); break; case STRING: printf("string: %s\n", current_tok.token.string); break; default: printf("oops, there was an unknown token, check valgrind or gdb\n"); } pop_token(&toks); } return box_int(12); }
bool foreach_in_range(const char *range, uint32_t start, uint32_t end, RangeCallback callback, void *userdata) { RangeToken t; pop_token(&range, &t); if (t.type == 0) return true; for (;;) { if (t.type == '-') { pop_token(&range, &t); if (t.type != '#') return false; if (t.num < start || t.num > end) return false; if (callback != NULL) callback(start, t.num, userdata); pop_token(&range, &t); if (t.type == 0) return true; if (t.type != ',') return false; } else if (t.type == '#') { RangeToken t2; if (t.num < start || t.num > end) return false; pop_token(&range, &t2); if (t2.type == 0) { if (callback != NULL) callback(t.num, t.num, userdata); return true; } if (t2.type == ',') { if (callback != NULL) callback(t.num, t.num, userdata); } else if (t2.type == '-') { pop_token(&range, &t2); if (t2.type == 0) { if (callback != NULL) callback(t.num, end, userdata); return true; } if (t2.type == ',') { if (callback != NULL) callback(t.num, end, userdata); } else if (t2.type == '#') { if (t2.num < start || t2.num > end) return false; if (callback != NULL) callback(t.num, t2.num, userdata); pop_token(&range, &t); if (t.type == 0) return true; if (t.type != ',') return false; } else { return false; } } } else { return false; } pop_token(&range, &t); } }