protected override void ApplyMaps(CstToken token)
		{
			SimpleMapCollection c = SimpleMap.CSharpMaps;
			foreach (SimpleMap map in c) 
			{
				if (map.IsRegExp) 
				{
					Regex regex = new Regex(map.Source);
					token.Text = regex.Replace(token.Text, map.Target);
				}
				else 
				{
					token.Text = token.Text.Replace(map.Source, map.Target);
				}
			}
		}
Beispiel #2
0
		private void BuildTokens() 
		{
			cstText = cstText.TrimStart();

			log.AddEntry("Building Token List...");

			Regex ex = new Regex(REGEXP_TOKENIZE, (RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture));
			
			int lastIndex = 0, currentIndex = 0;
			string data, rawtag;
			int commentListIndex = 0, scriptListIndex = 0, aspListIndex = 0;
			CstToken token = null;
			while(lastIndex >= 0) 
			{
				Match match = ex.Match(cstText, lastIndex);

				if (match.Success) 
				{
					log.AddEntry("--> Found token");
					
					currentIndex = match.Index;

					if (currentIndex > lastIndex) 
					{
						token = new CstToken(CstTokenType.Literal, cstText.Substring(lastIndex, currentIndex - lastIndex));
						template.Tokens.Add(token);
					}

					rawtag = match.Value;
					switch (rawtag) 
					{
						case CstParser.TMP_START:
							token = new CstToken(CstTokenType.EscapedStartTag, "<%");
							break;
						case CstParser.TMP_END:
							token = new CstToken(CstTokenType.EscapedEndTag, "%>");
							break;
						case CstParser.TMP_COMMENT:
							data = comments[commentListIndex].ToString();
							token = new CstToken(CstTokenType.Comment, data);
							commentListIndex++;
							break;
						case CstParser.TMP_SCRIPT:
							data = scriptBlocks[scriptListIndex].ToString();
							token = new CstToken(CstTokenType.RunAtServerCode, data);
							scriptListIndex++;
							break;
						case CstParser.TMP_ASP:
							data = aspBlocks[aspListIndex].ToString();
							if (data.StartsWith("=")) 
								token = new CstToken(CstTokenType.ResponseWriteShortcutCode, data.Remove(0, 1));
							else 
								token = new CstToken(CstTokenType.Code, data);
							aspListIndex++;
							break;
					}
					template.Tokens.Add(token);

					lastIndex = currentIndex + rawtag.Length;
				}
				else
				{
					data = cstText.Substring(lastIndex);
					token = new CstToken(CstTokenType.Literal, data);
					template.Tokens.Add(token);

					lastIndex = -1;
				}
			}
		}
		protected abstract void ApplyMaps(CstToken token);