Repository navigation
Add support for composing strings #2202
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,13 +245,18 @@ author to assert some invalid configurations. | |
|
|
||
| .. _format_directives_list_prepend: | ||
|
|
||
| (<) List Prepend | ||
| (<) Prepend | ||
| ~~~~~~~~~~~~~~~~ | ||
| Indicates that the list should be prepended to the target list, | ||
| instead of the default behavior which is to replace the target list. | ||
| Indicates that the value should be prepended to the target value, | ||
| instead of the default behaviour which is to replace the target value. | ||
|
|
||
| When applying to a list, it will insert the new list items before the target list items. | ||
| When applying to a string, it will prefix the new string onto the target string. | ||
|
|
||
| **Example:** | ||
|
|
||
| For lists: | ||
|
|
||
| .. code:: yaml | ||
|
|
||
| config: | ||
|
|
@@ -264,10 +269,24 @@ instead of the default behavior which is to replace the target list. | |
|
|
||
| .. _format_directives_list_append: | ||
|
|
||
| (>) List Append | ||
| For strings: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an example for prepend, so it should be above the |
||
|
|
||
| .. code:: yaml | ||
|
|
||
| string-property: | ||
| (<): "start" | ||
|
|
||
| .. _format_directives_string_append: | ||
|
|
||
| (>) Append | ||
| ~~~~~~~~~~~~~~~ | ||
| Indicates that the list should be appended to the target list, instead | ||
| of the default behavior which is to replace the target list. | ||
| Indicates that the values should be appended to its target, instead | ||
| of the default behavior which is to replace it. | ||
|
|
||
|
|
||
| When applying to a list, it will place the new list items at the end of the list. | ||
| When applying to a string, it will place the string value as a postfix. | ||
|
|
||
|
|
||
| **Example:** | ||
|
|
||
|
|
@@ -285,21 +304,20 @@ of the default behavior which is to replace the target list. | |
|
|
||
| .. _format_directives_list_overwrite: | ||
|
|
||
| (=) List Overwrite | ||
| (=) Overwrite | ||
| ~~~~~~~~~~~~~~~~~~ | ||
| Indicates that the list should be overwritten completely. | ||
| Indicates that the value should be overwritten completely. | ||
|
|
||
| This exists mostly for completeness, and we recommend using literal | ||
| lists most of the time instead of list overwrite directives when the | ||
| intent is to overwrite a list. | ||
| This exists mostly for completeness, and we recommend using literals | ||
| instead of the overwrite directive when the intent is to overwrite. | ||
|
|
||
| This has the same behavior as a literal list, except that an | ||
| This has the same behavior as a literal, except that an | ||
| error will be triggered in the case that there is no underlying | ||
| list to overwrite; whereas a literal list will simply create a new | ||
| list. | ||
| property to overwrite; whereas a literal entry will simply create a new | ||
| property. | ||
|
|
||
| The added error protection can be useful when intentionally | ||
| overwriting a list in an element's *public data*, which is mostly | ||
| overwriting a value in an element's *public data*, which is mostly | ||
| free form and not validated. | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -977,6 +977,9 @@ cdef class MappingNode(Node): | |||||||
| if type(target_value) is SequenceNode: | ||||||||
| # Composite list composes into a list | ||||||||
| self._compose_on_list(target_value) | ||||||||
| elif isinstance((<ScalarNode> target_value).value, str): | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this require a type check before the cast to |
||||||||
| # Composite list composes into a string | ||||||||
| self._compose_on_string(target_value) | ||||||||
| elif target_value._is_composite_list(): | ||||||||
| # Composite list merges into composite list | ||||||||
| self._compose_on_composite_dict(target_value) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
|
|
@@ -1016,6 +1019,26 @@ cdef class MappingNode(Node): | |||||||
| if suffix is not None: | ||||||||
| target.value.extend(suffix.value) | ||||||||
|
|
||||||||
| # _compose_on_string(target) | ||||||||
| # | ||||||||
| # Compose the current node on the given string. | ||||||||
| # | ||||||||
| # Args: | ||||||||
| # target (.SequenceNode): sequence on which to compose the current composite dict | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Not a |
||||||||
| # | ||||||||
| cdef void _compose_on_string(self, ScalarNode target): | ||||||||
| cdef ScalarNode clobber = self.value.get("(=)") | ||||||||
| cdef ScalarNode prefix = self.value.get("(<)") | ||||||||
| cdef ScalarNode suffix = self.value.get("(>)") | ||||||||
|
|
||||||||
| if clobber is not None: | ||||||||
| target.value.clear() | ||||||||
| target.value.extend(clobber.value) | ||||||||
|
Comment on lines
+1035
to
+1036
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look right for strings. I'd expect a simple assignment to work fine, though.
Suggested change
|
||||||||
| if prefix is not None: | ||||||||
| target.value = prefix.value + target.value | ||||||||
| if suffix is not None: | ||||||||
| target.value += suffix.value | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As |
||||||||
|
|
||||||||
| # _compose_on_composite_dict(target) | ||||||||
| # | ||||||||
| # Compose the current node on the given composite dict. | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| description: | ||
| (>): ")potato" | ||
| (<): "incoming potato(" |
Uh oh!
There was an error while loading. Please reload this page.