Skip to content

Commit c7b68ea

Browse files
committed
Make seeks in PARSE via GET-WORD! reset begin between rules
Cryptically, the INSERT command does not use the "current" parse position, but rather the "begin" position...where the parse position was when the current rule started. It's not clear why that was chosen though it looks to have been on purpose. This leads to quirky behavior when coordinating with GET-WORD! seeks that change the parse position, because those seeks never actually reset the `begin` point. This ties into a broader issue discussed in an issue about what MARK and SEEK mean when used while a partially expressed rule is in progress: metaeducation/rebol-issues#2269 As a minimum disruption to at least fix the most obvious problem for now, this makes any seeks that aren't "in the middle of a rule" (e.g. flags=0 due to post_rule_processing) reset the begin position, as if they were their own rule. #2269 is left open for discussion.
1 parent c5c58cd commit c7b68ea

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/core/u-parse.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,14 @@ REBNATIVE(subparse)
16391639

16401640
// word: - set a variable to the series at current index
16411641
if (IS_SET_WORD(P_RULE)) {
1642+
//
1643+
// !!! Review meaning of marking the parse in a slot that
1644+
// is a target of a rule, e.g. `thru pos: xxx` #
1645+
//
1646+
// https://github.com/rebol/rebol-issues/issues/2269
1647+
//
1648+
// if (flags != 0) fail (Error_Parse_Rule());
1649+
16421650
*Sink_Var_May_Fail(P_RULE, P_RULE_SPECIFIER)
16431651
= *P_INPUT_VALUE;
16441652
FETCH_NEXT_RULE_MAYBE_END(f);
@@ -1652,6 +1660,22 @@ REBNATIVE(subparse)
16521660
if (!ANY_SERIES(&temp)) // #1263
16531661
fail (Error(RE_PARSE_SERIES, P_RULE));
16541662
Set_Parse_Series(f, &temp);
1663+
1664+
// !!! `continue` is used here without any post-"match"
1665+
// processing, so the only way `begin` will get set for
1666+
// the next rule is if it's set here, else commands like
1667+
// INSERT that follow will insert at the old location.
1668+
//
1669+
// https://github.com/rebol/rebol-issues/issues/2269
1670+
//
1671+
// Without known resolution on #2269, it isn't clear if
1672+
// there is legitimate meaning to seeking a parse in mid
1673+
// rule or not. So only reset the begin position if the
1674+
// seek appears to be a "separate rule" in its own right.
1675+
//
1676+
if (flags == 0)
1677+
begin = P_POS;
1678+
16551679
FETCH_NEXT_RULE_MAYBE_END(f);
16561680
continue;
16571681
}

0 commit comments

Comments
 (0)