Skip to content

Commit 577b45a

Browse files
committed
FIX: PARSE's INSERT used after a seek puts data at the position before the seek
resolves: Oldes/Rebol-issues#2269
1 parent 3ce053a commit 577b45a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/core/u-parse.c

+6
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,12 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
832832
if (!ANY_SERIES(item)) Trap1(RE_PARSE_SERIES, rules-1);
833833
index = Set_Parse_Series(parse, item);
834834
series = parse->series;
835+
836+
// #2269 - reset the position if we are not in the middle of any rule
837+
// don't allow code like: [copy x :pos integer!]
838+
if (flags != 0) Trap1(RE_PARSE_RULE, rules-1);
839+
begin = index;
840+
835841
continue;
836842
}
837843

src/tests/units/parse-test.r3

+36
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,42 @@ Rebol [
220220
val = "f"
221221
pos = ser
222222
]
223+
--test-- "get-word use"
224+
;@@ https://github.com/Oldes/Rebol-issues/issues/2269
225+
s: copy "ab"
226+
--assert all [
227+
parse s [p: to end :p insert "x" to end]
228+
s = "xab"
229+
p = s
230+
]
231+
s: copy "ab"
232+
--assert all [
233+
parse s [p: 1 skip :p insert "x" to end]
234+
s = "xab"
235+
p = s
236+
]
237+
s: copy "ab"
238+
--assert all [
239+
parse s [1 skip p: 1 skip :p insert "x" to end]
240+
s = "axb"
241+
p = "xb"
242+
]
243+
s: copy "abcd"
244+
--assert all [
245+
error? e: try [parse s [x: "ab" thru :s "abcd"]]
246+
e/id = 'parse-rule
247+
]
248+
--assert parse s [x: "ab" :s thru "abcd"]
249+
s: copy "abcd" parse s ["ab" p: "c" :p copy x to end]
250+
--assert all [p = "cd" x = "cd"]
251+
s: copy "abcd" parse s ["ab" p: "c" :p set x to end]
252+
--assert all [p = "cd" x = #"c"]
253+
--assert all [
254+
; get-word used in middle of the rule
255+
error? e: try [parse "abcd" [x: "ab" copy y :s thru "abcd"]]
256+
e/id = 'parse-rule
257+
e/arg1 = quote :s
258+
]
223259

224260
===end-group===
225261

0 commit comments

Comments
 (0)