diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-08-06 21:47:06 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2023-08-06 21:47:06 +0200 |
| commit | 2b609359cb5a827568fcee957529d852ff7e1c40 (patch) | |
| tree | 34f50f81447d3d23c818763ed1506ee0b37996ee /src | |
| parent | a010fd2c8f9c3b3bd4cec75022c50aac94c0cb02 (diff) | |
Undo the control of newlines in comp_lit - it broke too many things and wasn't really compatible with the formatter design.
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/document.odin | 36 | ||||
| -rw-r--r-- | src/odin/printer/printer.odin | 19 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 19 |
3 files changed, 48 insertions, 26 deletions
diff --git a/src/odin/printer/document.odin b/src/odin/printer/document.odin index 3dd9eda..5e04181 100644 --- a/src/odin/printer/document.odin +++ b/src/odin/printer/document.odin @@ -65,6 +65,7 @@ Document_Group_Mode :: enum { Flat, Break, Fit, + Fill, } Document_Group_Options :: struct { @@ -156,6 +157,18 @@ enforce_fit :: proc( return document } +fill :: proc( + filled_document: ^Document, + allocator := context.allocator, +) -> ^Document { + document := new(Document, allocator) + document^ = Document_Group { + document = filled_document, + mode = .Fill, + } + return document +} + enforce_break :: proc( fitted_document: ^Document, options := Document_Group_Options{}, @@ -578,6 +591,17 @@ format :: proc( builder, p, ) + } else if data.mode == .Fill && consumed < width { + strings.write_string(builder, v.value) + consumed += len(v.value) + } else if data.mode == .Fill && v.newline { + format_newline( + data.indentation, + data.alignment, + &consumed, + builder, + p, + ) } else { strings.write_string(builder, v.value) consumed += len(v.value) @@ -660,7 +684,17 @@ format :: proc( }, ) } else { - if v.mode == .Fit { + if data.mode == .Fill || v.mode == .Fill { + append( + list, + Tuple{ + indentation = data.indentation, + mode = .Fill, + document = v.document, + alignment = data.alignment, + }, + ) + } else if v.mode == .Fit { append( list, Tuple{ diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index ba2b7e3..d2af255 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -38,16 +38,15 @@ Disabled_Info :: struct { } Config :: struct { - character_width: int, - spaces: int, //Spaces per indentation - newline_limit: int, //The limit of newlines between statements and declarations. - tabs: bool, //Enable or disable tabs - tabs_width: int, - convert_do: bool, //Convert all do statements to brace blocks - multiline_composite_literals: bool `json:"exp_multiline_composite_literals"`, - brace_style: Brace_Style, - indent_cases: bool, - newline_style: Newline_Style, + character_width: int, + spaces: int, //Spaces per indentation + newline_limit: int, //The limit of newlines between statements and declarations. + tabs: bool, //Enable or disable tabs + tabs_width: int, + convert_do: bool, //Convert all do statements to brace blocks + brace_style: Brace_Style, + indent_cases: bool, + newline_style: Newline_Style, } Brace_Style :: enum { diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index c23305e..76120da 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -1446,16 +1446,6 @@ contains_comments_in_range :: proc( } @(private) -comp_lit_spans_multiple_lines :: proc(lit: ast.Comp_Lit) -> bool { - for elem, i in lit.elems { - if elem.pos.line != lit.pos.line { - return true - } - } - return false -} - -@(private) contains_do_in_expression :: proc(p: ^Printer, expr: ^ast.Expr) -> bool { found_do := false @@ -2012,11 +2002,7 @@ visit_expr :: proc( } } - can_multiline := - p.config.multiline_composite_literals && - comp_lit_spans_multiple_lines(v^) should_newline := - can_multiline || comp_lit_contains_fields(p, v^) || contains_comments_in_range(p, v.pos, v.end) should_newline &= @@ -2026,7 +2012,10 @@ visit_expr :: proc( should_newline &= len(v.elems) != 0 if should_newline { - document = cons(document, visit_begin_brace(p, v.pos, .Comp_Lit)) + document = cons_with_nopl( + document, + visit_begin_brace(p, v.pos, .Comp_Lit), + ) set_source_position(p, v.open) document = cons( |