Skip to content

Commit 8db79a9

Browse files
committed
Permit SET-WORD! as the argument to COPY and SET in PARSE (CC #2023)
1 parent 4d9840f commit 8db79a9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/core/u-parse.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef struct reb_parse {
4646
} REBPARSE;
4747

4848
enum parse_flags {
49-
PF_SET,
49+
PF_SET_OR_COPY, // test PF_COPY first; if false, this means PF_SET
5050
PF_COPY,
5151
PF_NOT,
5252
PF_NOT2,
@@ -707,9 +707,9 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
707707
case SYM_COPY:
708708
SET_FLAG(flags, PF_COPY);
709709
case SYM_SET:
710-
SET_FLAG(flags, PF_SET);
710+
SET_FLAG(flags, PF_SET_OR_COPY);
711711
item = rules++;
712-
if (!IS_WORD(item)) Trap1(RE_PARSE_VARIABLE, item);
712+
if (!(IS_WORD(item) || IS_SET_WORD(item))) Trap1(RE_PARSE_VARIABLE, item);
713713
if (VAL_CMD(item)) Trap1(RE_PARSE_COMMAND, item);
714714
word = item;
715715
continue;
@@ -788,9 +788,12 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
788788
// Any other cmd must be a match command, so proceed...
789789

790790
} else { // It's not a PARSE command, get or set it:
791-
792-
// word: - set a variable to the series at current index
793-
if (IS_SET_WORD(item)) {
791+
792+
// word: - if not the target of a COPY or SET operation, this will
793+
// default to setting a variable to the series at current index
794+
if (IS_SET_WORD(item) &&
795+
!GET_FLAG(flags, PF_SET_OR_COPY) || GET_FLAG(flags, PF_COPY))
796+
{
794797
Set_Var_Series(item, parse->type, series, index);
795798
continue;
796799
}
@@ -991,7 +994,7 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
991994
: Copy_String(series, begin, count); // condenses
992995
Set_Var_Series(word, parse->type, ser, 0);
993996
}
994-
else if (GET_FLAG(flags, PF_SET)) {
997+
else if (GET_FLAG(flags, PF_SET_OR_COPY)) {
995998
if (IS_BLOCK_INPUT(parse)) {
996999
item = Get_Var_Safe(word);
9971000
if (count == 0) SET_NONE(item);

0 commit comments

Comments
 (0)