added hcl_getsynerrnum() and enhanced EOF handling

This commit is contained in:
2018-07-28 04:08:09 +00:00
parent 4280387771
commit 1b59610444
10 changed files with 56 additions and 8 deletions

View File

@ -420,6 +420,7 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -375,6 +375,12 @@ void hcl_getsynerr (hcl_t* hcl, hcl_synerr_t* synerr)
if (synerr) *synerr = hcl->c->synerr;
}
hcl_synerrnum_t hcl_getsynerrnum (hcl_t* hcl)
{
HCL_ASSERT (hcl, hcl->c != HCL_NULL);
return hcl->c->synerr.num;
}
void hcl_setsynerrbfmt (hcl_t* hcl, hcl_synerrnum_t num, const hcl_ioloc_t* loc, const hcl_oocs_t* tgt, const hcl_bch_t* msgfmt, ...)
{
static hcl_bch_t syntax_error[] = "syntax error - ";

View File

@ -169,6 +169,7 @@ enum hcl_iotok_type_t
HCL_IOTOK_LBRACE, /* { */
HCL_IOTOK_RBRACE, /* } */
HCL_IOTOK_VBAR,
HCL_IOTOK_EOL, /* end of line */
HCL_IOTOK_INCLUDE
};

View File

@ -2651,7 +2651,6 @@ int hcl_server_start (hcl_server_t* server, const hcl_bch_t* addrs)
free_worker (worker);
}
}
}
}
}

View File

@ -187,6 +187,9 @@ enum hcl_trait_t
HCL_DEBUG_BIGINT = (1u << 1),
#endif
/* command line mode */
HCL_CLI_MODE = (1u << 7),
/* perform no garbage collection when the heap is full.
* you still can use hcl_gc() explicitly. */
HCL_NOGC = (1u << 8),
@ -1754,6 +1757,9 @@ HCL_EXPORT void hcl_getsynerr (
hcl_synerr_t* synerr
);
HCL_EXPORT hcl_synerrnum_t hcl_getsynerrnum (
hcl_t* hcl
);
HCL_EXPORT void hcl_setsynerrbfmt (
hcl_t* hcl,

View File

@ -1674,6 +1674,7 @@ int main (int argc, char* argv[])
{ ":log", 'l' },
{ ":memsize", 'm' },
{ "large-pages", '\0' },
{ "cli-mode", '\0' },
#if defined(HCL_BUILD_DEBUG)
{ ":debug", '\0' }, /* NOTE: there is no short option for --debug */
#endif
@ -1688,6 +1689,7 @@ int main (int argc, char* argv[])
const char* logopt = HCL_NULL;
hcl_oow_t memsize = MIN_MEMSIZE;
int large_pages = 0;
int cli_mode = 0;
#if defined(HCL_BUILD_DEBUG)
const char* dbgopt = HCL_NULL;
@ -1722,6 +1724,11 @@ int main (int argc, char* argv[])
large_pages = 1;
break;
}
else if (hcl_comp_bcstr(opt.lngopt, "cli-mode") == 0)
{
cli_mode = 1;
break;
}
#if defined(HCL_BUILD_DEBUG)
else if (hcl_comp_bcstr(opt.lngopt, "debug") == 0)
{
@ -1788,6 +1795,8 @@ int main (int argc, char* argv[])
/*trait |= HCL_NOGC;*/
trait |= HCL_AWAIT_PROCS;
if (cli_mode) trait |= HCL_CLI_MODE;
hcl_setoption (hcl, HCL_TRAIT, &trait);
/* disable GC logs */
@ -1879,7 +1888,7 @@ count++;
else if (hcl->errnum == HCL_ESYNERR)
{
print_synerr (hcl);
if (xtn->reader_istty) continue;
if (xtn->reader_istty && hcl_getsynerrnum(hcl) != HCL_SYNERR_EOF) continue;
}
else
{

View File

@ -58,6 +58,7 @@ static struct voca_t
{ 7, { '#','\\','s','p','a','c','e' } },
{ 5, { '#','\\','t','a','b' } },
{ 6, { '#','\\','v','t','a','b' } },
{ 5, { '<','E','O','L','>' } },
{ 5, { '<','E','O','F','>' } }
};
@ -75,6 +76,7 @@ enum voca_id_t
VOCA_TAB,
VOCA_VTAB,
VOCA_EOL,
VOCA_EOF
};
typedef enum voca_id_t voca_id_t;
@ -1013,7 +1015,17 @@ retry:
do
{
/* skip spaces */
while (is_spacechar(hcl->c->lxc.c)) GET_CHAR (hcl);
while (is_spacechar(hcl->c->lxc.c))
{
if ((hcl->option.trait & HCL_CLI_MODE) && hcl->c->lxc.c == '\n')
{
SET_TOKEN_TYPE (hcl, HCL_IOTOK_EOL);
CLEAR_TOKEN_NAME (hcl);
ADD_TOKEN_STR(hcl, vocas[VOCA_EOL].str, vocas[VOCA_EOL].len);
hcl->c->tok.loc = hcl->c->lxc.l; /* set token location */
}
GET_CHAR (hcl);
}
/* the first character after the last space is in hcl->c->lxc */
if ((n = skip_comment(hcl)) <= -1) return -1;
}