WrapOnOperators specifies which operators to perform word wrapping on an output expression when its string length exceeds the column limit set by WrapOnColumn function. Word wrapping is supported on non-unary symbolic operators. Refer to operators.go for the full list This will replace any previou
(symbols ...string)
| 620 | // |
| 621 | // This will replace any previously supplied operators instead of merging them. |
| 622 | func WrapOnOperators(symbols ...string) UnparserOption { |
| 623 | return func(opt *unparserOption) (*unparserOption, error) { |
| 624 | opt.operatorsToWrapOn = make(map[string]bool) |
| 625 | for _, symbol := range symbols { |
| 626 | _, found := operators.FindReverse(symbol) |
| 627 | if !found { |
| 628 | return nil, fmt.Errorf("Invalid unparser option. Unsupported operator: %s", symbol) |
| 629 | } |
| 630 | arity := operators.Arity(symbol) |
| 631 | if arity < 2 { |
| 632 | return nil, fmt.Errorf("Invalid unparser option. Unary operators are unsupported: %s", symbol) |
| 633 | } |
| 634 | |
| 635 | opt.operatorsToWrapOn[symbol] = true |
| 636 | } |
| 637 | |
| 638 | return opt, nil |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | // WrapAfterColumnLimit dictates whether to insert a newline before or after the specified operator |
| 643 | // when word wrapping is performed. |