Disallow for in in favour of for _ in

This commit is contained in:
gingerBill
2023-08-08 14:56:12 +01:00
parent 939bf4bb5d
commit 49ab935ae9
7 changed files with 13 additions and 10 deletions

View File

@@ -127,7 +127,7 @@ advance_rune :: proc(t: ^Tokenizer) {
}
advance_rune_n :: proc(t: ^Tokenizer, n: int) {
for in 0..<n {
for _ in 0..<n {
advance_rune(t)
}
}

View File

@@ -1565,7 +1565,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "") {
// - fi: A pointer to the Info structure where the indents will be written.
//
fmt_write_indent :: proc(fi: ^Info) {
for in 0..<fi.indent {
for _ in 0..<fi.indent {
io.write_byte(fi.writer, '\t', &fi.n)
}
}
@@ -1720,7 +1720,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
}
defer {
if hash {
for in 0..<indent { io.write_byte(fi.writer, '\t', &fi.n) }
for _ in 0..<indent { io.write_byte(fi.writer, '\t', &fi.n) }
}
io.write_byte(fi.writer, ']' if is_soa else '}', &fi.n)
}
@@ -1956,7 +1956,7 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named)
for x := i; x >= 10; x /= 10 {
n -= 1
}
for in 0..<n {
for _ in 0..<n {
io.write_byte(fi.writer, '0', &fi.n)
}
io.write_i64(fi.writer, i, 10, &fi.n)
@@ -1989,7 +1989,7 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named)
v := v
w := len(buf)
print := false
for in 0..<prec {
for _ in 0..<prec {
digit := v % 10
print = print || digit != 0
if print {

View File

@@ -299,7 +299,7 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
if length := int(data & 63) + 1; (length * img.channels) > len(pixels) {
return img, .Corrupt
} else {
#no_bounds_check for in 0..<length {
#no_bounds_check for _ in 0..<length {
copy(pixels, pix[:img.channels])
pixels = pixels[img.channels:]
}

View File

@@ -416,7 +416,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> (
}
buf := make([]byte, size)
n := copy(buf, "..")
for in 0..<seps {
for _ in 0..<seps {
buf[n] = SEPARATOR
copy(buf[n+1:], "..")
n += 3

View File

@@ -200,7 +200,7 @@ peek :: proc(s: ^Scanner, n := 0) -> (ch: rune) {
ch = s.ch
if n > 0 {
prev_s := s^
for in 0..<n {
for _ in 0..<n {
next(s)
}
ch = s.ch
@@ -214,7 +214,7 @@ peek :: proc(s: ^Scanner, n := 0) -> (ch: rune) {
peek_token :: proc(s: ^Scanner, n := 0) -> (tok: rune) {
assert(n >= 0)
prev_s := s^
for in 0..<n {
for _ in 0..<n {
tok = scan(s)
}
tok = scan(s)

View File

@@ -1155,7 +1155,7 @@ threading_example :: proc() {
threads := make([dynamic]^thread.Thread, 0, len(prefix_table))
defer delete(threads)
for in prefix_table {
for _ in prefix_table {
if t := thread.create(worker_proc); t != nil {
t.init_context = context
t.user_index = len(threads)

View File

@@ -4271,6 +4271,8 @@ gb_internal Ast *parse_for_stmt(AstFile *f) {
if (f->curr_token.kind == Token_in) {
Token in_token = expect_token(f, Token_in);
syntax_error(in_token, "Prefer 'for _ in' over 'for in'");
Ast *rhs = nullptr;
bool prev_allow_range = f->allow_range;
f->allow_range = true;
@@ -4282,6 +4284,7 @@ gb_internal Ast *parse_for_stmt(AstFile *f) {
} else {
body = parse_block_stmt(f, false);
}
return ast_range_stmt(f, token, {}, in_token, rhs, body);
}