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
void
addImplicitResolver
pure @safe
(
string tag
,
Regex!char regexp
,
string first
)

Parameters

regexp
Type: Regex!char

Regular expression the scalar must match to have this _tag.

first
Type: string

String of possible starting characters of the scalar.

Examples

Resolve scalars starting with 'A' to !_tag

1 import std.file : write;
2 import std.regex : regex;
3 import dyaml.loader : Loader;
4 import dyaml.resolver : Resolver;
5 
6 write("example.yaml", "A");
7 
8 auto loader = Loader.fromFile("example.yaml");
9 auto resolver = new Resolver();
10 resolver.addImplicitResolver("!tag", regex("A.*"), "A");
11 loader.resolver = resolver;
12 
13 //Note that we have no constructor from tag "!tag", so we can't
14 //actually load anything that resolves to this tag.
15 //See Constructor API documentation and tutorial for more information.
16 
17 //auto node = loader.load();

Meta