treeToMap method
Generates a map from the AST.
Implementation
static dynamic treeToMap(dynamic result, TreeNode root) {
if (root.children.length > 0) {
if (root.isArr) {
List<String> arr = root.value.split(':');
result.value[arr[0]] = SequenceNode();
result.value[arr[0]].level = root.level;
root.children.forEach((f) {
result.value[arr[0]].value.add(f);
});
return result;
} else {
List<String> arr = root.value.split(':');
result.value[arr[0]] = MappingNode();
result.value[arr[0]].level = root.level;
root.children.forEach((f) {
result.value[arr[0]] = treeToMap(result.value[arr[0]], f);
});
return result;
}
} else {
List<String> arr = root.value.split(':');
result.value[arr[0]] = ScalarNode();
result.level = root.level;
result.value[arr[0]].value = arr[1];
return result;
}
}