Skip to content

Commit

Permalink
runtime: Tweak include key directive grammer in yaml merge processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
aszs committed Sep 30, 2024
1 parent ad5a774 commit 55b4999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions docs/processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ When a YAML configuration is loaded, will look for dictionary keys that match th

and treat them as merge directives that update the dictionary by processing the directive and merging in its resolved value.

Merge directives can have the following components:
Merge keys can have the following components:

.. productionlist::
merge key : merge_directive | merge_anchor | merge_strategy
merge_directive : "+"["?"]["include"][alias][relative_path][absolute_path]
merge_directive : "+"["?"][include][alias][relative_path][absolute_path]
include : "include"[ALPHNUM]*
alias : "*"[PCHAR]*[PCHAR except "."]
relative_path : "."+
absolute_path : ["/" PCHAR*]+
ALPHNUM : a-z, A-Z, 0-9, _, -
PCHAR : any printable character except "/"
merge_anchor : "+&"
merge_strategy : "+%"
Expand All @@ -30,7 +32,7 @@ Each of these components are optional but at least one needs to be present, othe

A leading '?' indicates that reference maybe missing, otherwise the processing will abort with an error.

``include`` indicates that value of the merge key includes a yaml or json file to load.
``include`` indicates that value of the merge key includes a yaml or json file to load. Can have optional trailing alphanumeric characters to ensure key is unique.

``*alias``: a reference to merge anchor that appears in either the current document or, a file was specified, from that file.

Expand Down
7 changes: 4 additions & 3 deletions unfurl/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,17 @@ def __repr__(self):
return self.key.key


RE_FIRST = re.compile(r"([?]?)(include\d*)?([*]\S+)?([.]+$)?")
RE_FIRST = re.compile(r"([?]?)(include[\w-]*)?([*]\S+)?([.]+$)?")

MergeKey = namedtuple("MergeKey", "key, maybe, include, anchor, relative, pointer")


def parse_merge_key(key: str) -> Optional[MergeKey]:
"""
r"""
+[maybe]?[include]?[anchor]?[relative]?[jsonpointer]?
[include] = "include"[number?]
[maybe] = "?"
[include] = "include"[\w-]*
[anchor] = "*"[anchorname]
relative = '.'+
"""
Expand Down

0 comments on commit 55b4999

Please sign in to comment.