Execute runs the given DSL to initialize the given expression. It returns true on success. It returns false and appends to Context.Errors on failure. Note that Run takes care of calling Execute on all expressions that implement Source. This function is intended for use by expressions that run the DS
(fn func(), def Expression)
| 67 | // (usually simple independent expressions). The DSL should use ReportError to |
| 68 | // record DSL execution errors. |
| 69 | func Execute(fn func(), def Expression) bool { |
| 70 | if fn == nil { |
| 71 | return true |
| 72 | } |
| 73 | var startCount int |
| 74 | if Context.Errors != nil { |
| 75 | startCount = len(Context.Errors) |
| 76 | } |
| 77 | Context.Stack = append(Context.Stack, def) |
| 78 | fn() |
| 79 | Context.Stack = Context.Stack[:len(Context.Stack)-1] |
| 80 | var endCount int |
| 81 | if Context.Errors != nil { |
| 82 | endCount = len(Context.Errors) |
| 83 | } |
| 84 | return endCount <= startCount |
| 85 | } |
| 86 | |
| 87 | // Current returns the expression whose DSL is currently being executed. |
| 88 | // As a special case Current returns Top when the execution stack is empty. |
no outgoing calls