Skip to content

Commit e5868f4

Browse files
committed
FEAT: made parse's ahead being a synonym for and for better compatibility with Red
resolves: Oldes/Rebol-issues#2095
1 parent 19974e2 commit e5868f4

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/boot/words.reb

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ any
143143
opt
144144
not
145145
and
146+
ahead
146147
then
147148
remove
148149
insert

src/core/u-parse.c

+1
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
739739
continue;
740740

741741
case SYM_AND:
742+
case SYM_AHEAD:
742743
SET_FLAG(flags, PF_AND);
743744
continue;
744745

src/tests/units/parse-test.r3

+20
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ Rebol [
6565
--assert not parse "" [not [0 "a"]]
6666
===end-group===
6767

68+
===start-group=== "AND / AHEAD"
69+
;@@ https://github.com/Oldes/Rebol-issues/issues/2095
70+
--test-- "and"
71+
--assert parse "a" [and #"a" skip]
72+
--assert all [parse "abc" [#"a" and #"b" copy x to end] x = "bc"]
73+
--assert parse [1] [and integer! skip]
74+
--assert parse [1 hi] [integer! and word! skip]
75+
--assert all [parse [hi @bob] ['hi and ref! copy x skip] x = @bob]
76+
--assert not parse "a" [and #"b" skip]
77+
--assert not parse [1] [and word! skip]
78+
--test-- "ahead"
79+
--assert parse "a" [ahead #"a" skip]
80+
--assert all [parse "abc" [#"a" ahead #"b" copy x to end] x = "bc"]
81+
--assert parse [1] [ahead integer! skip]
82+
--assert parse [1 hi] [integer! ahead word! skip]
83+
--assert all [parse [hi @bob] ['hi ahead ref! set x skip] x = @bob]
84+
--assert not parse "a" [ahead #"b" skip]
85+
--assert not parse [1] [ahead word! skip]
86+
===end-group===
87+
6888

6989
===start-group=== "THEN"
7090
--test-- "then"

0 commit comments

Comments
 (0)