Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format takes an input expression and source information and generates a human-readable expression, writing it to dst.
Note, formatting an AST will often generate the same expression as was originally parsed, but some formatting may be lost in translation, notably:
- All quoted literals are doubled quoted unless triple quoted string literal syntax is used. - Byte literals are represented as octal escapes (same as Google SQL) unless using triple quotes. - Floating point values are converted to the small number of digits needed to represent the value. - Spacing around punctuation marks may be lost. - Parentheses will only be applied when they affect operator precedence.
This function optionally takes in one or more UnparserOption to alter the formatting behavior, such as performing word wrapping on expressions.
Types ¶
type FormatOption ¶
type FormatOption func(*unparserOption) (*unparserOption, error)
FormatOption is a functional option for configuring the output formatting of the Unparse function.
func AlwaysComma ¶
func AlwaysComma() FormatOption
func Pretty ¶
func Pretty() FormatOption
func WrapAfterColumnLimit ¶
func WrapAfterColumnLimit(wrapAfter bool) FormatOption
WrapAfterColumnLimit dictates whether to insert a newline before or after the specified operator when word wrapping is performed.
Example usage:
Unparse(expr, sourceInfo, WrapOnColumn(40), WrapOnOperators(Operators.LogicalAnd), WrapAfterColumnLimit(false))
This will insert a newline immediately before the logical AND operator for the below example input, ensuring that the length of a line never exceeds the specified column limit:
Input: 'my-principal-group' in request.auth.claims && request.auth.claims.iat > now - duration('5m')
Output: 'my-principal-group' in request.auth.claims && request.auth.claims.iat > now - duration('5m')
func WrapOnColumn ¶
func WrapOnColumn(col int) FormatOption
WrapOnColumn wraps the output expression when its string length exceeds a specified limit for operators set by WrapOnOperators function or by default, "&&" and "||" will be wrapped.
Example usage:
Unparse(expr, sourceInfo, WrapOnColumn(40), WrapOnOperators(Operators.LogicalAnd))
This will insert a newline immediately after the logical AND operator for the below example input:
Input: 'my-principal-group' in request.auth.claims && request.auth.claims.iat > now - duration('5m')
Output: 'my-principal-group' in request.auth.claims && request.auth.claims.iat > now - duration('5m')
func WrapOnOperators ¶
func WrapOnOperators(symbols ...string) FormatOption
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 previously supplied operators instead of merging them.