diff --git a/doc/doctrees/environment.pickle b/doc/doctrees/environment.pickle index 4b69e2b..b8faa2b 100644 Binary files a/doc/doctrees/environment.pickle and b/doc/doctrees/environment.pickle differ diff --git a/doc/html/api/dyaml.resolver.html b/doc/html/api/dyaml.resolver.html index 4dc9533..60351b6 100644 --- a/doc/html/api/dyaml.resolver.html +++ b/doc/html/api/dyaml.resolver.html @@ -69,10 +69,11 @@

Add an implicit scalar resolver.

-

If a scalar matches regexp and starts with one of the characters in first, - its tag is set to tag. If the scalar matches more than one resolver - regular expression, resolvers added first override those added later. - Default resolvers override any user specified resolvers. +

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 @@ -86,6 +87,26 @@ string first String of possible starting characters of the scalar. +Examples:

Resolve scalars starting with 'A' to !tag : +
 import std.regex;
+
+ import yaml;
+
+ 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();
+ }
+
+
package const @property Tag defaultScalarTag(); diff --git a/dyaml/resolver.d b/dyaml/resolver.d index 67832cb..722da89 100644 --- a/dyaml/resolver.d +++ b/dyaml/resolver.d @@ -76,10 +76,11 @@ final class Resolver /** * Add an implicit scalar resolver. * - * If a scalar matches regexp and starts with one of the characters in first, - * its _tag is set to tag. If the scalar matches more than one resolver - * regular expression, resolvers added _first override those added later. - * Default resolvers override any user specified resolvers. + * 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. @@ -87,6 +88,29 @@ final class Resolver * Params: tag = Tag to resolve to. * regexp = Regular expression the scalar must match to have this _tag. * first = String of possible starting characters of the scalar. + * + * Examples: + * + * Resolve scalars starting with 'A' to !tag : + * -------------------- + * import std.regex; + * + * import yaml; + * + * 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(); + * } + * -------------------- */ void addImplicitResolver(string tag, Regex!char regexp, in string first) {