The simplest way to do this would be to create a custom tag with a
corresponding custom Construct subclass (see the Dice example). Your
custom Construct instance would then create another Yaml instance to
load the other file and return the root node of that file as the
value. This approach will accomplish the idea of "include the contents
of this file as this value", but it won't let you use anchors from one
file in another.
A more sophisticated approach would require substantial modification,
but could potentially let anchors work between files. This approach
would be much harder and potentially more error-prone. If you choose
to follow this approach, look at Composer. Your main challenge is
going to be dealing with the "anchors" Map and making sure that its
state accurately reflects where you are at construction-time (usually,
all anchors are cleared at the end of composeDocument(), which is
called via Yaml.loadFromReader() -> BaseConstructor.getSingleData() ->
Composer.getSingleNode() ), before any construction at all happens.
Before starting on the second option, answer the following questions
carefully (where "parent" is the document with the !include node, and
"child" is the document specified for inclusion):
1) If an anchor appears in the parent document, is it accessible by
the child document?
2) If an anchor appears in the child document, is it accessible by the
parent document (after the !include node)?
If your answer to 1) is "yes", then you need to prevent anchors from
being cleared by the end of a document.
If your answer to 2) is "yes", then you will need to dig very, very
deeply. You will need to make the modification at the Parser or
Scanner level, rather than the Compose or Construct levels.
I seriously recommend taking the simplest possible route on this one.
/Jordan
On May 5, 6:27 am, Me <
rubbish...@googlemail.com> wrote:
> Hi,
>
> Wondering if there is a way to do the above in SnakeYAML? Potentially
> similar to what being discussed in the thread below:
>
>
http://stackoverflow.com/questions/2278241/how-to-include-a-yaml-file...