From 24c91d337682215d3b491ff12c5924069403779c Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 18 Nov 2025 18:49:38 +0900 Subject: [PATCH] updated the parser to require a colone after a key for @{} --- lib/parse.c | 20 +++++++++++++++----- t/e-001.err | 7 +++++++ t/h-001.hawk | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/parse.c b/lib/parse.c index fe6dd6e6..fe34b875 100644 --- a/lib/parse.c +++ b/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_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_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() */ - hawk_nde_t* nde = HAWK_NULL; hawk_mod_t* mod; hawk_mod_sym_t sym; 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.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) @@ -6419,10 +6419,20 @@ static hawk_nde_t* parse_fncall (hawk_t* hawk, const hawk_oocs_t* name, hawk_fnc break; } - if (!MATCH(hawk, TOK_COMMA)) + if ((flags & FNCALL_FLAG_MAP) && (nargs & 1)) { - hawk_seterrfmt(hawk, &hawk->tok.loc, HAWK_ECOMMA, FMT_ECOMMA, HAWK_OOECS_LEN(hawk->tok.name), HAWK_OOECS_PTR(hawk->tok.name)); - goto oops; + 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)) + { + hawk_seterrfmt(hawk, &hawk->tok.loc, HAWK_ECOMMA, FMT_ECOMMA, HAWK_OOECS_LEN(hawk->tok.name), HAWK_OOECS_PTR(hawk->tok.name)); + goto oops; + } } do diff --git a/t/e-001.err b/t/e-001.err index 504ca0ae..34486e04 100644 --- a/t/e-001.err +++ b/t/e-001.err @@ -37,3 +37,10 @@ BEGIN { BEGIN { @nil = 10 ##ERROR: invalid assignment statement } + +--- + +BEGIN { + @{}; + @{ "hello", "world } ##ERROR: colon expected in place of ',' +} diff --git a/t/h-001.hawk b/t/h-001.hawk index a7a91a8a..3c1cda37 100644 --- a/t/h-001.hawk +++ b/t/h-001.hawk @@ -271,7 +271,7 @@ function main() 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["def"], 20.9, @SCRIPTNAME, @SCRIPTLINE); }