Skip to content

Commit

Permalink
Merge pull request #40 from richard-viney/fix-stdlib-deprecation-warn…
Browse files Browse the repository at this point in the history
…ings-2

Fix deprecation warnings in gleam_stdlib 0.44
  • Loading branch information
massivefermion authored Dec 18, 2024
2 parents eb885ce + cc9990e commit 8cdad6a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
3 changes: 2 additions & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ links = [{ title = "Gleam", href = "https://gleam.run" }]

[dependencies]
ranger = ">= 1.2.0 and < 2.0.0"
gleam_stdlib = ">= 0.43.0 and < 2.0.0"
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
gleam_regexp = ">= 1.0.0 and < 2.0.0"

[dev-dependencies]
gleeunit = ">= 1.2.0 and < 2.0.0"
8 changes: 5 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_stdlib", version = "0.43.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "69EF22E78FDCA9097CBE7DF91C05B2A8B5436826D9F66680D879182C0860A747" },
{ name = "gleam_regexp", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "A3655FDD288571E90EE9C4009B719FEF59FA16AFCDF3952A76A125AF23CF1592" },
{ name = "gleam_stdlib", version = "0.44.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "A6E55E309A6778206AAD4038D9C49E15DF71027A1DB13C6ADA06BFDB6CF1260E" },
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
{ name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" },
{ name = "ranger", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "B8F3AFF23A3A5B5D9526B8D18E7C43A7DFD3902B151B97EC65397FE29192B695" },
]

[requirements]
gleam_stdlib = { version = ">= 0.43.0 and < 2.0.0" }
gleam_regexp = { version = ">= 1.0.0 and < 2.0.0" }
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
gleeunit = { version = ">= 1.2.0 and < 2.0.0" }
ranger = { version = ">= 1.2.0 and < 2.0.0" }
58 changes: 33 additions & 25 deletions src/birl.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import gleam/iterator
import gleam/list
import gleam/option
import gleam/order
import gleam/regex
import gleam/regexp
import gleam/result
import gleam/string

Expand Down Expand Up @@ -292,7 +292,7 @@ pub fn to_iso8601(value: Time) -> String {
///
/// - `1905-12-22T16:38:23.000+03:30` -> `1905-12-22T16:38:23.000+03:30`
pub fn parse(value: String) -> Result(Time, Nil) {
let assert Ok(offset_pattern) = regex.from_string("(.*)([+|\\-].*)")
let assert Ok(offset_pattern) = regexp.from_string("(.*)([+|\\-].*)")
let value = string.trim(value)

use #(day_string, offsetted_time_string) <- result.then(case
Expand All @@ -318,13 +318,17 @@ pub fn parse(value: String) -> Result(Time, Nil) {
True ->
Ok(#(day_string, string.drop_end(offsetted_time_string, 1), "+00:00"))
False ->
case regex.scan(offset_pattern, offsetted_time_string) {
[regex.Match(_, [option.Some(time_string), option.Some(offset_string)])] ->
Ok(#(day_string, time_string, offset_string))
case regexp.scan(offset_pattern, offsetted_time_string) {
[
regexp.Match(
_,
[option.Some(time_string), option.Some(offset_string)],
),
] -> Ok(#(day_string, time_string, offset_string))
_ ->
case regex.scan(offset_pattern, day_string) {
case regexp.scan(offset_pattern, day_string) {
[
regex.Match(
regexp.Match(
_,
[option.Some(day_string), option.Some(offset_string)],
),
Expand Down Expand Up @@ -395,7 +399,7 @@ pub fn parse(value: String) -> Result(Time, Nil) {
///
/// - `T16:38:23.050+03:30` -> `#(TimeOfDay(16, 38, 23, 50), "+03:30")`
pub fn parse_time_of_day(value: String) -> Result(#(TimeOfDay, String), Nil) {
let assert Ok(offset_pattern) = regex.from_string("(.*)([+|\\-].*)")
let assert Ok(offset_pattern) = regexp.from_string("(.*)([+|\\-].*)")

let time_string = case
string.starts_with(value, "T"),
Expand All @@ -410,9 +414,13 @@ pub fn parse_time_of_day(value: String) -> Result(#(TimeOfDay, String), Nil) {
{
True -> Ok(#(string.drop_end(value, 1), "+00:00"))
False ->
case regex.scan(offset_pattern, value) {
[regex.Match(_, [option.Some(time_string), option.Some(offset_string)])] ->
Ok(#(time_string, offset_string))
case regexp.scan(offset_pattern, value) {
[
regexp.Match(
_,
[option.Some(time_string), option.Some(offset_string)],
),
] -> Ok(#(time_string, offset_string))
_ -> Error(Nil)
}
})
Expand Down Expand Up @@ -733,8 +741,8 @@ pub fn from_http(value: String) -> Result(Time, Nil) {
)

let rest = string.trim(rest)
let assert Ok(whitespace_pattern) = regex.from_string("\\s+")
case regex.split(whitespace_pattern, rest) {
let assert Ok(whitespace_pattern) = regexp.from_string("\\s+")
case regexp.split(whitespace_pattern, rest) {
[day_string, month_string, year_string, time_string, offset_string] -> {
let time_string = string.replace(time_string, ":", "")
case
Expand Down Expand Up @@ -1322,9 +1330,9 @@ fn to_parts(value: Time) -> #(#(Int, Int, Int), #(Int, Int, Int, Int), String) {

fn parse_offset(offset: String) -> Result(Int, Nil) {
use <- bool.guard(list.contains(["Z", "z"], offset), Ok(0))
let assert Ok(re) = regex.from_string("([+-])")
let assert Ok(re) = regexp.from_string("([+-])")

use #(sign, offset) <- result.then(case regex.split(re, offset) {
use #(sign, offset) <- result.then(case regexp.split(re, offset) {
["", "+", offset] -> Ok(#(1, offset))
["", "-", offset] -> Ok(#(-1, offset))
[_] -> Ok(#(1, offset))
Expand Down Expand Up @@ -1438,25 +1446,25 @@ fn parse_date_section(date: String) -> Result(List(Int), Nil) {
case string.contains(date, "-") {
True -> {
let assert Ok(dash_pattern) =
regex.from_string(
regexp.from_string(
"(\\d{4})(?:-(1[0-2]|0?[0-9]))?(?:-(3[0-1]|[1-2][0-9]|0?[0-9]))?",
)

case regex.scan(dash_pattern, date) {
[regex.Match(_, [option.Some(major)])] -> [
case regexp.scan(dash_pattern, date) {
[regexp.Match(_, [option.Some(major)])] -> [
int.parse(major),
Ok(1),
Ok(1),
]

[regex.Match(_, [option.Some(major), option.Some(middle)])] -> [
[regexp.Match(_, [option.Some(major), option.Some(middle)])] -> [
int.parse(major),
int.parse(middle),
Ok(1),
]

[
regex.Match(
regexp.Match(
_,
[option.Some(major), option.Some(middle), option.Some(minor)],
),
Expand Down Expand Up @@ -1517,22 +1525,22 @@ fn parse_section(
pattern_string: String,
default: Int,
) -> List(Result(Int, Nil)) {
let assert Ok(pattern) = regex.from_string(pattern_string)
case regex.scan(pattern, section) {
[regex.Match(_, [option.Some(major)])] -> [
let assert Ok(pattern) = regexp.from_string(pattern_string)
case regexp.scan(pattern, section) {
[regexp.Match(_, [option.Some(major)])] -> [
int.parse(major),
Ok(default),
Ok(default),
]

[regex.Match(_, [option.Some(major), option.Some(middle)])] -> [
[regexp.Match(_, [option.Some(major), option.Some(middle)])] -> [
int.parse(major),
int.parse(middle),
Ok(default),
]

[
regex.Match(
regexp.Match(
_,
[option.Some(major), option.Some(middle), option.Some(minor)],
),
Expand Down
10 changes: 5 additions & 5 deletions src/birl/duration.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gleam/int
import gleam/list
import gleam/option
import gleam/order
import gleam/regex
import gleam/regexp
import gleam/result
import gleam/string

Expand Down Expand Up @@ -325,7 +325,7 @@ const units = [
/// numbers with no unit are considered as microseconds.
/// specifying `accurate:` is equivalent to using `accurate_new`.
pub fn parse(expression: String) -> Result(Duration, Nil) {
let assert Ok(re) = regex.from_string("([+|\\-])?\\s*(\\d+)\\s*(\\w+)?")
let assert Ok(re) = regexp.from_string("([+|\\-])?\\s*(\\d+)\\s*(\\w+)?")

let #(constructor, expression) = case
string.starts_with(expression, "accurate:")
Expand All @@ -340,10 +340,10 @@ pub fn parse(expression: String) -> Result(Duration, Nil) {
case
expression
|> string.lowercase
|> regex.scan(re, _)
|> regexp.scan(re, _)
|> list.try_map(fn(item) {
case item {
regex.Match(_, [sign_option, option.Some(amount_string)]) -> {
regexp.Match(_, [sign_option, option.Some(amount_string)]) -> {
use amount <- result.then(int.parse(amount_string))

case sign_option {
Expand All @@ -353,7 +353,7 @@ pub fn parse(expression: String) -> Result(Duration, Nil) {
}
}

regex.Match(
regexp.Match(
_,
[sign_option, option.Some(amount_string), option.Some(unit)],
) -> {
Expand Down

0 comments on commit 8cdad6a

Please sign in to comment.