MCPcopy Index your code
hub / github.com/expr-lang/expr / String

Method String

ast/print.go:142–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140}
141
142func (n *MemberNode) String() string {
143 node := n.Node.String()
144 if _, ok := n.Node.(*BinaryNode); ok {
145 node = fmt.Sprintf("(%s)", node)
146 }
147
148 if n.Optional {
149 if str, ok := n.Property.(*StringNode); ok && utils.IsValidIdentifier(str.Value) {
150 return fmt.Sprintf("%s?.%s", node, str.Value)
151 } else {
152 return fmt.Sprintf("%s?.[%s]", node, n.Property.String())
153 }
154 }
155 if str, ok := n.Property.(*StringNode); ok && utils.IsValidIdentifier(str.Value) {
156 if _, ok := n.Node.(*PointerNode); ok {
157 return fmt.Sprintf(".%s", str.Value)
158 }
159 return fmt.Sprintf("%s.%s", node, str.Value)
160 }
161 return fmt.Sprintf("%s[%s]", node, n.Property.String())
162}
163
164func (n *SliceNode) String() string {
165 if n.From == nil && n.To == nil {

Callers 1

TestPrint_MemberNodeFunction · 0.95

Calls 3

IsValidIdentifierFunction · 0.92
SprintfMethod · 0.80
StringMethod · 0.65

Tested by 1

TestPrint_MemberNodeFunction · 0.76