ASTValidators configures a set of ASTValidator instances into the target environment. Validators are applied in the order in which they are specified. If an ASTValidator with the same name is already configured, it will be replaced.
(validators ...ASTValidator)
| 102 | // Validators are applied in the order in which they are specified. |
| 103 | // If an ASTValidator with the same name is already configured, it will be replaced. |
| 104 | func ASTValidators(validators ...ASTValidator) EnvOption { |
| 105 | return func(e *Env) (*Env, error) { |
| 106 | for _, v := range validators { |
| 107 | found := false |
| 108 | for i, existing := range e.validators { |
| 109 | if existing.Name() == v.Name() { |
| 110 | e.validators[i] = v |
| 111 | found = true |
| 112 | break |
| 113 | } |
| 114 | } |
| 115 | if !found { |
| 116 | e.validators = append(e.validators, v) |
| 117 | } |
| 118 | } |
| 119 | return e, nil |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // ASTValidator defines a singleton interface for validating a type-checked Ast against an environment. |
| 124 | // |