// append opens the given file or stream and parses it as a .dc file. The distributed // classes defined in the file are added to the list of classes associated with the File. // When appending from a stream, a filename is optional only used to report errors. bool append(File* f, istream &in, const string &filename) { init_file_parser(in, filename, *f); run_parser(); cleanup_parser(); return (parser_error_count() == 0); }
int main(int argc, char* *argv){ init_parser(); lenv *e = lenv_new(); lenv_add_builtins(e); if (access(STD_LIB, F_OK) != -1){ lval *err = builtin_load(e, lval_add(lval_sexpr(), lval_str((char *)STD_LIB))); if (err->type == LVAL_ERR) lval_println(err); lval_del(err); } else { printf("Can't find stdlib at %s.\n", STD_LIB); } if (argc > 1){ for (int i = 1; i < argc; i++){ lval *args = lval_add(lval_sexpr(), lval_str(argv[i])); lval *x = builtin_load(e, args); if (x->type == LVAL_ERR) lval_println(x); lval_del(x); } } else { puts("Aroma Version v0.0.0.1"); puts("Press Ctrl+C to Exit."); char *input = NULL; mpc_result_t r; while (true){ input = readline(">>> "); if (strlen(input) < 1) { continue; } add_history(input); if (mpc_parse("<stdin>", input, Lispy, &r)){ /* mpc_ast_print(r.output); */ lval *x = lval_eval(e, lval_read(r.output)); lval_println(x); lval_del(x); mpc_ast_delete(r.output); } else { mpc_err_print(r.error); mpc_err_delete(r.error); } /* printf("%s\n", input); */ free(input); } } lenv_del(e); cleanup_parser(); return 0; }
string parse_value(const DistributedType* dtype, istream &in, bool &err) { string value; try { init_value_parser(in, "parse_value()", dtype, value); run_parser(); cleanup_parser(); } catch(const exception& e) { err = true; return string("parse_value() error: ") + e.what(); } if(parser_error_count() > 0) { err = true; return string("parse value(): unknown error"); } err = false; return value; }
/** * Free the template arrays */ static void cleanup_template_parser(void) { cleanup_parser(&profile_parser); cleanup_parser(&room_parser); cleanup_parser(&vault_parser); }