Bracket Highlighting when a token can be both Start and End

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Adam Dickinson
Version: 4.0.0236
Avatar
I've written my SyntaxLanguage and parsers in C#, including a custom Token class, all modelled after the SimpleScript example. Instead of curly braces, our language uses keywords to denote blocks, similar to VB.

One example is PROC and ENDPROC. These are easy because PROC is always a PairedStart and ENDPROC is always a PairedEnd and they always match each other. However, we also have IF/ELIF/ELSE/ENDIF and CASE/BREAK/DEFAULT/FALLTHRU (with implied fallthrus meaning you don't need the keyword FALLTHRU). For example:

IF ( TRUE )

    // block of code

ELIF ( FALSE )

    IF ( FALSE )
        // do something
    ELSE
        // do something else
    ENDIF

ENDIF
Is there a way, in the above example, to get IF and ELIF paired together, say, when the caret is anywhere on IF or on the first half of ELIF? Then get ELIF and the bottom ENDIF paired if the caret is on the second half of ELIF or anywhere on ENDIF? Similar goes for the IF-ELSE-ENDIF block inside the ELIF block.

I've tried using the SemanticParseData to determine each token's MatchingTokenID but because a token's MatchingTokenID is context-sensitive, there's no way (I know of) that I can return the right value at the right time.

Thank you.

Comments (7)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
This won't be possible with how bracket highlighting is currently designed. But I wonder if we could add an event that fires or a method on the SyntaxLanguage class where you could scan and tell us the bracket and matching bracket, thereby overriding the default behavior. Would that work for you? Then you could incorporate your more complicated logic.


Actipro Software Support

Posted 17 years ago by Adam Dickinson
Avatar
Yes, that kind of functionality would be excellent. That way I could base the bracket pairs off of my semantic parse, rather than the lexical parse.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Question about this... after looking at the code I think we can do it. Probably by letting you set the BracketToken and MatchingBracketToken properties on the BracketHighlighting class. However there is a certain point at which you need to set these. So for that we could raise an event and call a method on the SyntaxLanguage class.

Now for the event, we would pass you the EditorView that is requesting an update. But my question for you is, should we do our default behavior first and then fire the event, allowing you to override it? With this design, the BracketToken and MatchingBracketToken properties would be pre-populated by us if there is bracket highlighting data available. If not, they would be null. Or should we do something different?


Actipro Software Support

Posted 17 years ago by Adam Dickinson
Avatar
Pre-populating sounds fine, and makes it simple for me because 9 times of 10 I want the default functionality anyways. But then again, that's me. Don't want to forget about everyone else. ;)
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok, got it done and it works great. Basically we added a SyntaxEditor.ViewBracketHighlightingUpdate event and SyntaxLanguage.OnSyntaxEditorViewBracketHighlightingUpdate method. They pass an event args that is pre-populated with the Bracket and MatchingBracket tokens that would normally have been used. You can update those event args properties to specify your own instead.


Actipro Software Support

Posted 17 years ago by Adam Dickinson
Avatar
You guys rock! I look forward to the next maintenance release!
Posted 17 years ago by Adam Dickinson
Avatar
Just tried out this new bit of functionality in 4.0.238.0. Works like a charm!
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.