/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the parser. /// </summary> /// <param name="input">The input.</param> /// <returns>A SurveyorParser</returns> /// ------------------------------------------------------------------------------------ private SurveyorParser CreateParser(string input) { m_Reader = new StringReader(input); m_Bldr = new StringBuilder(); SurveyorLexer lexer = new SurveyorLexer(m_Bldr, m_Reader); return(new SurveyorParser(m_Bldr, lexer)); }
/// ------------------------------------------------------------------------------------ /// <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)) { IDLImporter.Logger.Warning($"Parameter mentioned in @param doesn't exist: {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 }