mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-08 16:48:18 +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;
|
||||
|
||||
found_switch_brace: for line, line_index in p.lines[index:] {
|
||||
|
||||
for format_token in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Open_Brace && switch_found {
|
||||
brace_token = format_token;
|
||||
brace_line = line_index + index;
|
||||
@@ -652,13 +650,11 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
||||
case_count = 0;
|
||||
|
||||
for line, line_index in p.lines[brace_line + 1:] {
|
||||
|
||||
case_found := false;
|
||||
colon_found := false;
|
||||
length := 0;
|
||||
|
||||
for format_token, i in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Comment {
|
||||
continue;
|
||||
}
|
||||
@@ -691,9 +687,7 @@ align_enum :: proc(p: ^Printer, index: int) {
|
||||
brace_line: int;
|
||||
|
||||
found_enum_brace: for line, line_index in p.lines[index:] {
|
||||
|
||||
for format_token in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Open_Brace && enum_found {
|
||||
brace_token = format_token;
|
||||
brace_line = line_index + index;
|
||||
@@ -714,11 +708,9 @@ align_enum :: proc(p: ^Printer, index: int) {
|
||||
eq_count := 0;
|
||||
|
||||
for line, line_index in p.lines[brace_line + 1:] {
|
||||
|
||||
length := 0;
|
||||
|
||||
for format_token in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Comment {
|
||||
continue;
|
||||
}
|
||||
@@ -740,11 +732,9 @@ align_enum :: proc(p: ^Printer, index: int) {
|
||||
eq_count = 0;
|
||||
|
||||
for line, line_index in p.lines[brace_line + 1:] {
|
||||
|
||||
length := 0;
|
||||
|
||||
for format_token, i in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Comment {
|
||||
continue;
|
||||
}
|
||||
@@ -771,9 +761,7 @@ align_struct :: proc(p: ^Printer, index: int) {
|
||||
brace_line: int;
|
||||
|
||||
found_struct_brace: for line, line_index in p.lines[index:] {
|
||||
|
||||
for format_token in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Open_Brace && struct_found {
|
||||
brace_token = format_token;
|
||||
brace_line = line_index + index;
|
||||
@@ -794,11 +782,9 @@ align_struct :: proc(p: ^Printer, index: int) {
|
||||
colon_count := 0;
|
||||
|
||||
for line, line_index in p.lines[brace_line + 1:] {
|
||||
|
||||
length := 0;
|
||||
|
||||
for format_token in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Comment {
|
||||
continue;
|
||||
}
|
||||
@@ -820,11 +806,9 @@ align_struct :: proc(p: ^Printer, index: int) {
|
||||
colon_count = 0;
|
||||
|
||||
for line, line_index in p.lines[brace_line + 1:] {
|
||||
|
||||
length := 0;
|
||||
|
||||
for format_token, i in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Comment {
|
||||
continue;
|
||||
}
|
||||
@@ -858,13 +842,11 @@ align_comments :: proc(p: ^Printer) {
|
||||
current_info: Comment_Align_Info;
|
||||
|
||||
for line, line_index in p.lines {
|
||||
|
||||
if len(line.format_tokens) <= 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
if .Line_Comment in line.types {
|
||||
|
||||
if current_info.end + 1 != line_index || current_info.depth != line.depth ||
|
||||
(current_info.begin == current_info.end && current_info.length == 0) {
|
||||
|
||||
@@ -881,7 +863,6 @@ align_comments :: proc(p: ^Printer) {
|
||||
length := 0;
|
||||
|
||||
for format_token, i in line.format_tokens {
|
||||
|
||||
if format_token.kind == .Comment {
|
||||
current_info.length = max(current_info.length, length);
|
||||
current_info.end = line_index;
|
||||
@@ -903,13 +884,11 @@ align_comments :: proc(p: ^Printer) {
|
||||
}
|
||||
|
||||
for i := info.begin; i <= info.end; i += 1 {
|
||||
|
||||
l := p.lines[i];
|
||||
|
||||
length := 0;
|
||||
|
||||
for format_token, i in l.format_tokens {
|
||||
|
||||
if format_token.kind == .Comment {
|
||||
if len(l.format_tokens) == 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