make node types into enums and clean up code using them (#225)
* make node types into enums and clean up code using them * add some tests for anchorable
This commit is contained in:
parent
bbfe2bbb69
commit
b63ea1aaae
9 changed files with 505 additions and 453 deletions
|
@ -23,32 +23,30 @@ string statistics(ref Node document)
|
|||
tags[root.tag] = 0;
|
||||
}
|
||||
++tags[root.tag];
|
||||
|
||||
if(root.isScalar)
|
||||
final switch (root.nodeID)
|
||||
{
|
||||
++scalars;
|
||||
return;
|
||||
}
|
||||
if(root.isSequence)
|
||||
{
|
||||
++sequences;
|
||||
seqItems += root.length;
|
||||
foreach(ref Node node; root)
|
||||
{
|
||||
crawl(node);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(root.isMapping)
|
||||
{
|
||||
++mappings;
|
||||
mapPairs += root.length;
|
||||
foreach(ref Node key, ref Node value; root)
|
||||
{
|
||||
crawl(key);
|
||||
crawl(value);
|
||||
}
|
||||
return;
|
||||
case NodeID.scalar:
|
||||
++scalars;
|
||||
return;
|
||||
case NodeID.sequence:
|
||||
++sequences;
|
||||
seqItems += root.length;
|
||||
foreach(ref Node node; root)
|
||||
{
|
||||
crawl(node);
|
||||
}
|
||||
return;
|
||||
case NodeID.mapping:
|
||||
++mappings;
|
||||
mapPairs += root.length;
|
||||
foreach(ref Node key, ref Node value; root)
|
||||
{
|
||||
crawl(key);
|
||||
crawl(value);
|
||||
}
|
||||
return;
|
||||
case NodeID.invalid:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue