-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support partial expression evaluation #184
Comments
I just thought of an idea and have thrown together some code to illustrate it: main...denfren:hcl-rs:eval-via-extended-context Example foo "bar" {
value = 42
}
attribute = foo.bar.value When a traversal is evaluated ( |
In general I like the idea of making resolved attributes and blocks available in the context so that references to these can be resolved automatically. However, there are some issues that need to be addressed:
I'm currently playing around with partial evaluation support in the in-place-eval branch. It essentially tries to recursively evaluate as many expressions as possible and will collect errors it encounters along the way. Objects are evaluated in place. Maybe I can enhance this further to also automatically add variables to the context while they are discovered. |
Another option could be to give users a way to provide a callback to the expression evaluation process so that they can decide how to handle this (e.g. add fully evaluated attributes/blocks to the context or not, and if, how the newly exposed variable should be named). |
Closes #184. Key difference to the existing `Evaluate::evaluate` method: - It mutably borrows the value and tries to evaluate all nested expressions in-place. - It returns all errors that it encounters, not just the first one. This allows for partial expression evaluation, e.g. to support use cases where a HCL document contains variable references to other parts within the same document that themselves contain expressions that are not evaluated yet. In this case one would: 1. Partially evaluate the document via `evaluate_in_place`. 2. Update the `Context` with newly discovered variables. 3. Repeat 1. and 2. until there are no more errors left.
In #159 the idea came up to also support evaluating expressions partially, returning information about missing variables instead of failing.
The text was updated successfully, but these errors were encountered: