diff options
| author | SlashScreen <tallesttower1@gmail.com> | 2025-02-06 13:28:26 -0800 |
|---|---|---|
| committer | Slashscreen <SlashScreen@users.noreply.github.com> | 2025-02-06 14:06:35 -0800 |
| commit | a27ef1f954a581cefed4a85f8f438d6c42821dce (patch) | |
| tree | b9cce9c7c8189c7085f34c0625ec8be17a763aa5 /src | |
| parent | 94822db4b5dd90c39020fb48f89532e0f44e7110 (diff) | |
spacess 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 0911496..4304019 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -304,7 +304,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 { @@ -323,7 +323,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)) } @@ -2034,7 +2034,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 { @@ -2352,7 +2352,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()) } } |