diff --git a/lib/comp.c b/lib/comp.c index fcb3819..ccc5cdb 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -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 (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; dcl_saved = dcl; dcl = var; @@ -1442,12 +1447,9 @@ static int collect_vardcl_for_class (hcl_t* hcl, hcl_cnode_t* obj, hcl_cnode_t** goto next; } - if (!HCL_CNODE_IS_SYMBOL_PLAIN(var)) - { - synerr_varname: - hcl_setsynerrbfmt (hcl, HCL_SYNERR_VARNAME, HCL_CNODE_GET_LOC(var), HCL_CNODE_GET_TOK(var), "not variable name"); - return -1; - } + /* 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;*/ + HCL_ASSERT (hcl, HCL_CNODE_IS_SYMBOL_PLAIN(var) && !HCL_CNODE_IS_SYMBOL_PLAIN_BINOP(var)); checkpoint = hcl->c->tv.s.len; n = add_temporary_variable(hcl, HCL_CNODE_GET_TOK(var), tv_slen_saved); diff --git a/lib/hcl-prv.h b/lib/hcl-prv.h index 85b2e6f..af40bbb 100644 --- a/lib/hcl-prv.h +++ b/lib/hcl-prv.h @@ -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_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_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); +/* ========================================================================= */ +/* read.c */ +/* ========================================================================= */ +int hcl_is_binop_char (hcl_ooci_t c); + /* ========================================================================= */ /* exec.c */ /* ========================================================================= */ diff --git a/lib/read.c b/lib/read.c index d6d20ef..d5c2c89 100644 --- a/lib/read.c +++ b/lib/read.c @@ -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; } -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 == '%' || 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; } - 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 */ -/* 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"); return -1; } @@ -2175,7 +2175,7 @@ static int flx_start (hcl_t* hcl, hcl_ooci_t c) goto consumed; default: - if (is_binopchar(c)) + if (hcl_is_binop_char(c)) { init_flx_binop (FLX_BINOP(hcl)); 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); - if (is_binopchar(c)) + if (hcl_is_binop_char(c)) { ADD_TOKEN_CHAR (hcl, c); goto consumed; diff --git a/t/var-5001.err b/t/var-5001.err index b25746a..3894798 100644 --- a/t/var-5001.err +++ b/t/var-5001.err @@ -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 - + }