MCPcopy Create free account
hub / github.com/expr-lang/expr / String

Method String

ast/print.go:213–241  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

211}
212
213func (n *ConditionalNode) String() string {
214 if !n.Ternary {
215 cond := n.Cond.String()
216 exp1 := n.Exp1.String()
217 if c2, ok := n.Exp2.(*ConditionalNode); ok && !c2.Ternary {
218 return fmt.Sprintf("if %s { %s } else %s", cond, exp1, c2.String())
219 }
220 exp2 := n.Exp2.String()
221 return fmt.Sprintf("if %s { %s } else { %s }", cond, exp1, exp2)
222 }
223
224 var cond, exp1, exp2 string
225 if _, ok := n.Cond.(*ConditionalNode); ok {
226 cond = fmt.Sprintf("(%s)", n.Cond.String())
227 } else {
228 cond = n.Cond.String()
229 }
230 if _, ok := n.Exp1.(*ConditionalNode); ok {
231 exp1 = fmt.Sprintf("(%s)", n.Exp1.String())
232 } else {
233 exp1 = n.Exp1.String()
234 }
235 if _, ok := n.Exp2.(*ConditionalNode); ok {
236 exp2 = fmt.Sprintf("(%s)", n.Exp2.String())
237 } else {
238 exp2 = n.Exp2.String()
239 }
240 return fmt.Sprintf("%s ? %s : %s", cond, exp1, exp2)
241}
242
243func (n *ArrayNode) String() string {
244 nodes := make([]string, len(n.Nodes))

Callers

nothing calls this directly

Calls 2

SprintfMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected