From 93b66da54c76326e6d31f91d1253afcea4a0d491 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Tue, 18 Oct 2011 16:29:16 +0200 Subject: [PATCH] Added a Resolver example to the API documentation. --- doc/doctrees/environment.pickle | Bin 12705 -> 12705 bytes doc/html/api/dyaml.resolver.html | 29 ++++++++++++++++++++++++---- dyaml/resolver.d | 32 +++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/doc/doctrees/environment.pickle b/doc/doctrees/environment.pickle index 4b69e2b8e148cb6e0d09ecd098fd9a1a690e60fa..b8faa2befb088693fbc7544bd8359d1afb73004b 100644 GIT binary patch delta 62 zcmZ3OyfAq~o4#SP`+-P-3}tu6%gdA9ci1;(=s=izYp-OOLYTV~&t%v^m^-DrH*eQ} G#RvdaM;p}u delta 62 zcmZ3OyfAq~o4#R^rJbrmhO)ck<>g712C1sX>`?Z^LG7L Fi~#zZ88`p{ 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) {