private IEnumerable <CommentNode> ParseComments(QualifiedModuleName qualifiedName) { var code = qualifiedName.Component.CodeModule.Code(); var commentBuilder = new StringBuilder(); var continuing = false; var startLine = 0; var startColumn = 0; for (var i = 0; i < code.Length; i++) { var line = code[i]; var index = 0; if (continuing || line.HasComment(out index)) { startLine = continuing ? startLine : i; startColumn = continuing ? startColumn : index; var commentLength = line.Length - index; continuing = line.EndsWith("_"); if (!continuing) { commentBuilder.Append(line.Substring(index, commentLength).TrimStart()); var selection = new Selection(startLine + 1, startColumn + 1, i + 1, line.Length); var result = new CommentNode(commentBuilder.ToString(), new QualifiedSelection(qualifiedName, selection)); commentBuilder.Clear(); yield return(result); } else { // ignore line continuations in comment text: commentBuilder.Append(line.Substring(index, commentLength).TrimStart()); } } } }
/// <summary> /// Convenience method for validating that a selection is inside a specified parser rule context. /// </summary> /// <param name="selection">The selection that should be contained within the ParserRuleContext</param> /// <param name="context">The containing ParserRuleContext</param> /// <returns>Boolean with true indicating that the selection is inside the given context</returns> public static bool IsContainedIn(this Selection selection, ParserRuleContext context) { return context.GetSelection().Contains(selection); }