Skip to content

Commit

Permalink
FEAT: made parse's ahead being a synonym for and for better compa…
Browse files Browse the repository at this point in the history
…tibility with Red

resolves: Oldes/Rebol-issues#2095
  • Loading branch information
Oldes committed Sep 2, 2021
1 parent 19974e2 commit e5868f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/boot/words.reb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ any
opt
not
and
ahead
then
remove
insert
Expand Down
1 change: 1 addition & 0 deletions src/core/u-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
continue;

case SYM_AND:
case SYM_AHEAD:
SET_FLAG(flags, PF_AND);
continue;

Expand Down
20 changes: 20 additions & 0 deletions src/tests/units/parse-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ Rebol [
--assert not parse "" [not [0 "a"]]
===end-group===

===start-group=== "AND / AHEAD"
;@@ https://github.com/Oldes/Rebol-issues/issues/2095
--test-- "and"
--assert parse "a" [and #"a" skip]
--assert all [parse "abc" [#"a" and #"b" copy x to end] x = "bc"]
--assert parse [1] [and integer! skip]
--assert parse [1 hi] [integer! and word! skip]
--assert all [parse [hi @bob] ['hi and ref! copy x skip] x = @bob]
--assert not parse "a" [and #"b" skip]
--assert not parse [1] [and word! skip]
--test-- "ahead"
--assert parse "a" [ahead #"a" skip]
--assert all [parse "abc" [#"a" ahead #"b" copy x to end] x = "bc"]
--assert parse [1] [ahead integer! skip]
--assert parse [1 hi] [integer! ahead word! skip]
--assert all [parse [hi @bob] ['hi ahead ref! set x skip] x = @bob]
--assert not parse "a" [ahead #"b" skip]
--assert not parse [1] [ahead word! skip]
===end-group===


===start-group=== "THEN"
--test-- "then"
Expand Down

0 comments on commit e5868f4

Please # to comment.