2024-11-18 09:55:02 +00:00
|
|
|
#include "../debug.h"
|
|
|
|
|
#include "../line-ed/line-ed.h"
|
2024-11-01 21:41:44 +00:00
|
|
|
#include "cmd.h"
|
|
|
|
|
|
|
|
|
|
#include <blue/cmd.h>
|
2024-11-18 09:55:02 +00:00
|
|
|
#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();
|
2024-11-19 15:59:05 +00:00
|
|
|
line_ed_set_flags(ed, LINE_ED_REMOVE_CONTINUATIONS);
|
|
|
|
|
|
2024-11-18 09:55:02 +00:00
|
|
|
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);
|
|
|
|
|
}
|