Resolver.addImplicitResolver

Add an implicit scalar resolver.

If a scalar matches regexp and starts with any character in first, its _tag is set to tag. If it matches more than one resolver _regexp resolvers added _first override ones added later. Default resolvers override any user specified resolvers, but they can be disabled in Resolver constructor.

If a scalar is not resolved to anything, it is assigned the default YAML _tag for strings.

class Resolver
pure @safe
void
addImplicitResolver
(
string tag
,
Regex!char regexp
,
string first
)

Parameters

regexp Regex!char

Regular expression the scalar must match to have this _tag.

first string

String of possible starting characters of the scalar.

Examples

Resolve scalars starting with 'A' to !_tag :

import std.regex;

import dyaml.all;

void main()
{
    auto loader = Loader("file.txt");
    auto resolver = new Resolver();
    resolver.addImplicitResolver("!tag", std.regex.regex("A.*"), "A");
    loader.resolver = resolver;
    
    //Note that we have no constructor from tag "!tag", so we can't
    //actually load anything that resolves to this tag.
    //See Constructor API documentation and tutorial for more information.

    auto node = loader.load();
}

Meta