Skip to content
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

Use "for" instead of "loop" in iteration loops #541

Merged
merged 1 commit into from
Oct 25, 2024
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
2 changes: 1 addition & 1 deletion src/modules/loops/iter_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl SyntaxModule<ParserMetadata> 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());
Expand Down
2 changes: 1 addition & 1 deletion src/modules/variable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/std/array.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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]
}
Expand Down
2 changes: 1 addition & 1 deletion src/std/fs.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_absolute_missing_file.ab
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ main {
let files = glob("{tmpdir}/missing*") failed {
echo "FAILED"
}
loop file in files {
for file in files {
echo "[{file}]"
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_absolute_multiple_globs.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_absolute_wild_char.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_absolute_wild_star.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_absolute_with_spaces.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_injection_attack.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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}]"
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_relative_missing_file.ab
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ main {
let files = glob("missing*") failed {
echo "FAILED"
}
loop file in files {
for file in files {
echo "[{file}]"
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_relative_multiple_globs.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_relative_wild_char.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_relative_wild_star.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/glob_relative_with_spaces.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/stdlib/lines.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/tests/validity/function_optional_argument_array.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/validity/loop_in.ab
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
// 5

let a = [1, 2, 3, 4, 5]
loop i in a {
for i in a {
echo i
}
2 changes: 1 addition & 1 deletion src/tests/validity/loop_in_index_value.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/tests/validity/range_loop.ab
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// 3
// 4

loop i in 0..5 {
for i in 0..5 {
echo i
}
2 changes: 1 addition & 1 deletion src/tests/validity/range_loop_inclusive.ab
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
// 4
// 5

loop i in 0..=5 {
for i in 0..=5 {
echo i
}