reader improvement to filter out binop from a tuple
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-07-15 01:02:07 +09:00
parent 7754d7c7e9
commit 57d9668110
4 changed files with 21 additions and 13 deletions

View File

@ -1429,7 +1429,12 @@ static int collect_vardcl_for_class (hcl_t* hcl, hcl_cnode_t* obj, hcl_cnode_t**
if (HCL_CNODE_IS_CONS_CONCODED(var, HCL_CONCODE_TUPLE)) /* [ ... ] */ if (HCL_CNODE_IS_CONS_CONCODED(var, HCL_CONCODE_TUPLE)) /* [ ... ] */
{ {
if (enclosed) goto synerr_varname; if (enclosed)
{
synerr_varname:
hcl_setsynerrbfmt (hcl, HCL_SYNERR_VARNAME, HCL_CNODE_GET_LOC(var), HCL_CNODE_GET_TOK(var), "not variable name");
return -1;
}
enclosed = 1; enclosed = 1;
dcl_saved = dcl; dcl_saved = dcl;
dcl = var; dcl = var;
@ -1442,12 +1447,9 @@ static int collect_vardcl_for_class (hcl_t* hcl, hcl_cnode_t* obj, hcl_cnode_t**
goto next; goto next;
} }
if (!HCL_CNODE_IS_SYMBOL_PLAIN(var)) /* this check isn't needed as the reader guarantees this condition.
{ if (!HCL_CNODE_IS_SYMBOL_PLAIN(var) || HCL_CNODE_IS_SYMBOL_PLAIN_BINOP(var)) goto synerr_varname;*/
synerr_varname: HCL_ASSERT (hcl, HCL_CNODE_IS_SYMBOL_PLAIN(var) && !HCL_CNODE_IS_SYMBOL_PLAIN_BINOP(var));
hcl_setsynerrbfmt (hcl, HCL_SYNERR_VARNAME, HCL_CNODE_GET_LOC(var), HCL_CNODE_GET_TOK(var), "not variable name");
return -1;
}
checkpoint = hcl->c->tv.s.len; checkpoint = hcl->c->tv.s.len;
n = add_temporary_variable(hcl, HCL_CNODE_GET_TOK(var), tv_slen_saved); n = add_temporary_variable(hcl, HCL_CNODE_GET_TOK(var), tv_slen_saved);

View File

@ -416,6 +416,7 @@ typedef enum hcl_cnode_flag_t hcl_cnode_flag_t;
#define HCL_CNODE_IS_SYMBOL(x) ((x)->cn_type == HCL_CNODE_SYMBOL) #define HCL_CNODE_IS_SYMBOL(x) ((x)->cn_type == HCL_CNODE_SYMBOL)
#define HCL_CNODE_IS_SYMBOL_PLAIN(x) ((x)->cn_type == HCL_CNODE_SYMBOL && (x)->u.symbol.syncode == 0) #define HCL_CNODE_IS_SYMBOL_PLAIN(x) ((x)->cn_type == HCL_CNODE_SYMBOL && (x)->u.symbol.syncode == 0)
#define HCL_CNODE_IS_SYMBOL_PLAIN_BINOP(x) (HCL_CNODE_IS_SYMBOL_PLAIN(x) && hcl_is_binop_char((x)->cn_tok.ptr[0]))
#define HCL_CNODE_IS_SYMBOL_SYNCODED(x, code) ((x)->cn_type == HCL_CNODE_SYMBOL && (x)->u.symbol.syncode == (code)) #define HCL_CNODE_IS_SYMBOL_SYNCODED(x, code) ((x)->cn_type == HCL_CNODE_SYMBOL && (x)->u.symbol.syncode == (code))
#define HCL_CNODE_SYMBOL_SYNCODE(x) ((x)->u.symbol.syncode) #define HCL_CNODE_SYMBOL_SYNCODE(x) ((x)->u.symbol.syncode)
@ -1962,6 +1963,11 @@ hcl_oow_t hcl_countcnodecons (hcl_t* hcl, hcl_cnode_t* cons);
void hcl_dumpcnode (hcl_t* hcl, hcl_cnode_t* c, int newline); void hcl_dumpcnode (hcl_t* hcl, hcl_cnode_t* c, int newline);
/* ========================================================================= */
/* read.c */
/* ========================================================================= */
int hcl_is_binop_char (hcl_ooci_t c);
/* ========================================================================= */ /* ========================================================================= */
/* exec.c */ /* exec.c */
/* ========================================================================= */ /* ========================================================================= */

View File

@ -239,7 +239,7 @@ static HCL_INLINE int is_delimchar (hcl_ooci_t c)
c == '#' || c == '\"' || c == '\'' || c == '\\' || is_spacechar(c) || c == HCL_OOCI_EOF; c == '#' || c == '\"' || c == '\'' || c == '\\' || is_spacechar(c) || c == HCL_OOCI_EOF;
} }
static HCL_INLINE int is_binopchar (hcl_ooci_t c) int hcl_is_binop_char (hcl_ooci_t c)
{ {
return c == '&' || c == '*' || c == '+' || c == '-' || c == '/' || c == '%' || return c == '&' || c == '*' || c == '+' || c == '-' || c == '/' || c == '%' ||
c == '<' || c == '>' || c == '=' || c == '@' || c == '|' || c == '~'; c == '<' || c == '>' || c == '=' || c == '@' || c == '|' || c == '~';
@ -1022,10 +1022,10 @@ static int chain_to_list (hcl_t* hcl, hcl_cnode_t* obj, hcl_loc_t* loc)
fake_tok_ptr = &fake_tok; fake_tok_ptr = &fake_tok;
} }
if (list_concode == HCL_CONCODE_TUPLE && !HCL_CNODE_IS_SYMBOL_PLAIN(obj) && concode != HCL_CONCODE_TUPLE) if (list_concode == HCL_CONCODE_TUPLE && concode != HCL_CONCODE_TUPLE &&
(!HCL_CNODE_IS_SYMBOL_PLAIN(obj) || HCL_CNODE_IS_SYMBOL_PLAIN_BINOP(obj)))
{ {
/* a tuple must contain some simple symbol names or nested tuples only */ /* a tuple must contain some simple symbol names or nested tuples only */
/* TODO: filter out binop symbols */
hcl_setsynerrbfmt (hcl, HCL_SYNERR_VARNAME, HCL_CNODE_GET_LOC(obj), HCL_CNODE_GET_TOK(obj), "invalid name - not symbol in tuple"); hcl_setsynerrbfmt (hcl, HCL_SYNERR_VARNAME, HCL_CNODE_GET_LOC(obj), HCL_CNODE_GET_TOK(obj), "invalid name - not symbol in tuple");
return -1; return -1;
} }
@ -2175,7 +2175,7 @@ static int flx_start (hcl_t* hcl, hcl_ooci_t c)
goto consumed; goto consumed;
default: default:
if (is_binopchar(c)) if (hcl_is_binop_char(c))
{ {
init_flx_binop (FLX_BINOP(hcl)); init_flx_binop (FLX_BINOP(hcl));
FEED_CONTINUE (hcl, HCL_FLX_BINOP); FEED_CONTINUE (hcl, HCL_FLX_BINOP);
@ -2667,7 +2667,7 @@ static int flx_binop (hcl_t* hcl, hcl_ooci_t c) /* identifier */
{ {
hcl_flx_binop_t* binop = FLX_BINOP(hcl); hcl_flx_binop_t* binop = FLX_BINOP(hcl);
if (is_binopchar(c)) if (hcl_is_binop_char(c))
{ {
ADD_TOKEN_CHAR (hcl, c); ADD_TOKEN_CHAR (hcl, c);
goto consumed; goto consumed;

View File

@ -48,5 +48,5 @@ class A [ a + ] { ##ERROR: syntax error - prohibited binary operator - +
} }
--- ---
class A [ + ] { ##ERROR: syntax error - prohibited binary operator - + class A [ + ] { ##ERROR: syntax error - invalid name - not symbol in tuple - +
} }