291 lines
26 KiB
HTML
291 lines
26 KiB
HTML
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>Custom YAML data types — D:YAML v0.1 documentation</title>
|
|
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../',
|
|
VERSION: '0.1',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|
<link rel="top" title="D:YAML v0.1 documentation" href="../index.html" />
|
|
<link rel="next" title="YAML syntax" href="yaml_syntax.html" />
|
|
<link rel="prev" title="Getting started" href="getting_started.html" />
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="yaml_syntax.html" title="YAML syntax"
|
|
accesskey="N">next</a></li>
|
|
<li class="right" >
|
|
<a href="getting_started.html" title="Getting started"
|
|
accesskey="P">previous</a> |</li>
|
|
<li><a href="../index.html">D:YAML v0.1 documentation</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<div class="section" id="custom-yaml-data-types">
|
|
<h1>Custom YAML data types<a class="headerlink" href="#custom-yaml-data-types" title="Permalink to this headline">¶</a></h1>
|
|
<p>Often you might want to serialize complex data types such as classes. You can
|
|
use functions to process nodes such as a mapping containing class data members
|
|
indexed by name. Alternatively, YAML supports custom data types using
|
|
identifiers called <em>tags</em>. That is the topic of this tutorial.</p>
|
|
<p>Each YAML node has a tag specifying its type. For instance: strings use the tag
|
|
<tt class="docutils literal"><span class="pre">tag:yaml.org,2002:str</span></tt>. Tags of most default types are <em>implicitly resolved</em>
|
|
during parsing, so you don’t need to specify tag for each float, integer, etc.
|
|
It is also possible to implicitly resolve custom tags, as we will show later.</p>
|
|
<div class="section" id="constructor">
|
|
<h2>Constructor<a class="headerlink" href="#constructor" title="Permalink to this headline">¶</a></h2>
|
|
<p>D:YAML uses the <em>Constructor</em> class to process each node to hold data type
|
|
corresponding to its tag. <em>Constructor</em> stores a function for each supported
|
|
tag to process it. These functions are supplied by the user using the
|
|
<em>addConstructor()</em> method. <em>Constructor</em> is then passed to <em>Loader</em>, which
|
|
parses YAML input.</p>
|
|
<p>We will implement support for an RGB color type. It is implemented as the
|
|
following struct:</p>
|
|
<div class="highlight-d"><div class="highlight"><pre><span class="k">struct</span> <span class="n">Color</span>
|
|
<span class="p">{</span>
|
|
<span class="kt">ubyte</span> <span class="n">red</span><span class="p">;</span>
|
|
<span class="kt">ubyte</span> <span class="n">green</span><span class="p">;</span>
|
|
<span class="kt">ubyte</span> <span class="n">blue</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>First, we need a function to construct our data type. It must take two <em>Mark</em>
|
|
structs, which store position of the node in the file, and either a <em>string</em>, an
|
|
array of <em>Node</em> or of <em>Node.Pair</em>, depending on whether we’re constructing our
|
|
value from a scalar, sequence, or mapping, respectively. In this tutorial, we
|
|
have functions to construct a color from a scalar, using HTML-like format,
|
|
RRGGBB, or from a mapping, where we use the following format:
|
|
{r:RRR, g:GGG, b:BBB} . Code of these functions:</p>
|
|
<div class="highlight-d"><div class="highlight"><pre><span class="n">Color</span> <span class="n">constructColorScalar</span><span class="p">(</span><span class="n">Mark</span> <span class="n">start</span><span class="p">,</span> <span class="n">Mark</span> <span class="n">end</span><span class="p">,</span> <span class="nb">string</span> <span class="n">value</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="n">value</span><span class="p">.</span><span class="n">length</span> <span class="p">!=</span> <span class="mi">6</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="k">throw</span> <span class="k">new</span> <span class="n">ConstructorException</span><span class="p">(</span><span class="s">"Invalid color: "</span> <span class="p">~</span> <span class="n">value</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
<span class="c1">//We don't need to check for uppercase chars this way.</span>
|
|
<span class="n">value</span> <span class="p">=</span> <span class="n">value</span><span class="p">.</span><span class="n">toLower</span><span class="p">();</span>
|
|
|
|
<span class="c1">//Get value of a hex digit.</span>
|
|
<span class="kt">uint</span> <span class="n">hex</span><span class="p">(</span><span class="kt">char</span> <span class="n">c</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="k">if</span><span class="p">(!</span><span class="n">std</span><span class="p">.</span><span class="n">ascii</span><span class="p">.</span><span class="n">isHexDigit</span><span class="p">(</span><span class="n">c</span><span class="p">))</span>
|
|
<span class="p">{</span>
|
|
<span class="k">throw</span> <span class="k">new</span> <span class="n">ConstructorException</span><span class="p">(</span><span class="s">"Invalid color: "</span> <span class="p">~</span> <span class="n">value</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="n">std</span><span class="p">.</span><span class="n">ascii</span><span class="p">.</span><span class="n">isDigit</span><span class="p">(</span><span class="n">c</span><span class="p">))</span>
|
|
<span class="p">{</span>
|
|
<span class="k">return</span> <span class="n">c</span> <span class="p">-</span> <span class="sc">'0'</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="k">return</span> <span class="n">c</span> <span class="p">-</span> <span class="sc">'a'</span> <span class="p">+</span> <span class="mi">10</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="n">Color</span> <span class="n">result</span><span class="p">;</span>
|
|
<span class="n">result</span><span class="p">.</span><span class="n">red</span> <span class="p">=</span> <span class="k">cast</span><span class="p">(</span><span class="kt">ubyte</span><span class="p">)(</span><span class="mi">16</span> <span class="p">*</span> <span class="n">hex</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="p">+</span> <span class="n">hex</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">1</span><span class="p">]));</span>
|
|
<span class="n">result</span><span class="p">.</span><span class="n">green</span> <span class="p">=</span> <span class="k">cast</span><span class="p">(</span><span class="kt">ubyte</span><span class="p">)(</span><span class="mi">16</span> <span class="p">*</span> <span class="n">hex</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="p">+</span> <span class="n">hex</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">3</span><span class="p">]));</span>
|
|
<span class="n">result</span><span class="p">.</span><span class="n">blue</span> <span class="p">=</span> <span class="k">cast</span><span class="p">(</span><span class="kt">ubyte</span><span class="p">)(</span><span class="mi">16</span> <span class="p">*</span> <span class="n">hex</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span> <span class="p">+</span> <span class="n">hex</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="mi">5</span><span class="p">]));</span>
|
|
|
|
<span class="k">return</span> <span class="n">result</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="n">Color</span> <span class="n">constructColorMapping</span><span class="p">(</span><span class="n">Mark</span> <span class="n">start</span><span class="p">,</span> <span class="n">Mark</span> <span class="n">end</span><span class="p">,</span> <span class="n">Node</span><span class="p">.</span><span class="n">Pair</span><span class="p">[]</span> <span class="n">pairs</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="kt">int</span> <span class="n">r</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
|
|
<span class="n">r</span> <span class="p">=</span> <span class="n">g</span> <span class="p">=</span> <span class="n">b</span> <span class="p">=</span> <span class="p">-</span><span class="mi">1</span><span class="p">;</span>
|
|
<span class="kt">bool</span> <span class="n">error</span> <span class="p">=</span> <span class="n">pairs</span><span class="p">.</span><span class="n">length</span> <span class="p">!=</span> <span class="mi">3</span><span class="p">;</span>
|
|
|
|
<span class="k">foreach</span><span class="p">(</span><span class="k">ref</span> <span class="n">pair</span><span class="p">;</span> <span class="n">pairs</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="c1">//Key might not be a string, and value might not be an int,</span>
|
|
<span class="c1">//so we need to check for that</span>
|
|
<span class="k">try</span>
|
|
<span class="p">{</span>
|
|
<span class="k">switch</span><span class="p">(</span><span class="n">pair</span><span class="p">.</span><span class="n">key</span><span class="p">.</span><span class="n">get</span><span class="p">!</span><span class="nb">string</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="k">case</span> <span class="s">"r"</span><span class="p">:</span> <span class="n">r</span> <span class="p">=</span> <span class="n">pair</span><span class="p">.</span><span class="n">value</span><span class="p">.</span><span class="n">get</span><span class="p">!</span><span class="kt">int</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
|
|
<span class="k">case</span> <span class="s">"g"</span><span class="p">:</span> <span class="n">g</span> <span class="p">=</span> <span class="n">pair</span><span class="p">.</span><span class="n">value</span><span class="p">.</span><span class="n">get</span><span class="p">!</span><span class="kt">int</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
|
|
<span class="k">case</span> <span class="s">"b"</span><span class="p">:</span> <span class="n">b</span> <span class="p">=</span> <span class="n">pair</span><span class="p">.</span><span class="n">value</span><span class="p">.</span><span class="n">get</span><span class="p">!</span><span class="kt">int</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
|
|
<span class="k">default</span><span class="p">:</span> <span class="n">error</span> <span class="p">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
<span class="k">catch</span><span class="p">(</span><span class="n">NodeException</span> <span class="n">e</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="n">error</span> <span class="p">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="n">error</span> <span class="p">||</span> <span class="n">r</span> <span class="p"><</span> <span class="mi">0</span> <span class="p">||</span> <span class="n">r</span> <span class="p">></span> <span class="mi">255</span> <span class="p">||</span> <span class="n">g</span> <span class="p"><</span> <span class="mi">0</span> <span class="p">||</span> <span class="n">g</span> <span class="p">></span> <span class="mi">255</span> <span class="p">||</span> <span class="n">b</span> <span class="p"><</span> <span class="mi">0</span> <span class="p">||</span> <span class="n">b</span> <span class="p">></span> <span class="mi">255</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="k">throw</span> <span class="k">new</span> <span class="n">ConstructorException</span><span class="p">(</span><span class="s">"Invalid color"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="k">return</span> <span class="n">Color</span><span class="p">(</span><span class="k">cast</span><span class="p">(</span><span class="kt">ubyte</span><span class="p">)</span><span class="n">r</span><span class="p">,</span> <span class="k">cast</span><span class="p">(</span><span class="kt">ubyte</span><span class="p">)</span><span class="n">g</span><span class="p">,</span> <span class="k">cast</span><span class="p">(</span><span class="kt">ubyte</span><span class="p">)</span><span class="n">b</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Next, we need some YAML data using our new tag. Create a file called input.yaml
|
|
with the following contents:</p>
|
|
<div class="highlight-yaml"><div class="highlight"><pre><span class="l-Scalar-Plain">scalar-red</span><span class="p-Indicator">:</span> <span class="kt">!color</span> <span class="l-Scalar-Plain">FF0000</span>
|
|
<span class="l-Scalar-Plain">scalar-orange</span><span class="p-Indicator">:</span> <span class="kt">!color</span> <span class="l-Scalar-Plain">FFFF00</span>
|
|
<span class="l-Scalar-Plain">mapping-red</span><span class="p-Indicator">:</span> <span class="kt">!color-mapping</span> <span class="p-Indicator">{</span><span class="nv">r</span><span class="p-Indicator">:</span> <span class="nv">255</span><span class="p-Indicator">,</span> <span class="nv">g</span><span class="p-Indicator">:</span> <span class="nv">0</span><span class="p-Indicator">,</span> <span class="nv">b</span><span class="p-Indicator">:</span> <span class="nv">0</span><span class="p-Indicator">}</span>
|
|
<span class="l-Scalar-Plain">mapping-orange</span><span class="p-Indicator">:</span>
|
|
<span class="kt">!color-mapping</span>
|
|
<span class="l-Scalar-Plain">r</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">255</span>
|
|
<span class="l-Scalar-Plain">g</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">255</span>
|
|
<span class="l-Scalar-Plain">b</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">0</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>You can see that we’re using tag <tt class="docutils literal"><span class="pre">!color</span></tt> for scalar colors, and
|
|
<tt class="docutils literal"><span class="pre">!color-mapping</span></tt> for colors expressed as mappings.</p>
|
|
<p>Finally, the code to put it all together:</p>
|
|
<div class="highlight-d"><div class="highlight"><pre><span class="kt">void</span> <span class="n">main</span><span class="p">()</span>
|
|
<span class="p">{</span>
|
|
<span class="k">auto</span> <span class="n">red</span> <span class="p">=</span> <span class="n">Color</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
|
|
<span class="k">auto</span> <span class="n">orange</span> <span class="p">=</span> <span class="n">Color</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
|
|
|
|
<span class="k">try</span>
|
|
<span class="p">{</span>
|
|
<span class="k">auto</span> <span class="n">constructor</span> <span class="p">=</span> <span class="k">new</span> <span class="n">Constructor</span><span class="p">;</span>
|
|
<span class="c1">//both functions handle the same tag, but one handles scalar, one mapping.</span>
|
|
<span class="n">constructor</span><span class="p">.</span><span class="n">addConstructor</span><span class="p">(</span><span class="s">"!color"</span><span class="p">,</span> <span class="p">&</span><span class="n">constructColorScalar</span><span class="p">);</span>
|
|
<span class="n">constructor</span><span class="p">.</span><span class="n">addConstructor</span><span class="p">(</span><span class="s">"!color-mapping"</span><span class="p">,</span> <span class="p">&</span><span class="n">constructColorMapping</span><span class="p">);</span>
|
|
|
|
<span class="k">auto</span> <span class="n">loader</span> <span class="p">=</span> <span class="n">Loader</span><span class="p">(</span><span class="s">"input.yaml"</span><span class="p">);</span>
|
|
<span class="n">loader</span><span class="p">.</span><span class="n">constructor</span> <span class="p">=</span> <span class="n">constructor</span><span class="p">;</span>
|
|
|
|
<span class="k">auto</span> <span class="n">root</span> <span class="p">=</span> <span class="n">loader</span><span class="p">.</span><span class="n">load</span><span class="p">();</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="n">root</span><span class="p">[</span><span class="s">"scalar-red"</span><span class="p">].</span><span class="n">get</span><span class="p">!</span><span class="n">Color</span> <span class="p">==</span> <span class="n">red</span> <span class="p">&&</span>
|
|
<span class="n">root</span><span class="p">[</span><span class="s">"mapping-red"</span><span class="p">].</span><span class="n">get</span><span class="p">!</span><span class="n">Color</span> <span class="p">==</span> <span class="n">red</span> <span class="p">&&</span>
|
|
<span class="n">root</span><span class="p">[</span><span class="s">"scalar-orange"</span><span class="p">].</span><span class="n">get</span><span class="p">!</span><span class="n">Color</span> <span class="p">==</span> <span class="n">orange</span> <span class="p">&&</span>
|
|
<span class="n">root</span><span class="p">[</span><span class="s">"mapping-orange"</span><span class="p">].</span><span class="n">get</span><span class="p">!</span><span class="n">Color</span> <span class="p">==</span> <span class="n">orange</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="n">writeln</span><span class="p">(</span><span class="s">"SUCCESS"</span><span class="p">);</span>
|
|
<span class="k">return</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
<span class="k">catch</span><span class="p">(</span><span class="n">YAMLException</span> <span class="n">e</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="n">writeln</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">msg</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="n">writeln</span><span class="p">(</span><span class="s">"FAILURE"</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>First, we create a <em>Constructor</em> and pass functions to handle the <tt class="docutils literal"><span class="pre">!color</span></tt>
|
|
and <tt class="docutils literal"><span class="pre">!color-mapping</span></tt> tag. We construct a <em>Loader*m and pass the *Constructor</em>
|
|
to it. We then load the YAML document, and finally, read the colors using
|
|
<em>get()</em> method to test if they were loaded as expected.</p>
|
|
<p>You can find the source code for what we’ve done so far in the
|
|
<tt class="docutils literal"><span class="pre">examples/constructor</span></tt> directory in the D:YAML package.</p>
|
|
</div>
|
|
<div class="section" id="resolver">
|
|
<h2>Resolver<a class="headerlink" href="#resolver" title="Permalink to this headline">¶</a></h2>
|
|
<p>Specifying tag for every color value can be tedious. D:YAML can implicitly
|
|
resolve scalar tags using regular expressions. This is how default types such as
|
|
int are resolved. We will use the <em>Resolver</em> class to add implicit tag
|
|
resolution for the Color data type (in its scalar form).</p>
|
|
<p>We use the <em>addImplicitResolver</em> method of <em>Resolver</em>, passing the tag, regular
|
|
expression the value must match to resolve to this tag, and a string of possible
|
|
starting characters of the value. Then we pass the <em>Resolver</em> to <em>Loader</em>.</p>
|
|
<p>Note that resolvers added first override ones added later. If no resolver
|
|
matches a scalar, YAML string tag is used. Therefore our custom values must not
|
|
be resolvable as any non-string YAML data type.</p>
|
|
<p>Add this to your code to add implicit resolution of <tt class="docutils literal"><span class="pre">!color</span></tt>.</p>
|
|
<div class="highlight-d"><div class="highlight"><pre><span class="c1">//code from the previous example...</span>
|
|
|
|
<span class="k">auto</span> <span class="n">resolver</span> <span class="p">=</span> <span class="k">new</span> <span class="n">Resolver</span><span class="p">;</span>
|
|
<span class="n">resolver</span><span class="p">.</span><span class="n">addImplicitResolver</span><span class="p">(</span><span class="s">"!color"</span><span class="p">,</span> <span class="n">std</span><span class="p">.</span><span class="n">regex</span><span class="p">.</span><span class="n">regex</span><span class="p">(</span><span class="s">"[0-9a-fA-F]{6}"</span><span class="p">,</span>
|
|
<span class="s">"0123456789abcdefABCDEF"</span><span class="p">));</span>
|
|
|
|
<span class="k">auto</span> <span class="n">loader</span> <span class="p">=</span> <span class="n">Loader</span><span class="p">(</span><span class="s">"input.yaml"</span><span class="p">);</span>
|
|
|
|
<span class="n">loader</span><span class="p">.</span><span class="n">constructor</span> <span class="p">=</span> <span class="n">constructor</span><span class="p">;</span>
|
|
<span class="n">loader</span><span class="p">.</span><span class="n">resolver</span> <span class="p">=</span> <span class="n">resolver</span><span class="p">;</span>
|
|
|
|
<span class="c1">//code from the previous example...</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Now, change contents of input.yaml to this:</p>
|
|
<div class="highlight-yaml"><div class="highlight"><pre><span class="l-Scalar-Plain">scalar-red</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">FF0000</span>
|
|
<span class="l-Scalar-Plain">scalar-orange</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">FFFF00</span>
|
|
<span class="l-Scalar-Plain">mapping-red</span><span class="p-Indicator">:</span> <span class="kt">!color-mapping</span> <span class="p-Indicator">{</span><span class="nv">r</span><span class="p-Indicator">:</span> <span class="nv">255</span><span class="p-Indicator">,</span> <span class="nv">g</span><span class="p-Indicator">:</span> <span class="nv">0</span><span class="p-Indicator">,</span> <span class="nv">b</span><span class="p-Indicator">:</span> <span class="nv">0</span><span class="p-Indicator">}</span>
|
|
<span class="l-Scalar-Plain">mapping-orange</span><span class="p-Indicator">:</span>
|
|
<span class="kt">!color-mapping</span>
|
|
<span class="l-Scalar-Plain">r</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">255</span>
|
|
<span class="l-Scalar-Plain">g</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">255</span>
|
|
<span class="l-Scalar-Plain">b</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">0</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>We no longer need to specify the tag for scalar color values. Compile and test
|
|
the example. If everything went as expected, it should report success.</p>
|
|
<p>You can find the complete code in the <tt class="docutils literal"><span class="pre">examples/resolver</span></tt> directory in the
|
|
D:YAML package.</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<p class="logo"><a href="../index.html">
|
|
<img class="logo" src="../_static/logo210.png" alt="Logo"/>
|
|
</a></p>
|
|
<h3><a href="../index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference internal" href="#">Custom YAML data types</a><ul>
|
|
<li><a class="reference internal" href="#constructor">Constructor</a></li>
|
|
<li><a class="reference internal" href="#resolver">Resolver</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="yaml_syntax.html" title="YAML syntax"
|
|
>next</a></li>
|
|
<li class="right" >
|
|
<a href="getting_started.html" title="Getting started"
|
|
>previous</a> |</li>
|
|
<li><a href="../index.html">D:YAML v0.1 documentation</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2011, Ferdinand Majerech. Based on PyYAML http://www.pyyaml.org by Kirill Simonov.
|
|
Last updated on Oct 14, 2011.
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
|
|
</div>
|
|
</body>
|
|
</html> |