parse method

dynamic parse(
  1. dynamic text
)

Implementation

parse(text) {
  currentIndent = 0;

  allNodes = FBXTree();
  nodeStack = [];
  currentProp = [];
  currentPropName = '';

  var scope = this;

  var split = text.split(RegExp(r'[\r\n]+'));

  split.asMap().forEach((i, line) {
    var matchComment = RegExp(r"^[\s\t]*;").hasMatch(line);
    var matchEmpty = RegExp(r"^[\s\t]*$").hasMatch(line);

    if (matchComment || matchEmpty) return;

    var matchBeginning = line.match('^\\t{${scope.currentIndent}}(\\w+):(.*){', '');
    var matchProperty = line.match('^\\t{${scope.currentIndent}}(\\w+):[\\s\\t\\r\\n](.*)');
    var matchEnd = line.match('^\\t{${scope.currentIndent - 1}}}');

    if (matchBeginning) {
      scope.parseNodeBegin(line, matchBeginning);
    } else if (matchProperty) {
      scope.parseNodeProperty(line, matchProperty, split[++i]);
    } else if (matchEnd) {
      scope.popStack();
    } else if (RegExp(r"^[^\s\t}]").hasMatch(line)) {
      // large arrays are split over multiple lines terminated with a ',' character
      // if this is encountered the line needs to be joined to the previous line
      scope.parseNodePropertyContinued(line);
    }
  });

  return allNodes;
}