diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-02-08 20:24:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-08 20:24:44 +0100 |
| commit | b0b9c23d38d5d00bd1c6ccc6f8064cce9c653e7d (patch) | |
| tree | 73d4e4c2ce4d9e2153d50bffa55899a4b496fe5e /src | |
| parent | e1cafb6bb11dd6b2b89231ee8241b188a904cf06 (diff) | |
| parent | e170595126b2642a8e01d93f7a0e4987a4db9c2b (diff) | |
Merge pull request #589 from SlashScreen/spaces_around_colon
Add option for spaces around colons
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/printer.odin | 43 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 8 |
2 files changed, 27 insertions, 24 deletions
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index a02557e..81d0975 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -52,6 +52,7 @@ Config :: struct { newline_style: Newline_Style, sort_imports: bool, inline_single_stmt_case: bool, + spaces_around_colons: bool, //Put spaces to the left of a colon as well as the right. `foo: bar` => `foo : bar` } Brace_Style :: enum { @@ -91,29 +92,31 @@ Line_Suffix_Option :: enum { when ODIN_OS == .Windows { default_style := Config { - spaces = 4, - newline_limit = 2, - convert_do = false, - tabs = true, - tabs_width = 4, - brace_style = ._1TBS, - indent_cases = false, - newline_style = .CRLF, - character_width = 100, - sort_imports = true, + spaces = 4, + newline_limit = 2, + convert_do = false, + tabs = true, + tabs_width = 4, + brace_style = ._1TBS, + indent_cases = false, + newline_style = .CRLF, + character_width = 100, + sort_imports = true, + spaces_around_colons = false, } } else { default_style := Config { - spaces = 4, - newline_limit = 2, - convert_do = false, - tabs = true, - tabs_width = 4, - brace_style = ._1TBS, - indent_cases = false, - newline_style = .LF, - character_width = 100, - sort_imports = true, + spaces = 4, + newline_limit = 2, + convert_do = false, + tabs = true, + tabs_width = 4, + brace_style = ._1TBS, + indent_cases = false, + newline_style = .LF, + character_width = 100, + sort_imports = true, + spaces_around_colons = false, } } diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 2b0dcd3..a58a0de 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -310,7 +310,7 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) -> ^Do lhs = cons(lhs, visit_exprs(p, v.names, {.Add_Comma, .Glue})) if v.type != nil { - lhs = cons(lhs, text(":")) + lhs = cons(lhs, text(" :" if p.config.spaces_around_colons else ":")) lhs = cons_with_nopl(lhs, visit_expr(p, v.type)) } else { if !v.is_mutable { @@ -329,7 +329,7 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) -> ^Do rhs = cons_with_nopl(rhs, visit_exprs(p, v.values, {.Add_Comma}, .Value_Decl)) } else if len(v.values) > 0 && v.type != nil { - rhs = cons_with_nopl(rhs, cons_with_nopl(text(":"), visit_exprs(p, v.values, {.Add_Comma}))) + rhs = cons_with_nopl(rhs, cons_with_nopl(text(" :" if p.config.spaces_around_colons else ":"), visit_exprs(p, v.values, {.Add_Comma}))) } else { rhs = cons_with_nopl(rhs, visit_exprs(p, v.values, {.Add_Comma}, .Value_Decl)) } @@ -2040,7 +2040,7 @@ visit_struct_field_list :: proc(p: ^Printer, list: ^ast.Field_List, options := L if field.type != nil { if len(field.names) != 0 { - document = cons(document, text(":"), align) + document = cons(document, text(" :" if p.config.spaces_around_colons else ":"), align) } document = cons_with_opl(document, visit_expr(p, field.type)) } else { @@ -2358,7 +2358,7 @@ visit_signature_field :: proc(p: ^Printer, field: ^ast.Field, remove_blank := tr document = cons(document, cons_with_nopl(flag, visit_exprs(p, field.names, {.Add_Comma}))) if len(field.names) != 0 && field.type != nil { - document = cons(document, text(":"), break_with_no_newline()) + document = cons(document, text(" :" if p.config.spaces_around_colons else ":"), break_with_no_newline()) } } |