align not mutable correctly

This commit is contained in:
Daniel Gavin
2021-04-22 00:23:17 +02:00
parent 9b8563dfc0
commit de1838c0cb
2 changed files with 22 additions and 6 deletions
+20 -4
View File
@@ -449,6 +449,7 @@ align_var_decls :: proc(p: ^Printer) {
current_line: int;
current_typed: bool;
current_not_mutable: bool;
largest_lhs := 0;
largest_rhs := 0;
@@ -470,17 +471,31 @@ align_var_decls :: proc(p: ^Printer) {
}
typed := true;
not_mutable := false;
continue_flag := false;
for i := 0; i < len(line.format_tokens) - 1; i += 1 {
if line.format_tokens[i].kind == .Colon && line.format_tokens[i + 1].kind == .Eq {
typed = false;
break;
}
if line.format_tokens[i].kind == .Colon && line.format_tokens[i + 1].kind == .Colon {
not_mutable = true;
}
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;
}
}
if line_index != current_line + 1 || typed != current_typed {
if continue_flag {
continue;
}
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed {
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 {
for colon_token in colon_tokens {
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
}
@@ -507,6 +522,7 @@ align_var_decls :: proc(p: ^Printer) {
largest_rhs = 0;
largest_lhs = 0;
current_typed = typed;
current_not_mutable = not_mutable;
}
current_line = line_index;
@@ -549,7 +565,7 @@ align_var_decls :: proc(p: ^Printer) {
}
//repeating myself, move to sub procedure
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed {
if p.config.align_style == .Align_On_Colon_And_Equals || !current_typed || current_not_mutable {
for colon_token in colon_tokens {
colon_token.format_token.spaces_before = largest_lhs - colon_token.length + 1;
}
+2 -2
View File
@@ -424,11 +424,12 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
visit_exprs(p, v.names, true);
hint_current_line(p, {.Value_Decl});
if v.type != nil {
if !v.is_mutable {
push_generic_token(p, .Colon, 0);
} else {
hint_current_line(p, {.Value_Decl});
push_generic_token(p, .Colon, 0);
}
@@ -438,7 +439,6 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
push_generic_token(p, .Colon, 1);
push_generic_token(p, .Colon, 0);
} else {
hint_current_line(p, {.Value_Decl});
push_generic_token(p, .Colon, 1);
}
}