lib/read.c - updated code to reset some internal data upon an error so that another call to hcl_feed() and variants don't suffer
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
73e3f189a8
commit
658e69635a
12
bin/main.c
12
bin/main.c
@ -642,6 +642,7 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
hcl_oow_t pos;
|
||||||
|
|
||||||
/* read a while line regardless of the actual expression */
|
/* read a while line regardless of the actual expression */
|
||||||
n = get_line(hcl, xtn, fp);
|
n = get_line(hcl, xtn, fp);
|
||||||
@ -649,6 +650,7 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
|
|||||||
if (n == 0) break;
|
if (n == 0) break;
|
||||||
|
|
||||||
/* feed the line */
|
/* feed the line */
|
||||||
|
#if 0
|
||||||
while (xtn->feed.pos < xtn->feed.len)
|
while (xtn->feed.pos < xtn->feed.len)
|
||||||
{
|
{
|
||||||
hcl_bch_t c = xtn->feed.buf[xtn->feed.pos++];
|
hcl_bch_t c = xtn->feed.buf[xtn->feed.pos++];
|
||||||
@ -658,6 +660,16 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
|
|||||||
show_prompt (hcl, 0);
|
show_prompt (hcl, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
print_error (hcl, "failed to feed");
|
||||||
|
show_prompt (hcl, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
17
lib/read.c
17
lib/read.c
@ -167,7 +167,12 @@ static struct
|
|||||||
HCL_AID(HCL_CONCODE_VLIST) { HCL_TOK_VBAR, HCL_SYNERR_VBAR, VOCA_VLIST } /* VLIST | | */
|
HCL_AID(HCL_CONCODE_VLIST) { HCL_TOK_VBAR, HCL_SYNERR_VBAR, VOCA_VLIST } /* VLIST | | */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
static int init_compiler (hcl_t* hcl);
|
static int init_compiler (hcl_t* hcl);
|
||||||
|
static void feed_continue (hcl_t* hcl, hcl_flx_state_t state);
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------- */
|
||||||
|
|
||||||
static HCL_INLINE int is_spacechar (hcl_ooci_t c)
|
static HCL_INLINE int is_spacechar (hcl_ooci_t c)
|
||||||
{
|
{
|
||||||
@ -1250,7 +1255,7 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
/* this function composes an s-expression non-recursively
|
/* this function composes an s-expression non-recursively
|
||||||
* by manipulating its own stack. */
|
* by manipulating its own stack. */
|
||||||
|
|
||||||
/*hcl_logbfmt (hcl, HCL_LOG_STDERR, "TOKEN => [%.*js] type=%d LOC=%d.%d\n", TOKEN_NAME_LEN(hcl), TOKEN_NAME_PTR(hcl), TOKEN_TYPE(hcl), TOKEN_LOC(hcl)->line, TOKEN_LOC(hcl)->colm);*/
|
/*hcl_logbfmt (hcl, HCL_LOG_STDERR, "TOKEN [%d] EOL[%d]=> [%.*js] type=%d LOC=%d.%d\n", TOKEN_TYPE(hcl), HCL_TOK_EOL, TOKEN_NAME_LEN(hcl), TOKEN_NAME_PTR(hcl), TOKEN_TYPE(hcl), TOKEN_LOC(hcl)->line, TOKEN_LOC(hcl)->colm);*/
|
||||||
if (frd->expect_include_file)
|
if (frd->expect_include_file)
|
||||||
{
|
{
|
||||||
/* the #include directive is an exception to the general expression rule.
|
/* the #include directive is an exception to the general expression rule.
|
||||||
@ -1776,7 +1781,7 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* upon exit, we must be at the top level */
|
/* upon exit, we must be at the top level */
|
||||||
HCL_ASSERT (hcl, frd->level == 0);
|
HCL_ASSERT (hcl, frd->flagv & AT_BEGINNING);
|
||||||
|
|
||||||
HCL_ASSERT (hcl, hcl->c->r.st == HCL_NULL);
|
HCL_ASSERT (hcl, hcl->c->r.st == HCL_NULL);
|
||||||
HCL_ASSERT (hcl, frd->obj != HCL_NULL);
|
HCL_ASSERT (hcl, frd->obj != HCL_NULL);
|
||||||
@ -1815,9 +1820,11 @@ oops:
|
|||||||
hcl_freecnode (hcl, frd->obj);
|
hcl_freecnode (hcl, frd->obj);
|
||||||
frd->obj = HCL_NULL;
|
frd->obj = HCL_NULL;
|
||||||
}
|
}
|
||||||
|
HCL_MEMSET (frd, 0, HCL_SIZEOF(*frd));
|
||||||
|
|
||||||
/* clean up the reader stack for a list */
|
/* clean up the reader stack for a list */
|
||||||
feed_clean_up_reader_stack (hcl);
|
feed_clean_up_reader_stack (hcl);
|
||||||
|
feed_continue (hcl, HCL_FLX_START);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1921,10 +1928,9 @@ static int feed_wrap_up_with_str (hcl_t* hcl, const hcl_ooch_t* str, hcl_oow_t l
|
|||||||
return feed_wrap_up(hcl, type);
|
return feed_wrap_up(hcl, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int feed_continue (hcl_t* hcl, hcl_flx_state_t state)
|
static void feed_continue (hcl_t* hcl, hcl_flx_state_t state)
|
||||||
{
|
{
|
||||||
hcl->c->feed.lx.state = state;
|
hcl->c->feed.lx.state = state;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int feed_continue_with_char (hcl_t* hcl, hcl_ooci_t c, hcl_flx_state_t state)
|
static int feed_continue_with_char (hcl_t* hcl, hcl_ooci_t c, hcl_flx_state_t state)
|
||||||
@ -1937,7 +1943,7 @@ static int feed_continue_with_char (hcl_t* hcl, hcl_ooci_t c, hcl_flx_state_t st
|
|||||||
#define FEED_WRAP_UP(hcl, type) do { if (feed_wrap_up(hcl, type) <= -1) return -1; } while(0)
|
#define FEED_WRAP_UP(hcl, type) do { if (feed_wrap_up(hcl, type) <= -1) return -1; } while(0)
|
||||||
#define FEED_WRAP_UP_WITH_CHAR(hcl, c, type) do { if (feed_wrap_up_with_char(hcl, c, type) <= -1) return -1; } while(0)
|
#define FEED_WRAP_UP_WITH_CHAR(hcl, c, type) do { if (feed_wrap_up_with_char(hcl, c, type) <= -1) return -1; } while(0)
|
||||||
#define FEED_WRAP_UP_WITH_CHARS(hcl, str, len, type) do { if (feed_wrap_up_with_str(hcl, str, len, type) <= -1) return -1; } while(0)
|
#define FEED_WRAP_UP_WITH_CHARS(hcl, str, len, type) do { if (feed_wrap_up_with_str(hcl, str, len, type) <= -1) return -1; } while(0)
|
||||||
#define FEED_CONTINUE(hcl, state) do { if (feed_continue(hcl, state) <= -1) return -1; } while(0)
|
#define FEED_CONTINUE(hcl, state) (feed_continue(hcl, state))
|
||||||
#define FEED_CONTINUE_WITH_CHAR(hcl, c, state) do { if (feed_continue_with_char(hcl, c, state) <= -1) return -1; } while(0)
|
#define FEED_CONTINUE_WITH_CHAR(hcl, c, state) do { if (feed_continue_with_char(hcl, c, state) <= -1) return -1; } while(0)
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
@ -3311,6 +3317,7 @@ oops:
|
|||||||
* leave_list() error in flx_hmarked_ident() before a full cnode is processed
|
* leave_list() error in flx_hmarked_ident() before a full cnode is processed
|
||||||
*/
|
*/
|
||||||
feed_clean_up_reader_stack (hcl);
|
feed_clean_up_reader_stack (hcl);
|
||||||
|
feed_continue (hcl, HCL_FLX_START);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user