check comma count in enum instead

This commit is contained in:
Daniel Gavin
2021-04-22 00:55:25 +02:00
parent 43589a56b7
commit ab53900c95
2 changed files with 12 additions and 8 deletions
+11 -7
View File
@@ -486,13 +486,15 @@ align_var_decls :: proc(p: ^Printer) {
if tokenizer.Token_Kind.B_Keyword_Begin <= line.format_tokens[i].kind && line.format_tokens[i].kind <= tokenizer.Token_Kind.B_Keyword_End { if tokenizer.Token_Kind.B_Keyword_Begin <= line.format_tokens[i].kind && line.format_tokens[i].kind <= tokenizer.Token_Kind.B_Keyword_End {
continue_flag = true; continue_flag = true;
} }
} }
if continue_flag { if continue_flag {
continue; continue;
} }
fmt.println(line);
fmt.println(largest_rhs);
if line_index != current_line + 1 || typed != current_typed || not_mutable != current_not_mutable { if line_index != current_line + 1 || typed != current_typed || not_mutable != current_not_mutable {
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed || current_not_mutable { if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed || current_not_mutable {
@@ -705,7 +707,7 @@ align_enum :: proc(p: ^Printer, index: int) {
} }
largest := 0; largest := 0;
eq_count := 0; comma_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;
@@ -716,20 +718,21 @@ align_enum :: proc(p: ^Printer, index: int) {
} }
if format_token.kind == .Eq { if format_token.kind == .Eq {
eq_count += 1;
largest = max(length, largest); largest = max(length, largest);
break; break;
} else if format_token.kind == .Comma {
comma_count += 1;
} }
length += len(format_token.text) + format_token.spaces_before; length += len(format_token.text) + format_token.spaces_before;
} }
if eq_count >= brace_token.parameter_count { if comma_count >= brace_token.parameter_count {
break; break;
} }
} }
eq_count = 0; comma_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;
@@ -740,15 +743,16 @@ align_enum :: proc(p: ^Printer, index: int) {
} }
if format_token.kind == .Eq { if format_token.kind == .Eq {
eq_count += 1;
line.format_tokens[i].spaces_before = largest - length + 1; line.format_tokens[i].spaces_before = largest - length + 1;
break; break;
} else if format_token.kind == .Comma {
comma_count += 1;
} }
length += len(format_token.text) + format_token.spaces_before; length += len(format_token.text) + format_token.spaces_before;
} }
if eq_count >= brace_token.parameter_count { if comma_count >= brace_token.parameter_count {
break; break;
} }
} }