Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
150
Problem with SyntaxEditor Lexical syntax for multi line comments for /* xxx */
posted

Hi,

Based on provided sample here on multi line string I've tried to adapt this code to use multi line commenting using /*   and ending with */ literal combination. My written code seems to work correct when string is pre-loaded. However, typing manually in the SyntaxEditor view first character '/' is accepted but a star '*' is failing with exception:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Text.StringBuilder.get_Chars(Int32 index)
   at Infragistics.Documents.Lexing.StringTable.GetHashCode(StringBuilder contentBuffer, Int32 startIndex, Int32 length)
   at Infragistics.Documents.Lexing.StringTable.GetString(StringBuilder contentBuffer, Int32 startIndex, Int32 length)
   at Infragistics.Documents.Lexing.LexingContext.AddMatchToNextLine(StringBuilder contentBufferResolved, LexingMatchComplete match, Int32 startIndex, Boolean shouldClearTouchedLineInformation)
   at Infragistics.Documents.Lexing.LexingContext.GetNextMatch(Int32& startPosition)
   at Infragistics.Documents.Lexing.LexingContext.Tokenize()
   at Infragistics.Documents.Parsing.TokenLineBufferInternal.ReplaceTextCore(Int32& offset, Int32& length, String& newText, Boolean shouldAutoCase)
   at Infragistics.Documents.Parsing.TokenLineBufferInternal.ReplaceText(Int32& offset, Int32& length, String& newText, Boolean shouldAutoCase)
   at Infragistics.Documents.TextDocument.ReplaceHelper(Int32 offset, Int32 length, String newText, TextChangeSource source)
   at Infragistics.Documents.TextDocument.Insert(Int32 offset, String text, TextChangeSource source, Boolean isAutoIndent)
   at Infragistics.Controls.Editors.SyntaxEditorUtilities.InsertTextHelper(EditorDocumentView documentView, TextDocument document, SnapshotPoint caretSnapshotPoint, String text, Int32 offset)
   at Infragistics.Controls.Editors.ViewKeyboardHandler.ProcessText(String text)
   at Infragistics.Controls.Editors.ViewKeyboardHandler.OnTextInput(String text)
   at Infragistics.Controls.Editors.ViewKeyboardHandler.OnTextInput(TextCompositionEventArgs& e)
   at Infragistics.Controls.Editors.Primitives.EditorDocumentViewPresenter.OnTextInput(TextCompositionEventArgs e)
   at System.Windows.UIElement.OnTextInputThunk(Object sender, TextCompositionEventArgs e)

The code handling this:

		private static void AddCommentMultiLine(LexerState state)
		{
			var lexerStates = state.Grammar.LexerStates;

			var comment = state.Symbols.Add("COMMENT_START", "/*");
			comment.LanguageElement = LanguageElement.Comment;
			var commentLexerState = lexerStates.Add("Comment");
			commentLexerState.Symbols.Add("COMMENT_TEXT", @"([^\/\*])+",
					TerminalSymbolComparison.RegularExpression).LanguageElement = LanguageElement.Comment;
			commentLexerState.Symbols.Add("COMMENT_END", "*/", TerminalSymbolComparison.Literal, true)
				.LanguageElement = LanguageElement.Comment;
			comment.LexerStateToEnter = commentLexerState;
			comment.LanguageElement = LanguageElement.Comment;
		}

Placing same characters in reverse order is working but this is not acceptable.