public static JSDocNode Parse(JSDocSplitSet set, bool includeComments) { var items = JSDocHelper.GetItems(set); var result = JSDocNode.GetSpecificType(items); if (includeComments) { result.Snippet = set.Text; } result.Parse(items); return(result); }
public void Parse(string text, bool includeComments) { var blocks = JSDocHelper.SpecialSplit(text, "/**", "*/"); foreach (var block in blocks) { var node = JSDocNode.Parse(block, includeComments); if (node is JSDocFunction && !string.IsNullOrWhiteSpace(node?.Name)) { Functions.Add(node as JSDocFunction); } if (node is JSDocFile) { File = node as JSDocFile; } } }
public static JSDocSplitSet[] SpecialSplit(string text, string left, string right) { var list = new List <JSDocSplitSet>(); var indexLeft = -1; indexLeft = text.IndexOf(left, indexLeft + 1); while (indexLeft > -1) { var indexRight = text.IndexOf(right, indexLeft + left.Length); if (indexRight > -1) { var result = new JSDocSplitSet(); if (indexLeft > 0) { var before = JSDocHelper.PreviousLine(text, indexLeft); if (before.ToLowerInvariant().Contains("function")) { result.PreviousLine = before; } } if (indexRight > -1) { var after = JSDocHelper.NextLine(text, indexRight); if (after.ToLowerInvariant().Contains("function")) { result.NextLine = after; } } result.Text = text.Substring(indexLeft + left.Length, indexRight - indexLeft - left.Length); list.Add(result); indexLeft = indexRight; } indexLeft = text.IndexOf(left, indexLeft + 1); } return(list.ToArray()); }
internal override void Parse(JSDocItems items) { base.Parse(items); foreach (var item in items.List) { switch (item.Key) { case "param": { this.Parameters.Add(JSDocParam.Parse(item.Value)); break; } case "function": case "method": { if (!string.IsNullOrWhiteSpace(item.Value)) { this.Method = item.Value; } break; } case "func": case "alias": { if (!string.IsNullOrWhiteSpace(item.Value)) { this.Name = item.Value; } break; } case "returns": case "return": { this.Returns = JSDocParam.Parse(item.Value); break; } } } if (string.IsNullOrWhiteSpace(this.Name)) { var fnLine = (items.PreviousLine != null && items.PreviousLine.Contains("function")) ? items.PreviousLine : (items.NextLine != null && items.NextLine.Contains("function")) ? items.NextLine : string.Empty; if (!string.IsNullOrWhiteSpace(fnLine)) { var index = fnLine.IndexOf("function"); if (index > 0) { var before = fnLine.Substring(0, index).Trim(); if (!string.IsNullOrWhiteSpace(before)) { var iEquals = before.IndexOf("="); var beforeEquals = before.Substring(0, iEquals).Trim(); var lastWord = beforeEquals.Split(new[] { ' ' }).LastOrDefault(); this.Name = lastWord; } } else { var words = fnLine.Substring(index + 8).Trim().Split(new[] { ' ', '(' }); if (words.Length > 0) { this.Name = words[0]; } } if (fnLine.Contains("(")) { var parmset = JSDocHelper.Split(fnLine, "(", ")"); if (parmset.Length > 0) { var parms = parmset[0].Split(new[] { ',' }); foreach (var parm in parms) { var segments = parm.Split(new[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (segments.Length > 1) { var subparm = this.Parameters.FirstOrDefault(p => p.Name.Equals(segments[0])); if (subparm != null) { subparm.Default = segments[1].Trim(); } } } } } } } }