Skip to content

Commit

Permalink
Eliminate UPARSE?/PARSE?/PARSE2?, update tests
Browse files Browse the repository at this point in the history
This is a very large change which embraces the new DID and DIDN'T
concept, as opposed to needing to make LOGIC!-bearing variations
of functions that return [<opt> any-value!] where you might want
to test the NULL case as soft-failure.

But intead of rotely converting the tests based on UPARSE? to just
check DID UPARSE?, this painstakingly codified what the actual
successful return result was.  It was done by hand as an audit of
any unusual results, which triggered some modifications.  While
painful to go through the 1,000 or so cases, it should provide
more test coverage.
  • Loading branch information
hostilefork committed May 16, 2022
1 parent 0ee1a91 commit dd23a6e
Show file tree
Hide file tree
Showing 89 changed files with 1,598 additions and 1,508 deletions.
2 changes: 1 addition & 1 deletion extensions/console/ext-console-init.reb
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ ext-console-impl: func [
let directives: collect [
let i
if block? prior [
parse prior [some [set i: issue! (keep i)] end]
parse3 prior [some [set i: issue! (keep i)] end]
]
]

Expand Down
2 changes: 1 addition & 1 deletion extensions/filesystem/ext-filesystem-init.reb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sys.make-scheme [
info: system.standard.file-info ; for C enums
init: func [return: <none> port <local> path] [
if url? port.spec.ref [
parse port.spec.ref [thru #":" 0 2 slash path:]
parse3 port.spec.ref [thru #":" 0 2 slash path:]
append port.spec compose [path: (to file! path)]
]
]
Expand Down
4 changes: 2 additions & 2 deletions extensions/javascript/tools/prep-libr3-js.reb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ to-js-type: func [
; The differences between undefined and null are subtle and easy to
; get wrong, but a void-returning function should map to undefined.
;
parse2? s ["void" opt some space] ["undefined"]
did parse2 s ["void" opt some space] ["undefined"]
]
]

Expand Down Expand Up @@ -364,7 +364,7 @@ for-each-api [
]

no-reb-name: _
if not parse2? name ["reb" copy no-reb-name to end] [
if didn't parse2 name ["reb" copy no-reb-name to end] [
fail ["API name must start with `reb`" name]
]

Expand Down
4 changes: 2 additions & 2 deletions extensions/locale/iso3166.r
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ capitalize: func [
]

iso-3166-table: make map! 512
parse cnt [
parse3 cnt [
some [
copy name to ";"
";" copy code-2 to "^/" (
Expand All @@ -51,7 +51,7 @@ parse cnt [
init-code: to text! read init
space: charset " ^-^M^/"
iso-3166-table-count: find mold iso-3166-table #"["
parse init-code [
parse3 init-code [
thru "iso-3166-table:"
to #"["
change [
Expand Down
4 changes: 2 additions & 2 deletions extensions/locale/iso639.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ iso-639-table: make map! 1024
lower: charset [#"a" - #"z"]
letter: charset [#"a" - #"z" #"A" - #"Z"]

parse cnt [
parse3 cnt [
some [
;initialization
(code-2: name: _)
Expand Down Expand Up @@ -54,7 +54,7 @@ parse cnt [
init-code: to text! read init
space: charset " ^-^M^/"
iso-639-table-count: find mold iso-639-table #"["
parse init-code [
parse3 init-code [
thru "iso-639-table:"
to #"["
change [
Expand Down
2 changes: 1 addition & 1 deletion extensions/tcc/ext-tcc-init.reb
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ c99: func [
]
'OBJ [
if infile != <multi> [
parse copy infile [to [".c" end] change ".c" ".o"] else [
parse3 copy infile [to [".c" end] change ".c" ".o"] else [
fail "Input file must end in `.c` for use with -c"
]
]
Expand Down
4 changes: 2 additions & 2 deletions extensions/uuid/make-libuuid.reb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fix-randutils.c: func [
{"c.h"}
]

parse text [
parse3 text [
add-config.h
insert {^/#include <errno.h>^/}

Expand Down Expand Up @@ -96,7 +96,7 @@ fix-gen_uuid.c: function [
| {"sha1.h"}
]

parse text [
parse3 text [
add-config.h

opt some [
Expand Down
6 changes: 3 additions & 3 deletions scripts/changes-file/changes-file.reb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ parse-credits-for-authors: function [ ; used as switch in github-user-name
collect [
keep [{Carl Sassenrath} [{@carls}]]

parse to-text read credits-file [
parse3 to-text read credits-file [
thru {Code Contributors}
opt some [
{**} copy author: to {**} {**} newline
Expand Down Expand Up @@ -145,7 +145,7 @@ notable?: function [

; Let's try and categorize type of commit (default is 'Changed)
category: 'Changed
parse text: c.summary [[
parse3 text: c.summary [[
opt "* "
["Add" | "-add"] (category: 'Added)
| ["Fix" | "Patch" | "-fix"] (category: 'Fixed)
Expand All @@ -157,7 +157,7 @@ notable?: function [

; record any bug#NNNN or CC (CureCode) found
cc: make block! 0
parse text [
parse3 text [
opt some [
"bug#" copy cc-num: some numbers (
append c [type: 'Fixed] ; it's a bug fix!
Expand Down
26 changes: 13 additions & 13 deletions scripts/encap.reb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ elf-format: context [
string-section [binary!]
][
let index: 0
parse section-headers [
parse3 section-headers [
repeat (e_shnum) [
(mode: 'read) section-header-rule
(
Expand Down Expand Up @@ -266,7 +266,7 @@ elf-format: context [
][
assert [e_phoff < offset] ; program headers are before any changes

parse skip executable e_phoff [
parse3 skip executable e_phoff [
repeat (e_phnum) [
(mode: 'read) let pos: <here>, program-header-rule
(if p_offset >= offset [p_offset: p_offset + delta])
Expand All @@ -280,7 +280,7 @@ elf-format: context [
assert [e_shoff >= offset] ; section headers are after any changes

let pos
parse skip executable e_shoff [
parse3 skip executable e_shoff [
repeat (e_shnum) [
(mode: 'read) let pos: <here>, section-header-rule
(if sh_offset >= offset [sh_offset: sh_offset + delta])
Expand Down Expand Up @@ -323,7 +323,7 @@ elf-format: context [
;
let string-header-offset: e_shoff + (e_shstrndx * e_shentsize)

parse skip executable string-header-offset [
parse3 skip executable string-header-offset [
(mode: 'read) section-header-rule to <end>
] else [
fail "Error finding string section in ELF binary"
Expand Down Expand Up @@ -362,7 +362,7 @@ elf-format: context [

; Update the size of the embedded section in it's section header
;
parse skip executable e_shoff + (section-index * e_shentsize) [
parse3 skip executable e_shoff + (section-index * e_shentsize) [
(sh_size: new-size)
(mode: 'write) section-header-rule
<end>
Expand Down Expand Up @@ -407,7 +407,7 @@ elf-format: context [

; Update string table size in its corresponding header.
;
parse skip executable string-header-offset [
parse3 skip executable string-header-offset [
(mode: 'read) let pos: <here>, section-header-rule
(
assert [sh_offset = string-section-offset]
Expand All @@ -431,7 +431,7 @@ elf-format: context [
; miscellaneous program-specific purposes, and hence not touched
; by strip...it is also not mapped into memory.
;
parse new-section-header [
parse3 new-section-header [
(
sh_name: string-section-size ; w.r.t string-section-offset
sh_type: 7 ; SHT_NOTE
Expand Down Expand Up @@ -481,7 +481,7 @@ elf-format: context [
; (main header write is done after the branch.)
]

parse executable [
parse3 executable [
(mode: 'write) header-rule to <end>
] else [
fail "Error updating the ELF header"
Expand All @@ -494,7 +494,7 @@ elf-format: context [
][
let header-data: read/part file 64 ; 64-bit size, 32-bit is smaller

parse header-data [(mode: 'read) header-rule to <end>] else [
parse3 header-data [(mode: 'read) header-rule to <end>] else [
return null
]

Expand All @@ -504,7 +504,7 @@ elf-format: context [
; The string names of the sections are themselves stored in a section,
; (at index `e_shstrndx`)
;
parse skip section-headers-data (e_shstrndx * e_shentsize) [
parse3 skip section-headers-data (e_shstrndx * e_shentsize) [
(mode: 'read) section-header-rule to <end>
] else [
fail "Error finding string section in ELF binary"
Expand Down Expand Up @@ -614,7 +614,7 @@ pe-format: context [
| skip
]

parse rule [opt some block-rule] else [fail]
parse3 rule [opt some block-rule] else [fail]

set name make object! append def [~unset~]
return bind rule get name
Expand Down Expand Up @@ -820,7 +820,7 @@ pe-format: context [
exe-data [binary!]
][
reset
parse exe-data exe-rule
parse3 exe-data exe-rule
if err = 'missing-dos-signature [
return false ; soft failure (just wasn't an EXE, no "MZ")
]
Expand Down Expand Up @@ -1274,7 +1274,7 @@ encap: func [
print ["Compressed resource is" length of compressed "bytes long."]

case [
parse? executable [
parse3 executable [
(elf-format.mode: 'read) elf-format.header-rule to <end>
][
print "ELF format found"
Expand Down
10 changes: 5 additions & 5 deletions scripts/prot-http.r
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ REBOL [
digit: charset [#"0" - #"9"]
alpha: charset [#"a" - #"z" #"A" - #"Z"]
idate-to-date: function [return: [date!] date [text!]] [
parse date [
parse3 date [
5 skip
copy day: 2 digit
space
Expand Down Expand Up @@ -165,7 +165,7 @@ parse-write-dialect: function [
block [block!]
][
spec: port.spec
parse block [
parse3 block [
opt ['headers (spec.debug: true)]
opt ['no-redirect (spec.follow: 'ok)]
[set temp: word! (spec.method: temp) | (spec.method: 'post)]
Expand Down Expand Up @@ -468,7 +468,7 @@ read-body: function [
; even have enough input data for the chunk *size*, much less
; the chunk. READ until we have at least a chunk size.
;
loop [not parse? conn.data [
loop [didn't parse3 conn.data [
copy chunk-size: some hex-digits, thru crlfbin
mk1: <here>, to <end>
]][
Expand All @@ -494,7 +494,7 @@ read-body: function [
; Now we have the chunk size but may not have the chunk data.
; Loop until enough data is gathered.
;
loop [not parse? mk1 [
loop [didn't parse3 mk1 [
repeat (chunk-size) skip, mk2: <here>, crlfbin, to <end>
]][
read conn
Expand All @@ -515,7 +515,7 @@ read-body: function [
;
; https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer
;
parse mk1 [
parse3 mk1 [
crlfbin (trailer: "") to <end>
|
copy trailer to crlf2bin to <end>
Expand Down
4 changes: 2 additions & 2 deletions scripts/prot-tls.r
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ client-hello: func [
[version version]
]
block? version [
parse version [decimal! decimal!] else [
parse3 version [decimal! decimal!] else [
fail "BLOCK! /VERSION must be two DECIMAL! (min ver, max ver)"
]
version
Expand Down Expand Up @@ -1626,7 +1626,7 @@ do-commands: func [

let cmd
let arg
parse commands [
parse3 commands [
some [
; redundant `set cmd`, consider how ELIDE might improve it
; https://forum.rebol.info/t/1534/5
Expand Down
2 changes: 1 addition & 1 deletion scripts/redbol.reb
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ parse: emulate [
blank! [split input charset reduce [tab space CR LF]]
text! [split input to-bitset rules]
] else [
apply :uparse2? [input rules /case case_PARSE]
did apply :uparse2 [input rules /case case_PARSE]
]
]
]
Expand Down
2 changes: 1 addition & 1 deletion src/core/c-path.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ REB_R TO_Sequence(REBVAL *out, enum Reb_Kind kind, const REBVAL *arg) {
//
return rebValue(
"as", Datatype_From_Kind(kind), "catch [",
"parse let v: load @", arg, "[",
"parse3 let v: load @", arg, "[",
"[any-sequence! | any-array!] end (throw first v)",
"| (throw v)", // try to convert whatever other block
"]",
Expand Down
4 changes: 2 additions & 2 deletions src/core/u-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ static REB_R Parse_One_Rule(
// this patch handles the explicit case of wanting to match
// something like:
//
// >> parse? "ab" [thru ["ab"] ""]
// >> did parse3 "ab" [thru ["ab"] ""]
// == #[true]
//
// Just to show what should happen in the new model (R3-Alpha did
Expand Down Expand Up @@ -2804,7 +2804,7 @@ REBNATIVE(parse_p)
// native code in the future. But this is just to get people out of the
// habit of writing `IF PARSE ...`
//
return rebValue("'~use-PARSE?-for-logic~");
return rebValue("~use-DID-PARSE-for-logic~");
}


Expand Down
6 changes: 3 additions & 3 deletions src/main/main-startup.reb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ make-banner: func [
let spc: format ["**" 70 "**"] ""

let [a b s]
parse fmt [
parse3 fmt [
some [
[
set a: text! (s: format ["** " 68 "**"] a)
Expand Down Expand Up @@ -491,7 +491,7 @@ main-startup: func [

loop [not tail? argv] [

let is-option: parse?/case argv.1 [
let is-option: did parse3/case argv.1 [

["--" end] (
; Double-dash means end of command line arguments, and the
Expand Down Expand Up @@ -679,7 +679,7 @@ main-startup: func [
; heuristic is to check for more than one letter.
;
alphanum: charset [#"A" - #"Z" #"a" - #"z" #"0" #"9"]
o.script: parse o.script [alphanum some alphanum ":" to <end>] then [
o.script: parse3 o.script [alphanum some alphanum ":" to <end>] then [
to url! o.script
]
else [
Expand Down
13 changes: 6 additions & 7 deletions src/mezz/base-defs.r
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,15 @@ then?: func* [return: [logic!] ^optional [<opt> any-value!]] [
; UPARSE's design when it hardens. For now these routines provide some amount
; of interface parity with UPARSE.
;
parse: :parse*/fully ; could be more complex definition (UPARSE is!)
parse?: chain [:parse*/fully | :then?]
match-parse: enclose :parse func* [f] [
let input: f.input
do f then [input]
]
parse3: :parse*/fully ; could be more complex definition (UPARSE is!)
here: <here> ; temporary workaround for compatibility, will be removed

; Eventually, PARSE will be deprecated to force everyone to use either UPARSE
; or PARSE3. When that is ultimately settled, UPARSE will take the PARSE name.
;
parse: :parse3

parse2: :parse*/redbol/fully
parse2?: chain [:parse*/redbol/fully | :then?]

; The lower-level pointfree function separates out the action it takes, but
; the higher level one uses a block. Specialize out the action, and then
Expand Down
Loading

0 comments on commit dd23a6e

Please sign in to comment.