JuliaData/YAML.jl

documentation for reading application specific tags

Opened this issue · 0 comments

I noted that as of 2018, YAML could read tags. But, there is no documentation for constructing a handler.
The one example in Julia discourse is pretty involuted. A constructor seems to want two arguments but I don't understand what these arguments look like. And then the load command should have an argument that is a dict of the tags and the handlers, which ought to be functions. This example sure didn't work for me:

discourse example

I am a pretty simple and literal guy. Interfaces with lots of indirection and hidden attributes don't sing for me. I tried this:

tagmap = Dict("!agegrp"=>agegroup, "!status"=>status_cond_map, "!cond"=>status_cond_map, "!array_enum"=>array_enum)

I wrote a function called agegroup that takes the scalar value as read from a YAML string as its only argument:

function agegroup(x)
    # for tag !agegrp
    agegrp(x)
end

Btw, I have an enum called agegrp also defined. So, this trivially converts the integer to the enum value.

The trivial test string:

tststr = """
       ---
       - !agegrp 1
       """

Then, I run: YAML.load(tststr, tagmap)

The error messages tell me I need a constructor of type YAML.Constructor, which I assume must be a function--but I provided a function in the map of tags to functions. Guess I don't know where I pass it into and what I pass it into. Then I need a YAML.SequenceNode, which must be the raw value parsed out of the YAML string. But, it seems like the YAML code needs to construct these arguments out of inputs I provide and then it calls the handler function I supplied as part of the parsing process.

It's pretty non-obvious how to bind all this stuff together. All I need is a working super minimal example. The test cases don't provide that yet.