|
@@ -616,6 +616,13 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|
largest := 0;
|
|
largest := 0;
|
|
case_count := 0;
|
|
case_count := 0;
|
|
|
|
|
|
|
|
+ TokenAndLength :: struct {
|
|
|
|
+ format_token: ^Format_Token,
|
|
|
|
+ length: int,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ format_tokens := make([dynamic] TokenAndLength, 0, brace_token.parameter_count, context.temp_allocator);
|
|
|
|
+
|
|
//find all the switch cases that are one lined
|
|
//find all the switch cases that are one lined
|
|
for line, line_index in p.lines[brace_line + 1:] {
|
|
for line, line_index in p.lines[brace_line + 1:] {
|
|
|
|
|
|
@@ -623,7 +630,7 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|
colon_found := false;
|
|
colon_found := false;
|
|
length := 0;
|
|
length := 0;
|
|
|
|
|
|
- for format_token in line.format_tokens {
|
|
|
|
|
|
+ for format_token, i in line.format_tokens {
|
|
|
|
|
|
if format_token.kind == .Comment {
|
|
if format_token.kind == .Comment {
|
|
continue;
|
|
continue;
|
|
@@ -631,6 +638,7 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|
|
|
|
|
//this will only happen if the case is one lined
|
|
//this will only happen if the case is one lined
|
|
if case_found && colon_found {
|
|
if case_found && colon_found {
|
|
|
|
+ append(&format_tokens, TokenAndLength { format_token = &line.format_tokens[i], length = length });
|
|
largest = max(length, largest);
|
|
largest = max(length, largest);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -650,38 +658,10 @@ 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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //this will only happen if the case is one lined
|
|
|
|
- if case_found && colon_found {
|
|
|
|
- line.format_tokens[i].spaces_before = (largest - length) + 1;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if format_token.kind == .Case {
|
|
|
|
- case_found = true;
|
|
|
|
- case_count += 1;
|
|
|
|
- } else if format_token.kind == .Colon {
|
|
|
|
- colon_found = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- length += len(format_token.text) + format_token.spaces_before;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if case_count >= brace_token.parameter_count {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ for token in format_tokens {
|
|
|
|
+ token.format_token.spaces_before = largest - token.length + 1;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
align_enum :: proc(p: ^Printer, index: int) {
|
|
align_enum :: proc(p: ^Printer, index: int) {
|
|
@@ -710,30 +690,12 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|
largest := 0;
|
|
largest := 0;
|
|
comma_count := 0;
|
|
comma_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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if format_token.kind == .Eq {
|
|
|
|
- largest = max(length, largest);
|
|
|
|
- break;
|
|
|
|
- } else if format_token.kind == .Comma {
|
|
|
|
- comma_count += 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- length += len(format_token.text) + format_token.spaces_before;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if comma_count >= brace_token.parameter_count {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ TokenAndLength :: struct {
|
|
|
|
+ format_token: ^Format_Token,
|
|
|
|
+ length: int,
|
|
|
|
+ };
|
|
|
|
|
|
- comma_count = 0;
|
|
|
|
|
|
+ format_tokens := make([dynamic] TokenAndLength, 0, brace_token.parameter_count, context.temp_allocator);
|
|
|
|
|
|
for line, line_index in p.lines[brace_line + 1:] {
|
|
for line, line_index in p.lines[brace_line + 1:] {
|
|
length := 0;
|
|
length := 0;
|
|
@@ -744,7 +706,8 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|
}
|
|
}
|
|
|
|
|
|
if format_token.kind == .Eq {
|
|
if format_token.kind == .Eq {
|
|
- line.format_tokens[i].spaces_before = largest - length + 1;
|
|
|
|
|
|
+ append(&format_tokens, TokenAndLength { format_token = &line.format_tokens[i], length = length });
|
|
|
|
+ largest = max(length, largest);
|
|
break;
|
|
break;
|
|
} else if format_token.kind == .Comma {
|
|
} else if format_token.kind == .Comma {
|
|
comma_count += 1;
|
|
comma_count += 1;
|
|
@@ -757,6 +720,11 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ for token in format_tokens {
|
|
|
|
+ token.format_token.spaces_before = largest - token.length + 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
align_struct :: proc(p: ^Printer, index: int) {
|
|
align_struct :: proc(p: ^Printer, index: int) {
|