From e8a1c065bf98bd93992abff9f84b19255e8ef932 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 07:40:20 -0700 Subject: [PATCH 1/9] feat: add words function to standard library --- src/std/main.ab | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/std/main.ab b/src/std/main.ab index b2318c4e..a9c95825 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -40,6 +40,12 @@ pub fun lines(text: Text): [Text] { return result } +pub fun words(text: Text): [Text] { + let result = [Text] + unsafe $IFS=\$' ' read -rd '' -a {nameof result} <<<"\${nameof text}"$ + return result +} + pub fun join(list: [Text], delimiter: Text): Text { return unsafe $IFS="{delimiter}" ; echo "\$\{{nameof list}[*]}"$ } From 330e34ef993d43da6daad4a279c8b23cf768b671 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 07:49:36 -0700 Subject: [PATCH 2/9] Update validity.rs --- src/tests/validity.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tests/validity.rs b/src/tests/validity.rs index ce1e139b..8d9f8531 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -756,6 +756,10 @@ fn test_std_library() { loop line in lines(\"hello\nworld\") { echo line } + // Split a multiline string into a list of string by one or more spaces + loop word in words(\"hello world ciao mondo\") { + echo word + } // Join a list of strings into a string echo join(split(\"hello world\", \"l\"), \"l\") // Transform string into a lowercase string @@ -790,6 +794,10 @@ fn test_std_library() { "he o wor d", "hello", "world", + "hello", + "world", + "ciao", + "mondo", "hello world", "hello world", "HELLO WORLD", From a5d399f541300f1e52728924b65f5ccd305d2d84 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 09:09:24 -0700 Subject: [PATCH 3/9] Update src/std/main.ab --- src/std/main.ab | 1 + 1 file changed, 1 insertion(+) diff --git a/src/std/main.ab b/src/std/main.ab index a9c95825..58457f42 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -42,6 +42,7 @@ pub fun lines(text: Text): [Text] { pub fun words(text: Text): [Text] { let result = [Text] + let trimmed = trim(text) unsafe $IFS=\$' ' read -rd '' -a {nameof result} <<<"\${nameof text}"$ return result } From bfa1d5118beeaac1fb2fb5ec24de6a77dc43e4f6 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 09:09:38 -0700 Subject: [PATCH 4/9] Update src/std/main.ab --- src/std/main.ab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/main.ab b/src/std/main.ab index 58457f42..ba67cdf7 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -43,7 +43,7 @@ pub fun lines(text: Text): [Text] { pub fun words(text: Text): [Text] { let result = [Text] let trimmed = trim(text) - unsafe $IFS=\$' ' read -rd '' -a {nameof result} <<<"\${nameof text}"$ + unsafe $IFS=\$' ' read -rd '' -a {nameof result} <<<"\${nameof trimmed}"$ return result } From 7e71a638561c0a3aac77b7782c57c855909a4748 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 09:14:33 -0700 Subject: [PATCH 5/9] Update src/std/main.ab Co-authored-by: Phoenix Himself --- src/std/main.ab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/main.ab b/src/std/main.ab index ba67cdf7..f5c19f69 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -43,7 +43,7 @@ pub fun lines(text: Text): [Text] { pub fun words(text: Text): [Text] { let result = [Text] let trimmed = trim(text) - unsafe $IFS=\$' ' read -rd '' -a {nameof result} <<<"\${nameof trimmed}"$ + unsafe $read -rd '' -a {nameof result} <<<"\${nameof text}"$ return result } From aff55d2ecd52d2791b6ee86fec700cecda90008f Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 09:14:46 -0700 Subject: [PATCH 6/9] Update src/std/main.ab --- src/std/main.ab | 1 - 1 file changed, 1 deletion(-) diff --git a/src/std/main.ab b/src/std/main.ab index f5c19f69..977d5fa2 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -42,7 +42,6 @@ pub fun lines(text: Text): [Text] { pub fun words(text: Text): [Text] { let result = [Text] - let trimmed = trim(text) unsafe $read -rd '' -a {nameof result} <<<"\${nameof text}"$ return result } From 1b0ff5be1938ef73c47d95b8f9d40c5a33248311 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 12:09:23 -0700 Subject: [PATCH 7/9] Update src/std/main.ab --- src/std/main.ab | 1 - 1 file changed, 1 deletion(-) diff --git a/src/std/main.ab b/src/std/main.ab index 977d5fa2..a48e0848 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -41,7 +41,6 @@ pub fun lines(text: Text): [Text] { } pub fun words(text: Text): [Text] { - let result = [Text] unsafe $read -rd '' -a {nameof result} <<<"\${nameof text}"$ return result } From 4ca58d28bc9bcb6d3f33bc42b3534eb07922053c Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 12:10:02 -0700 Subject: [PATCH 8/9] Update src/std/main.ab --- src/std/main.ab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/main.ab b/src/std/main.ab index a48e0848..a547b7b6 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -41,7 +41,7 @@ pub fun lines(text: Text): [Text] { } pub fun words(text: Text): [Text] { - unsafe $read -rd '' -a {nameof result} <<<"\${nameof text}"$ + return split(text, " ") return result } From 88f90513044da419872333fb4b634732fd362307 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo <385716+kilianc@users.noreply.github.com> Date: Wed, 22 May 2024 12:10:12 -0700 Subject: [PATCH 9/9] Update src/std/main.ab --- src/std/main.ab | 1 - 1 file changed, 1 deletion(-) diff --git a/src/std/main.ab b/src/std/main.ab index a547b7b6..b180bf17 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -42,7 +42,6 @@ pub fun lines(text: Text): [Text] { pub fun words(text: Text): [Text] { return split(text, " ") - return result } pub fun join(list: [Text], delimiter: Text): Text {