bool IsInComment(SharpDevelopTextAreaControl editor) { ExpressionFinder ef = new ExpressionFinder(editor.FileName); int cursor = editor.ActiveTextAreaControl.Caret.Offset - 1; return(ef.SimplifyCode(editor.Document.GetText(0, cursor + 1), cursor) == null); }
bool IsInComment(ITextEditor editor) { ExpressionFinder ef = new ExpressionFinder(editor.FileName); int cursor = editor.Caret.Offset - 1; return(ef.SimplifyCode(editor.Document.GetText(0, cursor + 1), cursor) == null); }
void AddCommentsAndRegions(ICompilationUnit cu, string fileContent, string fileName) { ExpressionFinder ef = new ExpressionFinder(fileName); ef.ResetStateMachine(); int state = 0; StringBuilder commentBuilder = null; char commentStartChar = '\0'; int commentStartColumn = 0; Stack <string> regionTitleStack = new Stack <string>(); Stack <int> regionLineStack = new Stack <int>(); Stack <int> regionColumnStack = new Stack <int>(); int line = 1; int column = 0; for (int i = 0; i < fileContent.Length; i++) { column += 1; char c = fileContent[i]; if (c == '\n') { column = 0; line += 1; } state = ef.FeedStateMachine(state, c); if (state == ExpressionFinder.PossibleRegexStart) { // after / could be a regular expression, do a special check for that int regexEnd = ef.SkipRegularExpression(fileContent, i, fileContent.Length - 1); if (regexEnd > 0) { i = regexEnd; } else if (regexEnd == -1) { // end of file is in regex return; } // else: regexEnd is 0 if its not a regex } if (state == ExpressionFinder.LineCommentState) { if (commentBuilder == null) { commentStartChar = c; commentStartColumn = column; commentBuilder = new StringBuilder(); } else { if (commentBuilder.Length > 0) { commentBuilder.Append(c); } else if (!char.IsWhiteSpace(c)) { commentStartColumn = column; commentBuilder.Append(c); } } } else if (commentBuilder != null) { string text = commentBuilder.ToString(); commentBuilder = null; if (commentStartChar == '#' && text.StartsWith("region ")) { regionTitleStack.Push(text.Substring(7)); regionLineStack.Push(line); regionColumnStack.Push(commentStartColumn - 1); } else if (commentStartChar == '#' && text.StartsWith("endregion") && regionTitleStack.Count > 0) { // Add folding region cu.FoldingRegions.Add(new FoldingRegion(regionTitleStack.Pop(), new DomRegion(regionLineStack.Pop(), regionColumnStack.Pop(), line, column))); } else { foreach (string tag in lexerTags) { if (text.StartsWith(tag)) { string commentString = text.Substring(tag.Length); cu.TagComments.Add(new TagComment(tag, new DomRegion(line, commentStartColumn), commentString)); break; } } } } } }
void AddCommentsAndRegions(ICompilationUnit cu, string fileContent, string fileName) { ExpressionFinder ef = new ExpressionFinder(fileName); ef.ResetStateMachine(); int state = 0; StringBuilder commentBuilder = null; char commentStartChar = '\0'; int commentStartColumn = 0; Stack<string> regionTitleStack = new Stack<string>(); Stack<int> regionLineStack = new Stack<int>(); Stack<int> regionColumnStack = new Stack<int>(); int line = 1; int column = 0; for (int i = 0; i < fileContent.Length; i++) { column += 1; char c = fileContent[i]; if (c == '\n') { column = 0; line += 1; } state = ef.FeedStateMachine(state, c); if (state == ExpressionFinder.PossibleRegexStart) { // after / could be a regular expression, do a special check for that int regexEnd = ef.SkipRegularExpression(fileContent, i, fileContent.Length - 1); if (regexEnd > 0) { i = regexEnd; } else if (regexEnd == -1) { // end of file is in regex return; } // else: regexEnd is 0 if its not a regex } if (state == ExpressionFinder.LineCommentState) { if (commentBuilder == null) { commentStartChar = c; commentStartColumn = column; commentBuilder = new StringBuilder(); } else { if (commentBuilder.Length > 0) { commentBuilder.Append(c); } else if (!char.IsWhiteSpace(c)) { commentStartColumn = column; commentBuilder.Append(c); } } } else if (commentBuilder != null) { string text = commentBuilder.ToString(); commentBuilder = null; if (commentStartChar == '#' && text.StartsWith("region ")) { regionTitleStack.Push(text.Substring(7)); regionLineStack.Push(line); regionColumnStack.Push(commentStartColumn - 1); } else if (commentStartChar == '#' && text.StartsWith("endregion") && regionTitleStack.Count > 0) { // Add folding region cu.FoldingRegions.Add(new FoldingRegion(regionTitleStack.Pop(), new DomRegion(regionLineStack.Pop(), regionColumnStack.Pop(), line, column))); } else { foreach (string tag in lexerTags) { if (text.StartsWith(tag)) { string commentString = text.Substring(tag.Length); cu.TagComments.Add(new TagComment(tag, new DomRegion(line, commentStartColumn), commentString)); break; } } } } } }
bool IsInComment(SharpDevelopTextAreaControl editor) { ExpressionFinder ef = new ExpressionFinder(editor.FileName); int cursor = editor.ActiveTextAreaControl.Caret.Offset - 1; return ef.SimplifyCode(editor.Document.GetText(0, cursor + 1), cursor) == null; }