<!DOCTYPE html>
<html>
	<head>
		<title>VarStream</title>
	</head>
	<body>
		<h1>Some VarStreams</h1>
		<p>Open your web console to view what's done on this page.</p>
		<script type="text/javascript" src="VarStreamReader.js"></script>
		<script type="text/javascript" src="VarStreamWriter.js"></script>
		<script type="text/javascript">
			var myScope={};
			var myStreamReader=new VarStreamReader(myScope,true);
			myStreamReader.read('');
			myStreamReader.read('#comment');
			myStreamReader.read('# Database'+"\n"
			+'database.type=mysql'+"\n"
			+'database.hosts.+.domain=mysql1.example.com'+"\n"
			+'database.hosts.*.master=true'+"\n"
			+'database.hosts.+.domain=mysql2.example.com'+"\n"
			+'database.hosts.*.master=false'+"\n"
			+'database.hosts.0.master=true'+"\n"
			+'database.user=root'+"\n"
			+'database.base=myapp'+"\n"
			+'database.base=myapp2'+"\n"
			+'".base=myapp'+"\n"
			+'# REST servers'+"\n"
			+'rest.servers.+.domain=api.example.com'+"\n"
			+'rest.servers.*.auth=basic'+"\n"
			+'rest.servers.*.user&=database.user');
			myStreamReader.read('".password=pass');
			console.log('root=='+myScope.database.user+'=='+myScope.rest.servers[0].user+'!='+myScope.unexistingvar);

			myStreamReader.read('# Date'+"\n"
			+'l_timezone=Europe/Paris'+"\n"
			+'l_date_format=l d F Y'+"\n"
			+'l_day_format=d F'+"\n"
			+'l_time_format=l d F Y à H:i:s'+"\n"
			+'l_hour_format=H:i:s'+"\n"
			+'l_days.monday=Lundi'+"\n"
			+'l_days.tuesday=Mardi'+"\n"
			+'l_days.wednesday=Mercredi'+"\n"
			+'l_days.thursday=Jeudi'+"\n"
			+'l_days.friday=Vendredi'+"\n"
			+'l_days.saturday=Samedi'+"\n"
			+'l_days.sunday=Dimanche'+"\n"
			+'l_months.january=Janvier'+"\n"
			+'l_months.february=Février'+"\n"
			+'l_months.march=Mars'+"\n"
			+'l_months.april=Avril'+"\n"
			+'l_months.may=Mai'+"\n"
			+'l_months.june=Juin'+"\n"
			+'l_months.july=Juillet'+"\n"
			+'l_months.august=Août'+"\n"
			+'l_months.september=Septembre'+"\n"
			+'l_months.october=Octobre'+"\n"
			+'l_months.november=Novembre'+"\n"
			+'l_months.december=Decembre'+"\n"
			+'# Numbers'+"\n"
			+'l_number_dec_point=,'+"\n"
			+'l_number_thousands_sep= # Phone numbers'+"\n"
			+'l_phone_local_indicator=33'+"\n"
			+'l_phone_local_format=0'+"\n"
			+'l_phone_indicator_format=+XXXX (0)'+"\n"
			+'l_phone_number_format=X XX XX XX XX'+"\n"
			+'# GPS Locations'+"\n"
			+'l_gps_latitude=N'+"\n"
			+'l_gps_longitude=O'+"\n"
			+'# Multiline '+"\n"
			+'l_multiline=i curently have a \\'+"\n"
			+'multiline value. \\'+"\n"
			+'It\'s great !'+"\n"
			+'l_multiline2=i curently have a \\'+"\n"
			+'multiline value. \\'+"\n"
			+'It\'s really great !\\');
			myStreamReader.read('But i\'m chunked !\\');
			myStreamReader.read('Will it run ?\\');
			myStreamReader.read('Yes, it is !');
			
			console.log('root=='+myScope.database.user+'=='+myScope.rest.servers[0].user+'!='+myScope.unexistingvar);
			console.log('l_multiline='+myScope.l_multiline);
			console.log('l_multiline2='+myScope.l_multiline2);


			var myScope2={};
			var myStreamReader=new VarStreamReader(myScope2,true);
			myStreamReader.read(''); // Reading empty chunk
			myStreamReader.read('# Comment'); // This is a comment
			myStreamReader.read('# Database'+"\n"
			 +'database.type=mysql'+"\n"
			 +'database.sync=false'+"\n"
			 +'database.hosts.+.domain=mysql1.example.com'+"\n"
			 +'database.hosts.*.master=true'+"\n"
			 +'database.hosts.+.domain=mysql2.example.com'+"\n"
			 +'".master=false'+"\n"
			 +'database.hosts.+&=database.hosts.0'+"\n"
			 +'database.hosts.+.domain&=database.hosts.1.domain'+"\n"
			 ); // A more complicated chunk
			console.log(myScope2);
			console.log(myScope2.database.hosts[0].domain); // printsmysql1.example.com
			console.log(myScope2.database.hosts[1].domain); // printsmysql2.example.com
			console.log(myScope2.database.hosts[2].domain); // printsmysql1.example.com
			console.log(myScope2.database.hosts[3].domain); // printsmysql2.example.com
			
			var myStreamWriter=new VarStreamWriter(function(content) { console.log(content) },true,false);
			myStreamWriter.write(myScope2);
		</script>
	</body>
</html>