From 8fb51c7aa4cb72ac96e6214fdd70b4dad7c58fae Mon Sep 17 00:00:00 2001 From: hdwalters Date: Fri, 25 Oct 2024 20:38:13 +0100 Subject: [PATCH] Use "for" instead of "loop" in iteration loops. (#541) --- src/modules/loops/iter_loop.rs | 2 +- src/modules/variable/mod.rs | 2 +- src/std/array.ab | 4 ++-- src/std/fs.ab | 2 +- src/tests/stdlib/glob_absolute_missing_file.ab | 2 +- src/tests/stdlib/glob_absolute_multiple_globs.ab | 2 +- src/tests/stdlib/glob_absolute_wild_char.ab | 2 +- src/tests/stdlib/glob_absolute_wild_star.ab | 2 +- src/tests/stdlib/glob_absolute_with_spaces.ab | 2 +- src/tests/stdlib/glob_injection_attack.ab | 2 +- src/tests/stdlib/glob_relative_missing_file.ab | 2 +- src/tests/stdlib/glob_relative_multiple_globs.ab | 2 +- src/tests/stdlib/glob_relative_wild_char.ab | 2 +- src/tests/stdlib/glob_relative_wild_star.ab | 2 +- src/tests/stdlib/glob_relative_with_spaces.ab | 2 +- src/tests/stdlib/lines.ab | 2 +- src/tests/validity/function_optional_argument_array.ab | 2 +- .../validity/function_optional_argument_array_default.ab | 2 +- src/tests/validity/loop_in.ab | 2 +- src/tests/validity/loop_in_index_value.ab | 2 +- src/tests/validity/range_loop.ab | 2 +- src/tests/validity/range_loop_inclusive.ab | 2 +- 22 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/modules/loops/iter_loop.rs b/src/modules/loops/iter_loop.rs index bbb3f73c..e962bb90 100644 --- a/src/modules/loops/iter_loop.rs +++ b/src/modules/loops/iter_loop.rs @@ -31,7 +31,7 @@ impl SyntaxModule for IterLoop { } fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult { - token(meta, "loop")?; + token(meta, "for")?; self.iter_name = variable(meta, variable_name_extensions())?; if token(meta, ",").is_ok() { self.iter_index = Some(self.iter_name.clone()); diff --git a/src/modules/variable/mod.rs b/src/modules/variable/mod.rs index 742cdd77..2c1d0ef9 100644 --- a/src/modules/variable/mod.rs +++ b/src/modules/variable/mod.rs @@ -22,7 +22,7 @@ pub fn variable_name_keywords() -> Vec<&'static str> { // Control flow keywords "if", "then", "else", // Loop keywords - "loop", "break", "continue", "in", + "for", "loop", "break", "continue", "in", // Module keywords "pub", "import", "from", // Function keywords diff --git a/src/std/array.ab b/src/std/array.ab index 558d2d31..2fcf2e6f 100644 --- a/src/std/array.ab +++ b/src/std/array.ab @@ -2,7 +2,7 @@ /// /// If the value is not found, the function returns -1. pub fun array_first_index(array, value): Num { - loop index, element in array { + for index, element in array { if value as Text == element as Text { return index } @@ -13,7 +13,7 @@ pub fun array_first_index(array, value): Num { /// Searches for a value in an array and returns an array with the index of the various items. pub fun array_search(array, value): [Num] { let result = [Num] - loop index, element in array { + for index, element in array { if value as Text == element as Text { result += [index] } diff --git a/src/std/fs.ab b/src/std/fs.ab index 5c5dbe65..daeadace 100644 --- a/src/std/fs.ab +++ b/src/std/fs.ab @@ -94,7 +94,7 @@ pub fun glob_multiple(paths: [Text]): [Text]? { combined = escape_non_glob_chars(paths[0]) } else { let items = [Text] - loop item in paths { + for item in paths { item = escape_non_glob_chars(item) items += [item] } diff --git a/src/tests/stdlib/glob_absolute_missing_file.ab b/src/tests/stdlib/glob_absolute_missing_file.ab index 983fdd6a..d259a62d 100644 --- a/src/tests/stdlib/glob_absolute_missing_file.ab +++ b/src/tests/stdlib/glob_absolute_missing_file.ab @@ -18,7 +18,7 @@ main { let files = glob("{tmpdir}/missing*") failed { echo "FAILED" } - loop file in files { + for file in files { echo "[{file}]" } diff --git a/src/tests/stdlib/glob_absolute_multiple_globs.ab b/src/tests/stdlib/glob_absolute_multiple_globs.ab index 7cc9ea11..a489bdfd 100644 --- a/src/tests/stdlib/glob_absolute_multiple_globs.ab +++ b/src/tests/stdlib/glob_absolute_multiple_globs.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/glob_absolute_wild_char.ab b/src/tests/stdlib/glob_absolute_wild_char.ab index 2debfacd..961750cd 100644 --- a/src/tests/stdlib/glob_absolute_wild_char.ab +++ b/src/tests/stdlib/glob_absolute_wild_char.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/glob_absolute_wild_star.ab b/src/tests/stdlib/glob_absolute_wild_star.ab index d5ebeda8..a3d2648b 100644 --- a/src/tests/stdlib/glob_absolute_wild_star.ab +++ b/src/tests/stdlib/glob_absolute_wild_star.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/glob_absolute_with_spaces.ab b/src/tests/stdlib/glob_absolute_with_spaces.ab index f284f7bd..8258b58f 100644 --- a/src/tests/stdlib/glob_absolute_with_spaces.ab +++ b/src/tests/stdlib/glob_absolute_with_spaces.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/glob_injection_attack.ab b/src/tests/stdlib/glob_injection_attack.ab index 85e1826d..039ed079 100644 --- a/src/tests/stdlib/glob_injection_attack.ab +++ b/src/tests/stdlib/glob_injection_attack.ab @@ -17,7 +17,7 @@ main { let files = glob("xxx; do echo HACKED; done; for file in") failed { echo "FAILED" } - loop file in files { + for file in files { echo "[{file}]" } diff --git a/src/tests/stdlib/glob_relative_missing_file.ab b/src/tests/stdlib/glob_relative_missing_file.ab index 34f9c34e..0cdb210b 100644 --- a/src/tests/stdlib/glob_relative_missing_file.ab +++ b/src/tests/stdlib/glob_relative_missing_file.ab @@ -19,7 +19,7 @@ main { let files = glob("missing*") failed { echo "FAILED" } - loop file in files { + for file in files { echo "[{file}]" } diff --git a/src/tests/stdlib/glob_relative_multiple_globs.ab b/src/tests/stdlib/glob_relative_multiple_globs.ab index 0cb872c2..f0fca2e1 100644 --- a/src/tests/stdlib/glob_relative_multiple_globs.ab +++ b/src/tests/stdlib/glob_relative_multiple_globs.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/glob_relative_wild_char.ab b/src/tests/stdlib/glob_relative_wild_char.ab index 05d62cc4..d6e1017f 100644 --- a/src/tests/stdlib/glob_relative_wild_char.ab +++ b/src/tests/stdlib/glob_relative_wild_char.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/glob_relative_wild_star.ab b/src/tests/stdlib/glob_relative_wild_star.ab index 4851b709..d9961beb 100644 --- a/src/tests/stdlib/glob_relative_wild_star.ab +++ b/src/tests/stdlib/glob_relative_wild_star.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/glob_relative_with_spaces.ab b/src/tests/stdlib/glob_relative_with_spaces.ab index 6c64c461..f86587c6 100644 --- a/src/tests/stdlib/glob_relative_with_spaces.ab +++ b/src/tests/stdlib/glob_relative_with_spaces.ab @@ -6,7 +6,7 @@ fun compare(actual: [Text], expected: [Text]): Bool { if len(actual) != len(expected) { return false } - loop file in expected { + for file in expected { if not includes(actual, file) { return false } diff --git a/src/tests/stdlib/lines.ab b/src/tests/stdlib/lines.ab index 623c3593..d6003eaa 100644 --- a/src/tests/stdlib/lines.ab +++ b/src/tests/stdlib/lines.ab @@ -5,7 +5,7 @@ import { lines } from "std/text" // line: world main { - loop line in lines("hello\nworld") { + for line in lines("hello\nworld") { echo "line: " + line } } diff --git a/src/tests/validity/function_optional_argument_array.ab b/src/tests/validity/function_optional_argument_array.ab index 269148d1..88183737 100644 --- a/src/tests/validity/function_optional_argument_array.ab +++ b/src/tests/validity/function_optional_argument_array.ab @@ -3,7 +3,7 @@ fun sum_array(a : [Num] = [Num]): Num { let sum = 0 - loop n in a { + for n in a { sum += n; } return sum; diff --git a/src/tests/validity/function_optional_argument_array_default.ab b/src/tests/validity/function_optional_argument_array_default.ab index 60a00168..4d7b3080 100644 --- a/src/tests/validity/function_optional_argument_array_default.ab +++ b/src/tests/validity/function_optional_argument_array_default.ab @@ -3,7 +3,7 @@ fun sum_array(a : [Num] = [100,200,300,400]): Num { let sum = 0 - loop n in a { + for n in a { sum += n; } return sum; diff --git a/src/tests/validity/loop_in.ab b/src/tests/validity/loop_in.ab index edd2a1d9..54ef03f9 100644 --- a/src/tests/validity/loop_in.ab +++ b/src/tests/validity/loop_in.ab @@ -6,6 +6,6 @@ // 5 let a = [1, 2, 3, 4, 5] -loop i in a { +for i in a { echo i } diff --git a/src/tests/validity/loop_in_index_value.ab b/src/tests/validity/loop_in_index_value.ab index 2678dea8..4b927458 100644 --- a/src/tests/validity/loop_in_index_value.ab +++ b/src/tests/validity/loop_in_index_value.ab @@ -11,7 +11,7 @@ // 5 let a = [1, 2, 3, 4, 5] -loop i, v in a { +for i, v in a { echo i echo v } diff --git a/src/tests/validity/range_loop.ab b/src/tests/validity/range_loop.ab index 533d6ef8..780c1748 100644 --- a/src/tests/validity/range_loop.ab +++ b/src/tests/validity/range_loop.ab @@ -5,6 +5,6 @@ // 3 // 4 -loop i in 0..5 { +for i in 0..5 { echo i } diff --git a/src/tests/validity/range_loop_inclusive.ab b/src/tests/validity/range_loop_inclusive.ab index d51878ef..20f10aff 100644 --- a/src/tests/validity/range_loop_inclusive.ab +++ b/src/tests/validity/range_loop_inclusive.ab @@ -6,6 +6,6 @@ // 4 // 5 -loop i in 0..=5 { +for i in 0..=5 { echo i }