added special parser-level substitution word - @SCRIPTNAME, @SCRIPTLINE
This commit is contained in:
parent
8ad37dabf0
commit
7f479f156b
@ -136,7 +136,6 @@ enum tok_t
|
|||||||
TOK_COLON,
|
TOK_COLON,
|
||||||
TOK_DBLCOLON,
|
TOK_DBLCOLON,
|
||||||
TOK_QUEST,
|
TOK_QUEST,
|
||||||
/*TOK_DBLAT,*/
|
|
||||||
|
|
||||||
/* == begin reserved words == */
|
/* == begin reserved words == */
|
||||||
/* === extended reserved words === */
|
/* === extended reserved words === */
|
||||||
@ -398,7 +397,7 @@ static global_t gtab[] =
|
|||||||
|
|
||||||
#define ADD_TOKEN_CHAR(hawk,tok,c) \
|
#define ADD_TOKEN_CHAR(hawk,tok,c) \
|
||||||
do { \
|
do { \
|
||||||
if (hawk_ooecs_ccat((tok)->name,(c)) == (hawk_oow_t)-1) \
|
if (HAWK_UNLIKELY(hawk_ooecs_ccat((tok)->name,(c)) == (hawk_oow_t)-1)) \
|
||||||
{ \
|
{ \
|
||||||
ADJERR_LOC (hawk, &(tok)->loc); \
|
ADJERR_LOC (hawk, &(tok)->loc); \
|
||||||
return -1; \
|
return -1; \
|
||||||
@ -407,7 +406,7 @@ static global_t gtab[] =
|
|||||||
|
|
||||||
#define ADD_TOKEN_STR(hawk,tok,s,l) \
|
#define ADD_TOKEN_STR(hawk,tok,s,l) \
|
||||||
do { \
|
do { \
|
||||||
if (hawk_ooecs_ncat((tok)->name,(s),(l)) == (hawk_oow_t)-1) \
|
if (HAWK_UNLIKELY(hawk_ooecs_ncat((tok)->name,(s),(l)) == (hawk_oow_t)-1)) \
|
||||||
{ \
|
{ \
|
||||||
ADJERR_LOC (hawk, &(tok)->loc); \
|
ADJERR_LOC (hawk, &(tok)->loc); \
|
||||||
return -1; \
|
return -1; \
|
||||||
@ -6672,17 +6671,7 @@ retry:
|
|||||||
ADD_TOKEN_CHAR (hawk, tok, c);
|
ADD_TOKEN_CHAR (hawk, tok, c);
|
||||||
GET_CHAR_TO (hawk, c);
|
GET_CHAR_TO (hawk, c);
|
||||||
|
|
||||||
/*
|
if (c != HAWK_T('_') && !hawk_is_ooch_alpha(c))
|
||||||
if (c == HAWK_T('@'))
|
|
||||||
{
|
|
||||||
SET_TOKEN_TYPE (hawk, tok, TOK_DBLAT);
|
|
||||||
GET_CHAR (hawk);
|
|
||||||
}*/
|
|
||||||
/* other special extended operators here
|
|
||||||
else if (c == HAWK_T('*'))
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
/*else*/ if (c != HAWK_T('_') && !hawk_is_ooch_alpha(c))
|
|
||||||
{
|
{
|
||||||
/* this extended keyword is empty,
|
/* this extended keyword is empty,
|
||||||
* not followed by a valid word */
|
* not followed by a valid word */
|
||||||
@ -6699,6 +6688,20 @@ retry:
|
|||||||
}
|
}
|
||||||
while (c == HAWK_T('_') || hawk_is_ooch_alpha(c) || hawk_is_ooch_digit(c));
|
while (c == HAWK_T('_') || hawk_is_ooch_alpha(c) || hawk_is_ooch_digit(c));
|
||||||
|
|
||||||
|
if (hawk_comp_oochars_bcstr(HAWK_OOECS_PTR(tok->name), HAWK_OOECS_LEN(tok->name), "@SCRIPTNAME") == 0)
|
||||||
|
{
|
||||||
|
/* special parser-level word @SCRIPTNAME. substitute an actual value for it */
|
||||||
|
if (HAWK_UNLIKELY(hawk_ooecs_cpy(tok->name, tok->loc.file) == (hawk_oow_t)-1)) return -1;
|
||||||
|
SET_TOKEN_TYPE (hawk, tok, TOK_STR);
|
||||||
|
}
|
||||||
|
else if (hawk_comp_oochars_bcstr(HAWK_OOECS_PTR(tok->name), HAWK_OOECS_LEN(tok->name), "@SCRIPTLINE") == 0)
|
||||||
|
{
|
||||||
|
/* special parser-level word @SCRIPTLINE. subsitute an actual value for it */
|
||||||
|
if (HAWK_UNLIKELY(hawk_ooecs_fmt(tok->name, HAWK_T("%zu"), tok->loc.line) == (hawk_oow_t)-1)) return -1;
|
||||||
|
SET_TOKEN_TYPE (hawk, tok, TOK_INT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
type = classify_ident(hawk, HAWK_OOECS_OOCS(tok->name));
|
type = classify_ident(hawk, HAWK_OOECS_OOCS(tok->name));
|
||||||
if (type == TOK_IDENT)
|
if (type == TOK_IDENT)
|
||||||
{
|
{
|
||||||
@ -6708,6 +6711,7 @@ retry:
|
|||||||
SET_TOKEN_TYPE (hawk, tok, type);
|
SET_TOKEN_TYPE (hawk, tok, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (c == HAWK_T('B'))
|
else if (c == HAWK_T('B'))
|
||||||
{
|
{
|
||||||
GET_CHAR_TO (hawk, c);
|
GET_CHAR_TO (hawk, c);
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
@pragma entry main
|
@pragma entry main
|
||||||
|
|
||||||
|
|
||||||
function ensure (a, b, desc)
|
function ensure (a, b, desc, line)
|
||||||
{
|
{
|
||||||
if (a != b)
|
if (a != b)
|
||||||
{
|
{
|
||||||
print "FAILURE in", desc;
|
printf ("FAILURE[%d] %s\n", line, desc);
|
||||||
exit (-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,13 +33,13 @@ function main()
|
|||||||
x = 20;
|
x = 20;
|
||||||
y = 90;
|
y = 90;
|
||||||
r = call_by_ref_1(x, y, z);
|
r = call_by_ref_1(x, y, z);
|
||||||
ensure (r, 1800, SCRIPTNAME);
|
ensure (r, 1800, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (x, 20);
|
ensure (x, 20);
|
||||||
ensure (y, 90);
|
ensure (y, 90);
|
||||||
ensure (z, "hello, world");
|
ensure (z, "hello, world");
|
||||||
|
|
||||||
## TODO: add a new special word, @FILENAME, @FILELINE, @LINE <--- which are understood by the parser and swapped to the actual value
|
## TODO: add a new special word, @FILENAME, @FILELINE, @LINE <--- which are understood by the parser and swapped to the actual value
|
||||||
## SCRIPTNAME doesn't tell the main file.
|
## @SCRIPTNAME, @SCRIPTLINE doesn't tell the main file.
|
||||||
|
|
||||||
{
|
{
|
||||||
@local b;
|
@local b;
|
||||||
@ -60,9 +60,9 @@ function main()
|
|||||||
b[1] = 1;
|
b[1] = 1;
|
||||||
r = hawk::call("call_by_ref_2", 99, b);
|
r = hawk::call("call_by_ref_2", 99, b);
|
||||||
ensure (r, 99);
|
ensure (r, 99);
|
||||||
ensure (length(b), 2, SCRIPTNAME);
|
ensure (length(b), 2, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (b[1], 99, SCRIPTNAME);
|
ensure (b[1], 99, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (b[2], "perfect", SCRIPTNAME);
|
ensure (b[2], "perfect", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,11 +70,11 @@ function main()
|
|||||||
@local a;
|
@local a;
|
||||||
a[1] = hawk::array();
|
a[1] = hawk::array();
|
||||||
a[1][2]=20;
|
a[1][2]=20;
|
||||||
ensure (a[1][2], 20, SCRIPTNAME);
|
ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
a[1][2]++;
|
a[1][2]++;
|
||||||
ensure (a[1][2], 21, SCRIPTNAME);
|
ensure (a[1][2], 21, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
--a[1][2];
|
--a[1][2];
|
||||||
ensure (a[1][2], 20, SCRIPTNAME);
|
ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -83,24 +83,24 @@ function main()
|
|||||||
a[10] = "good";
|
a[10] = "good";
|
||||||
a[0][40] = "bye"
|
a[0][40] = "bye"
|
||||||
a[0][0] = "farewell"
|
a[0][0] = "farewell"
|
||||||
ensure (hawk::typename(a), "array", SCRIPTNAME);
|
ensure (hawk::typename(a), "array", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (hawk::typename(a[0]), "array", SCRIPTNAME);
|
ensure (hawk::typename(a[0]), "array", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
call_by_ref_3(a[9]);
|
call_by_ref_3(a[9]);
|
||||||
ensure (a[10], "good", SCRIPTNAME);
|
ensure (a[10], "good", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (a[9], "hello world", SCRIPTNAME);
|
ensure (a[9], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
call_by_ref_3(a[10]);
|
call_by_ref_3(a[10]);
|
||||||
ensure (a[10], "hello world", SCRIPTNAME);
|
ensure (a[10], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (a[9], "hello world", SCRIPTNAME);
|
ensure (a[9], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (a[0][40], "bye", SCRIPTNAME);
|
ensure (a[0][40], "bye", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
call_by_ref_3(a[0][40]);
|
call_by_ref_3(a[0][40]);
|
||||||
ensure (a[0][40], "hello world", SCRIPTNAME);
|
ensure (a[0][40], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (length(a[0]), 2, SCRIPTNAME);
|
ensure (length(a[0]), 2, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
delete a[0][40];
|
delete a[0][40];
|
||||||
ensure (length(a[0]), 1, SCRIPTNAME);
|
ensure (length(a[0]), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (a[0][0], "farewell", SCRIPTNAME);
|
ensure (a[0][0], "farewell", @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (a[0][40], nil, SCRIPTNAME);
|
ensure (a[0][40], nil, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
#hawk::splice (a[0], 40, 1, SCRIPTNAME);
|
#hawk::splice (a[0], 40, 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
#ensure (length(a[0]), 40, SCRIPTNAME);
|
#ensure (length(a[0]), 40, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,25 +108,25 @@ function main()
|
|||||||
@local a, i;
|
@local a, i;
|
||||||
|
|
||||||
a = hawk::array();
|
a = hawk::array();
|
||||||
ensure (length(a), 0, SCRIPTNAME);
|
ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
for (i = 0; i < 10; i++) a[i*i]=i;
|
for (i = 0; i < 10; i++) a[i*i]=i;
|
||||||
ensure (length(a), 10, SCRIPTNAME);
|
ensure (length(a), 10, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
delete a[0];
|
delete a[0];
|
||||||
ensure (length(a), 9, SCRIPTNAME);
|
ensure (length(a), 9, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
delete a[81];
|
delete a[81];
|
||||||
ensure (length(a), 8, SCRIPTNAME);
|
ensure (length(a), 8, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
delete a[36];
|
delete a[36];
|
||||||
ensure (length(a), 7, SCRIPTNAME);
|
ensure (length(a), 7, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
for (i = 0; i < 10; i++) delete a[i*i];
|
for (i = 0; i < 10; i++) delete a[i*i];
|
||||||
ensure (length(a), 0, SCRIPTNAME);
|
ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
delete a;
|
delete a;
|
||||||
ensure (length(a), 0, SCRIPTNAME);
|
ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -134,19 +134,19 @@ function main()
|
|||||||
a = hawk::array();
|
a = hawk::array();
|
||||||
a[10][20][30] = 20;
|
a[10][20][30] = 20;
|
||||||
b[12][20][30] = 20;
|
b[12][20][30] = 20;
|
||||||
ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, SCRIPTNAME);
|
ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, SCRIPTNAME);
|
ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
b = hawk::map();
|
b = hawk::map();
|
||||||
b[10][20][30] = 20;
|
b[10][20][30] = 20;
|
||||||
b[12][20][30] = 20;
|
b[12][20][30] = 20;
|
||||||
ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, SCRIPTNAME);
|
ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, SCRIPTNAME);
|
ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
c = hawk::map();
|
c = hawk::map();
|
||||||
c[10,20,30] = "heloo";
|
c[10,20,30] = "heloo";
|
||||||
ensure (((10,20,30) in c), 1, SCRIPTNAME);
|
ensure (((10,20,30) in c), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
ensure (((10,30,30) in c), 0, SCRIPTNAME);
|
ensure (((10,30,30) in c), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
print "SUCCESS"
|
print "SUCCESS"
|
||||||
|
Loading…
Reference in New Issue
Block a user