-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add support for Reclass reference interpolation #19
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ba4fd5c
to
844b12c
Compare
257203a
to
44131b9
Compare
844b12c
to
2b781ab
Compare
44131b9
to
b721fc0
Compare
2b781ab
to
9fc5634
Compare
6a15bf8
to
cf4a759
Compare
8b23c25
to
29b7e08
Compare
0c8b5ce
to
2b7cd26
Compare
fd3a3b0
to
9f4f423
Compare
2b7cd26
to
fc05daf
Compare
9f4f423
to
23ed4a9
Compare
fc05daf
to
dd45fd2
Compare
23ed4a9
to
6cf1747
Compare
6cf1747
to
3a7e144
Compare
bastjan
approved these changes
Sep 12, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Took a while to understand the interpolate and resolve part.
This method generates strings which are suitable for looking up values in the Reclass parameters during reference interpolation. The implementation tries to match Python's `str()` formatting where necessary (e.g. boolean keys and values).
We leave the tests associated with `enum Token` in a separate source file which we rename to `refs/token_tests.rs`. Additionally, we move the tests for the `parse_ref()` function to a separate source file.
This commit introduces methods `Mapping::interpolate()` and `Value::interpolate()`, which use `Token::parse()` to parse Reclass references, and then call `Token::render()` to interpolate the references. The commit also renames method `Node::flatten_parameters()` to `Node::render_parameters()` and extends the method to also interpolate all references.
Add Rust and Python test cases for the new node
3a7e144
to
7e20e88
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces methods
Mapping::interpolate()
andValue::interpolate()
, which useToken::parse()
to parse Reclass references, and then callToken::render()
to interpolate the references.Additionally, the PR introduces methods
Value::rendered()
,Value::render()
andValue::render_with_self()
which users should use when wanting to interpolate Reclass references and flatten ValueLists in aValue
.The PR also renames method
Node::flatten_parameters()
toNode::render_parameters()
and extends the method to also interpolate all references by callingValue::render_with_self()
on the node's parameters.Internally, the PR introduces a method
Value::raw_string()
(see 3c7e449) which produces a stringified version of the Value which is suitable for looking up Reclass reference values and can be used to emit complex values (Mappings and Sequences) for references which are embedded in strings (e.g. using a reference in a multi-line string which is used as a YAML or JSON config file). Complex values are serialized as JSON by the function, while simple values are serialized in a format that matches Python'sstr()
.Additionally, we restructure the
refs
module to better match the structure of the implementation, see a42b0a0, and introduce a new methodToken::parse()
(cf. 236c238) to parse an arbitrary string which may contain Reclass references into aToken
.Checklist
bug
,enhancement
,documentation
,change
,breaking
,dependency
,internal
as they show up in the changelog