updated the reader to forge an outer xlist automatically if the beginning is a complex literal expression like array([]), dictionary(#{}), etc
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
eb6e0484af
commit
48a54d61c1
@ -582,7 +582,8 @@ oops:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFAULT_HEAPSIZE 512000ul
|
//#define DEFAULT_HEAPSIZE (512000ul)
|
||||||
|
#define DEFAULT_HEAPSIZE (0ul) /* don't use the pre-allocated heap */
|
||||||
|
|
||||||
int main (int argc, char* argv[])
|
int main (int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
46
lib/read.c
46
lib/read.c
@ -1042,6 +1042,38 @@ static HCL_INLINE int is_at_block_beginning (hcl_t* hcl)
|
|||||||
return !rstl || (LIST_FLAG_GET_CONCODE(rstl->flagv) == HCL_CONCODE_BLOCK && (hcl->c->feed.rd.flagv & AT_BEGINNING));
|
return !rstl || (LIST_FLAG_GET_CONCODE(rstl->flagv) == HCL_CONCODE_BLOCK && (hcl->c->feed.rd.flagv & AT_BEGINNING));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int forge_auto_xlist_if_at_block_beginning (hcl_t* hcl, hcl_frd_t* frd)
|
||||||
|
{
|
||||||
|
if (is_at_block_beginning(hcl))
|
||||||
|
{
|
||||||
|
int forged_flagv;
|
||||||
|
|
||||||
|
/* both MLIST and ALIST begin as XLIST and get converted to MLIST
|
||||||
|
* or ALIST after more tokens are processed. so handling of MLIST
|
||||||
|
* or ALIST is needed at this phase */
|
||||||
|
forged_flagv = AUTO_FORGED;
|
||||||
|
LIST_FLAG_SET_CONCODE (forged_flagv, HCL_CONCODE_XLIST);
|
||||||
|
|
||||||
|
/* this portion is similar to the code below the start_list label */
|
||||||
|
if (frd->level >= HCL_TYPE_MAX(int)) /* the nesting level too deep */
|
||||||
|
{
|
||||||
|
hcl_setsynerr (hcl, HCL_SYNERR_NESTING, TOKEN_LOC(hcl), TOKEN_NAME(hcl));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* since the actual list opener doesn't exist, the location of the
|
||||||
|
* first element wil be the location of the list */
|
||||||
|
if (enter_list(hcl, TOKEN_LOC(hcl), forged_flagv) <= -1) return -1;
|
||||||
|
frd->level++; /* level after the forged list has been added */
|
||||||
|
/* a new list has been created automatically. unlike normal list creation
|
||||||
|
* by an explicit symbol such as a left parenthesis, a left brace, etc,
|
||||||
|
* the first element opens up this new list. so the AT_BEGINNING bit is
|
||||||
|
* turned off here */
|
||||||
|
frd->flagv &= ~AT_BEGINNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
static int feed_process_token (hcl_t* hcl)
|
static int feed_process_token (hcl_t* hcl)
|
||||||
{
|
{
|
||||||
hcl_frd_t* frd = &hcl->c->feed.rd;
|
hcl_frd_t* frd = &hcl->c->feed.rd;
|
||||||
@ -1139,26 +1171,36 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HCL_TOK_LBRACK: /* [ */
|
case HCL_TOK_LBRACK: /* [ */
|
||||||
|
/* [] is a data list. so let's treat it like other literal
|
||||||
|
* expressions(e.g. 1, "abc"). when it's placed at the block beginning,
|
||||||
|
* create the outer XLIST. */
|
||||||
|
if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops;
|
||||||
|
|
||||||
frd->flagv = DATA_LIST;
|
frd->flagv = DATA_LIST;
|
||||||
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_ARRAY);
|
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_ARRAY);
|
||||||
goto start_list;
|
goto start_list;
|
||||||
|
|
||||||
case HCL_TOK_BAPAREN: /* #[ */
|
case HCL_TOK_BAPAREN: /* #[ */
|
||||||
|
if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops;
|
||||||
|
|
||||||
frd->flagv = DATA_LIST;
|
frd->flagv = DATA_LIST;
|
||||||
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_BYTEARRAY);
|
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_BYTEARRAY);
|
||||||
goto start_list;
|
goto start_list;
|
||||||
|
|
||||||
case HCL_TOK_LBRACE: /* { */
|
case HCL_TOK_LBRACE: /* { */
|
||||||
|
/* this is a block opener itself. auto xlist forge at the block beginning */
|
||||||
frd->flagv = 0;
|
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;
|
||||||
|
|
||||||
case HCL_TOK_DLPAREN: /* #{ */
|
case HCL_TOK_DLPAREN: /* #{ */
|
||||||
|
if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops;
|
||||||
frd->flagv = DATA_LIST;
|
frd->flagv = DATA_LIST;
|
||||||
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_DIC);
|
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_DIC);
|
||||||
goto start_list;
|
goto start_list;
|
||||||
|
|
||||||
case HCL_TOK_QLPAREN: /* #( */
|
case HCL_TOK_QLPAREN: /* #( */
|
||||||
|
if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops;
|
||||||
frd->flagv = DATA_LIST;
|
frd->flagv = DATA_LIST;
|
||||||
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_QLIST);
|
LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_QLIST);
|
||||||
goto start_list;
|
goto start_list;
|
||||||
@ -1458,6 +1500,7 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
goto auto_xlist;
|
goto auto_xlist;
|
||||||
|
|
||||||
auto_xlist:
|
auto_xlist:
|
||||||
|
#if 0
|
||||||
if (is_at_block_beginning(hcl))
|
if (is_at_block_beginning(hcl))
|
||||||
{
|
{
|
||||||
int forged_flagv;
|
int forged_flagv;
|
||||||
@ -1485,6 +1528,9 @@ static int feed_process_token (hcl_t* hcl)
|
|||||||
* turned off here */
|
* turned off here */
|
||||||
frd->flagv &= ~AT_BEGINNING;
|
frd->flagv &= ~AT_BEGINNING;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,11 @@ check_SCRIPTS = \
|
|||||||
insta-02.hcl \
|
insta-02.hcl \
|
||||||
ret-01.hcl \
|
ret-01.hcl \
|
||||||
retvar-01.hcl \
|
retvar-01.hcl \
|
||||||
va-01.hcl
|
va-01.hcl \
|
||||||
|
var-02.hcl
|
||||||
|
|
||||||
check_ERRORS = \
|
check_ERRORS = \
|
||||||
|
call-01.err \
|
||||||
class-01.err \
|
class-01.err \
|
||||||
do-01.err \
|
do-01.err \
|
||||||
do-02.err \
|
do-02.err \
|
||||||
|
@ -477,9 +477,11 @@ check_SCRIPTS = \
|
|||||||
insta-02.hcl \
|
insta-02.hcl \
|
||||||
ret-01.hcl \
|
ret-01.hcl \
|
||||||
retvar-01.hcl \
|
retvar-01.hcl \
|
||||||
va-01.hcl
|
va-01.hcl \
|
||||||
|
var-01.hcl
|
||||||
|
|
||||||
check_ERRORS = \
|
check_ERRORS = \
|
||||||
|
call-01.err \
|
||||||
class-01.err \
|
class-01.err \
|
||||||
do-01.err \
|
do-01.err \
|
||||||
do-02.err \
|
do-02.err \
|
||||||
|
3
t/call-01.err
Normal file
3
t/call-01.err
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
## the expression begins with a dictionary expression.
|
||||||
|
## it is not a function name and can'be be invoked.
|
||||||
|
#{100:1, 200: 3}; ##ERROR: syntax error - invalid callable
|
24
t/var-02.hcl
Normal file
24
t/var-02.hcl
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
defun x (a ::: x y z) {
|
||||||
|
x := (* a a);
|
||||||
|
y := (+ a a);
|
||||||
|
z := (- x y);
|
||||||
|
};
|
||||||
|
|
||||||
|
j := 21;
|
||||||
|
|
||||||
|
if (eqv? j 20) {
|
||||||
|
[a,b,c] := (x 20);
|
||||||
|
q := (x 20);
|
||||||
|
} else {
|
||||||
|
[a,b,c] := (x 30);
|
||||||
|
q := (x 30);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (/= a 900) { print "ERROR: a is not 900\n" }
|
||||||
|
else { printf "OK: %d\n" a };
|
||||||
|
|
||||||
|
if (/= b 60) { print "ERROR: b is not 60\n" }
|
||||||
|
else { printf "OK: %d\n" b };
|
||||||
|
|
||||||
|
if (/= c 840) { print "ERROR: c is not 840\n" }
|
||||||
|
else { printf "OK: %d\n" c };
|
Loading…
Reference in New Issue
Block a user