/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up the comments. /// </summary> /// ------------------------------------------------------------------------------------ public void CleanupComment() { if (!m_fClean) { m_CommentBldr.Replace("&", "&"); m_CommentBldr.Replace("<", "<"); m_CommentBldr.Replace(">", ">"); } m_fClean = true; ConvertSurveyorTag(@"@null\{(?<content>[^}]*)\}", ""); // no output ConvertSurveyorTag(@"/\*:Ignore ([^/*:]|/|\*|:)+/\*:End Ignore\*/", ""); // no output ConvertSurveyorTag(@"//:>([^\n]+)\n", ""); // no output ConvertSurveyorTag(@"@h3\{Hungarian: (?<content>[^}]*)\}", "Hungarian: <c>{0}</c>"); ConvertSurveyorTag(@"@h3\{(?<content>[^}]*)\}", "<h3>{0}</h3>"); ConvertSurveyorTag(@"@b\{(?<content>[^}]*)\}", "<b>{0}</b>"); ConvertSurveyorTag(@"@i\{(?<content>[^}]*)\}", "<i>{0}</i>"); ConvertSurveyorTag(@"@code\{(?<content>[^}]*)\}", "<code>{0}</code>"); ConvertSurveyorTag(@"@return (?<content>[^\n]+\n)", "{0}"); //ConvertSurveyorTag(@"@HTTP\{(?<content>[^}]*)\}", @"<see href=""{0}"">{0}</see>"); // Remove //--- and /*********** lines var line = new Regex(@"(\r\n)?(/\*|//)?(-|\*)+(\r\n|/)?"); if (line.IsMatch(m_CommentBldr.ToString())) { MatchCollection matches = line.Matches(m_CommentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_CommentBldr.Remove(match.Index, match.Length); } } var param = new Regex(@"@param (?<name>(\w|/)+) (?<comment>([^@]|@i|@b)*)"); if (param.IsMatch(m_CommentBldr.ToString())) { MatchCollection matches = param.Matches(m_CommentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_CommentBldr.Remove(match.Index, match.Length); string paramName = IDLConversions.ConvertParamName(match.Groups["name"].Value); if (!Children.ContainsKey(paramName)) { Console.WriteLine("Parameter mentioned in @param doesn't exist: {0}", match.Groups["name"].Value); continue; } StringBuilder bldr = Children[paramName] .m_CommentBldr; bldr.Length = 0; bldr.Append(match.Groups["comment"].Value); Children[paramName].m_fClean = true; } } var exception = new Regex(@"@exception (?<hresult>\w+) (?<comment>([^@]|@i|@b)*)"); if (exception.IsMatch(m_CommentBldr.ToString())) { MatchCollection matches = exception.Matches(m_CommentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_CommentBldr.Remove(match.Index, match.Length); string exceptionType = TranslateHResultToException(match.Groups["hresult"].Value); if (Attributes.ContainsKey("exception")) Attributes["exception"] = Attributes["exception"] + "," + exceptionType; else Attributes.Add("exception", exceptionType); Attributes.Add(exceptionType, string.Format("{0} ({1})", match.Groups["comment"].Value.Replace("//", "").TrimEnd('\n', '\r', ' '), match.Groups["hresult"].Value)); } } var list = new Regex(@"@list\{(?<content>[^}]*)\}"); if (list.IsMatch(m_CommentBldr.ToString())) { MatchCollection matches = list.Matches(m_CommentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_CommentBldr.Remove(match.Index, match.Length); if (i == matches.Count) m_CommentBldr.Insert(match.Index, string.Format(" {0}</list>", Environment.NewLine)); m_CommentBldr.Insert(match.Index, string.Format("<item><description>{0} {1}{0} </description></item>", Environment.NewLine, match.Groups["content"].Value)); if (i == 1) m_CommentBldr.Insert(match.Index, string.Format(@"<list type=""bullet"">{0} ", Environment.NewLine)); } } if (m_CommentBldr.Length > 0) { using (var reader = new StringReader(m_CommentBldr.ToString())) { var bldr = new StringBuilder(); var lexer = new SurveyorLexer(bldr, reader); lexer.setLine(LineNumber); var parser = new SurveyorParser(bldr, lexer); parser.surveyorTags(); m_CommentBldr = bldr; } } // Do this at the end because we might need it above to determine the end of the other tags ConvertSurveyorTag(@"@end", ""); // no output }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up the comments. /// </summary> /// ------------------------------------------------------------------------------------ public void CleanupComment() { if (!m_fClean) { m_commentBldr.Replace("&", "&"); m_commentBldr.Replace("<", "<"); m_commentBldr.Replace(">", ">"); } m_fClean = true; ConvertSurveyorTag(@"@null\{(?<content>[^}]*)\}", ""); // no output ConvertSurveyorTag(@"/\*:Ignore ([^/*:]|/|\*|:)+/\*:End Ignore\*/", ""); // no output ConvertSurveyorTag(@"//:>([^\n]+)\n", ""); // no output ConvertSurveyorTag(@"@h3\{Hungarian: (?<content>[^}]*)\}", "Hungarian: <c>{0}</c>"); ConvertSurveyorTag(@"@h3\{(?<content>[^}]*)\}", "<h3>{0}</h3>"); ConvertSurveyorTag(@"@b\{(?<content>[^}]*)\}", "<b>{0}</b>"); ConvertSurveyorTag(@"@i\{(?<content>[^}]*)\}", "<i>{0}</i>"); ConvertSurveyorTag(@"@code\{(?<content>[^}]*)\}", "<code>{0}</code>"); ConvertSurveyorTag(@"@return (?<content>[^\n]+\n)", "{0}"); //ConvertSurveyorTag(@"@HTTP\{(?<content>[^}]*)\}", @"<see href=""{0}"">{0}</see>"); // Remove //--- and /*********** lines Regex line = new Regex(@"(\r\n)?(/\*|//)?(-|\*)+(\r\n|/)?"); if (line.IsMatch(m_commentBldr.ToString())) { MatchCollection matches = line.Matches(m_commentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_commentBldr.Remove(match.Index, match.Length); } } Regex param = new Regex(@"@param (?<name>(\w|/)+) (?<comment>([^@]|@i|@b)*)"); if (param.IsMatch(m_commentBldr.ToString())) { MatchCollection matches = param.Matches(m_commentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_commentBldr.Remove(match.Index, match.Length); string paramName = IDLConversions.ConvertParamName(match.Groups["name"].Value); if (!Children.ContainsKey(paramName)) { Console.WriteLine("Parameter mentioned in @param doesn't exist: {0}", match.Groups["name"].Value); continue; } StringBuilder bldr = Children[paramName] .m_commentBldr; bldr.Length = 0; bldr.Append(match.Groups["comment"].Value); Children[paramName].m_fClean = true; } } Regex exception = new Regex(@"@exception (?<hresult>\w+) (?<comment>([^@]|@i|@b)*)"); if (exception.IsMatch(m_commentBldr.ToString())) { MatchCollection matches = exception.Matches(m_commentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_commentBldr.Remove(match.Index, match.Length); string exceptionType = TranslateHResultToException(match.Groups["hresult"].Value); if (Attributes.ContainsKey("exception")) { Attributes["exception"] = Attributes["exception"] + "," + exceptionType; } else { Attributes.Add("exception", exceptionType); } Attributes.Add(exceptionType, string.Format("{0} ({1})", match.Groups["comment"].Value.Replace("//", "").TrimEnd('\n', '\r', ' '), match.Groups["hresult"].Value)); } } Regex list = new Regex(@"@list\{(?<content>[^}]*)\}"); if (list.IsMatch(m_commentBldr.ToString())) { MatchCollection matches = list.Matches(m_commentBldr.ToString()); for (int i = matches.Count; i > 0; i--) { Match match = matches[i - 1]; m_commentBldr.Remove(match.Index, match.Length); if (i == matches.Count) { m_commentBldr.Insert(match.Index, string.Format(" {0}</list>", Environment.NewLine)); } m_commentBldr.Insert(match.Index, string.Format("<item><description>{0} {1}{0} </description></item>", Environment.NewLine, match.Groups["content"].Value)); if (i == 1) { m_commentBldr.Insert(match.Index, string.Format(@"<list type=""bullet"">{0} ", Environment.NewLine)); } } } if (m_commentBldr.Length > 0) { using (StringReader reader = new StringReader(m_commentBldr.ToString())) { StringBuilder bldr = new StringBuilder(); SurveyorLexer lexer = new SurveyorLexer(bldr, reader); lexer.setLine(LineNumber); SurveyorParser parser = new SurveyorParser(bldr, lexer); parser.surveyorTags(); m_commentBldr = bldr; } } // Do this at the end because we might need it above to determine the end of the other tags ConvertSurveyorTag(@"@end", ""); // no output }