frontend: split interactive and non-interactive modes into separate commands
This commit is contained in:
@@ -1,3 +1,66 @@
|
||||
#include "../debug.h"
|
||||
#include "../line-ed/line-ed.h"
|
||||
#include "cmd.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/term.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
|
||||
{
|
||||
char buf[1024];
|
||||
struct line_ed *ed = line_ed_create();
|
||||
struct ivy_lexer *lex;
|
||||
enum ivy_status status = ivy_lexer_create(&lex);
|
||||
|
||||
if (status != IVY_OK) {
|
||||
line_ed_destroy(ed);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ivy_lexer_set_source(lex, &ed->l_line_source);
|
||||
|
||||
while (true) {
|
||||
struct ivy_token *tok = ivy_lexer_read(lex);
|
||||
status = ivy_lexer_get_status(lex);
|
||||
if (status == IVY_ERR_EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (status != IVY_OK) {
|
||||
b_err("lex error (%s)",
|
||||
ivy_status_to_string(ivy_lexer_get_status(lex)));
|
||||
break;
|
||||
}
|
||||
|
||||
print_lex_token(tok);
|
||||
#if 0
|
||||
long v = line_ed_readline(ed, buf, sizeof buf);
|
||||
if (v == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (v == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
buf[strcspn(buf, "\n")] = 0;
|
||||
|
||||
printf("input: '%s'\n", buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
ivy_lexer_destroy(lex);
|
||||
line_ed_destroy(ed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
B_COMMAND(CMD_REPL, CMD_ROOT)
|
||||
{
|
||||
B_COMMAND_NAME("shell");
|
||||
B_COMMAND_SHORT_NAME('S');
|
||||
B_COMMAND_DESC("start an interactive Ivy shell.");
|
||||
B_COMMAND_HELP_OPTION();
|
||||
B_COMMAND_FUNCTION(repl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user