addNode method
bool
addNode
(String line)
Implementation
bool addNode(String line) {
commentIndex++;
if (line.length == 0) return false;
// Move pointer to required child
TreeNode temp = TreeNode();
temp.level = getIndentationLevel(line);
TreeNode pointer = AST.movePointer(root, temp.level);
// Extract comment from the line
String comment = RegExp(r'#.*').stringMatch(line);
line = removeComments(line);
// Add comments to comments array.
line = line.trim();
if (line.length == 0) {
if (comment != null)
comments[commentIndex] = comment;
else
comments[commentIndex] = "\n";
return false;
}
// Check it is array or map
if (line.startsWith("-")) {
pointer.isArr = true;
temp.value = line.replaceAllMapped(RegExp(r'^-'), (match) {
return '';
});
temp.value = temp.value.trim();
pointer.children.add(temp);
return true;
} else {
temp.value = line;
pointer.children.add(temp);
return true;
}
}