MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Unparse

Function Unparse

parser/unparser.go:45–69  ·  view source on GitHub ↗

Unparse takes an input expression and source position information and generates a human-readable expression. Note, unparsing 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. -

(expr ast.Expr, info *ast.SourceInfo, opts ...UnparserOption)

Source from the content-addressed store, hash-verified

43// This function optionally takes in one or more UnparserOption to alter the unparsing behavior, such as
44// performing word wrapping on expressions.
45func Unparse(expr ast.Expr, info *ast.SourceInfo, opts ...UnparserOption) (string, error) {
46 unparserOpts := &unparserOption{
47 wrapOnColumn: defaultWrapOnColumn,
48 wrapAfterColumnLimit: defaultWrapAfterColumnLimit,
49 operatorsToWrapOn: defaultOperatorsToWrapOn,
50 }
51
52 var err error
53 for _, opt := range opts {
54 unparserOpts, err = opt(unparserOpts)
55 if err != nil {
56 return "", err
57 }
58 }
59
60 un := &unparser{
61 info: info,
62 options: unparserOpts,
63 }
64 err = un.visit(expr)
65 if err != nil {
66 return "", err
67 }
68 return un.str.String(), nil
69}
70
71var identifierPartPattern *regexp.Regexp = regexp.MustCompile(`^[A-Za-z_][0-9A-Za-z_]*$`)
72

Callers 7

reportCoverageFunction · 0.92
TestPruneFunction · 0.92
ExprToStringFunction · 0.92
TestUnparseFunction · 0.85
TestUnparseErrorsFunction · 0.85
TestUnparseEscapedCallsFunction · 0.85

Calls 2

visitMethod · 0.95
StringMethod · 0.65

Tested by 4

TestPruneFunction · 0.74
TestUnparseFunction · 0.68
TestUnparseErrorsFunction · 0.68
TestUnparseEscapedCallsFunction · 0.68