Added a simple REPL.
This commit is contained in:
parent
238a9a3bbe
commit
3a2afdea69
3 changed files with 93 additions and 1 deletions
24
src/parser.c
24
src/parser.c
|
|
@ -1202,4 +1202,28 @@ Bytecode *parse_file_to_bytecode(const char *path) {
|
|||
|
||||
free(src);
|
||||
return bc;
|
||||
}
|
||||
|
||||
Bytecode *parse_string_to_bytecode(const char *source) {
|
||||
if (!source) {
|
||||
fprintf(stderr, "Error: null source provided\n");
|
||||
return NULL;
|
||||
}
|
||||
size_t len = strlen(source);
|
||||
|
||||
/* reset error state */
|
||||
g_has_error = 0;
|
||||
g_err_pos = 0;
|
||||
g_err_msg[0] = '\0';
|
||||
|
||||
Bytecode *bc = compile_minimal(source, len);
|
||||
|
||||
if (g_has_error) {
|
||||
int line = 1, col = 1;
|
||||
calc_line_col(source, len, g_err_pos, &line, &col);
|
||||
fprintf(stderr, "Parse error <input>:%d:%d: %s\n", line, col, g_err_msg);
|
||||
if (bc) bytecode_free(bc);
|
||||
return NULL;
|
||||
}
|
||||
return bc;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue