parse method

dynamic parse(
  1. dynamic text
)

Implementation

parse( text ) {

	this.currentIndent = 0;

	this.allNodes = new FBXTree();
	this.nodeStack = [];
	this.currentProp = [];
	this.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.toString() + '}(\\w+):(.*){', '' );
		var matchProperty = line.match( '^\\t{' + ( scope.currentIndent.toString() ) + '}(\\w+):[\\s\\t\\r\\n](.*)' );
		var matchEnd = line.match( '^\\t{' + ( scope.currentIndent - 1 ).toString() + '}}' );

		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 this.allNodes;

}