public static List<DocumentationComment> Read(string s) { XmlDocument doc = new XmlDocument(); doc.LoadXml(s); XmlNode n = doc.SelectSingleNode("/Documentation"); List<DocumentationComment> ret = new List<DocumentationComment>(); foreach (XmlNode n2 in n.ChildNodes) { DocumentationComment dc = new DocumentationComment(); dc.Ident = n2.Name; string s2 = n2.InnerText; string[] lines = s2.Split('\n'); foreach (string line in lines) dc.Lines.Add(line.Replace("\r", "").Replace("\n", "")); ret.Add(dc); } return ret; }
static string generate(DocumentationComment dc) { try { XmlDocument d = new XmlDocument(); d.LoadXml("<doc>" + dc.Text + "</doc>"); StringBuilder sb = new StringBuilder(); if (d.SelectNodes("/doc/param").Count > 0) { sb.Append(dc.Ident + "("); //foreach (XmlNode n in d.SelectNodes("/doc/param")) for (int i = 0; i < d.SelectNodes("/doc/param").Count; i++) { sb.Append(d.SelectNodes("/doc/param")[i].Attributes["name"].InnerText.Trim()); if (i != d.SelectNodes("/doc/param").Count - 1) sb.Append(", "); } sb.Append(")"); sb.AppendLine(); sb.AppendLine(); } sb.AppendLine(d.SelectSingleNode("/doc/summary").InnerText.Trim().Replace("<br />", "\r\n").Replace("<br>", "\r\n").Replace("<br/>", "\r\n")); foreach (XmlNode n in d.SelectNodes("/doc/param")) { sb.Append(n.Attributes["name"].InnerText.Trim()); sb.Append(": "); sb.AppendLine(n.InnerText.Trim()); } foreach (XmlNode n in d.SelectNodes("/doc/returns")) { sb.AppendLine("Returns: " + n.InnerText.Trim()); } if (sb.Length >= 2) sb.Remove(sb.Length - 2, 2); // remove last \n return sb.ToString(); } catch (Exception ex) { //MessageBox.Show(ex.ToString()); LoggingService.Error(dc.Text, ex); } return dc.Text; }
public static List <DocumentationComment> Read(string s) { XmlDocument doc = new XmlDocument(); doc.LoadXml(s); XmlNode n = doc.SelectSingleNode("/Documentation"); List <DocumentationComment> ret = new List <DocumentationComment>(); foreach (XmlNode n2 in n.ChildNodes) { DocumentationComment dc = new DocumentationComment(); dc.Ident = n2.Name; string s2 = n2.InnerText; string[] lines = s2.Split('\n'); foreach (string line in lines) { dc.Lines.Add(line.Replace("\r", "").Replace("\n", "")); } ret.Add(dc); } return(ret); }
public static List<DocumentationComment> Extract(Chunk c) { if (c.ScannedTokens != null && c.ScannedTokens.Count > 0) { List<DocumentationComment> cmnts = new List<DocumentationComment>(); for (int p = 0; p < c.ScannedTokens.Count; p++) { Token t_ = c.ScannedTokens[p]; Token t = t_.Leading.Count > 0 ? t_.Leading[0] : null; if (t != null) { int i = 0; DocumentationComment cmt = new DocumentationComment(); do { if (t_.Leading.Count <= i) break; t = t_.Leading[i++]; if (t.Type == TokenType.DocumentationComment) cmt.Lines.Add(t.Data); } while (t.Type == TokenType.WhitespaceN || t.Type == TokenType.WhitespaceR || t.Type == TokenType.WhitespaceSpace || t.Type == TokenType.WhitespaceTab || t.Type == TokenType.DocumentationComment); // find the ident it's for if (c.ScannedTokens.Count > p) { t = c.ScannedTokens[p]; if (t.Type == TokenType.Keyword && t.Data == "local") if (c.ScannedTokens[p + 1].Type == TokenType.Keyword && c.ScannedTokens[p + 1].Data == "function") { int i2 = 2; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) i2++; cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } else { int i2 = 2; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) i2++; cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } else if (t.Type == TokenType.Keyword && t.Data == "function") { int i2 = 1; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) i2++; cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } else if (t.Type == TokenType.Ident) { int i2 = 1; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) i2++; cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } } if (cmt.Ident != null && string.IsNullOrEmpty(cmt.Ident) == false && cmt.Lines.Count > 0) { //Console.WriteLine("YEP: " + cmt.Ident); cmnts.Add(cmt); } else { /* Console.Write("NOPE: (" + (cmt.Ident == null ? "" : cmt.Ident) + ")"); Console.WriteLine( cmt.Ident == null ? "Ident is null" : (string.IsNullOrEmpty(cmt.Ident) ? "Ident is empty" : (cmt.Lines.Count == 0 ? "No doc lines" : "wut?")) ); */ } } } return cmnts; } return new List<DocumentationComment>(); }
public static List <DocumentationComment> Extract(Chunk c) { if (c.ScannedTokens != null && c.ScannedTokens.Count > 0) { List <DocumentationComment> cmnts = new List <DocumentationComment>(); for (int p = 0; p < c.ScannedTokens.Count; p++) { Token t_ = c.ScannedTokens[p]; Token t = t_.Leading.Count > 0 ? t_.Leading[0] : null; if (t != null) { int i = 0; DocumentationComment cmt = new DocumentationComment(); do { if (t_.Leading.Count <= i) { break; } t = t_.Leading[i++]; if (t.Type == TokenType.DocumentationComment) { cmt.Lines.Add(t.Data); } } while (t.Type == TokenType.WhitespaceN || t.Type == TokenType.WhitespaceR || t.Type == TokenType.WhitespaceSpace || t.Type == TokenType.WhitespaceTab || t.Type == TokenType.DocumentationComment); // find the ident it's for if (c.ScannedTokens.Count > p) { t = c.ScannedTokens[p]; if (t.Type == TokenType.Keyword && t.Data == "local") { if (c.ScannedTokens[p + 1].Type == TokenType.Keyword && c.ScannedTokens[p + 1].Data == "function") { int i2 = 2; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) { i2++; } cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } else { int i2 = 2; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) { i2++; } cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } } else if (t.Type == TokenType.Keyword && t.Data == "function") { int i2 = 1; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) { i2++; } cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } else if (t.Type == TokenType.Ident) { int i2 = 1; while ( (c.ScannedTokens[p + i2].Type == TokenType.Symbol && c.ScannedTokens[p + i2].Data == ".") || (c.ScannedTokens[p + i2].Type == TokenType.Ident)) { i2++; } cmt.Ident = c.ScannedTokens[p + i2 - 1].Data; p += i2; } } if (cmt.Ident != null && string.IsNullOrEmpty(cmt.Ident) == false && cmt.Lines.Count > 0) { //Console.WriteLine("YEP: " + cmt.Ident); cmnts.Add(cmt); } else { /* * Console.Write("NOPE: (" + (cmt.Ident == null ? "" : cmt.Ident) + ")"); * Console.WriteLine( * cmt.Ident == null ? "Ident is null" * : (string.IsNullOrEmpty(cmt.Ident) * ? "Ident is empty" * : (cmt.Lines.Count == 0 * ? "No doc lines" * : "wut?")) * ); */ } } } return(cmnts); } return(new List <DocumentationComment>()); }