mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
odinfmt on printer
This commit is contained in:
@@ -593,9 +593,7 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|||||||
brace_line: int;
|
brace_line: int;
|
||||||
|
|
||||||
found_switch_brace: for line, line_index in p.lines[index:] {
|
found_switch_brace: for line, line_index in p.lines[index:] {
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
for format_token in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Open_Brace && switch_found {
|
if format_token.kind == .Open_Brace && switch_found {
|
||||||
brace_token = format_token;
|
brace_token = format_token;
|
||||||
brace_line = line_index + index;
|
brace_line = line_index + index;
|
||||||
@@ -652,13 +650,11 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|||||||
case_count = 0;
|
case_count = 0;
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
|
|
||||||
case_found := false;
|
case_found := false;
|
||||||
colon_found := false;
|
colon_found := false;
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token, i in line.format_tokens {
|
for format_token, i in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -691,9 +687,7 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|||||||
brace_line: int;
|
brace_line: int;
|
||||||
|
|
||||||
found_enum_brace: for line, line_index in p.lines[index:] {
|
found_enum_brace: for line, line_index in p.lines[index:] {
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
for format_token in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Open_Brace && enum_found {
|
if format_token.kind == .Open_Brace && enum_found {
|
||||||
brace_token = format_token;
|
brace_token = format_token;
|
||||||
brace_line = line_index + index;
|
brace_line = line_index + index;
|
||||||
@@ -714,11 +708,9 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|||||||
eq_count := 0;
|
eq_count := 0;
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
|
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
for format_token in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -740,11 +732,9 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|||||||
eq_count = 0;
|
eq_count = 0;
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
|
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token, i in line.format_tokens {
|
for format_token, i in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -771,9 +761,7 @@ align_struct :: proc(p: ^Printer, index: int) {
|
|||||||
brace_line: int;
|
brace_line: int;
|
||||||
|
|
||||||
found_struct_brace: for line, line_index in p.lines[index:] {
|
found_struct_brace: for line, line_index in p.lines[index:] {
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
for format_token in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Open_Brace && struct_found {
|
if format_token.kind == .Open_Brace && struct_found {
|
||||||
brace_token = format_token;
|
brace_token = format_token;
|
||||||
brace_line = line_index + index;
|
brace_line = line_index + index;
|
||||||
@@ -794,11 +782,9 @@ align_struct :: proc(p: ^Printer, index: int) {
|
|||||||
colon_count := 0;
|
colon_count := 0;
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
|
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
for format_token in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -820,11 +806,9 @@ align_struct :: proc(p: ^Printer, index: int) {
|
|||||||
colon_count = 0;
|
colon_count = 0;
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
|
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token, i in line.format_tokens {
|
for format_token, i in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -858,13 +842,11 @@ align_comments :: proc(p: ^Printer) {
|
|||||||
current_info: Comment_Align_Info;
|
current_info: Comment_Align_Info;
|
||||||
|
|
||||||
for line, line_index in p.lines {
|
for line, line_index in p.lines {
|
||||||
|
|
||||||
if len(line.format_tokens) <= 0 {
|
if len(line.format_tokens) <= 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if .Line_Comment in line.types {
|
if .Line_Comment in line.types {
|
||||||
|
|
||||||
if current_info.end + 1 != line_index || current_info.depth != line.depth ||
|
if current_info.end + 1 != line_index || current_info.depth != line.depth ||
|
||||||
(current_info.begin == current_info.end && current_info.length == 0) {
|
(current_info.begin == current_info.end && current_info.length == 0) {
|
||||||
|
|
||||||
@@ -881,7 +863,6 @@ align_comments :: proc(p: ^Printer) {
|
|||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token, i in line.format_tokens {
|
for format_token, i in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
current_info.length = max(current_info.length, length);
|
current_info.length = max(current_info.length, length);
|
||||||
current_info.end = line_index;
|
current_info.end = line_index;
|
||||||
@@ -903,13 +884,11 @@ align_comments :: proc(p: ^Printer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := info.begin; i <= info.end; i += 1 {
|
for i := info.begin; i <= info.end; i += 1 {
|
||||||
|
|
||||||
l := p.lines[i];
|
l := p.lines[i];
|
||||||
|
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token, i in l.format_tokens {
|
for format_token, i in l.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
if len(l.format_tokens) == 1 {
|
if len(l.format_tokens) == 1 {
|
||||||
l.format_tokens[i].spaces_before = info.length + 1;
|
l.format_tokens[i].spaces_before = info.length + 1;
|
||||||
@@ -923,4 +902,3 @@ align_comments :: proc(p: ^Printer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user