MCPcopy Create free account
hub / github.com/jmespath/go-jmespath / PrettyPrint

Method PrettyPrint

parser.go:55–78  ·  view source on GitHub ↗

PrettyPrint will pretty print the parsed AST. The AST is an implementation detail and this pretty print function is provided as a convenience method to help with debugging. You should not rely on its output as the internal structure of the AST may change at any time.

(indent int)

Source from the content-addressed store, hash-verified

53// debugging. You should not rely on its output as the internal
54// structure of the AST may change at any time.
55func (node ASTNode) PrettyPrint(indent int) string {
56 spaces := strings.Repeat(" ", indent)
57 output := fmt.Sprintf("%s%s {\n", spaces, node.nodeType)
58 nextIndent := indent + 2
59 if node.value != nil {
60 if converted, ok := node.value.(fmt.Stringer); ok {
61 // Account for things like comparator nodes
62 // that are enums with a String() method.
63 output += fmt.Sprintf("%svalue: %s\n", strings.Repeat(" ", nextIndent), converted.String())
64 } else {
65 output += fmt.Sprintf("%svalue: %#v\n", strings.Repeat(" ", nextIndent), node.value)
66 }
67 }
68 lastIndex := len(node.children)
69 if lastIndex > 0 {
70 output += fmt.Sprintf("%schildren: {\n", strings.Repeat(" ", nextIndent))
71 childIndent := nextIndent + 2
72 for _, elem := range node.children {
73 output += elem.PrettyPrint(childIndent)
74 }
75 }
76 output += fmt.Sprintf("%s}\n", spaces)
77 return output
78}
79
80var bindingPowers = map[tokType]int{
81 tEOF: 0,

Callers 3

StringMethod · 0.95
TestPrettyPrintedASTFunction · 0.80

Calls 1

StringMethod · 0.45

Tested by 2

TestPrettyPrintedASTFunction · 0.64