Skip to content

remove Stdlib_Char module #7367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

- Fix `Error.fromException`. https://github.com/rescript-lang/rescript/pull/7364

#### :house: Internal

- Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367

# 12.0.0-alpha.10

#### :rocket: New Feature
Expand Down
4 changes: 0 additions & 4 deletions analysis/reanalyze/src/ExnLib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
in
let stdlibBigInt = [("fromStringExn", [jsExnError])] in
let stdlibBool = [("fromStringExn", [invalidArgument])] in
let stdlibChar = [("fromIntExn", [invalidArgument])] in
let stdlibError = [("raise", [jsExnError])] in
let stdlibExn =
[
Expand Down Expand Up @@ -143,7 +142,6 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
("Belt_SetString", beltSet);
("BigInt", stdlibBigInt);
("Bool", stdlibBool);
("Char", stdlibChar);
("Error", stdlibError);
("Exn", stdlibExn);
("Js.Json", [("parseExn", [jsExnError])]);
Expand All @@ -164,8 +162,6 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
("Stdlib.BigInt", stdlibBigInt);
("Stdlib_Bool", stdlibBool);
("Stdlib.Bool", stdlibBool);
("Stdlib_Char", stdlibChar);
("Stdlib.Char", stdlibChar);
("Stdlib_Error", stdlibError);
("Stdlib.Error", stdlibError);
("Stdlib_Exn", stdlibExn);
Expand Down
37 changes: 10 additions & 27 deletions lib/es6/Stdlib_Char.js → lib/es6/Char.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@



function fromIntExn(n) {
if (n < 0 || n > 255) {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "`Char.fromIntExn` expects an integer between 0 and 255",
Error: new Error()
};
}
return n;
}

function fromInt(n) {
if (n < 0 || n > 255) {
return;
} else {
return n;
}
}

function escaped(param) {
let exit = 0;
if (param >= 40) {
Expand Down Expand Up @@ -73,33 +54,35 @@ function escaped(param) {
}
}

function toLowerCaseAscii(c) {
function lowercase_ascii(c) {
if (c >= /* 'A' */65 && c <= /* 'Z' */90) {
return c + 32 | 0;
} else {
return c;
}
}

function toUpperCaseAscii(c) {
function uppercase_ascii(c) {
if (c >= /* 'a' */97 && c <= /* 'z' */122) {
return c - 32 | 0;
} else {
return c;
}
}

let lowercase_ascii = toLowerCaseAscii;
function compare(c1, c2) {
return c1 - c2 | 0;
}

let uppercase_ascii = toUpperCaseAscii;
function equal(c1, c2) {
return (c1 - c2 | 0) === 0;
}

export {
escaped,
lowercase_ascii,
uppercase_ascii,
toLowerCaseAscii,
toUpperCaseAscii,
fromIntExn,
fromInt,
compare,
equal,
}
/* No side effect */
5 changes: 1 addition & 4 deletions lib/es6/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
119,
118,
4
],
Error: new Error()
Expand All @@ -29,8 +29,6 @@ let $$BigInt;

let Bool;

let Char;

let Console;

let $$DataView;
Expand Down Expand Up @@ -123,7 +121,6 @@ export {
$$Array,
$$BigInt,
Bool,
Char,
Console,
$$DataView,
$$Date,
Expand Down
37 changes: 10 additions & 27 deletions lib/js/Stdlib_Char.js → lib/js/Char.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
'use strict';


function fromIntExn(n) {
if (n < 0 || n > 255) {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "`Char.fromIntExn` expects an integer between 0 and 255",
Error: new Error()
};
}
return n;
}

function fromInt(n) {
if (n < 0 || n > 255) {
return;
} else {
return n;
}
}

function escaped(param) {
let exit = 0;
if (param >= 40) {
Expand Down Expand Up @@ -73,31 +54,33 @@ function escaped(param) {
}
}

function toLowerCaseAscii(c) {
function lowercase_ascii(c) {
if (c >= /* 'A' */65 && c <= /* 'Z' */90) {
return c + 32 | 0;
} else {
return c;
}
}

function toUpperCaseAscii(c) {
function uppercase_ascii(c) {
if (c >= /* 'a' */97 && c <= /* 'z' */122) {
return c - 32 | 0;
} else {
return c;
}
}

let lowercase_ascii = toLowerCaseAscii;
function compare(c1, c2) {
return c1 - c2 | 0;
}

let uppercase_ascii = toUpperCaseAscii;
function equal(c1, c2) {
return (c1 - c2 | 0) === 0;
}

exports.escaped = escaped;
exports.lowercase_ascii = lowercase_ascii;
exports.uppercase_ascii = uppercase_ascii;
exports.toLowerCaseAscii = toLowerCaseAscii;
exports.toUpperCaseAscii = toUpperCaseAscii;
exports.fromIntExn = fromIntExn;
exports.fromInt = fromInt;
exports.compare = compare;
exports.equal = equal;
/* No side effect */
5 changes: 1 addition & 4 deletions lib/js/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
119,
118,
4
],
Error: new Error()
Expand All @@ -29,8 +29,6 @@ let $$BigInt;

let Bool;

let Char;

let Console;

let $$DataView;
Expand Down Expand Up @@ -122,7 +120,6 @@ exports.IntervalId = IntervalId;
exports.$$Array = $$Array;
exports.$$BigInt = $$BigInt;
exports.Bool = Bool;
exports.Char = Char;
exports.Console = Console;
exports.$$DataView = $$DataView;
exports.$$Date = $$Date;
Expand Down
16 changes: 8 additions & 8 deletions packages/artifacts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ lib/es6/Belt_internalMapString.js
lib/es6/Belt_internalSetBuckets.js
lib/es6/Belt_internalSetInt.js
lib/es6/Belt_internalSetString.js
lib/es6/Char.js
lib/es6/Dom.js
lib/es6/Dom_storage.js
lib/es6/Dom_storage2.js
Expand Down Expand Up @@ -149,7 +150,6 @@ lib/es6/Stdlib_BigInt.js
lib/es6/Stdlib_BigInt64Array.js
lib/es6/Stdlib_BigUint64Array.js
lib/es6/Stdlib_Bool.js
lib/es6/Stdlib_Char.js
lib/es6/Stdlib_Console.js
lib/es6/Stdlib_DataView.js
lib/es6/Stdlib_Date.js
Expand Down Expand Up @@ -244,6 +244,7 @@ lib/js/Belt_internalMapString.js
lib/js/Belt_internalSetBuckets.js
lib/js/Belt_internalSetInt.js
lib/js/Belt_internalSetString.js
lib/js/Char.js
lib/js/Dom.js
lib/js/Dom_storage.js
lib/js/Dom_storage2.js
Expand Down Expand Up @@ -321,7 +322,6 @@ lib/js/Stdlib_BigInt.js
lib/js/Stdlib_BigInt64Array.js
lib/js/Stdlib_BigUint64Array.js
lib/js/Stdlib_Bool.js
lib/js/Stdlib_Char.js
lib/js/Stdlib_Console.js
lib/js/Stdlib_DataView.js
lib/js/Stdlib_Date.js
Expand Down Expand Up @@ -621,6 +621,12 @@ lib/ocaml/Belt_internalSetString.cmi
lib/ocaml/Belt_internalSetString.cmj
lib/ocaml/Belt_internalSetString.cmt
lib/ocaml/Belt_internalSetString.res
lib/ocaml/Char.cmi
lib/ocaml/Char.cmj
lib/ocaml/Char.cmt
lib/ocaml/Char.cmti
lib/ocaml/Char.res
lib/ocaml/Char.resi
lib/ocaml/Dom.cmi
lib/ocaml/Dom.cmj
lib/ocaml/Dom.cmt
Expand Down Expand Up @@ -969,12 +975,6 @@ lib/ocaml/Stdlib_Bool.cmt
lib/ocaml/Stdlib_Bool.cmti
lib/ocaml/Stdlib_Bool.res
lib/ocaml/Stdlib_Bool.resi
lib/ocaml/Stdlib_Char.cmi
lib/ocaml/Stdlib_Char.cmj
lib/ocaml/Stdlib_Char.cmt
lib/ocaml/Stdlib_Char.cmti
lib/ocaml/Stdlib_Char.res
lib/ocaml/Stdlib_Char.resi
lib/ocaml/Stdlib_Console.cmi
lib/ocaml/Stdlib_Console.cmj
lib/ocaml/Stdlib_Console.cmt
Expand Down
34 changes: 10 additions & 24 deletions runtime/Stdlib_Char.res → runtime/Char.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// FIXME:
// This exists for compatibility reason.
// Move this into Pervasives or Core

// Below is all deprecated and should be removed in v13

type t = char

external code: t => int = "%identity"
Expand All @@ -6,22 +12,6 @@ external unsafe_chr: int => t = "%identity"

external chr: int => t = "%identity"

external fromIntUnsafe: int => t = "%identity"

let fromIntExn = n =>
if n < 0 || n > 255 {
throw(Invalid_argument("`Char.fromIntExn` expects an integer between 0 and 255"))
} else {
fromIntUnsafe(n)
}

let fromInt = n =>
if n < 0 || n > 255 {
None
} else {
Some(fromIntUnsafe(n))
}

external bytes_create: int => array<char> = "Array"

external bytes_unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
Expand Down Expand Up @@ -51,23 +41,19 @@ let escaped = param =>
unsafe_to_string(s)
}

let toLowerCaseAscii = c =>
let lowercase_ascii = c =>
if c >= 'A' && c <= 'Z' {
unsafe_chr(code(c) + 32)
} else {
c
}

let lowercase_ascii = toLowerCaseAscii

let toUpperCaseAscii = c =>
let uppercase_ascii = c =>
if c >= 'a' && c <= 'z' {
unsafe_chr(code(c) - 32)
} else {
c
}

let uppercase_ascii = toUpperCaseAscii

external equal: (char, char) => bool = "%equal"
external compare: (char, char) => Stdlib_Ordering.t = "%compare"
let compare = (c1, c2) => code(c1) - code(c2)
let equal = (c1: t, c2: t) => compare(c1, c2) == 0
Loading
Loading