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)
| 692 | // |
| 693 | // This will replace any previously supplied operators instead of merging them. |
| 694 | func WrapOnOperators(symbols ...string) UnparserOption { |
| 695 | return func(opt *unparserOption) (*unparserOption, error) { |
| 696 | opt.operatorsToWrapOn = make(map[string]bool) |
| 697 | for _, symbol := range symbols { |
| 698 | _, found := operators.FindReverse(symbol) |
| 699 | if !found { |
| 700 | return nil, fmt.Errorf("Invalid unparser option. Unsupported operator: %s", symbol) |
| 701 | } |
| 702 | arity := operators.Arity(symbol) |
| 703 | if arity < 2 { |
| 704 | return nil, fmt.Errorf("Invalid unparser option. Unary operators are unsupported: %s", symbol) |
| 705 | } |
| 706 | |
| 707 | opt.operatorsToWrapOn[symbol] = true |
| 708 | } |
| 709 | |
| 710 | return opt, nil |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | // WrapAfterColumnLimit dictates whether to insert a newline before or after the specified operator |
| 715 | // when word wrapping is performed. |