some code to handle the auto-forged xlist beginning with no opening parenthesis but ending with a semicolon
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
44fd446274
commit
9110a083eb
117
lib/read.c
117
lib/read.c
@ -88,7 +88,8 @@ enum list_flag_t
|
|||||||
COLONED = (1 << 3),
|
COLONED = (1 << 3),
|
||||||
CLOSED = (1 << 4),
|
CLOSED = (1 << 4),
|
||||||
JSON = (1 << 5),
|
JSON = (1 << 5),
|
||||||
DATA_LIST = (1 << 6)
|
DATA_LIST = (1 << 6),
|
||||||
|
AUTO_FORGED = (1 << 7) /* automatically added. only applicable to XLIST */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LIST_FLAG_GET_CONCODE(x) (((x) >> 8) & 0xFF)
|
#define LIST_FLAG_GET_CONCODE(x) (((x) >> 8) & 0xFF)
|
||||||
@ -673,10 +674,10 @@ static HCL_INLINE int is_at_block_beginning (hcl_t* hcl)
|
|||||||
{
|
{
|
||||||
hcl_rstl_t* rstl;
|
hcl_rstl_t* rstl;
|
||||||
|
|
||||||
HCL_ASSERT (hcl, hcl->c->r.st != HCL_NULL);
|
//HCL_ASSERT (hcl, hcl->c->r.st != HCL_NULL);
|
||||||
rstl = hcl->c->r.st;
|
rstl = hcl->c->r.st;
|
||||||
|
|
||||||
return (LIST_FLAG_GET_CONCODE(rstl->flagv) == HCL_CONCODE_BLOCK && rstl->count <= 0);
|
return !rstl || LIST_FLAG_GET_CONCODE(rstl->flagv) == HCL_CONCODE_BLOCK && rstl->count <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HCL_INLINE int can_dot_list (hcl_t* hcl)
|
static HCL_INLINE int can_dot_list (hcl_t* hcl)
|
||||||
@ -1098,7 +1099,7 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
goto start_list;
|
goto start_list;
|
||||||
|
|
||||||
case HCL_TOK_LBRACE: /* { */
|
case HCL_TOK_LBRACE: /* { */
|
||||||
frd->flagv = DATA_LIST;
|
frd->flagv = 0;
|
||||||
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_BLOCK);
|
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_BLOCK);
|
||||||
goto start_list;
|
goto start_list;
|
||||||
|
|
||||||
@ -1168,8 +1169,36 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
goto ok;
|
goto ok;
|
||||||
|
|
||||||
case HCL_TOK_SEMICOLON:
|
case HCL_TOK_SEMICOLON:
|
||||||
/* TODO: */
|
{
|
||||||
goto ok;
|
int oldflagv;
|
||||||
|
int concode;
|
||||||
|
|
||||||
|
if (frd->level <= 0)
|
||||||
|
{
|
||||||
|
/* redundant semicolons */
|
||||||
|
hcl_setsynerr (hcl, HCL_SYNERR_UNBALPBB, TOKEN_LOC(hcl), HCL_NULL);
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(frd->flagv & AUTO_FORGED))
|
||||||
|
{
|
||||||
|
/* TODO: change error info */
|
||||||
|
hcl_setsynerr (hcl, HCL_SYNERR_UNBALPBB, TOKEN_LOC(hcl), HCL_NULL);
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
|
concode = LIST_FLAG_GET_CONCODE(frd->flagv);
|
||||||
|
if (concode != HCL_CONCODE_XLIST)
|
||||||
|
{
|
||||||
|
/* TODO: change error info */
|
||||||
|
hcl_setsynerr (hcl, HCL_SYNERR_UNBALPBB, TOKEN_LOC(hcl), HCL_NULL);
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
|
frd->obj = leave_list(hcl, &frd->flagv, &oldflagv);
|
||||||
|
frd->level--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case HCL_TOK_RPAREN: /* xlist (), qlist #() */
|
case HCL_TOK_RPAREN: /* xlist (), qlist #() */
|
||||||
case HCL_TOK_RBRACK: /* bytearray #[], array [] */
|
case HCL_TOK_RBRACK: /* bytearray #[], array [] */
|
||||||
@ -1181,13 +1210,13 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
hcl_synerrnum_t synerr;
|
hcl_synerrnum_t synerr;
|
||||||
} req[] =
|
} req[] =
|
||||||
{
|
{
|
||||||
{ HCL_TOK_RPAREN, HCL_SYNERR_RPAREN }, /* XLIST ( ) */
|
/*[HCL_CONCODE_XLIST] =*/ { HCL_TOK_RPAREN, HCL_SYNERR_RPAREN }, /* XLIST ( ) */
|
||||||
{ HCL_TOK_RPAREN, HCL_SYNERR_RPAREN }, /* MLIST (: ) */
|
/*[HCL_CONCODE_MLIST] =*/ { HCL_TOK_RPAREN, HCL_SYNERR_RPAREN }, /* MLIST (: ) */
|
||||||
{ HCL_TOK_RBRACE, HCL_SYNERR_RBRACE }, /* BLOCK { } */
|
/*[HCL_CONCODE_BLOCK] =*/ { HCL_TOK_RBRACE, HCL_SYNERR_RBRACE }, /* BLOCK { } */
|
||||||
{ HCL_TOK_RBRACK, HCL_SYNERR_RBRACK }, /* ARRAY [ ] */
|
/*[HCL_CONCODE_ARRAY] =*/ { HCL_TOK_RBRACK, HCL_SYNERR_RBRACK }, /* ARRAY [ ] */
|
||||||
{ HCL_TOK_RBRACK, HCL_SYNERR_RBRACK }, /* BYTEARRAY #[ ] */
|
/*[HCL_CONCODE_BYTEARRAY] =*/ { HCL_TOK_RBRACK, HCL_SYNERR_RBRACK }, /* BYTEARRAY #[ ] */
|
||||||
{ HCL_TOK_RBRACE, HCL_SYNERR_RBRACE }, /* DIC #{ } */
|
/*[HCL_CONCODE_DIC] =*/ { HCL_TOK_RBRACE, HCL_SYNERR_RBRACE }, /* DIC #{ } */
|
||||||
{ HCL_TOK_RPAREN, HCL_SYNERR_RPAREN } /* QLIST #( ) */
|
/*[HCL_CONCODE_QLIST] =*/ { HCL_TOK_RPAREN, HCL_SYNERR_RPAREN } /* QLIST #( ) */
|
||||||
};
|
};
|
||||||
|
|
||||||
int oldflagv;
|
int oldflagv;
|
||||||
@ -1201,6 +1230,14 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
|
|
||||||
concode = LIST_FLAG_GET_CONCODE(frd->flagv);
|
concode = LIST_FLAG_GET_CONCODE(frd->flagv);
|
||||||
|
|
||||||
|
if (concode == HCL_CONCODE_XLIST && (frd->flagv & AUTO_FORGED))
|
||||||
|
{
|
||||||
|
/* the auto-created xlist can't be terminated with the regular closing symbol
|
||||||
|
* it must end with the semicolon */
|
||||||
|
hcl_setsynerr (hcl, HCL_SYNERR_UNBALPBB, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
if (req[concode].closer != TOKEN_TYPE(hcl))
|
if (req[concode].closer != TOKEN_TYPE(hcl))
|
||||||
{
|
{
|
||||||
hcl_setsynerr (hcl, req[concode].synerr, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
hcl_setsynerr (hcl, req[concode].synerr, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
@ -1238,35 +1275,35 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
|
|
||||||
case HCL_TOK_NIL:
|
case HCL_TOK_NIL:
|
||||||
frd->obj = hcl_makecnodenil(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodenil(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_TRUE:
|
case HCL_TOK_TRUE:
|
||||||
frd->obj = hcl_makecnodetrue(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodetrue(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_FALSE:
|
case HCL_TOK_FALSE:
|
||||||
frd->obj = hcl_makecnodefalse(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodefalse(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_SELF:
|
case HCL_TOK_SELF:
|
||||||
frd->obj = hcl_makecnodeself(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodeself(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_SUPER:
|
case HCL_TOK_SUPER:
|
||||||
frd->obj = hcl_makecnodesuper(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodesuper(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_ELLIPSIS:
|
case HCL_TOK_ELLIPSIS:
|
||||||
frd->obj = hcl_makecnodeellipsis(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodeellipsis(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_TRPCOLONS:
|
case HCL_TOK_TRPCOLONS:
|
||||||
frd->obj = hcl_makecnodetrpcolons(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodetrpcolons(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_DCSTAR:
|
case HCL_TOK_DCSTAR:
|
||||||
frd->obj = hcl_makecnodedcstar(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodedcstar(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_SMPTRLIT:
|
case HCL_TOK_SMPTRLIT:
|
||||||
{
|
{
|
||||||
@ -1287,7 +1324,7 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
frd->obj = hcl_makecnodesmptrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v);
|
frd->obj = hcl_makecnodesmptrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v);
|
||||||
break;
|
goto auto_xlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
case HCL_TOK_ERRLIT:
|
case HCL_TOK_ERRLIT:
|
||||||
@ -1309,24 +1346,24 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
frd->obj = hcl_makecnodeerrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v);
|
frd->obj = hcl_makecnodeerrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), v);
|
||||||
break;
|
goto auto_xlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
case HCL_TOK_CHARLIT:
|
case HCL_TOK_CHARLIT:
|
||||||
frd->obj = hcl_makecnodecharlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), TOKEN_NAME_CHAR(hcl, 0));
|
frd->obj = hcl_makecnodecharlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl), TOKEN_NAME_CHAR(hcl, 0));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_NUMLIT:
|
case HCL_TOK_NUMLIT:
|
||||||
frd->obj = hcl_makecnodenumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodenumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_RADNUMLIT:
|
case HCL_TOK_RADNUMLIT:
|
||||||
frd->obj = hcl_makecnoderadnumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnoderadnumlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_FPDECLIT:
|
case HCL_TOK_FPDECLIT:
|
||||||
frd->obj = hcl_makecnodefpdeclit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodefpdeclit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
case HCL_TOK_REAL:
|
case HCL_TOK_REAL:
|
||||||
@ -1336,14 +1373,36 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
|
|
||||||
case HCL_TOK_STRLIT:
|
case HCL_TOK_STRLIT:
|
||||||
frd->obj = hcl_makecnodestrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodestrlit(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_IDENT:
|
case HCL_TOK_IDENT:
|
||||||
frd->obj = hcl_makecnodesymbol(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodesymbol(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
break;
|
goto auto_xlist;
|
||||||
|
|
||||||
case HCL_TOK_IDENT_DOTTED:
|
case HCL_TOK_IDENT_DOTTED:
|
||||||
frd->obj = hcl_makecnodedsymbol(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
frd->obj = hcl_makecnodedsymbol(hcl, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
|
goto auto_xlist;
|
||||||
|
|
||||||
|
auto_xlist:
|
||||||
|
if (is_at_block_beginning(hcl)) /* TODO: make this optional */
|
||||||
|
{
|
||||||
|
hcl_oop_t obj = frd->obj;
|
||||||
|
|
||||||
|
frd->flagv = AUTO_FORGED;
|
||||||
|
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_XLIST);
|
||||||
|
|
||||||
|
/* this portion is te same as the code below the start_list label above */
|
||||||
|
if (frd->level >= HCL_TYPE_MAX(int)) /* the nesting level too deep */
|
||||||
|
{
|
||||||
|
hcl_setsynerr (hcl, HCL_SYNERR_NESTING, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
if (enter_list(hcl, TOKEN_LOC(hcl), frd->flagv) <= -1) goto oops;
|
||||||
|
frd->level++;
|
||||||
|
|
||||||
|
frd = &hcl->c->feed.rd;
|
||||||
|
frd->obj = obj;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user