Skip to content

Commit

Permalink
FEAT: implemented case and no-case PARSE keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jul 6, 2022
1 parent 6b47c24 commit b5fc6f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/boot/words.reb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ while
return
limit
??
case
no-case
accept
break
; match words:
Expand Down
7 changes: 7 additions & 0 deletions src/core/u-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,13 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
case SYM_QQ:
Print_Parse_Index(parse->type, rules, series, index);
continue;

case SYM_CASE:
parse->flags |= AM_FIND_CASE;
continue;
case SYM_NO_CASE:
parse->flags &= ~AM_FIND_CASE;
continue;
}
}
// Any other cmd must be a match command, so proceed...
Expand Down
18 changes: 18 additions & 0 deletions src/tests/units/parse-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ Rebol [
===end-group===


===start-group=== "CASE / NO-CASE"
;@@ https://github.com/Oldes/Rebol-issues/issues/1898
--test-- "case/no-case 1"
--assert parse "aAaBbBcccDDD" [no-case "AAA" case "BbB" "ccc" no-case "ddd"]
--assert parse/case "aAaBbBcccDDD" [no-case "AAA" case "BbB" "ccc" no-case "ddd"]
--test-- "case/no-case 2"
--assert all [parse b: ["aAa"][case ["AAA" | change "aAa" "AAA"]] b == ["AAA"]]
--assert all [parse b: ["aAa"][case "AAA" | no-case change "aaa" "AAA"] b == ["AAA"]]
--test-- "case/no-case 3"
--assert parse "aaaAB" [case thru #"A" #"B"]
--assert parse "aaaAB" [case thru #"A" no-case #"b"]
--test-- "case/no-case 4"
--assert parse to binary! "aaaAB" [thru #"A" #"B"]
--assert parse to binary! "aaaAB" [thru #"A" no-case #"b"]
--assert not parse to binary! "aaaAB" [thru #"A" #"b"]
===end-group===


===start-group=== "CHANGE"

--test-- "CHANGE string"
Expand Down

0 comments on commit b5fc6f2

Please sign in to comment.