enhanced the interactive mode processing a bit
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
658e69635a
commit
65d64f7c5f
36
bin/main.c
36
bin/main.c
@ -538,6 +538,7 @@ static int on_fed_cnode_in_interactive_mode (hcl_t* hcl, hcl_cnode_t* obj)
|
||||
xtn->feed.pos = xtn->feed.len; /* arrange to discard the rest of the line */
|
||||
show_prompt (hcl, 0);
|
||||
}
|
||||
#if 0
|
||||
else
|
||||
{
|
||||
hcl_oow_t i;
|
||||
@ -559,6 +560,7 @@ static int on_fed_cnode_in_interactive_mode (hcl_t* hcl, hcl_cnode_t* obj)
|
||||
show_prompt (hcl, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -643,6 +645,7 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
|
||||
{
|
||||
int n;
|
||||
hcl_oow_t pos;
|
||||
hcl_oow_t len;
|
||||
|
||||
/* read a while line regardless of the actual expression */
|
||||
n = get_line(hcl, xtn, fp);
|
||||
@ -664,11 +667,42 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
|
||||
pos = xtn->feed.pos;
|
||||
/* do this before calling hcl_feedbchars() so that the callback sees the updated value */
|
||||
xtn->feed.pos = xtn->feed.len;
|
||||
if (hcl_feedbchars(hcl, &xtn->feed.buf[pos], xtn->feed.len - pos) <= -1)
|
||||
len = xtn->feed.len - pos;
|
||||
if (hcl_feedbchars(hcl, &xtn->feed.buf[pos], len) <= -1)
|
||||
{
|
||||
print_error (hcl, "failed to feed");
|
||||
show_prompt (hcl, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* a := (1 + 2 ##askldfjasldkfjasd
|
||||
); b := (2 + 3
|
||||
// TODO: how to know if 'b := (2 + 3' is still not completely compiled?.
|
||||
|
||||
|
||||
just new lines..
|
||||
or lines with comments only...
|
||||
+ 1 2 <-- prohibited binary operator + <--- don't look right...
|
||||
*/
|
||||
|
||||
if (xtn->feed.ongoing && hcl_getbclen(hcl) > 0 && !hcl_feedpending(hcl))
|
||||
{
|
||||
execute_in_interactive_mode (hcl);
|
||||
xtn->feed.ongoing = 0;
|
||||
if (len > 0) show_prompt (hcl, 0);
|
||||
}
|
||||
else if (len > 0)
|
||||
{
|
||||
if (!xtn->feed.ongoing && !hcl_feedpending(hcl))
|
||||
show_prompt (hcl, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* eof reached */
|
||||
hcl_logbfmt (hcl, HCL_LOG_STDOUT, "\n");
|
||||
if (hcl_feedpending(hcl)) print_error (hcl, "sudden end of input");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -2489,6 +2489,10 @@ HCL_EXPORT int hcl_feeduchars (
|
||||
hcl_oow_t len
|
||||
);
|
||||
|
||||
HCL_EXPORT int hcl_feedpending (
|
||||
hcl_t* hcl
|
||||
);
|
||||
|
||||
HCL_EXPORT int hcl_feedbchars (
|
||||
hcl_t* hcl,
|
||||
const hcl_bch_t* data,
|
||||
|
20
lib/read.c
20
lib/read.c
@ -2990,7 +2990,7 @@ not_consumed:
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int _feed_char (hcl_t* hcl, hcl_ooci_t c)
|
||||
static int feed_char (hcl_t* hcl, hcl_ooci_t c)
|
||||
{
|
||||
/*hcl_logbfmt (hcl, HCL_LOG_STDERR, "FEED->[%jc] %d STATE->%d\n", c, c, FLX_STATE(hcl));*/
|
||||
|
||||
@ -3022,19 +3022,6 @@ static int _feed_char (hcl_t* hcl, hcl_ooci_t c)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int feed_char (hcl_t* hcl, hcl_ooci_t c)
|
||||
{
|
||||
int n;
|
||||
n = _feed_char(hcl, c);
|
||||
if (n <= -1)
|
||||
{
|
||||
/* arrange to read from the start phase next time
|
||||
* in case feeding continues after an error */
|
||||
FEED_CONTINUE (hcl, HCL_FLX_START);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void feed_update_lx_loc (hcl_t* hcl, hcl_ooci_t ch)
|
||||
{
|
||||
if (is_linebreak(ch))
|
||||
@ -3234,6 +3221,11 @@ int hcl_endfeed (hcl_t* hcl)
|
||||
return hcl_feed(hcl, HCL_NULL, 0);
|
||||
}
|
||||
|
||||
int hcl_feedpending (hcl_t* hcl)
|
||||
{
|
||||
return hcl->c->r.st != HCL_NULL;
|
||||
}
|
||||
|
||||
int hcl_feed (hcl_t* hcl, const hcl_ooch_t* data, hcl_oow_t len)
|
||||
{
|
||||
/* TODO: need to return the number of processed characters?
|
||||
|
Loading…
Reference in New Issue
Block a user