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:
Cameron Ross 2019-01-27 22:26:00 -03:30 committed by Basile-z
parent bbfe2bbb69
commit b63ea1aaae
9 changed files with 505 additions and 453 deletions

View file

@ -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);
}
}