using System;
using System.Collections;

namespace Jovian.Compiler
{
	public class RewriteRule
	{
		public string Name;
		public string Encoder;

		public static RewriteRule [] ParseRewriteRuleSet(string X)
		{
			ArrayList L = new ArrayList();

			string Y = X;
			int k = Y.IndexOf("]}");
			while(k >= 0)
			{
				string Z = Y.Substring(0,k);
				int kSTART = Z.IndexOf("{[");
				RewriteRule r = new RewriteRule();
				r.Name = Z.Substring(0,kSTART).Trim().ToLower();
				r.Encoder = Z.Substring(kSTART + 2).Trim();
				L.Add(r);
				Y = Y.Substring(k + 2);
				k = Y.IndexOf("]}");
			}



			RewriteRule [] RR = new RewriteRule[L.Count];
			for(k = 0; k < L.Count; k++)
				RR[k] = (L[k] as RewriteRule);
			return RR;
		}
	}
}
