fmt: force break in front of long unbreakable parts, avoid very small sub-expressions
							parent
							
								
									328cb7ed7e
								
							
						
					
					
						commit
						46379d92f4
					
				|  | @ -13,7 +13,7 @@ const ( | ||||||
| 		'\t\t\t\t\t\t\t\t' | 		'\t\t\t\t\t\t\t\t' | ||||||
| 	] | 	] | ||||||
| 	// when to break a line dependant on penalty
 | 	// when to break a line dependant on penalty
 | ||||||
| 	max_len = [0, 30, 85, 95, 100] | 	max_len = [0, 35, 85, 93, 100] | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| pub struct Fmt { | pub struct Fmt { | ||||||
|  | @ -150,7 +150,7 @@ fn (mut f Fmt) adjust_complete_line() { | ||||||
| 			mut sub_expr_end_idx := f.penalties.len | 			mut sub_expr_end_idx := f.penalties.len | ||||||
| 			// search for next position with low penalty and same precedence to form subexpression
 | 			// search for next position with low penalty and same precedence to form subexpression
 | ||||||
| 			for j in i..f.penalties.len { | 			for j in i..f.penalties.len { | ||||||
| 				if f.penalties[j] <= 1 && f.precedences[j] == precedence { | 				if f.penalties[j] <= 1 && f.precedences[j] == precedence && len_sub_expr >= max_len[1] { | ||||||
| 					sub_expr_end_idx = j | 					sub_expr_end_idx = j | ||||||
| 					break | 					break | ||||||
| 				} else if f.precedences[j] < precedence { | 				} else if f.precedences[j] < precedence { | ||||||
|  | @ -174,6 +174,10 @@ fn (mut f Fmt) adjust_complete_line() { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 		// emergency fallback: decrease penalty in front of long unbreakable parts 
 | ||||||
|  | 		if i > 0 && buf.len > max_len[3] - max_len[1] && f.penalties[i-1] > 0 { | ||||||
|  | 			f.penalties[i-1] = if buf.len >= max_len[2] { 0 } else { 1 } | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -10,8 +10,8 @@ const ( | ||||||
| 	eulers              = 2.7182 | 	eulers              = 2.7182 | ||||||
| 	supported_platforms = ['windows', 'mac', 'macos', 'darwin', 'linux', 'freebsd', 'openbsd', | 	supported_platforms = ['windows', 'mac', 'macos', 'darwin', 'linux', 'freebsd', 'openbsd', | ||||||
| 		'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] | 		'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] | ||||||
| 	one_line_supported  = ['windows', 'mac', 'macos', 'darwin', 'linux', 'freebsd', 'openbsd', 'netbsd', | 	one_line_supported  = ['windows', 'mac', 'macos', 'darwin', 'linux', 'freebsd', 'openbsd', | ||||||
| 		'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] | 		'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] | ||||||
| 	another_const       = ['a', 'b', 'c', 'd', 'e', 'f'] | 	another_const       = ['a', 'b', 'c', 'd', 'e', 'f'] | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -50,6 +50,13 @@ fn main() { | ||||||
| 	s := []string{} | 	s := []string{} | ||||||
| 	s << '	`$v_str`' | 	s << '	`$v_str`' | ||||||
| 	println(s) | 	println(s) | ||||||
|  | 	println('this is quite a long string' + | ||||||
|  | 		' that is followd by an even longer part that should go to another line') | ||||||
|  | 	if (a == b && b > r) || | ||||||
|  | 		(d > r) || (a < b) || (b < d && a + b > r) || | ||||||
|  | 		(a + b + d >= 0 && r < 0) || (a > b && d - r < b) { | ||||||
|  | 		println('ok') | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn gen_str_for_multi_return(mut g gen.Gen, info table.MultiReturn, styp, str_fn_name string) { | fn gen_str_for_multi_return(mut g gen.Gen, info table.MultiReturn, styp, str_fn_name string) { | ||||||
|  |  | ||||||
|  | @ -60,6 +60,10 @@ fn main() { | ||||||
| 	s := []string{} | 	s := []string{} | ||||||
| 	s << '	`$v_str`' | 	s << '	`$v_str`' | ||||||
| 	println(s) | 	println(s) | ||||||
|  | 	println('this is quite a long string' + ' that is followd by an even longer part that should go to another line') | ||||||
|  | 	if (a == b && b > r) || (d > r) || (a < b) || (b< d && a+b > r) || (a+b+d >= 0 && r < 0) || (a > b && d-r < b) { | ||||||
|  | 		println('ok') | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn gen_str_for_multi_return(mut g gen.Gen, | fn gen_str_for_multi_return(mut g gen.Gen, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue