ExprMap tests if the given expression is a static map construct and, if so, extracts the expressions that represent the map elements. If the given expression is not a static map, error diagnostics are returned. A particular Expression implementation can support this function by offering a method ca
(expr Expression)
| 15 | // UnwrapExpression to delegate handling of this function to a wrapped |
| 16 | // Expression object. |
| 17 | func ExprMap(expr Expression) ([]KeyValuePair, Diagnostics) { |
| 18 | type exprMap interface { |
| 19 | ExprMap() []KeyValuePair |
| 20 | } |
| 21 | |
| 22 | physExpr := UnwrapExpressionUntil(expr, func(expr Expression) bool { |
| 23 | _, supported := expr.(exprMap) |
| 24 | return supported |
| 25 | }) |
| 26 | |
| 27 | if exM, supported := physExpr.(exprMap); supported { |
| 28 | if pairs := exM.ExprMap(); pairs != nil { |
| 29 | return pairs, nil |
| 30 | } |
| 31 | } |
| 32 | return nil, Diagnostics{ |
| 33 | &Diagnostic{ |
| 34 | Severity: DiagError, |
| 35 | Summary: "Invalid expression", |
| 36 | Detail: "A static map expression is required.", |
| 37 | Subject: expr.StartRange().Ptr(), |
| 38 | }, |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // KeyValuePair represents a pair of expressions that serve as a single item |
| 43 | // within a map or object definition construct. |
nothing calls this directly
no test coverage detected