ran the odinfmt - looks good, except for multi line binary operations

This commit is contained in:
Daniel Gavin
2021-04-15 00:19:13 +02:00
parent a09300fb0e
commit 22daa50374
2 changed files with 1346 additions and 1370 deletions
+2 -18
View File
@@ -8,7 +8,7 @@ import "core:fmt"
import "core:unicode/utf8" import "core:unicode/utf8"
import "core:mem" import "core:mem"
Line_Type_Enum :: enum{Line_Comment, Value_Decl, Switch_Stmt, Struct}; Line_Type_Enum :: enum {Line_Comment, Value_Decl, Switch_Stmt, Struct}
Line_Type :: bit_set[Line_Type_Enum]; Line_Type :: bit_set[Line_Type_Enum];
@@ -103,7 +103,7 @@ default_style := Config {
indent_cases = false, indent_cases = false,
align_switch = true, align_switch = true,
align_structs = true, align_structs = true,
newline_style = .LF, newline_style = .CRLF,
}; };
make_printer :: proc(config: Config, allocator := context.allocator) -> Printer { make_printer :: proc(config: Config, allocator := context.allocator) -> Printer {
@@ -194,7 +194,6 @@ fix_lines :: proc(p: ^Printer) {
} }
align_var_decls :: proc(p: ^Printer) { align_var_decls :: proc(p: ^Printer) {
} }
align_switch_smt :: proc(p: ^Printer, index: int) { align_switch_smt :: proc(p: ^Printer, index: int) {
@@ -216,9 +215,7 @@ align_switch_smt :: proc(p: ^Printer, index: int) {
} else if format_token.kind == .Switch { } else if format_token.kind == .Switch {
switch_found = true; switch_found = true;
} }
} }
} }
if !switch_found { if !switch_found {
@@ -260,7 +257,6 @@ align_switch_smt :: proc(p: ^Printer, index: int) {
if case_count >= brace_token.parameter_count { if case_count >= brace_token.parameter_count {
break; break;
} }
} }
case_count = 0; case_count = 0;
@@ -291,14 +287,12 @@ align_switch_smt :: proc(p: ^Printer, index: int) {
} }
length += len(format_token.text) + format_token.spaces_before; length += len(format_token.text) + format_token.spaces_before;
} }
if case_count >= brace_token.parameter_count { if case_count >= brace_token.parameter_count {
break; break;
} }
} }
} }
align_struct :: proc(p: ^Printer, index: int) { align_struct :: proc(p: ^Printer, index: int) {
@@ -320,9 +314,7 @@ align_struct :: proc(p: ^Printer, index: int) {
} else if format_token.kind == .Struct { } else if format_token.kind == .Struct {
struct_found = true; struct_found = true;
} }
} }
} }
if !struct_found { if !struct_found {
@@ -381,7 +373,6 @@ align_struct :: proc(p: ^Printer, index: int) {
break; break;
} }
} }
} }
align_blocks :: proc(p: ^Printer) { align_blocks :: proc(p: ^Printer) {
@@ -399,9 +390,7 @@ align_blocks :: proc(p: ^Printer) {
if .Struct in line.types && p.config.align_structs { if .Struct in line.types && p.config.align_structs {
align_struct(p, line_index); align_struct(p, line_index);
} }
} }
} }
align_comments :: proc(p: ^Printer) { align_comments :: proc(p: ^Printer) {
@@ -449,9 +438,7 @@ align_comments :: proc(p: ^Printer) {
length += format_token.spaces_before + len(format_token.text); length += format_token.spaces_before + len(format_token.text);
} }
} }
} }
if (current_info.begin != 0 && current_info.end != 0) || current_info.length > 0 { if (current_info.begin != 0 && current_info.end != 0) || current_info.length > 0 {
@@ -482,9 +469,6 @@ align_comments :: proc(p: ^Printer) {
length += format_token.spaces_before + len(format_token.text); length += format_token.spaces_before + len(format_token.text);
} }
} }
} }
} }
+1 -9
View File
@@ -116,7 +116,6 @@ push_comment :: proc(p: ^Printer, comment: tokenizer.Token) -> int {
} else { } else {
strings.write_byte(&builder, c); strings.write_byte(&builder, c);
} }
} }
if strings.builder_len(builder) > 0 { if strings.builder_len(builder) > 0 {
@@ -851,7 +850,6 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
set_source_position(p, stmt.end); set_source_position(p, stmt.end);
} }
@(private) @(private)
visit_expr :: proc(p: ^Printer, expr: ^ast.Expr) { visit_expr :: proc(p: ^Printer, expr: ^ast.Expr) {
@@ -1198,7 +1196,6 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr) {
} }
} }
visit_begin_brace :: proc(p: ^Printer, begin: tokenizer.Pos, type: Block_Type, count := 0) { visit_begin_brace :: proc(p: ^Printer, begin: tokenizer.Pos, type: Block_Type, count := 0) {
set_source_position(p, begin); set_source_position(p, begin);
@@ -1346,7 +1343,6 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type) {
visit_signature_list(p, proc_type.results); visit_signature_list(p, proc_type.results);
} }
} }
} }
visit_binary_expr :: proc(p: ^Printer, binary: ast.Binary_Expr) { visit_binary_expr :: proc(p: ^Printer, binary: ast.Binary_Expr) {
@@ -1372,7 +1368,6 @@ visit_binary_expr :: proc(p: ^Printer, binary: ast.Binary_Expr) {
} else { } else {
visit_expr(p, binary.right); visit_expr(p, binary.right);
} }
} }
visit_call_exprs :: proc(p: ^Printer, list: [] ^ast.Expr, ellipsis := false) { visit_call_exprs :: proc(p: ^Printer, list: [] ^ast.Expr, ellipsis := false) {
@@ -1401,7 +1396,6 @@ visit_call_exprs :: proc(p: ^Printer, list: []^ast.Expr, ellipsis := false) {
//we have to newline the expressions to respect the source //we have to newline the expressions to respect the source
move_line_limit(p, expr.pos, 1); move_line_limit(p, expr.pos, 1);
if i == len(list) - 1 && ellipsis { if i == len(list) - 1 && ellipsis {
push_generic_token(p, .Ellipsis, 0); push_generic_token(p, .Ellipsis, 0);
} }
@@ -1415,7 +1409,6 @@ visit_call_exprs :: proc(p: ^Printer, list: []^ast.Expr, ellipsis := false) {
} }
} }
visit_signature_list :: proc(p: ^Printer, list: ^ast.Field_List, remove_blank := true) { visit_signature_list :: proc(p: ^Printer, list: ^ast.Field_List, remove_blank := true) {
if list.list == nil { if list.list == nil {
@@ -1454,7 +1447,7 @@ visit_signature_list :: proc(p: ^Printer, list: ^ast.Field_List, remove_blank :=
if field.type != nil && field.default_value != nil { if field.type != nil && field.default_value != nil {
visit_expr(p, field.type); visit_expr(p, field.type);
push_generic_token(p, .Eq, 0); push_generic_token(p, .Eq, 1);
visit_expr(p, field.default_value); visit_expr(p, field.default_value);
} else if field.type != nil { } else if field.type != nil {
visit_expr(p, field.type); visit_expr(p, field.type);
@@ -1469,4 +1462,3 @@ visit_signature_list :: proc(p: ^Printer, list: ^ast.Field_List, remove_blank :=
} }
} }
} }