vfmt: support `match a { x...y {} }`
							parent
							
								
									35096cda3f
								
							
						
					
					
						commit
						4bf1c2fdcc
					
				|  | @ -46,6 +46,7 @@ pub mut: | |||
| 	use_short_fn_args bool | ||||
| 	it_name           string // the name to replace `it` with
 | ||||
| 	inside_lambda     bool | ||||
| 	is_mbranch_expr   bool // math a { x...y { } }
 | ||||
| } | ||||
| 
 | ||||
| pub fn fmt(file ast.File, table &table.Table, is_debug bool) string { | ||||
|  | @ -896,7 +897,11 @@ pub fn (mut f Fmt) expr(node ast.Expr) { | |||
| 		} | ||||
| 		ast.RangeExpr { | ||||
| 			f.expr(node.low) | ||||
| 			f.write('..') | ||||
| 			if f.is_mbranch_expr { | ||||
| 				f.write('...') | ||||
| 			} else { | ||||
| 				f.write('..') | ||||
| 			} | ||||
| 			f.expr(node.high) | ||||
| 		} | ||||
| 		ast.SelectExpr { | ||||
|  | @ -1530,12 +1535,14 @@ pub fn (mut f Fmt) match_expr(it ast.MatchExpr) { | |||
| 		} | ||||
| 		if !branch.is_else { | ||||
| 			// normal branch
 | ||||
| 			f.is_mbranch_expr = true | ||||
| 			for j, expr in branch.exprs { | ||||
| 				f.expr(expr) | ||||
| 				if j < branch.exprs.len - 1 { | ||||
| 					f.write(', ') | ||||
| 				} | ||||
| 			} | ||||
| 			f.is_mbranch_expr = false | ||||
| 		} else { | ||||
| 			// else branch
 | ||||
| 			f.write('else') | ||||
|  |  | |||
|  | @ -0,0 +1,15 @@ | |||
| pub fn (b byte) str_escaped() string { | ||||
| 	str := match b { | ||||
| 		0 { '`\\' + '0`' } // Bug is preventing \\0 in a literal
 | ||||
| 		7 { '`\\a`' } | ||||
| 		8 { '`\\b`' } | ||||
| 		9 { '`\\t`' } | ||||
| 		10 { '`\\n`' } | ||||
| 		11 { '`\\v`' } | ||||
| 		12 { '`\\f`' } | ||||
| 		13 { '`\\r`' } | ||||
| 		32...126 { b.str() } | ||||
| 		else { '0x' + b.hex() } | ||||
| 	} | ||||
| 	return str | ||||
| } | ||||
		Loading…
	
		Reference in New Issue