Implementing Custom Block Highlighting

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Cody Thompson - Space Systems Engineer, a.i. solutions
Version: 12.1.0302
Avatar

I know that the xml language definition files have some support for bracket highlighting, which is what I've been using up until now. I have encountered an issue just recently, however, where I find need to perform custom block highlighting on slightly ambiguous cases, and I'm not very knowledgeable on how I would go about approaching such a task. Here is an example of what I want to achieve:

If (X == 1) then;

    DoSomething();

    While (Y == 1)

        DoSomething();

    End;

End;

In the above case, the carat would be on the End corresponding to the While, and would be highlighting it. Note the ambiguous "End" syntax. That is a design parameter and cannot be changed. I need some method of implementing syntax highlighting that will highlight the correct starting block. I could achieve this programmatically, but so far I have only been using an XML language file for Actipro and am unsure if it is possible and, if so, where one would approach programming it in and how. Any guidance on the matter that could be provided would be most helpful.

Comments (4)

Posted 12 years ago by Cody Thompson - Space Systems Engineer, a.i. solutions
Avatar

I have been trying to implement this by using the EditorViewBracketHighlightingEventHandler event in order to manually change the bracket tokens to highlight. Additionally, I've read over the section on 'Advanced Highlighting' in the documentation, which has been helpful, but assumes a level of implementation knowledge that I currently do not have in working with Actipro in my project. Is there any way I could get a C# example of such a bracket highlighting implementation?

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Cody,

Are you trying to do syntax highlighting differently for that block, meaning that the coloring of While and End are different regardless of where the caret is, or do you mean you want bracket highlights that show only when the caret is by one of the two words?


Actipro Software Support

Posted 12 years ago by Cody Thompson - Space Systems Engineer, a.i. solutions
Avatar

Only when the caret is just before/on/just after one of those words. I just need to determine how to implement it such that it finds the correct "End" to go with the selected starting token (And vice versa, so that if you select the End token, it knows which starting token to highlight).

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Cody,

Yes to do bracket highlighting for that scenario, you'd want to do what you started on and follow the information in that "Advanced Bracket Highlighting" section.  The last paragraph in particular tells you what you should do in the implementation of a ViewBracketHighlightingUpdate event handler.  You just iterate tokens in the TextStream one way or the other based on which bracket token is at the caret offset, if any.  Then update the e.BracketToken and e.MatchingBracketToken properties, or leave them null to indicate no brackets.  Sorry but we don't have any prepared examples of this.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.