added code to process the binop symbol
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-09-16 11:12:11 +09:00
parent a3e2b589be
commit ec4a6facee
3 changed files with 42 additions and 0 deletions

View File

@ -860,6 +860,7 @@ enum hcl_flx_state_t
HCL_FLX_DOLLARED_IDENT,
HCL_FLX_HMARKED_TOKEN, /* hash-marked token */
HCL_FLX_HMARKED_B, /* #b - intermediate state before #b[ or #b-radixed binary number */
HCL_FLX_HMARKED_BINOP, /* #++ - binary operator symbol */
HCL_FLX_HMARKED_CHAR, /* hash-marked character that begins with #\ */
HCL_FLX_HMARKED_IDENT, /* hash-marked identifier like #include, etc */
HCL_FLX_HMARKED_NUMBER, /* hash-marked number - radixed number like #xABCD */

View File

@ -272,6 +272,7 @@ static HCL_INLINE int is_delimchar (hcl_ooci_t c)
c == '#' || c == '\"' || c == '\'' || c == '\\' || is_spacechar(c) || c == HCL_OOCI_EOF;
}
int hcl_is_binop_char (hcl_ooci_t c)
{
return c == '&' || c == '*' || c == '+' || c == '-' || c == '/' || c == '%' ||
@ -2458,6 +2459,13 @@ static int flx_hmarked_token (hcl_t* hcl, hcl_ooci_t c)
* #"..." symbol literal
*/
if (hcl_is_binop_char(c))
{
reset_flx_token (hcl);
FEED_CONTINUE_WITH_CHAR (hcl, c, HCL_FLX_HMARKED_BINOP);
goto consumed;
}
switch (c)
{
case '#':
@ -2707,6 +2715,34 @@ not_consumed:
return 0;
}
static int flx_hmarked_binop (hcl_t* hcl, hcl_ooci_t c)
{
if (hcl_is_binop_char(c))
{
ADD_TOKEN_CHAR(hcl, c);
goto consumed;
}
else if (is_delimchar(c))
{
FEED_WRAP_UP(hcl, HCL_TOK_SYMLIT);
goto not_consumed;
}
else
{
hcl_setsynerrbfmt (hcl, HCL_SYNERR_SYMLIT,
TOKEN_LOC(hcl), HCL_NULL /* no token name as incomplete */,
"invalid binary selector character '%jc' after #%.*js",
c, TOKEN_NAME_LEN(hcl), TOKEN_NAME_PTR(hcl));
return -1;
}
consumed:
return 1;
not_consumed:
return 0;
}
static int flx_hmarked_number (hcl_t* hcl, hcl_ooci_t c)
{
hcl_flx_hn_t* rn = FLX_HN(hcl);
@ -3230,6 +3266,7 @@ static int feed_char (hcl_t* hcl, hcl_ooci_t c)
case HCL_FLX_DOLLARED_IDENT: return flx_dollared_ident(hcl, c);
case HCL_FLX_HMARKED_TOKEN: return flx_hmarked_token(hcl, c);
case HCL_FLX_HMARKED_B: return flx_hmarked_b(hcl, c);
case HCL_FLX_HMARKED_BINOP: return flx_hmarked_binop(hcl, c);
case HCL_FLX_HMARKED_CHAR: return flx_hmarked_char(hcl, c);
case HCL_FLX_HMARKED_IDENT: return flx_hmarked_ident(hcl, c);
case HCL_FLX_HMARKED_NUMBER: return flx_hmarked_number(hcl, c);

View File

@ -83,3 +83,7 @@ defun :* fun1() { ##ERROR: syntax error - function name not symbol in defun
---
(10 + 20 30) ##ERROR: syntax error - too many operands
---
#**a ##ERROR: syntax error - invalid binary selector character 'a' after #**