From 388be3e0e1fcd5cfc184c2f41bb5e0a171b59097 Mon Sep 17 00:00:00 2001 From: Jang Rush Date: Sun, 18 Sep 2022 04:43:56 +0000 Subject: [PATCH 1/6] Update Js.String[2].match_ return type `Js.String2.match_` and `Js.String.match_` return type was changed in rescript-lang/rescript-compiler#5070 and released on 10.0.0. This commit updates the API documentation. close #551 --- pages/docs/manual/latest/api/js/string-2.mdx | 17 +++++++++-------- pages/docs/manual/latest/api/js/string.mdx | 10 +++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pages/docs/manual/latest/api/js/string-2.mdx b/pages/docs/manual/latest/api/js/string-2.mdx index 7d88129c4..fd007efd1 100644 --- a/pages/docs/manual/latest/api/js/string-2.mdx +++ b/pages/docs/manual/latest/api/js/string-2.mdx @@ -315,22 +315,23 @@ Js.String2.localeCompare("CAT", "cat") > 0.0 ## match ```res sig -let match_: (t, Js_re.t) => option> +let match_: (t, Js_re.t) => option>> ``` -`match(str, regexp)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: +`match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses -For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. +For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ```res example -Js.String2.match_("The better bats", %re("/b[aeiou]t/")) == Some(["bet"]) -Js.String2.match_("The better bats", %re("/b[aeiou]t/g")) == Some(["bet", "bat"]) -Js.String2.match_("Today is 2018-04-05.", %re("/(\d+)-(\d+)-(\d+)/")) == - Some(["2018-04-05", "2018", "04", "05"]) -Js.String2.match_("The large container.", %re("/b[aeiou]g/")) == None +Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some([Some("bet")]) +Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some([Some("bet"), Some("bat")]) +Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") == + Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) +Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None ``` + ## normalize ```res sig diff --git a/pages/docs/manual/latest/api/js/string.mdx b/pages/docs/manual/latest/api/js/string.mdx index 7e4eb846d..706eb1e35 100644 --- a/pages/docs/manual/latest/api/js/string.mdx +++ b/pages/docs/manual/latest/api/js/string.mdx @@ -315,19 +315,19 @@ Js.String.localeCompare("cat", "CAT") > 0.0 ## match ```res sig -let match_: (Js_re.t, t) => option> +let match_: (Js_re.t, t) => option>> ``` `match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses -For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. +For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ```res example -Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some(["bet"]) -Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some(["bet", "bat"]) +Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some([Some("bet")]) +Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some([Some("bet"), Some("bat")]) Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") == - Some(["2018-04-05", "2018", "04", "05"]) + Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None ``` From 543cbc310e7b98ef7583ec2a41b2a4cd4222ec63 Mon Sep 17 00:00:00 2001 From: Jang Rush Date: Sun, 18 Sep 2022 06:35:38 +0000 Subject: [PATCH 2/6] Update test-examples to test against 10.0.0 --- compilers/package-lock.json | 19 +++++++++++++++++++ compilers/package.json | 3 ++- scripts/test-examples.mjs | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/compilers/package-lock.json b/compilers/package-lock.json index e7c6749ba..c0364fb4d 100644 --- a/compilers/package-lock.json +++ b/compilers/package-lock.json @@ -9,11 +9,25 @@ "version": "1.0.0", "license": "MIT", "dependencies": { + "rescript-1000": "npm:rescript@10.0.0", "rescript-820": "npm:bs-platform@8.2.0", "rescript-902": "npm:bs-platform@9.0.2", "rescript-912": "npm:rescript@9.1.2" } }, + "node_modules/rescript-1000": { + "name": "rescript", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.0.0.tgz", + "integrity": "sha512-LhNg/4+0j8NvoFeslgAeYLlzUwkq6kR6l6v8BnZ61VDTxopK2l96uT1lq5lv1aMxzMDynvE2qnX0zalre+6XxA==", + "hasInstallScript": true, + "bin": { + "bsc": "bsc", + "bsrefmt": "bsrefmt", + "bstracing": "lib/bstracing", + "rescript": "rescript" + } + }, "node_modules/rescript-820": { "name": "bs-platform", "version": "8.2.0", @@ -41,6 +55,11 @@ } }, "dependencies": { + "rescript-1000": { + "version": "npm:rescript@10.0.0", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.0.0.tgz", + "integrity": "sha512-LhNg/4+0j8NvoFeslgAeYLlzUwkq6kR6l6v8BnZ61VDTxopK2l96uT1lq5lv1aMxzMDynvE2qnX0zalre+6XxA==" + }, "rescript-820": { "version": "npm:bs-platform@8.2.0", "resolved": "https://registry.npmjs.org/bs-platform/-/bs-platform-8.2.0.tgz", diff --git a/compilers/package.json b/compilers/package.json index 44e912546..9ed24d9b3 100644 --- a/compilers/package.json +++ b/compilers/package.json @@ -7,6 +7,7 @@ "dependencies": { "rescript-820": "npm:bs-platform@8.2.0", "rescript-902": "npm:bs-platform@9.0.2", - "rescript-912": "npm:rescript@9.1.2" + "rescript-912": "npm:rescript@9.1.2", + "rescript-1000": "npm:rescript@10.0.0" } } diff --git a/scripts/test-examples.mjs b/scripts/test-examples.mjs index 602e4d49f..ccdcf851e 100644 --- a/scripts/test-examples.mjs +++ b/scripts/test-examples.mjs @@ -13,7 +13,7 @@ let tempFileNameRegex = /_tempFile\.res/g // see the package.json on how to define another rescript version let compilersDir = path.join(__dirname, "..", "compilers") -let bsc = path.join(compilersDir, 'node_modules', 'rescript-912', process.platform, 'bsc.exe') +let bsc = path.join(compilersDir, 'node_modules', 'rescript-1000', process.platform, 'bsc.exe') const prepareCompilers = () => { if (fs.existsSync(bsc)) { @@ -82,7 +82,7 @@ glob.sync(__dirname + '/../pages/docs/manual/latest/**/*.mdx').forEach((file) => try { // -109 for suppressing `Toplevel expression is expected to have unit type.` // Most doc snippets do e.g. `Belt.Array.length(["test"])`, which triggers this - child_process.execFileSync(bsc, ['-i', tempFileName, '-w', '-109'], {stdio: 'pipe'}) + child_process.execFileSync(bsc, [tempFileName, '-w', '-109'], {stdio: 'pipe'}) } catch (e) { process.stdout.write(postprocessOutput(file, e)) success = false From 2481a27830bdf5cff5791835c33e896e3ccfa956 Mon Sep 17 00:00:00 2001 From: Jang Rush Date: Sun, 18 Sep 2022 06:36:38 +0000 Subject: [PATCH 3/6] update examples to 10.0.0 `/** */` is considered as doc comment now. The old example just uses it as multi-line comments for print output. Thus, I change it to `/* */` instead. --- pages/docs/manual/latest/api/belt/range.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/docs/manual/latest/api/belt/range.mdx b/pages/docs/manual/latest/api/belt/range.mdx index 983789986..9223d2dc7 100644 --- a/pages/docs/manual/latest/api/belt/range.mdx +++ b/pages/docs/manual/latest/api/belt/range.mdx @@ -27,7 +27,7 @@ equivalent to `Belt.Array.(forEach(range(start, finish), action))` ```res example Belt.Range.forEach(0, 4, (i) => Js.log(i)) -/** +/* * prints: * 0 * 1 From 3cb0a25311c502fa4287d1d23cb60c4390b88ea8 Mon Sep 17 00:00:00 2001 From: Jang Rush Date: Sun, 18 Sep 2022 06:40:03 +0000 Subject: [PATCH 4/6] Ignore generated files via test example script --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 45fba9594..b3dd781d4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,11 @@ node_modules/ .next/ index_data/*.json +# Generated via test examples script +_tempFile.cmi +_tempFile.cmj +_tempFile.cmt + # these docs are checked in, but we consider them frozen. pages/docs/manual/v8.0.0/ pages/docs/manual/v9.0.0/ From 0a8d9d095ffc5fae309f8764d8b55ea8cf7e504d Mon Sep 17 00:00:00 2001 From: Jang Rush Date: Sun, 18 Sep 2022 06:50:25 +0000 Subject: [PATCH 5/6] markdown formatting for api/js/string[2] --- pages/docs/manual/latest/api/js/string-2.mdx | 1 + pages/docs/manual/latest/api/js/string.mdx | 1 + 2 files changed, 2 insertions(+) diff --git a/pages/docs/manual/latest/api/js/string-2.mdx b/pages/docs/manual/latest/api/js/string-2.mdx index fd007efd1..d489fa262 100644 --- a/pages/docs/manual/latest/api/js/string-2.mdx +++ b/pages/docs/manual/latest/api/js/string-2.mdx @@ -321,6 +321,7 @@ let match_: (t, Js_re.t) => option>> `match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses + For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ```res example diff --git a/pages/docs/manual/latest/api/js/string.mdx b/pages/docs/manual/latest/api/js/string.mdx index 706eb1e35..d31b13409 100644 --- a/pages/docs/manual/latest/api/js/string.mdx +++ b/pages/docs/manual/latest/api/js/string.mdx @@ -321,6 +321,7 @@ let match_: (Js_re.t, t) => option>> `match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses + For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ```res example From dec5b5fb66e36d410f0cd6e9645210871a4e4a4d Mon Sep 17 00:00:00 2001 From: Jang Rush Date: Sun, 18 Sep 2022 10:43:50 +0000 Subject: [PATCH 6/6] fixup! Update Js.String[2].match_ return type --- pages/docs/manual/latest/api/js/string-2.mdx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pages/docs/manual/latest/api/js/string-2.mdx b/pages/docs/manual/latest/api/js/string-2.mdx index d489fa262..ee4a90439 100644 --- a/pages/docs/manual/latest/api/js/string-2.mdx +++ b/pages/docs/manual/latest/api/js/string-2.mdx @@ -318,21 +318,20 @@ Js.String2.localeCompare("CAT", "cat") > 0.0 let match_: (t, Js_re.t) => option>> ``` -`match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: +`match(str, regexp)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ```res example -Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some([Some("bet")]) -Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some([Some("bet"), Some("bat")]) -Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") == +Js.String2.match_("The better bats", %re("/b[aeiou]t/")) == Some([Some("bet")]) +Js.String2.match_("The better bats", %re("/b[aeiou]t/g")) == Some([Some("bet"), Some("bat")]) +Js.String2.match_("Today is 2018-04-05.", %re("/(\d+)-(\d+)-(\d+)/")) == Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) -Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None +Js.String2.match_("The large container.", %re("/b[aeiou]g/")) == None ``` - ## normalize ```res sig