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

Function Unparse

parser/unparser.go:44–68  ·  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

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

Callers 6

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

Calls 2

visitMethod · 0.95
StringMethod · 0.65

Tested by 3

TestPruneFunction · 0.74
TestUnparseFunction · 0.68
TestUnparseErrorsFunction · 0.68