dist/yaml.legacy.js
function(value /* String */)
	{
		this.currentLineNb = -1;
		this.currentLine = '';
		this.lines = this.cleanup(value).split("\n");
		
		var data = null;
      var context = null;
      		
		while ( this.moveToNextLine() )
		{
			if ( this.isCurrentLineEmpty() )
			{
				continue;
			}
			
			// tab?
			if ( this.currentLine.charAt(0) == '\t' )
			{
				throw new YamlParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine);
			}
			
			var isRef = false;
			var isInPlace = false;
			var isProcessed = false;
			var values = null;
			var matches = null;
			var c = null;
			var parser = null;
			var block = null;
			var key = null;
			var parsed = null;
			var len = null;
			var reverse = null;
			
			if ( values = /^\-((\s+)(.+?))?\s*$/.exec(this.currentLine) )
			{

				if (context && 'mapping' == context) {
					throw new YamlParseException('You cannot define a sequence item when in a mapping', this.getRealCurrentLineNb() + 1, this.currentLine);
				}
				context = 'sequence';

				if ( !this.isDefined(data) ) data = [];
				//if ( !(data instanceof Array) ) throw new YamlParseException("Non array entry", this.getRealCurrentLineNb() + 1, this.currentLine);
				
				values = {leadspaces: values[2], value: values[3]};
				
				if ( this.isDefined(values.value) && ( matches = /^&([^ ]+) *(.*)/.exec(values.value) ) )
				{
					matches = {ref: matches[1], value: matches[2]};
					isRef = matches.ref;
					values.value = matches.value;
				}
				
				// array
				if ( !this.isDefined(values.value) || '' == this.trim(values.value) || values.value.replace(/^ +/,'').charAt(0) == '#' )
				{
					c = this.getRealCurrentLineNb() + 1;
					parser = new YamlParser(c);
					parser.refs = this.refs;
					data.push(parser.parse(this.getNextEmbedBlock()));
					this.refs = parser.refs;
				}
				else
				{
					if ( this.isDefined(values.leadspaces) && 
						' ' == values.leadspaces && 
						( matches = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"\{\[].*?) *\:(\\s+(.+?))?\\s*$').exec(values.value) ) 
					) {
						matches = {key: matches[1], value: matches[3]};
						// this is a compact notation element, add to next block and parse
						c = this.getRealCurrentLineNb();
						parser = new YamlParser(c);
						parser.refs = this.refs;
						block = values.value;
						
						if ( !this.isNextLineIndented() )
						{
							block += "\n"+this.getNextEmbedBlock(this.getCurrentLineIndentation() + 2);
						}

						data.push(parser.parse(block));
						this.refs = parser.refs;
					}
					else
					{
						data.push(this.parseValue(values.value));
					}
				}
			}
			else if ( values = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"\[\{].*?) *\:(\\s+(.+?))?\\s*$').exec(this.currentLine) )
			{
				if ( !this.isDefined(data) ) data = {};
				if (context && 'sequence' == context) {
					throw new YamlParseException('You cannot define a mapping item when in a sequence', this.getRealCurrentLineNb() + 1, this.currentLine);
				}
				context = 'mapping';				
				//if ( data instanceof Array ) throw new YamlParseException("Non mapped entry", this.getRealCurrentLineNb() + 1, this.currentLine);
				
				values = {key: values[1], value: values[3]};
				
				try {
					key = new YamlInline().parseScalar(values.key);
				} catch (e) {
					if ( e instanceof YamlParseException ) {
						e.setParsedLine(this.getRealCurrentLineNb() + 1);
						e.setSnippet(this.currentLine);
					}
					throw e;
				}				
				
				
				if ( '<<' == key )
				{
					if ( this.isDefined(values.value) && '*' == (values.value+'').charAt(0) )
					{
						isInPlace = values.value.substr(1);
						if ( this.refs[isInPlace] == undefined )
						{
							throw new YamlParseException('Reference "'+value+'" does not exist', this.getRealCurrentLineNb() + 1, this.currentLine);
						}
					}
					else
					{
						if ( this.isDefined(values.value) && values.value != '' )
						{
							value = values.value;
						}
						else
						{
							value = this.getNextEmbedBlock();
						}
						
						c = this.getRealCurrentLineNb() + 1;
						parser = new YamlParser(c);
						parser.refs = this.refs;
						parsed = parser.parse(value);
						this.refs = parser.refs;
				
						var merged = [];
						if ( !this.isObject(parsed) )
						{
							throw new YamlParseException("YAML merge keys used with a scalar value instead of an array", this.getRealCurrentLineNb() + 1, this.currentLine);
						}
						else if ( this.isDefined(parsed[0]) )
						{
							// Numeric array, merge individual elements
							reverse = this.reverseArray(parsed);
							len = reverse.length;
							for ( var i = 0; i < len; i++ )
							{
								var parsedItem = reverse[i];
								if ( !this.isObject(reverse[i]) )
								{
									throw new YamlParseException("Merge items must be arrays", this.getRealCurrentLineNb() + 1, this.currentLine);
								}
								merged = this.mergeObject(reverse[i], merged);
							}
						}
						else
						{
							// Associative array, merge
							merged = this.mergeObject(merged, parsed);
						}
				
						isProcessed = merged;
					}
				}
				else if ( this.isDefined(values.value) && (matches = /^&([^ ]+) *(.*)/.exec(values.value) ) )
				{
					matches = {ref: matches[1], value: matches[2]};
					isRef = matches.ref;
					values.value = matches.value;
				}
				
				if ( isProcessed )
				{
					// Merge keys
					data = isProcessed;
				}
				// hash
				else if ( !this.isDefined(values.value) || '' == this.trim(values.value) || this.trim(values.value).charAt(0) == '#' )
				{
					// if next line is less indented or equal, then it means that the current value is null
					if ( this.isNextLineIndented() && !this.isNextLineUnIndentedCollection() )
					{
						data[key] = null;
					}
					else
					{
						c = this.getRealCurrentLineNb() + 1;
						parser = new YamlParser(c);
						parser.refs = this.refs;
						data[key] = parser.parse(this.getNextEmbedBlock());
						this.refs = parser.refs;
					}
				}
				else
				{
					if ( isInPlace )
					{
						data = this.refs[isInPlace];
					}
					else
					{
						data[key] = this.parseValue(values.value);
					}
				}
			}
			else
			{
				// 1-liner followed by newline
				if ( 2 == this.lines.length && this.isEmpty(this.lines[1]) )
				{
					try {
						value = new YamlInline().parse(this.lines[0]);
					} catch (e) {
						if ( e instanceof YamlParseException ) {
							e.setParsedLine(this.getRealCurrentLineNb() + 1);
							e.setSnippet(this.currentLine);
						}
						throw e;
					}
					
					if ( this.isObject(value) )
					{
						var first = value[0];
						if ( typeof(value) == 'string' && '*' == first.charAt(0) )
						{
							data = [];
							len = value.length;
							for ( var i = 0; i < len; i++ )
							{
								data.push(this.refs[value[i].substr(1)]);
							}
							value = data;
						}
					}
				
					return value;
				}
				
				throw new YamlParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine);
			}
		
			if ( isRef )
			{
				if ( data instanceof Array )
					this.refs[isRef] = data[data.length-1];
				else
				{
					var lastKey = null;
					for ( var k in data )
					{
						if ( data.hasOwnProperty(k) ) lastKey = k;
					}
					this.refs[isRef] = data[k];
				}
			}
		}
		
		return this.isEmpty(data) ? null : data;
	}
function(value /* String */)
	{
		this.currentLineNb = -1;
		this.currentLine = '';
		this.lines = this.cleanup(value).split("\n");
		
		var data = null;
      var context = null;
      		
		while ( this.moveToNextLine() )
		{
			if ( this.isCurrentLineEmpty() )
			{
				continue;
			}
			
			// tab?
			if ( this.currentLine.charAt(0) == '\t' )
			{
				throw new YamlParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine);
			}
			
			var isRef = false;
			var isInPlace = false;
			var isProcessed = false;
			var values = null;
			var matches = null;
			var c = null;
			var parser = null;
			var block = null;
			var key = null;
			var parsed = null;
			var len = null;
			var reverse = null;
			
			if ( values = /^\-((\s+)(.+?))?\s*$/.exec(this.currentLine) )
			{

				if (context && 'mapping' == context) {
					throw new YamlParseException('You cannot define a sequence item when in a mapping', this.getRealCurrentLineNb() + 1, this.currentLine);
				}
				context = 'sequence';

				if ( !this.isDefined(data) ) data = [];
				//if ( !(data instanceof Array) ) throw new YamlParseException("Non array entry", this.getRealCurrentLineNb() + 1, this.currentLine);
				
				values = {leadspaces: values[2], value: values[3]};
				
				if ( this.isDefined(values.value) && ( matches = /^&([^ ]+) *(.*)/.exec(values.value) ) )
				{
					matches = {ref: matches[1], value: matches[2]};
					isRef = matches.ref;
					values.value = matches.value;
				}
				
				// array
				if ( !this.isDefined(values.value) || '' == this.trim(values.value) || values.value.replace(/^ +/,'').charAt(0) == '#' )
				{
					c = this.getRealCurrentLineNb() + 1;
					parser = new YamlParser(c);
					parser.refs = this.refs;
					data.push(parser.parse(this.getNextEmbedBlock()));
					this.refs = parser.refs;
				}
				else
				{
					if ( this.isDefined(values.leadspaces) && 
						' ' == values.leadspaces && 
						( matches = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"\{\[].*?) *\:(\\s+(.+?))?\\s*$').exec(values.value) ) 
					) {
						matches = {key: matches[1], value: matches[3]};
						// this is a compact notation element, add to next block and parse
						c = this.getRealCurrentLineNb();
						parser = new YamlParser(c);
						parser.refs = this.refs;
						block = values.value;
						
						if ( !this.isNextLineIndented() )
						{
							block += "\n"+this.getNextEmbedBlock(this.getCurrentLineIndentation() + 2);
						}

						data.push(parser.parse(block));
						this.refs = parser.refs;
					}
					else
					{
						data.push(this.parseValue(values.value));
					}
				}
			}
			else if ( values = new RegExp('^('+YamlInline.REGEX_QUOTED_STRING+'|[^ \'"\[\{].*?) *\:(\\s+(.+?))?\\s*$').exec(this.currentLine) )
			{
				if ( !this.isDefined(data) ) data = {};
				if (context && 'sequence' == context) {
					throw new YamlParseException('You cannot define a mapping item when in a sequence', this.getRealCurrentLineNb() + 1, this.currentLine);
				}
				context = 'mapping';				
				//if ( data instanceof Array ) throw new YamlParseException("Non mapped entry", this.getRealCurrentLineNb() + 1, this.currentLine);
				
				values = {key: values[1], value: values[3]};
				
				try {
					key = new YamlInline().parseScalar(values.key);
				} catch (e) {
					if ( e instanceof YamlParseException ) {
						e.setParsedLine(this.getRealCurrentLineNb() + 1);
						e.setSnippet(this.currentLine);
					}
					throw e;
				}				
				
				
				if ( '<<' == key )
				{
					if ( this.isDefined(values.value) && '*' == (values.value+'').charAt(0) )
					{
						isInPlace = values.value.substr(1);
						if ( this.refs[isInPlace] == undefined )
						{
							throw new YamlParseException('Reference "'+value+'" does not exist', this.getRealCurrentLineNb() + 1, this.currentLine);
						}
					}
					else
					{
						if ( this.isDefined(values.value) && values.value != '' )
						{
							value = values.value;
						}
						else
						{
							value = this.getNextEmbedBlock();
						}
						
						c = this.getRealCurrentLineNb() + 1;
						parser = new YamlParser(c);
						parser.refs = this.refs;
						parsed = parser.parse(value);
						this.refs = parser.refs;
				
						var merged = [];
						if ( !this.isObject(parsed) )
						{
							throw new YamlParseException("YAML merge keys used with a scalar value instead of an array", this.getRealCurrentLineNb() + 1, this.currentLine);
						}
						else if ( this.isDefined(parsed[0]) )
						{
							// Numeric array, merge individual elements
							reverse = this.reverseArray(parsed);
							len = reverse.length;
							for ( var i = 0; i < len; i++ )
							{
								var parsedItem = reverse[i];
								if ( !this.isObject(reverse[i]) )
								{
									throw new YamlParseException("Merge items must be arrays", this.getRealCurrentLineNb() + 1, this.currentLine);
								}
								merged = this.mergeObject(reverse[i], merged);
							}
						}
						else
						{
							// Associative array, merge
							merged = this.mergeObject(merged, parsed);
						}
				
						isProcessed = merged;
					}
				}
				else if ( this.isDefined(values.value) && (matches = /^&([^ ]+) *(.*)/.exec(values.value) ) )
				{
					matches = {ref: matches[1], value: matches[2]};
					isRef = matches.ref;
					values.value = matches.value;
				}
				
				if ( isProcessed )
				{
					// Merge keys
					data = isProcessed;
				}
				// hash
				else if ( !this.isDefined(values.value) || '' == this.trim(values.value) || this.trim(values.value).charAt(0) == '#' )
				{
					// if next line is less indented or equal, then it means that the current value is null
					if ( this.isNextLineIndented() && !this.isNextLineUnIndentedCollection() )
					{
						data[key] = null;
					}
					else
					{
						c = this.getRealCurrentLineNb() + 1;
						parser = new YamlParser(c);
						parser.refs = this.refs;
						data[key] = parser.parse(this.getNextEmbedBlock());
						this.refs = parser.refs;
					}
				}
				else
				{
					if ( isInPlace )
					{
						data = this.refs[isInPlace];
					}
					else
					{
						data[key] = this.parseValue(values.value);
					}
				}
			}
			else
			{
				// 1-liner followed by newline
				if ( 2 == this.lines.length && this.isEmpty(this.lines[1]) )
				{
					try {
						value = new YamlInline().parse(this.lines[0]);
					} catch (e) {
						if ( e instanceof YamlParseException ) {
							e.setParsedLine(this.getRealCurrentLineNb() + 1);
							e.setSnippet(this.currentLine);
						}
						throw e;
					}
					
					if ( this.isObject(value) )
					{
						var first = value[0];
						if ( typeof(value) == 'string' && '*' == first.charAt(0) )
						{
							data = [];
							len = value.length;
							for ( var i = 0; i < len; i++ )
							{
								data.push(this.refs[value[i].substr(1)]);
							}
							value = data;
						}
					}
				
					return value;
				}
				
				throw new YamlParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine);
			}
		
			if ( isRef )
			{
				if ( data instanceof Array )
					this.refs[isRef] = data[data.length-1];
				else
				{
					var lastKey = null;
					for ( var k in data )
					{
						if ( data.hasOwnProperty(k) ) lastKey = k;
					}
					this.refs[isRef] = data[k];
				}
			}
		}
		
		return this.isEmpty(data) ? null : data;
	}
function ( value /* String */ ) { this . currentLineNb = - 1 ; this . currentLine = '' ; this . lines = this . cleanup ( value ) . split ( "\n" ) ; var data = null ; var context = null ; while ( this . moveToNextLine ( ) ) { if ( this . isCurrentLineEmpty ( ) ) { continue ; } // tab? if ( this . currentLine . charAt ( 0 ) == '\t' ) { throw new YamlParseException ( 'A YAML file cannot contain tabs as indentation.' , this . getRealCurrentLineNb ( ) + 1 , this . currentLine ) ; } var isRef = false ; var isInPlace = false ; var isProcessed = false ; var values = null ; var matches = null ; var c = null ; var parser = null ; var block = null ; var key = null ; var parsed = null ; var len = null ; var reverse = null ; if ( values = / ^\-((\s+)(.+?))?\s*$ / . exec ( this . currentLine ) ) { if ( context && 'mapping' == context ) { throw new YamlParseException ( 'You cannot define a sequence item when in a mapping' , this . getRealCurrentLineNb ( ) + 1 , this . currentLine ) ; } context = 'sequence' ; if ( ! this . isDefined ( data ) ) data = [ ] ; //if ( !(data instanceof Array) ) throw new YamlParseException("Non array entry", this.getRealCurrentLineNb() + 1, this.currentLine); values = { leadspaces : values [ 2 ] , value : values [ 3 ] } ; if ( this . isDefined ( values . value ) && ( matches = / ^&([^ ]+) *(.*) / . exec ( values . value ) ) ) { matches = { ref : matches [ 1 ] , value : matches [ 2 ] } ; isRef = matches . ref ; values . value = matches . value ; } // array if ( ! this . isDefined ( values . value ) || '' == this . trim ( values . value ) || values . value . replace ( / ^ + / , '' ) . charAt ( 0 ) == '#' ) { c = this . getRealCurrentLineNb ( ) + 1 ; parser = new YamlParser ( c ) ; parser . refs = this . refs ; data . push ( parser . parse ( this . getNextEmbedBlock ( ) ) ) ; this . refs = parser . refs ; } else { if ( this . isDefined ( values . leadspaces ) && ' ' == values . leadspaces && ( matches = new RegExp ( '^(' + YamlInline . REGEX_QUOTED_STRING + '|[^ \'"\{\[].*?) *\:(\\s+(.+?))?\\s*$' ) . exec ( values . value ) ) ) { matches = { key : matches [ 1 ] , value : matches [ 3 ] } ; // this is a compact notation element, add to next block and parse c = this . getRealCurrentLineNb ( ) ; parser = new YamlParser ( c ) ; parser . refs = this . refs ; block = values . value ; if ( ! this . isNextLineIndented ( ) ) { block += "\n" + this . getNextEmbedBlock ( this . getCurrentLineIndentation ( ) + 2 ) ; } data . push ( parser . parse ( block ) ) ; this . refs = parser . refs ; } else { data . push ( this . parseValue ( values . value ) ) ; } } } else if ( values = new RegExp ( '^(' + YamlInline . REGEX_QUOTED_STRING + '|[^ \'"\[\{].*?) *\:(\\s+(.+?))?\\s*$' ) . exec ( this . currentLine ) ) { if ( ! this . isDefined ( data ) ) data = { } ; if ( context && 'sequence' == context ) { throw new YamlParseException ( 'You cannot define a mapping item when in a sequence' , this . getRealCurrentLineNb ( ) + 1 , this . currentLine ) ; } context = 'mapping' ; //if ( data instanceof Array ) throw new YamlParseException("Non mapped entry", this.getRealCurrentLineNb() + 1, this.currentLine); values = { key : values [ 1 ] , value : values [ 3 ] } ; try { key = new YamlInline ( ) . parseScalar ( values . key ) ; } catch ( e ) { if ( e instanceof YamlParseException ) { e . setParsedLine ( this . getRealCurrentLineNb ( ) + 1 ) ; e . setSnippet ( this . currentLine ) ; } throw e ; } if ( '<<' == key ) { if ( this . isDefined ( values . value ) && '*' == ( values . value + '' ) . charAt ( 0 ) ) { isInPlace = values . value . substr ( 1 ) ; if ( this . refs [ isInPlace ] == undefined ) { throw new YamlParseException ( 'Reference "' + value + '" does not exist' , this . getRealCurrentLineNb ( ) + 1 , this . currentLine ) ; } } else { if ( this . isDefined ( values . value ) && values . value != '' ) { value = values . value ; } else { value = this . getNextEmbedBlock ( ) ; } c = this . getRealCurrentLineNb ( ) + 1 ; parser = new YamlParser ( c ) ; parser . refs = this . refs ; parsed = parser . parse ( value ) ; this . refs = parser . refs ; var merged = [ ] ; if ( ! this . isObject ( parsed ) ) { throw new YamlParseException ( "YAML merge keys used with a scalar value instead of an array" , this . getRealCurrentLineNb ( ) + 1 , this . currentLine ) ; } else if ( this . isDefined ( parsed [ 0 ] ) ) { // Numeric array, merge individual elements reverse = this . reverseArray ( parsed ) ; len = reverse . length ; for ( var i = 0 ; i < len ; i ++ ) { var parsedItem = reverse [ i ] ; if ( ! this . isObject ( reverse [ i ] ) ) { throw new YamlParseException ( "Merge items must be arrays" , this . getRealCurrentLineNb ( ) + 1 , this . currentLine ) ; } merged = this . mergeObject ( reverse [ i ] , merged ) ; } } else { // Associative array, merge merged = this . mergeObject ( merged , parsed ) ; } isProcessed = merged ; } } else if ( this . isDefined ( values . value ) && ( matches = / ^&([^ ]+) *(.*) / . exec ( values . value ) ) ) { matches = { ref : matches [ 1 ] , value : matches [ 2 ] } ; isRef = matches . ref ; values . value = matches . value ; } if ( isProcessed ) { // Merge keys data = isProcessed ; } // hash else if ( ! this . isDefined ( values . value ) || '' == this . trim ( values . value ) || this . trim ( values . value ) . charAt ( 0 ) == '#' ) { // if next line is less indented or equal, then it means that the current value is null if ( this . isNextLineIndented ( ) && ! this . isNextLineUnIndentedCollection ( ) ) { data [ key ] = null ; } else { c = this . getRealCurrentLineNb ( ) + 1 ; parser = new YamlParser ( c ) ; parser . refs = this . refs ; data [ key ] = parser . parse ( this . getNextEmbedBlock ( ) ) ; this . refs = parser . refs ; } } else { if ( isInPlace ) { data = this . refs [ isInPlace ] ; } else { data [ key ] = this . parseValue ( values . value ) ; } } } else { // 1-liner followed by newline if ( 2 == this . lines . length && this . isEmpty ( this . lines [ 1 ] ) ) { try { value = new YamlInline ( ) . parse ( this . lines [ 0 ] ) ; } catch ( e ) { if ( e instanceof YamlParseException ) { e . setParsedLine ( this . getRealCurrentLineNb ( ) + 1 ) ; e . setSnippet ( this . currentLine ) ; } throw e ; } if ( this . isObject ( value ) ) { var first = value [ 0 ] ; if ( typeof ( value ) == 'string' && '*' == first . charAt ( 0 ) ) { data = [ ] ; len = value . length ; for ( var i = 0 ; i < len ; i ++ ) { data . push ( this . refs [ value [ i ] . substr ( 1 ) ] ) ; } value = data ; } } return value ; } throw new YamlParseException ( 'Unable to parse.' , this . getRealCurrentLineNb ( ) + 1 , this . currentLine ) ; } if ( isRef ) { if ( data instanceof Array ) this . refs [ isRef ] = data [ data . length - 1 ] ; else { var lastKey = null ; for ( var k in data ) { if ( data . hasOwnProperty ( k ) ) lastKey = k ; } this . refs [ isRef ] = data [ k ] ; } } } return this . isEmpty ( data ) ? null : data ; }
Parses a YAML string to a JS value.

@param String value A YAML string

@return mixed A JS value
Parses a YAML string to a JS value .