updated the parser to require a colone after a key for @{}
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:
14
lib/parse.c
14
lib/parse.c
@@ -247,6 +247,7 @@ static hawk_nde_t* parse_hashidx (hawk_t* hawk, const hawk_oocs_t* name, const h
|
|||||||
|
|
||||||
#define FNCALL_FLAG_NOARG (1 << 0) /* no argument */
|
#define FNCALL_FLAG_NOARG (1 << 0) /* no argument */
|
||||||
#define FNCALL_FLAG_VAR (1 << 1)
|
#define FNCALL_FLAG_VAR (1 << 1)
|
||||||
|
#define FNCALL_FLAG_MAP (1 << 2)
|
||||||
static hawk_nde_t* parse_fncall (hawk_t* hawk, const hawk_oocs_t* name, hawk_fnc_t* fnc, const hawk_loc_t* xloc, int flags, int closer_token);
|
static hawk_nde_t* parse_fncall (hawk_t* hawk, const hawk_oocs_t* name, hawk_fnc_t* fnc, const hawk_loc_t* xloc, int flags, int closer_token);
|
||||||
|
|
||||||
static hawk_nde_t* parse_primary_ident_segs (hawk_t* hawk, const hawk_loc_t* xloc, const hawk_oocs_t* full, const hawk_oocs_t segs[], int nsegs);
|
static hawk_nde_t* parse_primary_ident_segs (hawk_t* hawk, const hawk_loc_t* xloc, const hawk_oocs_t* full, const hawk_oocs_t segs[], int nsegs);
|
||||||
@@ -5169,7 +5170,6 @@ static hawk_nde_t* _parse_primary_array_or_map (hawk_t* hawk, const hawk_loc_t*
|
|||||||
{
|
{
|
||||||
/* treat it as if it's hawk::array() */
|
/* treat it as if it's hawk::array() */
|
||||||
|
|
||||||
hawk_nde_t* nde = HAWK_NULL;
|
|
||||||
hawk_mod_t* mod;
|
hawk_mod_t* mod;
|
||||||
hawk_mod_sym_t sym;
|
hawk_mod_sym_t sym;
|
||||||
hawk_fnc_t fnc;
|
hawk_fnc_t fnc;
|
||||||
@@ -5193,7 +5193,7 @@ static hawk_nde_t* _parse_primary_array_or_map (hawk_t* hawk, const hawk_loc_t*
|
|||||||
fnc.spec = sym.u.fnc_;
|
fnc.spec = sym.u.fnc_;
|
||||||
fnc.mod = mod;
|
fnc.mod = mod;
|
||||||
|
|
||||||
return parse_fncall(hawk, full, &fnc, xloc, 0, closer_token);
|
return parse_fncall(hawk, full, &fnc, xloc, (closer_token == TOK_RBRACE? FNCALL_FLAG_MAP: 0), closer_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
static hawk_nde_t* parse_primary_array (hawk_t* hawk, const hawk_loc_t* xloc)
|
static hawk_nde_t* parse_primary_array (hawk_t* hawk, const hawk_loc_t* xloc)
|
||||||
@@ -6419,11 +6419,21 @@ static hawk_nde_t* parse_fncall (hawk_t* hawk, const hawk_oocs_t* name, hawk_fnc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((flags & FNCALL_FLAG_MAP) && (nargs & 1))
|
||||||
|
{
|
||||||
|
if (!MATCH(hawk, TOK_COLON))
|
||||||
|
{
|
||||||
|
hawk_seterrfmt(hawk, &hawk->tok.loc, HAWK_ECOLON, FMT_ECOLON, HAWK_OOECS_LEN(hawk->tok.name), HAWK_OOECS_PTR(hawk->tok.name));
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (!MATCH(hawk, TOK_COMMA))
|
if (!MATCH(hawk, TOK_COMMA))
|
||||||
{
|
{
|
||||||
hawk_seterrfmt(hawk, &hawk->tok.loc, HAWK_ECOMMA, FMT_ECOMMA, HAWK_OOECS_LEN(hawk->tok.name), HAWK_OOECS_PTR(hawk->tok.name));
|
hawk_seterrfmt(hawk, &hawk->tok.loc, HAWK_ECOMMA, FMT_ECOMMA, HAWK_OOECS_LEN(hawk->tok.name), HAWK_OOECS_PTR(hawk->tok.name));
|
||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,3 +37,10 @@ BEGIN {
|
|||||||
BEGIN {
|
BEGIN {
|
||||||
@nil = 10 ##ERROR: invalid assignment statement
|
@nil = 10 ##ERROR: invalid assignment statement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
@{};
|
||||||
|
@{ "hello", "world } ##ERROR: colon expected in place of ','
|
||||||
|
}
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ function main()
|
|||||||
tap_ensure (((10,30,30) in c), 0, @SCRIPTNAME, @SCRIPTLINE);
|
tap_ensure (((10,30,30) in c), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
|
|
||||||
c = @{ "abc", 10, "def", 20.9 };
|
c = @{ "abc": 10, "def": 20.9 };
|
||||||
tap_ensure (c["abc"], 10, @SCRIPTNAME, @SCRIPTLINE);
|
tap_ensure (c["abc"], 10, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
tap_ensure (c["def"], 20.9, @SCRIPTNAME, @SCRIPTLINE);
|
tap_ensure (c["def"], 20.9, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user