2011-08-16 12:53:13 +00:00
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
< html lang = 'en' >
< head >
< meta http-equiv = "content-type" content = "text/html; charset=utf-8" >
2012-01-23 17:40:05 +00:00
< title > dyaml.resolver - D:YAML 0.4 API documentation< / title >
2011-08-16 12:53:13 +00:00
< link rel = "stylesheet" type = "text/css" href = "css/style.css" >
< / head >
< body > < div id = "top" >
< div id = "header" >
2012-01-23 17:40:05 +00:00
< img id = "logo" alt = "D:YAML logo" src = "images/logo.png" > < a id = "main-heading" href = "index.html" > D:YAML 0.4 API documentation< / a >
2011-08-16 12:53:13 +00:00
< / div >
< / div >
< div id = "navigation" >
< div class = "navblock" >
< div id = "toctop" >
< ul > < li > < a href = "../index.html" > Documentation home< / a > < / li >
< / ul >
< / div >
< / div >
< div class = "navblock" >
< ul > < li > < a href = "index.html" > Main page< / a > < / li >
< li > < a href = "dyaml.constructor.html" > dyaml.constructor< / a > < / li >
2011-10-14 08:34:53 +00:00
< li > < a href = "dyaml.dumper.html" > dyaml.dumper< / a > < / li >
< li > < a href = "dyaml.encoding.html" > dyaml.encoding< / a > < / li >
2011-08-16 12:53:13 +00:00
< li > < a href = "dyaml.exception.html" > dyaml.exception< / a > < / li >
2014-05-19 17:54:48 +00:00
< li > < a href = "dyaml.hacks.html" > dyaml.hacks< / a > < / li >
2011-10-14 08:34:53 +00:00
< li > < a href = "dyaml.linebreak.html" > dyaml.linebreak< / a > < / li >
2011-08-16 12:53:13 +00:00
< li > < a href = "dyaml.loader.html" > dyaml.loader< / a > < / li >
< li > < a href = "dyaml.node.html" > dyaml.node< / a > < / li >
2011-10-14 08:34:53 +00:00
< li > < a href = "dyaml.representer.html" > dyaml.representer< / a > < / li >
2011-08-16 12:53:13 +00:00
< li > < a href = "dyaml.resolver.html" > dyaml.resolver< / a > < / li >
2011-10-29 18:43:30 +00:00
< li > < a href = "dyaml.style.html" > dyaml.style< / a > < / li >
2011-08-16 12:53:13 +00:00
< / ul >
< / div >
< / div >
< div id = "content" >
< h1 > dyaml.resolver< / h1 >
<!-- Generated by Ddoc from dyaml/resolver.d -->
< p > Implements a class that resolves YAML tags. This can be used to implicitly
resolve tags for custom data types, removing the need to explicitly
specify tags in YAML. A tutorial can be found
< a href = "../tutorials/custom_types.html" > here< / a > .
< / p >
< p > Code based on < a href = "http://www.pyyaml.org" > PyYAML< / a > .< / p >
2013-12-17 14:19:01 +00:00
< dl > < dt class = "d_decl" > < a name = "Resolver" > < / a > class < a name = "Resolver" > < / a > < span class = "ddoc_psymbol" > Resolver< / span > ;
2011-08-16 12:53:13 +00:00
< / dt >
< dd > < p > Resolves YAML tags (data types).
< / p >
< p > Can be used to implicitly resolve custom data types of scalar values.< / p >
2013-12-17 14:19:01 +00:00
< dl > < dt class = "d_decl" > < a name = "Resolver.this" > < / a > @safe this(Flag!"useDefaultImplicitResolvers" < b > defaultImplicitResolvers< / b > = Yes.useDefaultImplicitResolvers);
2011-08-16 12:53:13 +00:00
< / dt >
< dd > < p > Construct a Resolver.
< / p >
< p > If you don't want to implicitly resolve default YAML tags/data types,
you can use < b > defaultImplicitResolvers< / b > to disable default resolvers.
< / p >
2013-12-17 14:19:01 +00:00
< b > Parameters:< / b > < div class = "pbr" > < table class = parms > < tr > < td valign = top > Flag!"useDefaultImplicitResolvers" < b > defaultImplicitResolvers< / b > < / td >
2011-08-16 12:53:13 +00:00
< td valign = top > Use default YAML implicit resolvers?< / td > < / tr >
< / table > < / div >
< / dd >
2013-12-17 14:19:01 +00:00
< dt class = "d_decl" > < a name = "Resolver.addImplicitResolver" > < / a > pure @safe void < a name = "addImplicitResolver" > < / a > < span class = "ddoc_psymbol" > addImplicitResolver< / span > (string < b > tag< / b > , Regex!char < b > regexp< / b > , string < b > first< / b > );
2011-08-16 12:53:13 +00:00
< / dt >
< dd > < p > Add an implicit scalar resolver.
< / p >
2011-10-18 14:29:16 +00:00
< p > If a scalar matches < b > regexp< / b > and starts with any character in < b > first< / b > ,
its tag is set to < b > tag< / b > . 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.
2011-08-16 12:53:13 +00:00
< br >
If a scalar is not resolved to anything, it is assigned the default
YAML tag for strings.
< / p >
< b > Parameters:< / b > < div class = "pbr" > < table class = parms > < tr > < td valign = top > string < b > tag< / b > < / td >
< td valign = top > Tag to resolve to.< / td > < / tr >
2013-12-17 14:19:01 +00:00
< tr > < td valign = top > Regex!char < b > regexp< / b > < / td >
2011-08-16 12:53:13 +00:00
< td valign = top > Regular expression the scalar must match to have this tag.< / td > < / tr >
< tr > < td valign = top > string < b > first< / b > < / td >
< td valign = top > String of possible starting characters of the scalar.< / td > < / tr >
< / table > < / div >
2011-10-18 19:40:37 +00:00
< b > Examples:< / b > < div class = "pbr" > Resolve scalars starting with 'A' to !tag :
2013-12-17 14:19:01 +00:00
< pre class = "d_code" > < span class = "d_keyword" > import< / span > std.regex;
2011-10-18 14:29:16 +00:00
2013-12-17 14:19:01 +00:00
< span class = "d_keyword" > import< / span > dyaml.all;
2011-10-18 14:29:16 +00:00
2013-12-17 14:19:01 +00:00
< span class = "d_keyword" > void< / span > main()
{
< span class = "d_keyword" > auto< / span > loader = Loader(< span class = "d_string" > "file.txt"< / span > );
< span class = "d_keyword" > auto< / span > resolver = < span class = "d_keyword" > new< / span > Resolver();
resolver.< span class = "d_psymbol" > addImplicitResolver< / span > (< span class = "d_string" > "!tag"< / span > , std.regex.regex(< span class = "d_string" > "A.*"< / span > ), < span class = "d_string" > "A"< / span > );
loader.resolver = resolver;
2011-10-18 14:29:16 +00:00
2013-12-17 14:19:01 +00:00
< span class = "d_comment" > //Note that we have no constructor from tag "!tag", so we can't
< / span > < span class = "d_comment" > //actually load anything that resolves to this tag.
< / span > < span class = "d_comment" > //See Constructor API documentation and tutorial for more information.
2011-10-18 14:29:16 +00:00
< / span >
2013-12-17 14:19:01 +00:00
< span class = "d_keyword" > auto< / span > node = loader.load();
}
2011-10-18 14:29:16 +00:00
< / pre >
< / div >
2011-08-16 12:53:13 +00:00
2011-10-14 08:34:53 +00:00
< / dd >
2013-12-17 14:19:01 +00:00
< dt class = "d_decl" > < a name = "Resolver.defaultScalarTag" > < / a > package const pure nothrow @property @safe Tag < a name = "defaultScalarTag" > < / a > < span class = "ddoc_psymbol" > defaultScalarTag< / span > ();
2011-10-14 08:34:53 +00:00
< / dt >
< dd > < p > Return default scalar tag.< / p >
< / dd >
2013-12-17 14:19:01 +00:00
< dt class = "d_decl" > < a name = "Resolver.defaultSequenceTag" > < / a > package const pure nothrow @property @safe Tag < a name = "defaultSequenceTag" > < / a > < span class = "ddoc_psymbol" > defaultSequenceTag< / span > ();
2011-10-14 08:34:53 +00:00
< / dt >
< dd > < p > Return default sequence tag.< / p >
< / dd >
2013-12-17 14:19:01 +00:00
< dt class = "d_decl" > < a name = "Resolver.defaultMappingTag" > < / a > package const pure nothrow @property @safe Tag < a name = "defaultMappingTag" > < / a > < span class = "ddoc_psymbol" > defaultMappingTag< / span > ();
2011-10-14 08:34:53 +00:00
< / dt >
< dd > < p > Return default mapping tag.< / p >
2011-08-16 12:53:13 +00:00
< / dd >
< / dl >
< / dd >
< / dl >
< / div >
< div id = "copyright" >
Copyright © Ferdinand Majerech 2011. Based on < a href = "http://www.pyyaml.org" > PyYAML< / a > by Kirill Simonov. |
2012-01-23 14:57:26 +00:00
Page generated by AutoDDoc and < a href = "http://www.digitalmars.com/d/2.0/ddoc.html" > Ddoc< / a > .
2011-08-16 12:53:13 +00:00
< / div >
< / body >
< / html >