experimenting with a new line as a terminator like a semicolon. this breaks some test cases as of now
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-01-18 18:16:05 +08:00
parent 656af796ed
commit b3f363c94f
8 changed files with 94 additions and 48 deletions

View File

@ -460,7 +460,7 @@ static int check_block_expression_as_body (hcl_t* hcl, hcl_cnode_t* c, const hcl
{
no_block:
hcl_setsynerrbfmt (
hcl, HCL_SYNERR_BLOCK, (car? HCL_CNODE_GET_LOC(car): HCL_CNODE_GET_LOC(c)), HCL_NULL,
hcl, HCL_SYNERR_BLOCK, (car? HCL_CNODE_GET_LOC(car): c? HCL_CNODE_GET_LOC(c): HCL_CNODE_GET_LOC(ctx)), HCL_NULL,
"block expression expected as body for %.*js", HCL_CNODE_GET_TOKLEN(ctx), HCL_CNODE_GET_TOKPTR(ctx)
);
return -1;
@ -2298,7 +2298,7 @@ static HCL_INLINE int compile_else (hcl_t* hcl)
return -1;
}
if (hcl->c->flags & HCL_COMPILE_ENABLE_BLOCK)
if (hcl->option.trait & HCL_TRAIT_LANG_ENABLE_BLOCK)
{
if (check_block_expression_as_body(hcl, obj, cmd, 0) <= -1) return -1;
}
@ -2582,7 +2582,7 @@ static HCL_INLINE int compile_class_p1 (hcl_t* hcl)
if (emit_push_literal(hcl, tmp, &cf->u._class.start_loc) <= -1) goto oops;
}
if (hcl->c->flags & HCL_COMPILE_ENABLE_BLOCK)
if (hcl->option.trait & HCL_TRAIT_LANG_ENABLE_BLOCK)
{
if (check_block_expression_as_body(hcl, obj, cf->u._class.cmd_cnode, 0) <= -1) return -1;
}
@ -2921,7 +2921,7 @@ static int compile_lambda (hcl_t* hcl, hcl_cnode_t* src, int defun)
}
HCL_ASSERT (hcl, nargs + nrvars == hcl->c->tv.wcount - saved_tv_wcount);
if (hcl->c->flags & HCL_COMPILE_ENABLE_BLOCK)
if (hcl->option.trait & HCL_TRAIT_LANG_ENABLE_BLOCK)
{
/*
* defun aa(a b) { ... };
@ -3610,7 +3610,7 @@ static int compile_while (hcl_t* hcl, hcl_cnode_t* src, int next_cop)
cond = HCL_CNODE_CONS_CAR(obj);
body = HCL_CNODE_CONS_CDR(obj);
if (hcl->c->flags & HCL_COMPILE_ENABLE_BLOCK)
if (hcl->option.trait & HCL_TRAIT_LANG_ENABLE_BLOCK)
{
if (check_block_expression_as_body(hcl, body, cmd, 0) <= -1) return -1;
}
@ -4488,7 +4488,7 @@ redo:
*/
case HCL_CONCODE_BLOCK:
if (!(hcl->c->flags & HCL_COMPILE_ENABLE_BLOCK))
if (!(hcl->option.trait & HCL_TRAIT_LANG_ENABLE_BLOCK))
{
hcl_setsynerrbfmt (hcl, HCL_SYNERR_BLOCKBANNED, HCL_CNODE_GET_LOC(oprnd), HCL_NULL, "block expression disallowed");
return -1;
@ -4544,7 +4544,7 @@ redo:
*/
case HCL_CONCODE_BLOCK:
if (!(hcl->c->flags & HCL_COMPILE_ENABLE_BLOCK))
if (!(hcl->option.trait & HCL_TRAIT_LANG_ENABLE_BLOCK))
{
/* this is treated the same as HCL_CNODE_CONS with CONCODE BLOCK */
hcl_setsynerrbfmt (hcl, HCL_SYNERR_BLOCKBANNED, HCL_CNODE_GET_LOC(oprnd), HCL_NULL, "block expression disallowed");
@ -4978,7 +4978,7 @@ static HCL_INLINE int post_if_cond (hcl_t* hcl)
HCL_ASSERT (hcl, hcl->code.bc.len < HCL_SMOOI_MAX);
body_pos = hcl->code.bc.len;
if (hcl->c->flags & HCL_COMPILE_ENABLE_BLOCK)
if (hcl->option.trait & HCL_TRAIT_LANG_ENABLE_BLOCK)
{
if (check_block_expression_as_body(hcl, cf->operand, cf->u.post_if.cmd_cnode, 1) <= -1) return -1;
}

View File

@ -195,9 +195,9 @@ enum hcl_option_t
HCL_SYSDIC_SIZE, /* default system dictionary size */
HCL_PROCSTK_SIZE, /* default process stack size */
HCL_MOD_LIBDIRS,
HCL_MOD_PREFIX,
HCL_MOD_POSTFIX,
HCL_MOD_LIBDIRS,
HCL_MOD_PREFIX,
HCL_MOD_POSTFIX,
HCL_MOD_INCTX
};
@ -229,7 +229,13 @@ enum hcl_trait_t
HCL_TRAIT_NOGC = (1u << 8),
/* wait for running process when exiting from the main method */
HCL_TRAIT_AWAIT_PROCS = (1u << 9)
HCL_TRAIT_AWAIT_PROCS = (1u << 9),
/* treat a line break character like a semicolon */ /* TODO: make this pragma controllable */
HCL_TRAIT_LANG_NL_TERMINATOR = (1u << 14),
/* enable block expression as mandatory argument to some expresions */
HCL_TRAIT_LANG_ENABLE_BLOCK = (1u << 15),
};
typedef enum hcl_trait_t hcl_trait_t;
@ -1479,7 +1485,7 @@ enum hcl_compile_flag_t
HCL_COMPILE_CLEAR_FNBLK = (1 << 1),
/* enable the block {} mode */
HCL_COMPILE_ENABLE_BLOCK = (1 << 2)
HCL_COMPILE_ENABLE_BLOCK = (1 << 2) /*TODO: make this #pragma controllable */
};
typedef enum hcl_compile_flag_t hcl_compile_flag_t;
#endif

View File

@ -1796,6 +1796,15 @@ static int flx_start (hcl_t* hcl, hcl_ooci_t c)
{
HCL_ASSERT (hcl, FLX_STATE(hcl) == HCL_FLX_START);
if ((hcl->option.trait & HCL_TRAIT_LANG_NL_TERMINATOR) && is_linebreak(c))
{
/* TODO: check some other context to make this a semicolon.
e.g if in ||, don't convert... */
FEED_WRAP_UP_WITH_CHAR (hcl, c, HCL_TOK_SEMICOLON);
reset_flx_token (hcl);
goto consumed;
}
if (is_spacechar(c)) goto consumed; /* skip spaces */
reset_flx_token (hcl);
@ -1824,9 +1833,12 @@ static int flx_start (hcl_t* hcl, hcl_ooci_t c)
FEED_WRAP_UP_WITH_CHARS (hcl, vocas[VOCA_EOF].str, vocas[VOCA_EOF].len, HCL_TOK_EOF);
goto consumed;
/* this part is never hit because the semicolon sign is part of delim_tok_tab{}
TODO: remove this part once the language spec is finalized to not require this
case ';':
FEED_CONTINUE_WITH_CHAR (hcl, c, HCL_FLX_COMMENT);
goto consumed;
*/
case '#':
/* no state date to initialize. just change the state */