@@ -56,6 +56,7 @@ enum parse_flags {
56
56
PF_CHANGE ,
57
57
PF_RETURN ,
58
58
PF_WHILE ,
59
+ PF_ADVANCE , // used to report that although index was not changed, rule is suppose to advance
59
60
};
60
61
61
62
#define MAX_PARSE_DEPTH 512
@@ -839,8 +840,8 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
839
840
// #2269 - reset the position if we are not in the middle of any rule
840
841
// don't allow code like: [copy x :pos integer!]
841
842
if (flags != 0 ) Trap1 (RE_PARSE_RULE , rules - 1 );
842
- begin = index ;
843
-
843
+ begin = index ;
844
+ SET_FLAG ( parse -> flags , PF_ADVANCE );
844
845
continue ;
845
846
}
846
847
@@ -978,10 +979,20 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
978
979
if (i != NOT_FOUND ) {
979
980
count ++ ; // may overflow to negative
980
981
if (count < 0 ) count = MAX_I32 ; // the forever case
982
+
981
983
// If input did not advance:
982
- if (i == index && !GET_FLAG (flags , PF_WHILE )) {
983
- if (count < mincount ) index = NOT_FOUND ; // was not enough
984
- break ;
984
+ if (i == index ) {
985
+ // check if there was processed some _modifying_ rule, which should advance
986
+ // even if index was not changed (https://github.com/Oldes/Rebol-issues/issues/2452)
987
+ if (GET_FLAG (parse -> flags , PF_ADVANCE )) {
988
+ // clear the state in case, that there are other rules to be processed
989
+ // keep it in case that we were at the last one
990
+ if (count < maxcount ) CLR_FLAG (parse -> flags , PF_ADVANCE );
991
+ }
992
+ else if (!GET_FLAG (flags , PF_WHILE )) {
993
+ if (count < mincount ) index = NOT_FOUND ; // was not enough
994
+ break ;
995
+ }
985
996
}
986
997
}
987
998
//if (i >= series->tail) { // OLD check: no more input
@@ -1058,6 +1069,7 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
1058
1069
if (IS_PROTECT_SERIES (series )) Trap0 (RE_PROTECTED );
1059
1070
Remove_Series (series , begin , count );
1060
1071
}
1072
+ SET_FLAG (parse -> flags , PF_ADVANCE );
1061
1073
index = begin ;
1062
1074
}
1063
1075
if (flags & (1 <<PF_INSERT | 1 <<PF_CHANGE )) {
@@ -1090,6 +1102,7 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
1090
1102
index = Modify_String (GET_FLAG (flags , PF_CHANGE ) ? A_CHANGE : A_INSERT ,
1091
1103
series , begin , item , cmd , count , 1 );
1092
1104
}
1105
+ SET_FLAG (parse -> flags , PF_ADVANCE );
1093
1106
}
1094
1107
if (GET_FLAG (flags , PF_AND )) index = begin ;
1095
1108
}
0 commit comments